BIND 10 trac2432, updated. 6c738ab17c6b6632f1a607cea6cea480fd1c72aa [2432] Add tests for absent RRClass

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Dec 26 04:39:56 UTC 2012


The branch, trac2432 has been updated
       via  6c738ab17c6b6632f1a607cea6cea480fd1c72aa (commit)
       via  7eee12217563565248904b7051a6d68f2374ebe0 (commit)
      from  b5aa1d1b12636ba96e3fff48e27fb6acf6e38333 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 6c738ab17c6b6632f1a607cea6cea480fd1c72aa
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Dec 26 10:05:39 2012 +0530

    [2432] Add tests for absent RRClass

commit 7eee12217563565248904b7051a6d68f2374ebe0
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Dec 26 10:01:51 2012 +0530

    [2432] Add RRClass too in the RRsetCollection key, and make find() search for them
    
    This commit also changes the base class's find() prototype to include
    the RRClass as an argument. Otherwise, we don't know what RRClass to
    look for. The arguments for the base class's find() method are in a
    different order from those of the find() methods in the RRsetCollection
    implementation as there's no way to overload the method when only its
    return value is different.

-----------------------------------------------------------------------

Summary of changes:
 src/lib/dns/rrset_collection.cc                |   21 ++++++++++++---------
 src/lib/dns/rrset_collection.h                 |   13 +++++++++----
 src/lib/dns/rrset_collection_base.h            |    6 ++++--
 src/lib/dns/tests/rrset_collection_unittest.cc |   18 ++++++++++++++----
 4 files changed, 39 insertions(+), 19 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/dns/rrset_collection.cc b/src/lib/dns/rrset_collection.cc
index bf535c7..6cf2809 100644
--- a/src/lib/dns/rrset_collection.cc
+++ b/src/lib/dns/rrset_collection.cc
@@ -39,7 +39,8 @@ RRsetCollection::addRRset(const Name& name, const RRClass& rrclass,
 
 void
 RRsetCollection::addRRset(RRsetPtr rrset) {
-    const CollectionKey key(rrset->getName(), rrset->getType());
+    const CollectionKey key(rrset->getClass(), rrset->getType(),
+                            rrset->getName());
     rrsets_.insert(std::pair<CollectionKey, RRsetPtr>(key, rrset));
 }
 
@@ -57,8 +58,9 @@ RRsetCollection::RRsetCollection(const char* filename, const Name& origin,
 }
 
 const AbstractRRset*
-RRsetCollection::find(const Name& name, const RRType& rrtype) const {
-    const CollectionKey key(name, rrtype);
+RRsetCollection::find(const Name& name, const RRType& rrtype,
+                      const RRClass& rrclass) const {
+    const CollectionKey key(rrclass, rrtype, name);
     CollectionMap::const_iterator it = rrsets_.find(key);
     if (it != rrsets_.end()) {
         return (&(*it->second));
@@ -67,8 +69,9 @@ RRsetCollection::find(const Name& name, const RRType& rrtype) const {
 }
 
 RRsetPtr
-RRsetCollection::find(const Name& name, const RRClass&, const RRType& rrtype) {
-    const CollectionKey key(name, rrtype);
+RRsetCollection::find(const Name& name, const RRClass& rrclass,
+                      const RRType& rrtype) {
+    const CollectionKey key(rrclass, rrtype, name);
     CollectionMap::iterator it = rrsets_.find(key);
     if (it != rrsets_.end()) {
         return (it->second);
@@ -77,10 +80,10 @@ RRsetCollection::find(const Name& name, const RRClass&, const RRType& rrtype) {
 }
 
 ConstRRsetPtr
-RRsetCollection::find(const Name& name, const RRClass&,
+RRsetCollection::find(const Name& name, const RRClass& rrclass,
                       const RRType& rrtype) const
 {
-    const CollectionKey key(name, rrtype);
+    const CollectionKey key(rrclass, rrtype, name);
     CollectionMap::const_iterator it = rrsets_.find(key);
     if (it != rrsets_.end()) {
         return (it->second);
@@ -89,10 +92,10 @@ RRsetCollection::find(const Name& name, const RRClass&,
 }
 
 void
-RRsetCollection::removeRRset(const Name& name, const RRClass&,
+RRsetCollection::removeRRset(const Name& name, const RRClass& rrclass,
                              const RRType& rrtype)
 {
-    const CollectionKey key(name, rrtype);
+    const CollectionKey key(rrclass, rrtype, name);
     rrsets_.erase(key);
 }
 
diff --git a/src/lib/dns/rrset_collection.h b/src/lib/dns/rrset_collection.h
index 5f3dcb7..5c6f8fd 100644
--- a/src/lib/dns/rrset_collection.h
+++ b/src/lib/dns/rrset_collection.h
@@ -18,7 +18,9 @@
 #include <dns/rrset_collection_base.h>
 #include <dns/rrclass.h>
 
-#include <utility>
+#include <boost/tuple/tuple.hpp>
+#include <boost/tuple/tuple_comparison.hpp>
+
 #include <map>
 
 namespace isc {
@@ -63,9 +65,11 @@ public:
     ///
     /// \param name The name of the RRset to search for.
     /// \param rrtype The type of the RRset to search for.
+    /// \param rrclass The class of the RRset to search for.
     /// \returns A pointer to the RRset if found, \c NULL otherwise.
-    virtual const isc::dns::AbstractRRset* find(const isc::dns::Name& name,
-                                                const isc::dns::RRType& rrtype)
+    virtual const isc::dns::AbstractRRset* find
+        (const isc::dns::Name& name, const isc::dns::RRType& rrtype,
+	 const isc::dns::RRClass& rrclass)
         const;
 
     isc::dns::RRsetPtr find(const isc::dns::Name& name,
@@ -82,7 +86,8 @@ private:
                   const isc::dns::rdata::RdataPtr& data);
     void loaderCallback(const std::string&, size_t, const std::string&);
 
-    typedef std::pair<isc::dns::Name, isc::dns::RRType> CollectionKey;
+    typedef boost::tuple<isc::dns::RRClass, isc::dns::RRType, isc::dns::Name>
+        CollectionKey;
     typedef std::map<CollectionKey, isc::dns::RRsetPtr> CollectionMap;
 
     CollectionMap rrsets_;
diff --git a/src/lib/dns/rrset_collection_base.h b/src/lib/dns/rrset_collection_base.h
index f1b473d..5c4314c 100644
--- a/src/lib/dns/rrset_collection_base.h
+++ b/src/lib/dns/rrset_collection_base.h
@@ -46,9 +46,11 @@ public:
     ///
     /// \param name The name of the RRset to search for.
     /// \param rrtype The type of the RRset to search for.
+    /// \param rrclass The class of the RRset to search for.
     /// \returns A pointer to the RRset if found, \c NULL otherwise.
-    virtual const isc::dns::AbstractRRset* find(const isc::dns::Name& name,
-                                                const isc::dns::RRType& rrtype)
+    virtual const isc::dns::AbstractRRset* find
+        (const isc::dns::Name& name, const isc::dns::RRType& rrtype,
+	 const isc::dns::RRClass& rrclass)
         const = 0;
 
 protected:
diff --git a/src/lib/dns/tests/rrset_collection_unittest.cc b/src/lib/dns/tests/rrset_collection_unittest.cc
index d29fc32..0481ab1 100644
--- a/src/lib/dns/tests/rrset_collection_unittest.cc
+++ b/src/lib/dns/tests/rrset_collection_unittest.cc
@@ -40,7 +40,7 @@ public:
 TEST_F(RRsetCollectionTest, findBase) {
     // Test the find() that returns isc::dns::AbstractRRset*
     const AbstractRRset* rrset = collection.find(Name("www.example.org"),
-                                                 RRType::A());
+                                                 RRType::A(), rrclass);
     EXPECT_NE(static_cast<AbstractRRset*>(NULL), rrset);
     EXPECT_EQ(RRType::A(), rrset->getType());
     EXPECT_EQ(RRTTL(3600), rrset->getTTL());
@@ -48,16 +48,21 @@ TEST_F(RRsetCollectionTest, findBase) {
     EXPECT_EQ(Name("www.example.org"), rrset->getName());
 
     // foo.example.org doesn't exist
-    rrset = collection.find(Name("foo.example.org"), RRType::A());
+    rrset = collection.find(Name("foo.example.org"), RRType::A(), rrclass);
     EXPECT_EQ(static_cast<AbstractRRset*>(NULL), rrset);
 
     // www.example.org exists, but not with MX
-    rrset = collection.find(Name("www.example.org"), RRType::MX());
+    rrset = collection.find(Name("www.example.org"), RRType::MX(), rrclass);
     EXPECT_EQ(static_cast<AbstractRRset*>(NULL), rrset);
 
     // www.example.org exists, with AAAA
-    rrset = collection.find(Name("www.example.org"), RRType::AAAA());
+    rrset = collection.find(Name("www.example.org"), RRType::AAAA(), rrclass);
     EXPECT_NE(static_cast<AbstractRRset*>(NULL), rrset);
+
+    // www.example.org with AAAA does not exist in RRClass::CH()
+    rrset = collection.find(Name("www.example.org"), RRType::AAAA(),
+                            RRClass::CH());
+    EXPECT_EQ(static_cast<AbstractRRset*>(NULL), rrset);
 }
 
 template <typename T, typename TP>
@@ -81,6 +86,11 @@ void doFind(T& collection, const RRClass& rrclass) {
     // www.example.org exists, with AAAA
     rrset = collection.find(Name("www.example.org"), rrclass, RRType::AAAA());
     EXPECT_TRUE(rrset);
+
+    // www.example.org with AAAA does not exist in RRClass::CH()
+    rrset = collection.find(Name("www.example.org"), RRClass::CH(),
+                            RRType::AAAA());
+    EXPECT_FALSE(rrset);
 }
 
 TEST_F(RRsetCollectionTest, findConst) {



More information about the bind10-changes mailing list