]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2432] Return status in removeRRset()
authorMukund Sivaraman <muks@isc.org>
Thu, 3 Jan 2013 10:37:56 +0000 (16:07 +0530)
committerMukund Sivaraman <muks@isc.org>
Thu, 3 Jan 2013 10:42:04 +0000 (16:12 +0530)
src/lib/dns/rrset_collection.cc
src/lib/dns/rrset_collection.h
src/lib/dns/tests/rrset_collection_unittest.cc

index 53f9702810a027a3a7331386f512b11efa367818..8ee85be7f1b8df236ab7b5166a528cde1125a1e5 100644 (file)
@@ -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
index fe9152c22e0f9fcd073bbc6bf2225eb19d61214c..b44faabc9276102ac0746aea53dc50927b12941b 100644 (file)
@@ -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);
 
index a4834e9fa05c1bf9190af7137d1087acf3962fc0..5c0caedee0ed42d64c69663f24aa2ab32b578427 100644 (file)
@@ -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) {