// BEGIN_RDATA_NAMESPACE
PTR::PTR(const std::string& type_str) :
- ptr_name_(type_str)
-{}
+ // Fill in dummy name and replace them soon below.
+ ptr_name_(Name::ROOT_NAME())
+{
+ try {
+ std::istringstream ss(type_str);
+ MasterLexer lexer;
+ lexer.pushSource(ss);
+
+ ptr_name_ = createNameFromLexer(lexer, NULL);
+
+ if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) {
+ isc_throw(InvalidRdataText, "extra input text for PTR: "
+ << type_str);
+ }
+ } catch (const MasterLexer::LexerError& ex) {
+ isc_throw(InvalidRdataText, "Failed to construct PTR from '" <<
+ type_str << "': " << ex.what());
+ }
+}
PTR::PTR(InputBuffer& buffer, size_t) :
ptr_name_(buffer)
// there's nothing to specialize
};
-const generic::PTR rdata_ptr("ns.example.com");
-const generic::PTR rdata_ptr2("ns2.example.com");
+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 };
0x03, 0x6e, 0x73, 0x32, 0xc0, 0x03 };
TEST_F(Rdata_PTR_Test, createFromText) {
- EXPECT_EQ(0, rdata_ptr.compare(generic::PTR("ns.example.com")));
+ 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")));
+ 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")));
+ "ns.example.com.")));
}
TEST_F(Rdata_PTR_Test, createFromWire) {
"rdata_ns_fromWire", 71),
DNSMessageFORMERR);
- EXPECT_EQ(0, generic::PTR("ns2.example.com").compare(
+ EXPECT_EQ(0, generic::PTR("ns2.example.com.").compare(
*rdataFactoryFromFile(RRType("PTR"), RRClass("IN"),
"rdata_ns_fromWire", 55)));
EXPECT_THROW(*rdataFactoryFromFile(RRType("PTR"), RRClass("IN"),
}
TEST_F(Rdata_PTR_Test, compare) {
- generic::PTR small("a.example");
- generic::PTR large("example");
+ generic::PTR small("a.example.");
+ generic::PTR large("example.");
EXPECT_TRUE(Name("a.example") > Name("example"));
EXPECT_GT(0, small.compare(large));
}