Browse Source

[1975] Fix the fake data source

It behaved wrongly in partial matches, since the lower_bound function
went to the other side of the wanted iterator than I wanted.
Michal 'vorner' Vaner 13 years ago
parent
commit
e654de7dea
1 changed files with 22 additions and 13 deletions
  1. 22 13
      src/lib/datasrc/tests/container_unittest.cc

+ 22 - 13
src/lib/datasrc/tests/container_unittest.cc

@@ -79,20 +79,20 @@ public:
         }
         }
     }
     }
     virtual FindResult findZone(const Name& name) const {
     virtual FindResult findZone(const Name& name) const {
-        set<Name>::const_iterator it(zones.lower_bound(name));
-        if (it == zones.end()) {
+        if (zones.empty()) {
             return (FindResult(result::NOTFOUND, ZoneFinderPtr()));
             return (FindResult(result::NOTFOUND, ZoneFinderPtr()));
-        } else {
-            NameComparisonResult compar(it->compare(name));
-            const ZoneFinderPtr finder(new Finder(*it));
-            switch (compar.getRelation()) {
-                case NameComparisonResult::EQUAL:
-                    return (FindResult(result::SUCCESS, finder));
-                case NameComparisonResult::SUPERDOMAIN:
-                    return (FindResult(result::PARTIALMATCH, finder));
-                default:
-                    return (FindResult(result::NOTFOUND, ZoneFinderPtr()));
-            }
+        }
+        set<Name>::const_iterator it(zones.upper_bound(name));
+        -- it;
+        NameComparisonResult compar(it->compare(name));
+        const ZoneFinderPtr finder(new Finder(*it));
+        switch (compar.getRelation()) {
+            case NameComparisonResult::EQUAL:
+                return (FindResult(result::SUCCESS, finder));
+            case NameComparisonResult::SUPERDOMAIN:
+                return (FindResult(result::PARTIALMATCH, finder));
+            default:
+                return (FindResult(result::NOTFOUND, ZoneFinderPtr()));
         }
         }
     }
     }
     // These methods are not used. They just need to be there to have
     // These methods are not used. They just need to be there to have
@@ -194,6 +194,15 @@ public:
     vector<ConfigurableContainer::DataSourceInfo> ds_info_;
     vector<ConfigurableContainer::DataSourceInfo> ds_info_;
 };
 };
 
 
+// Test the test itself
+TEST_F(ContainerTest, selfTest) {
+    EXPECT_EQ(result::SUCCESS, ds_[0]->findZone(Name("example.org")).code);
+    EXPECT_EQ(result::PARTIALMATCH,
+              ds_[0]->findZone(Name("sub.example.org")).code);
+    EXPECT_EQ(result::NOTFOUND, ds_[0]->findZone(Name("org")).code);
+    EXPECT_EQ(result::NOTFOUND, ds_[1]->findZone(Name("example.org")).code);
+}
+
 // Test the container we create with empty configuration is, in fact, empty
 // Test the container we create with empty configuration is, in fact, empty
 TEST_F(ContainerTest, emptyContainer) {
 TEST_F(ContainerTest, emptyContainer) {
     EXPECT_TRUE(container_->dataSources().empty());
     EXPECT_TRUE(container_->dataSources().empty());