|
@@ -22,11 +22,14 @@
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
#include <dns/rrclass.h>
|
|
|
+#include <dns/rdata.h>
|
|
|
+#include <dns/rdataclass.h>
|
|
|
#include <dns/rrparamregistry.h>
|
|
|
#include <dns/rrtype.h>
|
|
|
|
|
|
using namespace std;
|
|
|
using namespace isc::dns;
|
|
|
+using namespace isc::dns::rdata;
|
|
|
|
|
|
namespace {
|
|
|
class RRParamRegistryTest : public ::testing::Test {
|
|
@@ -41,6 +44,17 @@ protected:
|
|
|
oss2 << test_type_code;
|
|
|
test_type_unknown_str = "TYPE" + oss2.str();
|
|
|
}
|
|
|
+ ~RRParamRegistryTest()
|
|
|
+ {
|
|
|
+ // cleanup any non well-known parameters that possibly remain
|
|
|
+ // as a side effect.
|
|
|
+ RRParamRegistry::getRegistry().removeType(test_type_code);
|
|
|
+ RRParamRegistry::getRegistry().removeClass(test_class_code);
|
|
|
+ RRParamRegistry::getRegistry().removeRdataFactory(
|
|
|
+ RRType(test_type_code), RRClass(test_class_code));
|
|
|
+ RRParamRegistry::getRegistry().removeRdataFactory(
|
|
|
+ RRType(test_type_code));
|
|
|
+ }
|
|
|
|
|
|
string test_class_unknown_str;
|
|
|
string test_type_unknown_str;
|
|
@@ -64,16 +78,16 @@ TEST_F(RRParamRegistryTest, addRemove)
|
|
|
EXPECT_EQ(65534, RRType("TESTTYPE").getCode());
|
|
|
|
|
|
// the first removal attempt should succeed
|
|
|
- EXPECT_TRUE(RRParamRegistry::getRegistry().removeType(65534));
|
|
|
+ EXPECT_TRUE(RRParamRegistry::getRegistry().removeType(test_type_code));
|
|
|
// then toText() should treat it as an "unknown"
|
|
|
EXPECT_EQ(test_type_unknown_str, RRType(test_type_code).toText());
|
|
|
// attempt of removing non-existent mapping should result in 'false'
|
|
|
- EXPECT_FALSE(RRParamRegistry::getRegistry().removeType(65534));
|
|
|
+ EXPECT_FALSE(RRParamRegistry::getRegistry().removeType(test_type_code));
|
|
|
|
|
|
// same set of tests for RR class.
|
|
|
- EXPECT_TRUE(RRParamRegistry::getRegistry().removeClass(65533));
|
|
|
+ EXPECT_TRUE(RRParamRegistry::getRegistry().removeClass(test_class_code));
|
|
|
EXPECT_EQ(test_class_unknown_str, RRClass(test_class_code).toText());
|
|
|
- EXPECT_FALSE(RRParamRegistry::getRegistry().removeClass(65533));
|
|
|
+ EXPECT_FALSE(RRParamRegistry::getRegistry().removeClass(test_class_code));
|
|
|
}
|
|
|
|
|
|
TEST_F(RRParamRegistryTest, addError)
|
|
@@ -89,4 +103,56 @@ TEST_F(RRParamRegistryTest, addError)
|
|
|
RRTypeExists);
|
|
|
EXPECT_EQ("A", RRType(1).toText());
|
|
|
}
|
|
|
+
|
|
|
+class TestRdataFactory : public AbstractRdataFactory {
|
|
|
+public:
|
|
|
+ virtual RdataPtr create(const string& rdata_str) const
|
|
|
+ { return RdataPtr(new in::A(rdata_str)); }
|
|
|
+ virtual RdataPtr create(InputBuffer& buffer, size_t rdata_len) const
|
|
|
+ { return RdataPtr(new in::A(buffer, rdata_len)); }
|
|
|
+ virtual RdataPtr create(const Rdata& source) const
|
|
|
+ { return RdataPtr(new in::A(dynamic_cast<const in::A&>(source))); }
|
|
|
+};
|
|
|
+
|
|
|
+TEST_F(RRParamRegistryTest, addRemoveFactory)
|
|
|
+{
|
|
|
+ // By default, the test type/code pair should be considered "unknown",
|
|
|
+ // so the following should trigger an exception.
|
|
|
+ EXPECT_THROW(createRdata(RRType(test_type_code), RRClass(test_class_code),
|
|
|
+ "192.0.2.1"),
|
|
|
+ InvalidRdataText);
|
|
|
+ // Add factories so that we can treat this pair just like in::A.
|
|
|
+ RRParamRegistry::getRegistry().add(test_type_str, test_type_code,
|
|
|
+ test_class_str, test_class_code,
|
|
|
+ RdataFactoryPtr(new TestRdataFactory));
|
|
|
+ // Now it should be accepted, and should be identical to the same data of
|
|
|
+ // in::A.
|
|
|
+ EXPECT_EQ(0, in::A("192.0.2.1").compare(
|
|
|
+ *createRdata(RRType(test_type_code), RRClass(test_class_code),
|
|
|
+ "192.0.2.1")));
|
|
|
+ // It should still fail with other classes as we specified the factories
|
|
|
+ // as class-specific.
|
|
|
+ EXPECT_THROW(createRdata(RRType(test_type_code), RRClass("IN"),
|
|
|
+ "192.0.2.1"),
|
|
|
+ InvalidRdataText);
|
|
|
+ // Add the factories also as a class independent RRtype
|
|
|
+ RRParamRegistry::getRegistry().add(test_type_str, test_type_code,
|
|
|
+ RdataFactoryPtr(new TestRdataFactory));
|
|
|
+ // Now it should be okay for other classes than the test class.
|
|
|
+ EXPECT_EQ(0, in::A("192.0.2.1").compare(
|
|
|
+ *createRdata(RRType(test_type_code), RRClass("IN"),
|
|
|
+ "192.0.2.1")));
|
|
|
+
|
|
|
+ // Remove the added factories: first attempt should succeed; the second
|
|
|
+ // should return false as there's no match
|
|
|
+ EXPECT_TRUE(RRParamRegistry::getRegistry().removeRdataFactory(
|
|
|
+ RRType(test_type_code), RRClass(test_class_code)));
|
|
|
+ EXPECT_FALSE(RRParamRegistry::getRegistry().removeRdataFactory(
|
|
|
+ RRType(test_type_code), RRClass(test_class_code)));
|
|
|
+ EXPECT_TRUE(RRParamRegistry::getRegistry().removeRdataFactory(
|
|
|
+ RRType(test_type_code)));
|
|
|
+ EXPECT_FALSE(RRParamRegistry::getRegistry().removeRdataFactory(
|
|
|
+ RRType(test_type_code)));
|
|
|
+}
|
|
|
+
|
|
|
}
|