From: Michal 'vorner' Vaner Date: Tue, 5 Jun 2012 19:14:31 +0000 (+0200) Subject: [1975] Fix the fake data source X-Git-Tag: trac2351_base~97^2~9^2~4^2~16 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e654de7dea5adaa224dd56dc06201a9f902248d3;p=thirdparty%2Fkea.git [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. --- diff --git a/src/lib/datasrc/tests/container_unittest.cc b/src/lib/datasrc/tests/container_unittest.cc index 84385839ad..491700eaae 100644 --- a/src/lib/datasrc/tests/container_unittest.cc +++ b/src/lib/datasrc/tests/container_unittest.cc @@ -79,20 +79,20 @@ public: } } virtual FindResult findZone(const Name& name) const { - set::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::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 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());