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

added support for PTR RR


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1206 e5f2f494-b856-4b98-b285-d166d9295462
parent 06da514e
// Copyright (C) 2010 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 <string>
#include "buffer.h"
#include "name.h"
#include "messagerenderer.h"
#include "rdata.h"
#include "rdataclass.h"
using namespace std;
// BEGIN_ISC_NAMESPACE
// BEGIN_RDATA_NAMESPACE
PTR::PTR(const string& type_str) :
ptr_name_(type_str)
{}
PTR::PTR(InputBuffer& buffer, size_t rdata_len) :
ptr_name_(buffer)
{
// we don't need rdata_len for parsing. if necessary, the caller will
// check consistency.
}
PTR::PTR(const PTR& source) :
ptr_name_(source.ptr_name_)
{}
std::string
PTR::toText() const
{
return (ptr_name_.toText());
}
void
PTR::toWire(OutputBuffer& buffer) const
{
ptr_name_.toWire(buffer);
}
void
PTR::toWire(MessageRenderer& renderer) const
{
renderer.writeName(ptr_name_);
}
int
PTR::compare(const Rdata& other) const
{
// The compare method normally begins with this dynamic cast.
const PTR& other_ptr = dynamic_cast<const PTR&>(other);
return (compareNames(ptr_name_, other_ptr.ptr_name_));
}
const Name&
PTR::getPTRName() const
{
return (ptr_name_);
}
// END_RDATA_NAMESPACE
// END_ISC_NAMESPACE
// Copyright (C) 2010 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$
// BEGIN_HEADER_GUARD
#include <string>
#include "name.h"
#include "rdata.h"
// BEGIN_ISC_NAMESPACE
// BEGIN_COMMON_DECLARATIONS
// END_COMMON_DECLARATIONS
// BEGIN_RDATA_NAMESPACE
class PTR : public Rdata {
public:
// BEGIN_COMMON_MEMBERS
// END_COMMON_MEMBERS
private:
// RR-type specific members are here.
///
/// Specialized constructor
///
explicit PTR(const Name& ptr_name) : ptr_name_(ptr_name) {}
///
/// Specialized methods
///
const Name& getPTRName() const;
private:
Name ptr_name_;
};
// END_RDATA_NAMESPACE
// END_ISC_NAMESPACE
// END_HEADER_GUARD
// Local Variables:
// mode: c++
// End:
......@@ -15,7 +15,7 @@ run_unittests_SOURCES += rdata_unittest.h rdata_unittest.cc
run_unittests_SOURCES += rdata_in_a_unittest.cc rdata_in_aaaa_unittest.cc
run_unittests_SOURCES += rdata_ns_unittest.cc rdata_soa_unittest.cc
run_unittests_SOURCES += rdata_txt_unittest.cc rdata_mx_unittest.cc
run_unittests_SOURCES += rdata_cname_unittest.cc
run_unittests_SOURCES += rdata_ptr_unittest.cc rdata_cname_unittest.cc
run_unittests_SOURCES += rdata_dname_unittest.cc
run_unittests_SOURCES += rdata_opt_unittest.cc
run_unittests_SOURCES += rdata_dnskey_unittest.cc
......
// Copyright (C) 2010 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/messagerenderer.h>
#include <dns/rdata.h>
#include <dns/rdataclass.h>
#include <dns/rrclass.h>
#include <dns/rrtype.h>
#include <gtest/gtest.h>
#include "unittest_util.h"
#include "rdata_unittest.h"
using isc::UnitTestUtil;
using namespace std;
using namespace isc::dns;
using namespace isc::dns::rdata;
//
// This test currently simply copies the NS RDATA tests.
//
namespace {
class Rdata_PTR_Test : public RdataTest {
// there's nothing to specialize
};
const generic::PTR rdata_ptr("ns.example.com");
const generic::PTR rdata_ptr2("ns2.example.com");
const uint8_t wiredata_ptr[] = {
0x02, 0x6e, 0x73, 0x07, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x03,
0x63, 0x6f, 0x6d, 0x00 };
const uint8_t wiredata_ptr2[] = {
// first name: ns.example.com.
0x02, 0x6e, 0x73, 0x07, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x03,
0x63, 0x6f, 0x6d, 0x00,
// second name: ns2.example.com. all labels except the first should be
// compressed.
0x03, 0x6e, 0x73, 0x32, 0xc0, 0x03 };
TEST_F(Rdata_PTR_Test, createFromText)
{
EXPECT_EQ(0, rdata_ptr.compare(generic::PTR("ns.example.com")));
// explicitly add a trailing dot. should be the same RDATA.
EXPECT_EQ(0, rdata_ptr.compare(generic::PTR("ns.example.com.")));
// should be case sensitive.
EXPECT_EQ(0, rdata_ptr.compare(generic::PTR("NS.EXAMPLE.COM")));
// RDATA of a class-independent type should be recognized for any
// "unknown" class.
EXPECT_EQ(0, rdata_ptr.compare(*createRdata(RRType("PTR"), RRClass(65000),
"ns.example.com")));
}
TEST_F(Rdata_PTR_Test, createFromWire)
{
EXPECT_EQ(0, rdata_ptr.compare(
*rdataFactoryFromFile(RRType("PTR"), RRClass("IN"),
"testdata/rdata_ns_fromWire")));
// RDLENGTH is too short
EXPECT_THROW(rdataFactoryFromFile(RRType("PTR"), RRClass("IN"),
"testdata/rdata_ns_fromWire", 18),
InvalidRdataLength);
// RDLENGTH is too long
EXPECT_THROW(rdataFactoryFromFile(RRType("PTR"), RRClass("IN"),
"testdata/rdata_ns_fromWire", 36),
InvalidRdataLength);
// incomplete name. the error should be detected in the name constructor
EXPECT_THROW(rdataFactoryFromFile(RRType("PTR"), RRClass("IN"),
"testdata/rdata_ns_fromWire", 71),
IncompleteName);
EXPECT_EQ(0, generic::PTR("ns2.example.com").compare(
*rdataFactoryFromFile(RRType("PTR"), RRClass("IN"),
"testdata/rdata_ns_fromWire", 55)));
EXPECT_THROW(*rdataFactoryFromFile(RRType("PTR"), RRClass("IN"),
"testdata/rdata_ns_fromWire", 63),
InvalidRdataLength);
}
TEST_F(Rdata_PTR_Test, toWireBuffer)
{
rdata_ptr.toWire(obuffer);
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
obuffer.getData(), obuffer.getLength(),
wiredata_ptr, sizeof(wiredata_ptr));
}
TEST_F(Rdata_PTR_Test, toWireRenderer)
{
rdata_ptr.toWire(renderer);
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
obuffer.getData(), obuffer.getLength(),
wiredata_ptr, sizeof(wiredata_ptr));
rdata_ptr2.toWire(renderer);
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
obuffer.getData(), obuffer.getLength(),
wiredata_ptr2, sizeof(wiredata_ptr2));
}
TEST_F(Rdata_PTR_Test, toText)
{
EXPECT_EQ("ns.example.com.", rdata_ptr.toText());
}
TEST_F(Rdata_PTR_Test, compare)
{
generic::PTR small("a.example");
generic::PTR large("example");
EXPECT_EQ(true, Name("a.example") > Name("example"));
EXPECT_GT(0, small.compare(large));
}
TEST_F(Rdata_PTR_Test, getPTRName)
{
EXPECT_EQ(Name("ns.example.com"), rdata_ptr.getPTRName());
}
}
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