Commit 43917432 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

imported A/AAAA/NS implementations and added some simple test cases.


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/f2f200910@127 e5f2f494-b856-4b98-b285-d166d9295462
parent b056392c
......@@ -28,6 +28,9 @@
using ISC::DNS::RRClass;
using ISC::DNS::RRType;
using ISC::DNS::TTL;
using ISC::DNS::Rdata::IN::A;
using ISC::DNS::Rdata::IN::AAAA;
using ISC::DNS::Rdata::Generic::NS;
RRClass::RRClass(const std::string& classstr)
{
......@@ -104,88 +107,88 @@ TTL::to_wire(Buffer& buffer) const
buffer.write_uint32(ttlval_);
}
#ifdef notyet
ARdata::ARdata(const std::string& addrstr)
A::A(const std::string& addrstr)
{
if (inet_pton(AF_INET, addrstr.c_str(), &_addr) != 1)
if (inet_pton(AF_INET, addrstr.c_str(), &addr_) != 1)
throw ISCInvalidAddressString();
}
void
ARdata::from_wire(IOBuffer& buffer, NameDecompressor& decompressor)
A::from_wire(Buffer& buffer, NameDecompressor& decompressor)
{
//TBD
}
void
ARdata::to_wire(IOBuffer& buffer, NameCompressor& compressor) const
A::to_wire(Buffer& buffer, NameCompressor& compressor) const
{
buffer.write_uint16(sizeof(_addr));
buffer.write_data(&_addr, sizeof(_addr));
buffer.write_uint16(sizeof(addr_));
buffer.write_data(&addr_, sizeof(addr_));
}
std::string
ARdata::to_text() const
A::to_text() const
{
char addrbuf[sizeof("255.255.255.255")];
if (inet_ntop(AF_INET, &_addr, addrbuf, sizeof(addrbuf)) == NULL)
throw runtime_error("unexpected inet_ntop() failure");
if (inet_ntop(AF_INET, &addr_, addrbuf, sizeof(addrbuf)) == NULL)
throw std::runtime_error("unexpected inet_ntop() failure");
return (std::string(addrbuf));
}
AAAARdata::AAAARdata(const std::string& addrstr)
AAAA::AAAA(const std::string& addrstr)
{
if (inet_pton(AF_INET6, addrstr.c_str(), &_addr) != 1)
if (inet_pton(AF_INET6, addrstr.c_str(), &addr_) != 1)
throw ISCInvalidAddressString();
}
void
AAAARdata::from_wire(IOBuffer& buffer, NameDecompressor& decompressor)
AAAA::from_wire(Buffer& buffer, NameDecompressor& decompressor)
{
//TBD
}
void
AAAARdata::to_wire(IOBuffer& buffer, NameCompressor& compressor) const
AAAA::to_wire(Buffer& buffer, NameCompressor& compressor) const
{
buffer.write_uint16(sizeof(_addr));
buffer.write_data(&_addr, sizeof(_addr));
buffer.write_uint16(sizeof(addr_));
buffer.write_data(&addr_, sizeof(addr_));
}
std::string
AAAARdata::to_text() const
AAAA::to_text() const
{
char addrbuf[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
if (inet_ntop(AF_INET6, &_addr, addrbuf, sizeof(addrbuf)) == NULL)
throw runtime_error("unexpected inet_ntop() failure");
if (inet_ntop(AF_INET6, &addr_, addrbuf, sizeof(addrbuf)) == NULL)
throw std::runtime_error("unexpected inet_ntop() failure");
return (std::string(addrbuf));
}
void
NSRdata::from_wire(IOBuffer& buffer, NameDecompressor& decompressor)
NS::from_wire(Buffer& buffer, NameDecompressor& decompressor)
{
//TBD
}
void
NSRdata::to_wire(IOBuffer& buffer, NameCompressor& compressor) const
NS::to_wire(Buffer& buffer, NameCompressor& compressor) const
{
// XXX: note that a complete implementation cannot be that simple
// XXX: note that a complete implementation cannot be this simple
// because we need to disable compression for the NS name.
buffer.write_uint16(_nsname.get_length());
_nsname.to_wire(buffer, compressor);
buffer.write_uint16(nsname_.get_length());
nsname_.to_wire(buffer, compressor);
}
std::string
NSRdata::to_text() const
NS::to_text() const
{
return (_nsname.to_text());
return (nsname_.to_text());
}
#ifdef notyet
void
RdataSet::add_rdata(rdataptr_t rdata)
{
......@@ -247,7 +250,7 @@ RRSet::to_wire(Message& message, section_t section)
// sort Rdata list based on rrset-order and sortlist, and possible
// other options. Details to be considered.
IOBuffer& b = message.get_iobuffer();
Buffer& b = message.get_iobuffer();
NameCompressor& c = message.get_compressor();
for (vector<rdataptr_t>::iterator it = _rdatalist.begin();
it != _rdatalist.end();
......@@ -277,7 +280,7 @@ Question::to_text() const
int
Question::to_wire(Message& message, section_t section)
{
IOBuffer& b = message.get_iobuffer();
Buffer& b = message.get_iobuffer();
NameCompressor& c = message.get_compressor();
_name.to_wire(b, c);
......
// Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
#include <dns/buffer.h>
#include <dns/rrset.h>
#include <gtest/gtest.h>
namespace {
using ISC::DNS::RRClass;
using ISC::DNS::RRType;
using ISC::DNS::TTL;
using ISC::DNS::Rdata::IN::A;
using ISC::DNS::Rdata::IN::AAAA;
using ISC::DNS::Rdata::Generic::NS;
// The fixture for testing class RRClass.
class RRClassTest : public ::testing::Test {
protected:
RRClassTest() : rrclass_in("IN"), rrclass_ch("CH") {}
RRClass rrclass_in;
RRClass rrclass_ch;
};
TEST_F(RRClassTest, from_to_text)
{
EXPECT_EQ("IN", rrclass_in.to_text());
EXPECT_EQ("CH", rrclass_ch.to_text());
}
// The fixture for testing class RRType.
class RRTypeTest : public ::testing::Test {
protected:
RRTypeTest() :
rrtype_a("A"), rrtype_aaaa("AAAA"), rrtype_ns("NS") {}
RRType rrtype_a;
RRType rrtype_aaaa;
RRType rrtype_ns;
};
TEST_F(RRTypeTest, from_to_text)
{
EXPECT_EQ("A", rrtype_a.to_text());
EXPECT_EQ("AAAA", rrtype_aaaa.to_text());
EXPECT_EQ("NS", rrtype_ns.to_text());
}
// The fixture for testing class TTL.
class TTLTest : public ::testing::Test {
protected:
TTLTest() : ttl3600(3600), ttl0(0) {}
TTL ttl3600;
TTL ttl0;
};
TEST_F(TTLTest, to_text)
{
EXPECT_EQ("3600", ttl3600.to_text());
EXPECT_EQ("0", ttl0.to_text());
}
TEST_F(TTLTest, get_value)
{
EXPECT_EQ(3600, ttl3600.get_value());
EXPECT_EQ(0, ttl0.get_value());
}
// The fixture for testing class IN/A Rdata
class Rdata_IN_A_Test : public ::testing::Test {
protected:
Rdata_IN_A_Test() : rdata("192.0.2.1") {}
A rdata;
};
TEST_F(Rdata_IN_A_Test, from_to_text)
{
EXPECT_EQ("192.0.2.1", rdata.to_text());
EXPECT_THROW(A("2001:db8::1234"), ISC::ISCInvalidAddressString);
}
// The fixture for testing class IN/AAAA Rdata
class Rdata_IN_AAAA_Test : public ::testing::Test {
protected:
Rdata_IN_AAAA_Test() : rdata("2001:db8::abcd") {}
AAAA rdata;
};
TEST_F(Rdata_IN_AAAA_Test, from_to_text)
{
EXPECT_EQ("2001:db8::abcd", rdata.to_text());
EXPECT_THROW(AAAA("192.0.2.255"), ISC::ISCInvalidAddressString);
}
// The fixture for testing class Generic/NS Rdata
class Rdata_Generic_NS_Test : public ::testing::Test {
protected:
Rdata_Generic_NS_Test() : rdata("ns.example.com") {}
NS rdata;
};
TEST_F(Rdata_Generic_NS_Test, from_to_text)
{
EXPECT_EQ("ns.example.com.", rdata.to_text());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment