From: Mukund Sivaraman Date: Thu, 3 Jan 2013 10:37:56 +0000 (+0530) Subject: [2432] Return status in removeRRset() X-Git-Tag: bind10-1.0.0-rc-release~141 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bdf19add5fca40dbc91c6ce4c0d87d8bb6080bde;p=thirdparty%2Fkea.git [2432] Return status in removeRRset() --- diff --git a/src/lib/dns/rrset_collection.cc b/src/lib/dns/rrset_collection.cc index 53f9702810..8ee85be7f1 100644 --- a/src/lib/dns/rrset_collection.cc +++ b/src/lib/dns/rrset_collection.cc @@ -115,12 +115,19 @@ RRsetCollection::find(const Name& name, const RRClass& rrclass, return (ConstRRsetPtr()); } -void +bool RRsetCollection::removeRRset(const Name& name, const RRClass& rrclass, const RRType& rrtype) { const CollectionKey key(rrclass, rrtype, name); - rrsets_.erase(key); + + CollectionMap::iterator it = rrsets_.find(key); + if (it == rrsets_.end()) { + return (false); + } + + rrsets_.erase(it); + return (true); } RRsetCollectionBase::IterPtr diff --git a/src/lib/dns/rrset_collection.h b/src/lib/dns/rrset_collection.h index fe9152c22e..b44faabc92 100644 --- a/src/lib/dns/rrset_collection.h +++ b/src/lib/dns/rrset_collection.h @@ -87,7 +87,10 @@ public: /// /// RRset(s) matching the \c name, \c rrclass and \c rrtype are /// removed from the collection. - void removeRRset(const isc::dns::Name& name, + /// + /// \returns \c true if a matching RRset was deleted, \c false if no + /// such RRset exists. + bool removeRRset(const isc::dns::Name& name, const isc::dns::RRClass& rrclass, const isc::dns::RRType& rrtype); diff --git a/src/lib/dns/tests/rrset_collection_unittest.cc b/src/lib/dns/tests/rrset_collection_unittest.cc index a4834e9fa0..5c0caedee0 100644 --- a/src/lib/dns/tests/rrset_collection_unittest.cc +++ b/src/lib/dns/tests/rrset_collection_unittest.cc @@ -152,13 +152,20 @@ doAddAndRemove(RRsetCollection& collection, const RRClass& rrclass) { collection.addRRset(rrset); }, isc::InvalidParameter); - // Remove foo.example.org/A - collection.removeRRset(Name("foo.example.org"), rrclass, RRType::A()); + // Remove foo.example.org/A, which should pass + bool exists = collection.removeRRset(Name("foo.example.org"), + rrclass, RRType::A()); + EXPECT_TRUE(exists); // foo.example.org/A should not exist now rrset_found = collection.find(Name("foo.example.org"), rrclass, RRType::A()); EXPECT_FALSE(rrset_found); + + // Removing foo.example.org/A should fail now + exists = collection.removeRRset(Name("foo.example.org"), + rrclass, RRType::A()); + EXPECT_FALSE(exists); } TEST_F(RRsetCollectionTest, addAndRemove) {