#include <util/buffer.h>
#include <dns/messagerenderer.h>
#include <dns/rrclass.h>
+#include <dns/rrparamregistry.h>
#include <dns/tests/unittest_util.h>
#include <util/unittests/wiredata.h>
// are defined and have the correct parameter values. Test data are generated
// from the list available at:
// http://www.iana.org/assignments/dns-parameters/dns-parameters.xml
-struct ClassParam {
+struct WellKnownClassParam {
const char* const txt; // "IN", "CH", etc
const uint16_t code; // 1, 3, etc
const RRClass& (*obj)(); // RRClass::IN(), RRClass::CH(), etc
-} known_classes[] = {
+} well_known_classes[] = {
{"IN", 1, RRClass::IN},
{"CH", 3, RRClass::CH},
{"NONE", 254, RRClass::NONE},
};
TEST(RRClassConstTest, wellKnowns) {
- for (int i = 0; known_classes[i].txt; ++i) {
+ for (size_t i = 0; well_known_classes[i].txt; ++i) {
SCOPED_TRACE("Checking well known RRClass: " +
- string(known_classes[i].txt));
- EXPECT_EQ(known_classes[i].code,
- RRClass(known_classes[i].txt).getCode());
- EXPECT_EQ(known_classes[i].code,
- (*known_classes[i].obj)().getCode());
+ string(well_known_classes[i].txt));
+ EXPECT_EQ(well_known_classes[i].code,
+ RRClass(well_known_classes[i].txt).getCode());
+ EXPECT_EQ(well_known_classes[i].code,
+ (*well_known_classes[i].obj)().getCode());
}
}
+
+// Below, we'll check definitions for all registered RR classes.
+struct RegisteredClassParam {
+ const char* const txt; // "IN", "CH", etc
+ const uint16_t code; // 1, 3, etc
+} registered_classes[] = {
+ {"IN", 1},
+ {"CH", 3},
+ {"HS", 4},
+ {"NONE", 254},
+ {"ANY", 255},
+ {0, 0}
+};
+
+TEST(RRClassConstTest, registered) {
+ for (size_t i = 0; registered_classes[i].txt; ++i) {
+ SCOPED_TRACE("Checking registered RRClass: " +
+ string(registered_classes[i].txt));
+ uint16_t code = 0;
+ EXPECT_NO_THROW(RRParamRegistry::getRegistry().textToClassCode(registered_classes[i].txt, code));
+ EXPECT_EQ(code, registered_classes[i].code);
+ string txt;
+ EXPECT_NO_THROW(txt = RRParamRegistry::getRegistry().codeToClassText(registered_classes[i].code));
+ EXPECT_EQ(txt, registered_classes[i].txt);
+ }
+}
+
}
#include <util/buffer.h>
#include <dns/messagerenderer.h>
+#include <dns/rrparamregistry.h>
#include <dns/rrtype.h>
#include <dns/tests/unittest_util.h>
// are defined and have the correct parameter values. Test data are generated
// from the list available at:
// http://www.iana.org/assignments/dns-parameters/dns-parameters.xml
-struct TypeParam {
+struct WellKnownTypeParam {
const char* const txt; // "A", "AAAA", "NS", etc
const uint16_t code; // 1, 28, 2, etc
const RRType& (*obj)(); // RRType::A(), etc
-} known_types[] = {
+} well_known_types[] = {
{"A", 1, RRType::A},
{"NS", 2, RRType::NS},
{"SOA", 6, RRType::SOA},
{"TKEY", 249, RRType::TKEY},
{"TSIG", 250, RRType::TSIG},
{"ANY", 255, RRType::ANY},
- {"MD", 3, []() -> const RRType& {static const RRType r("MD"); return (r);}},
- {"MF", 4, []() -> const RRType& {static const RRType r("MF"); return (r);}},
- {"CNAME", 5, []() -> const RRType& {static const RRType r("CNAME"); return (r);}},
- {"MB", 7, []() -> const RRType& {static const RRType r("MB"); return (r);}},
- {"MG", 8, []() -> const RRType& {static const RRType r("MG"); return (r);}},
- {"MR", 9, []() -> const RRType& {static const RRType r("MR"); return (r);}},
- {"NULL", 10, []() -> const RRType& {static const RRType r("NULL"); return (r);}},
- {"WKS", 11, []() -> const RRType& {static const RRType r("WKS"); return (r);}},
- {"HINFO", 13, []() -> const RRType& {static const RRType r("HINFO"); return (r);}},
- {"MINFO", 14, []() -> const RRType& {static const RRType r("MINFO"); return (r);}},
- {"MX", 15, []() -> const RRType& {static const RRType r("MX"); return (r);}},
- {"RP", 17, []() -> const RRType& {static const RRType r("RP"); return (r);}},
- {"AFSDB", 18, []() -> const RRType& {static const RRType r("AFSDB"); return (r);}},
- {"X25", 19, []() -> const RRType& {static const RRType r("X25"); return (r);}},
- {"ISDN", 20, []() -> const RRType& {static const RRType r("ISDN"); return (r);}},
- {"RT", 21, []() -> const RRType& {static const RRType r("RT"); return (r);}},
- {"NSAP", 22, []() -> const RRType& {static const RRType r("NSAP"); return (r);}},
- {"NSAP-PTR", 23, []() -> const RRType& {static const RRType r("NSAP-PTR"); return (r);}},
- {"SIG", 24, []() -> const RRType& {static const RRType r("SIG"); return (r);}},
- {"KEY", 25, []() -> const RRType& {static const RRType r("KEY"); return (r);}},
- {"PX", 26, []() -> const RRType& {static const RRType r("PX"); return (r);}},
- {"GPOS", 27, []() -> const RRType& {static const RRType r("GPOS"); return (r);}},
- {"LOC", 29, []() -> const RRType& {static const RRType r("LOC"); return (r);}},
- {"NXT", 30, []() -> const RRType& {static const RRType r("NXT"); return (r);}},
- {"EID", 31, []() -> const RRType& {static const RRType r("EID"); return (r);}},
- {"NIMLOC", 32, []() -> const RRType& {static const RRType r("NIMLOC"); return (r);}},
- {"SRV", 33, []() -> const RRType& {static const RRType r("SRV"); return (r);}},
- {"ATMA", 34, []() -> const RRType& {static const RRType r("ATMA"); return (r);}},
- {"NAPTR", 35, []() -> const RRType& {static const RRType r("NAPTR"); return (r);}},
- {"KX", 36, []() -> const RRType& {static const RRType r("KX"); return (r);}},
- {"CERT", 37, []() -> const RRType& {static const RRType r("CERT"); return (r);}},
- {"A6", 38, []() -> const RRType& {static const RRType r("A6"); return (r);}},
- {"DNAME", 39, []() -> const RRType& {static const RRType r("DNAME"); return (r);}},
- {"SINK", 40, []() -> const RRType& {static const RRType r("SINK"); return (r);}},
- {"APL", 42, []() -> const RRType& {static const RRType r("APL"); return (r);}},
- {"DS", 43, []() -> const RRType& {static const RRType r("DS"); return (r);}},
- {"SSHFP", 44, []() -> const RRType& {static const RRType r("SSHFP"); return (r);}},
- {"IPSECKEY", 45, []() -> const RRType& {static const RRType r("IPSECKEY"); return (r);}},
- {"NSEC", 47, []() -> const RRType& {static const RRType r("NSEC"); return (r);}},
- {"DNSKEY", 48, []() -> const RRType& {static const RRType r("DNSKEY"); return (r);}},
- {"NSEC3", 50, []() -> const RRType& {static const RRType r("NSEC3"); return (r);}},
- {"NSEC3PARAM", 51, []() -> const RRType& {static const RRType r("NSEC3PARAM"); return (r);}},
- {"TLSA", 52, []() -> const RRType& {static const RRType r("TLSA"); return (r);}},
- {"SMIMEA", 53, []() -> const RRType& {static const RRType r("SMIMEA"); return (r);}},
- // Unassigned 54
- {"HIP", 55, []() -> const RRType& {static const RRType r("HIP"); return (r);}},
- {"NINFO", 56, []() -> const RRType& {static const RRType r("NINFO"); return (r);}},
- {"RKEY", 57, []() -> const RRType& {static const RRType r("RKEY"); return (r);}},
- {"TALINK", 58, []() -> const RRType& {static const RRType r("TALINK"); return (r);}},
- {"CDS", 59, []() -> const RRType& {static const RRType r("CDS"); return (r);}},
- {"CDNSKEY", 60, []() -> const RRType& {static const RRType r("CDNSKEY"); return (r);}},
- {"OPENPGPKEY", 61, []() -> const RRType& {static const RRType r("OPENPGPKEY"); return (r);}},
- {"CSYNC", 62 , []() -> const RRType& {static const RRType r("CSYNC"); return (r);}},
- {"ZONEMD", 63, []() -> const RRType& {static const RRType r("ZONEMD"); return (r);}},
- {"SVCB", 64, []() -> const RRType& {static const RRType r("SVCB"); return (r);}},
- {"HTTPS", 65, []() -> const RRType& {static const RRType r("HTTPS"); return (r);}},
- // Unassigned 66-98
- {"SPF", 99, []() -> const RRType& {static const RRType r("SPF"); return (r);}},
- {"UINFO", 100, []() -> const RRType& {static const RRType r("UINFO"); return (r);}},
- {"UID", 101, []() -> const RRType& {static const RRType r("UID"); return (r);}},
- {"GID", 102, []() -> const RRType& {static const RRType r("GID"); return (r);}},
- {"UNSPEC", 103, []() -> const RRType& {static const RRType r("UNSPEC"); return (r);}},
- {"NID", 104, []() -> const RRType& {static const RRType r("NID"); return (r);}},
- {"L32", 105, []() -> const RRType& {static const RRType r("L32"); return (r);}},
- {"L64", 106, []() -> const RRType& {static const RRType r("L64"); return (r);}},
- {"LP", 107, []() -> const RRType& {static const RRType r("LP"); return (r);}},
- {"EUI48", 108, []() -> const RRType& {static const RRType r("EUI48"); return (r);}},
- {"EUI64", 109, []() -> const RRType& {static const RRType r("EUI64"); return (r);}},
- // Unassigned 110-248
- {"IXFR", 251, []() -> const RRType& {static const RRType r("IXFR"); return (r);}},
- {"AXFR", 252, []() -> const RRType& {static const RRType r("AXFR"); return (r);}},
- {"MAILB", 253, []() -> const RRType& {static const RRType r("MAILB"); return (r);}},
- {"MAILA", 254, []() -> const RRType& {static const RRType r("MAILA"); return (r);}},
- {"ANY", 255, []() -> const RRType& {static const RRType r("ANY"); return (r);}}, // also known as "*"
- {"URI", 256, []() -> const RRType& {static const RRType r("URI"); return (r);}},
- {"CAA", 257, []() -> const RRType& {static const RRType r("CAA"); return (r);}},
- {"AVC", 258, []() -> const RRType& {static const RRType r("AVC"); return (r);}},
- {"DOA", 259, []() -> const RRType& {static const RRType r("DOA"); return (r);}},
- {"AMTRELAY", 260, []() -> const RRType& {static const RRType r("AMTRELAY"); return (r);}},
- {"RESINFO", 261, []() -> const RRType& {static const RRType r("RESINFO"); return (r);}},
- // Unassigned 262-32767
- {"TA", 32768, []() -> const RRType& {static const RRType r("TA"); return (r);}},
- {"DLV", 32769, []() -> const RRType& {static const RRType r("DLV"); return (r);}},
{0, 0, 0}
};
TEST(RRTypeConstTest, wellKnowns) {
- for (int i = 0; known_types[i].txt; ++i) {
+ for (size_t i = 0; well_known_types[i].txt; ++i) {
SCOPED_TRACE("Checking well known RRType: " +
- string(known_types[i].txt));
- EXPECT_EQ(known_types[i].code, RRType(known_types[i].txt).getCode());
- EXPECT_EQ(known_types[i].code,
- (*known_types[i].obj)().getCode());
+ string(well_known_types[i].txt));
+ EXPECT_EQ(well_known_types[i].code,
+ RRType(well_known_types[i].txt).getCode());
+ EXPECT_EQ(well_known_types[i].code,
+ (*well_known_types[i].obj)().getCode());
}
}
+
+// Below, we'll check definitions for all registered RR types.
+struct RegisteredTypeParam {
+ const char* const txt; // "A", "AAAA", "NS", etc
+ const uint16_t code; // 1, 28, 2, etc
+} registered_types[] = {
+ {"A", 1},
+ {"NS", 2},
+ {"MD", 3},
+ {"MF", 4},
+ {"CNAME", 5},
+ {"SOA", 6},
+ {"MB", 7},
+ {"MG", 8},
+ {"MR", 9},
+ {"NULL", 10},
+ {"WKS", 11},
+ {"PTR", 12},
+ {"HINFO", 13},
+ {"MINFO", 14},
+ {"MX", 15},
+ {"TXT", 16},
+ {"RP", 17},
+ {"AFSDB", 18},
+ {"X25", 19},
+ {"ISDN", 20},
+ {"RT", 21},
+ {"NSAP", 22},
+ {"NSAP-PTR", 23},
+ {"SIG", 24},
+ {"KEY", 25},
+ {"PX", 26},
+ {"GPOS", 27},
+ {"AAAA", 28},
+ {"LOC", 29},
+ {"NXT", 30},
+ {"EID", 31},
+ {"NIMLOC", 32},
+ {"SRV", 33},
+ {"ATMA", 34},
+ {"NAPTR", 35},
+ {"KX", 36},
+ {"CERT", 37},
+ {"A6", 38},
+ {"DNAME", 39},
+ {"SINK", 40},
+ {"OPT", 41},
+ {"APL", 42},
+ {"DS", 43},
+ {"SSHFP", 44},
+ {"IPSECKEY", 45},
+ {"RRSIG", 46},
+ {"NSEC", 47},
+ {"DNSKEY", 48},
+ {"DHCID", 49},
+ {"NSEC3", 50},
+ {"NSEC3PARAM", 51},
+ {"TLSA", 52},
+ {"SMIMEA", 53},
+ {"HIP", 55},
+ {"NINFO", 56},
+ {"RKEY", 57},
+ {"TALINK", 58},
+ {"CDS", 59},
+ {"CDNSKEY", 60},
+ {"OPENPGPKEY", 61},
+ {"CSYNC", 62},
+ {"ZONEMD", 63},
+ {"SVCB", 64},
+ {"HTTPS", 65},
+ {"SPF", 99},
+ {"UINFO", 100},
+ {"UID", 101},
+ {"GID", 102},
+ {"UNSPEC", 103},
+ {"NID", 104},
+ {"L32", 105},
+ {"L64", 106},
+ {"LP", 107},
+ {"EUI48", 108},
+ {"EUI64", 109},
+ {"TKEY", 249},
+ {"TSIG", 250},
+ {"IXFR", 251},
+ {"AXFR", 252},
+ {"MAILB", 253},
+ {"MAILA", 254},
+ {"ANY", 255},
+ {"URI", 256},
+ {"CAA", 257},
+ {"AVC", 258},
+ {"DOA", 259},
+ {"AMTRELAY", 260},
+ {"RESINFO", 261},
+ {"TA", 32768},
+ {"DLV", 32769},
+ {0, 0}
+};
+
+TEST(RRTypeConstTest, registered) {
+ for (size_t i = 0; registered_types[i].txt; ++i) {
+ SCOPED_TRACE("Checking registered RRType: " +
+ string(registered_types[i].txt));
+ uint16_t code = 0;
+ EXPECT_NO_THROW(RRParamRegistry::getRegistry().textToTypeCode(registered_types[i].txt, code));
+ EXPECT_EQ(code, registered_types[i].code);
+ string txt;
+ EXPECT_NO_THROW(txt = RRParamRegistry::getRegistry().codeToTypeText(registered_types[i].code));
+ EXPECT_EQ(txt, registered_types[i].txt);
+ }
+}
+
}