From: JINMEI Tatuya Date: Sat, 11 Feb 2012 01:25:46 +0000 (-0800) Subject: [1641] added tests for NSEC::compare(). there's no bug, just confirming it. X-Git-Tag: trac2351_base~97^2~37^2~12 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4a20cc2eef19a7ada8e2c594724ca44e40be5cf8;p=thirdparty%2Fkea.git [1641] added tests for NSEC::compare(). there's no bug, just confirming it. --- diff --git a/src/lib/dns/tests/rdata_nsec3_unittest.cc b/src/lib/dns/tests/rdata_nsec3_unittest.cc index 282e3178eb..0364d1e8d3 100644 --- a/src/lib/dns/tests/rdata_nsec3_unittest.cc +++ b/src/lib/dns/tests/rdata_nsec3_unittest.cc @@ -269,7 +269,6 @@ TEST_F(Rdata_NSEC3_Test, compare) { EXPECT_GT(0, (*it).compare(*(it + 1))); EXPECT_LT(0, (*(it + 1)).compare(*it)); } - } } diff --git a/src/lib/dns/tests/rdata_nsec_unittest.cc b/src/lib/dns/tests/rdata_nsec_unittest.cc index f081cd8216..feb70c210d 100644 --- a/src/lib/dns/tests/rdata_nsec_unittest.cc +++ b/src/lib/dns/tests/rdata_nsec_unittest.cc @@ -38,7 +38,7 @@ class Rdata_NSEC_Test : public RdataTest { // there's nothing to specialize }; -string nsec_txt("www2.isc.org. CNAME RRSIG NSEC"); +const char* const nsec_txt = "www2.isc.org. CNAME RRSIG NSEC"; TEST_F(Rdata_NSEC_Test, toText_NSEC) { const generic::NSEC rdata_nsec(nsec_txt); @@ -95,4 +95,31 @@ TEST_F(Rdata_NSEC_Test, getNextName) { EXPECT_EQ(Name("www2.isc.org"), generic::NSEC((nsec_txt)).getNextName()); } +TEST_F(Rdata_NSEC_Test, compare) { + // trivial case: self equivalence + EXPECT_EQ(0, generic::NSEC("example A"). + compare(generic::NSEC("example. A"))); + EXPECT_EQ(0, generic::NSEC("EXAMPLE A"). // should be case insensitive + compare(generic::NSEC("example. A"))); + + // comparison attempt between incompatible RR types should be rejected + EXPECT_THROW(generic::NSEC(nsec_txt).compare(*rdata_nomatch), + bad_cast); + + // test RDATAs, sorted in the ascendent order. We only compare the + // next name here. Bitmap comparison is tested in the bitmap tests. + // Note that names are compared as wire-format data, not based on the + // domain name comparison. + vector compare_set; + compare_set.push_back(generic::NSEC("a.example. A")); + compare_set.push_back(generic::NSEC("example. A")); + vector::const_iterator it; + const vector::const_iterator it_end = compare_set.end(); + for (it = compare_set.begin(); it != it_end - 1; ++it) { + SCOPED_TRACE("compare " + it->toText() + " to " + (it + 1)->toText()); + EXPECT_GT(0, (*it).compare(*(it + 1))); + EXPECT_LT(0, (*(it + 1)).compare(*it)); + } +} + }