Browse Source

[trac550] added minimum support for empty node for wildcard testing.

the subsequent tests will be invalidated once we merge #507, but
for the purpose of this ticket it should work.
JINMEI Tatuya 14 years ago
parent
commit
3715569dde

+ 7 - 2
src/lib/datasrc/memory_datasrc.cc

@@ -59,7 +59,7 @@ struct MemoryZone::MemoryZoneImpl {
     typedef Domain::value_type DomainPair;
     typedef boost::shared_ptr<Domain> DomainPtr;
     // The tree stores domains
-    typedef RBTree<Domain> DomainTree;
+    typedef RBTree<Domain, true> DomainTree;
     typedef RBNode<Domain> DomainNode;
 
     // Information about the zone
@@ -330,7 +330,12 @@ struct MemoryZone::MemoryZoneImpl {
                 assert(0);
         }
         assert(node);
-        assert(!node->isEmpty());
+
+        // If there is an exact match but the node is empty, it's equivalent
+        // to NXRRSET.
+        if (node->isEmpty()) {
+            return (FindResult(NXRRSET, ConstRRsetPtr()));
+        }
 
         Domain::const_iterator found;
 

+ 1 - 1
src/lib/datasrc/rbtree.h

@@ -483,7 +483,7 @@ public:
     ///
     /// This acts the same as many std::*.swap functions, exchanges the
     /// contents. This doesn't throw anything.
-    void swap(RBTree<T>& other) {
+    void swap(RBTree<T, returnEmptyNode>& other) {
         std::swap(root_, other.root_);
         std::swap(NULLNODE, other.NULLNODE);
         std::swap(node_count_, other.node_count_);

+ 9 - 0
src/lib/datasrc/tests/memory_datasrc_unittest.cc

@@ -196,6 +196,8 @@ public:
             {"dname.child.example.org. 300 IN DNAME example.com.",
              &rr_child_dname_},
             {"example.com. 300 IN A 192.0.2.10", &rr_out_},
+            {"*.wild.example.org. 300 IN A 192.0.2.1", &rr_wild_},
+            {"bar.tmp.example.org. 300 IN A 192.0.2.1", &rr_tmp2_},
             {NULL, NULL}
         };
 
@@ -241,6 +243,7 @@ public:
     RRsetPtr rr_grandchild_ns_; // NS below a zone cut (unusual)
     RRsetPtr rr_grandchild_glue_; // glue RR below a deeper zone cut
     RRsetPtr rr_child_dname_; // A DNAME under NS
+    RRsetPtr rr_wild_, rr_tmp2_;
 
     /**
      * \brief Test one find query to the zone.
@@ -606,6 +609,12 @@ TEST_F(MemoryZoneTest, load) {
         MasterLoadError);
 }
 
+TEST_F(MemoryZoneTest, loadWildcard) {
+    EXPECT_EQ(SUCCESS, zone_.add(rr_wild_));
+    EXPECT_EQ(SUCCESS, zone_.add(rr_tmp2_));
+    findTest(Name("tmp.example.org"), RRType::A(), Zone::NXRRSET);
+}
+
 TEST_F(MemoryZoneTest, swap) {
     // build one zone with some data
     MemoryZone zone1(class_, origin_);