Browse Source

[1641] moved bitmap comparison tests to bitmap tests to share it with NSEC

JINMEI Tatuya 13 years ago
parent
commit
5c4967145b

+ 4 - 14
src/lib/dns/tests/rdata_nsec3_unittest.cc

@@ -238,7 +238,9 @@ TEST_F(Rdata_NSEC3_Test, compare) {
     EXPECT_THROW(generic::NSEC3(nsec3_txt).compare(*rdata_nomatch),
                  bad_cast);
 
-    // test RDATAs, sorted in the ascendent order.
+    // test RDATAs, sorted in the ascendent order.  We only check comparison
+    // on NSEC3-specific fields.  Bitmap comparison is tested in the bitmap
+    // tests.
     vector<generic::NSEC3> compare_set;
     compare_set.push_back(generic::NSEC3("0 0 0 D399EAAB D1K6GQ38"));
     compare_set.push_back(generic::NSEC3("1 0 0 D399EAAB D1K6GQ38"));
@@ -249,19 +251,7 @@ TEST_F(Rdata_NSEC3_Test, compare) {
     compare_set.push_back(generic::NSEC3("1 1 1 FF99EA0000 D1K6GQ38"));
     compare_set.push_back(generic::NSEC3("1 1 1 FF99EA0000 D1K6GQ0000000000"));
     compare_set.push_back(generic::NSEC3("1 1 1 FF99EA0000 D1K6GQ00UUUUUUUU"));
-    compare_set.push_back(generic::NSEC3("1 1 2 FF99EA0000 D1K6GQ38"));
-
-    // Bit map: [win=0][len=1] 00000010
-    compare_set.push_back(generic::NSEC3("1 1 2 FF99EA0000 D1K6GQ38 SOA"));
-    // Bit map: [win=0][len=1] 00100000, [win=4][len=1] 10000000
-    compare_set.push_back(generic::NSEC3(
-                              "1 1 2 FF99EA0000 D1K6GQ38 NS TYPE1024"));
-    // Bit map: [win=0][len=1] 00100010
-    compare_set.push_back(generic::NSEC3("1 1 2 FF99EA0000 D1K6GQ38 NS SOA"));
-    // Bit map: [win=0][len=2] 00100000, 00000001
-    compare_set.push_back(generic::NSEC3("1 1 2 FF99EA0000 D1K6GQ38 NS MX"));
-    // Bit map: [win=4][len=1] 10000000
-    compare_set.push_back(generic::NSEC3("1 1 2 FF99EA0000 D1K6GQ38 TYPE1024"));
+
     vector<generic::NSEC3>::const_iterator it;
     const vector<generic::NSEC3>::const_iterator it_end = compare_set.end();
     for (it = compare_set.begin(); it != it_end - 1; ++it) {

+ 35 - 0
src/lib/dns/tests/rdata_nsecbitmap_unittest.cc

@@ -45,6 +45,20 @@ protected:
         return (RDATA_TYPE(rdata_text));
     }
 
+    vector<RDATA_TYPE> compare_set; // used in compare() tests
+
+    void compareCheck() const {
+        typename vector<RDATA_TYPE>::const_iterator it;
+        typename vector<RDATA_TYPE>::const_iterator const 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));
+        }
+    }
+
     // These depend on the specific RR type.  We use specialized methods
     // for them.
     static RRType getType();    // return either RRType::NSEC() or NSEC3()
@@ -186,6 +200,27 @@ TYPED_TEST(NSECLikeBitmapTest, toText) {
     EXPECT_EQ(rdata_text, this->fromText(rdata_text).toText());
 }
 
+TYPED_TEST(NSECLikeBitmapTest, compare) {
+    // Bit map: [win=0][len=1] 00000010
+    this->compare_set.push_back(this->fromText(this->getCommonText() + "SOA"));
+    // Bit map: [win=0][len=1] 00000010, [win=4][len=1] 10000000
+    this->compare_set.push_back(this->fromText(this->getCommonText() +
+                                               "SOA TYPE1024"));
+    // Bit map: [win=0][len=1] 00100000,
+    this->compare_set.push_back(this->fromText(this->getCommonText() + "NS"));
+    // Bit map: [win=0][len=1] 00100010
+    this->compare_set.push_back(this->fromText(this->getCommonText() +
+                                               "NS SOA"));
+    // Bit map: [win=0][len=2] 00100000, 00000001
+    this->compare_set.push_back(this->fromText(this->getCommonText() +
+                                               "NS MX"));
+    // Bit map: [win=4][len=1] 10000000
+    this->compare_set.push_back(this->fromText(this->getCommonText() +
+                                               "TYPE1024"));
+
+    this->compareCheck();
+}
+
 // NSEC bitmaps must not be empty
 TEST_F(NSECBitmapTest, emptyMap) {
     EXPECT_THROW(this->fromText("next.example").toText(), InvalidRdataText);