]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1975] Fix the fake data source
authorMichal 'vorner' Vaner <michal.vaner@nic.cz>
Tue, 5 Jun 2012 19:14:31 +0000 (21:14 +0200)
committerMichal 'vorner' Vaner <michal.vaner@nic.cz>
Tue, 5 Jun 2012 19:16:09 +0000 (21:16 +0200)
It behaved wrongly in partial matches, since the lower_bound function
went to the other side of the wanted iterator than I wanted.

src/lib/datasrc/tests/container_unittest.cc

index 84385839ad923cd7e8d0b0fbe4c2ac625f725b86..491700eaaeedd15d6a5d7eb0e94e9a7679ad5c15 100644 (file)
@@ -79,20 +79,20 @@ public:
         }
     }
     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()));
-        } 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
@@ -194,6 +194,15 @@ public:
     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_F(ContainerTest, emptyContainer) {
     EXPECT_TRUE(container_->dataSources().empty());