]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2432] Don't throw when comparing iterators from different RRsetCollectionBase implem...
authorMukund Sivaraman <muks@isc.org>
Wed, 26 Dec 2012 05:47:52 +0000 (11:17 +0530)
committerMukund Sivaraman <muks@isc.org>
Wed, 26 Dec 2012 05:47:52 +0000 (11:17 +0530)
src/lib/dns/rrset_collection.h
src/lib/dns/tests/rrset_collection_unittest.cc

index fa8592768eeede73d40d9bb7b6a6b44054ddf1cb..9cbf98c4252ed5a9b8acf482127ff4449f8e236a 100644 (file)
@@ -117,8 +117,11 @@ protected:
         }
 
         virtual bool equals(Iter& other) {
-            const DnsIter& other_real = dynamic_cast<DnsIter&>(other);
-            return (iter_ == other_real.iter_);
+            const DnsIter* other_real = dynamic_cast<DnsIter*>(&other);
+            if (other_real == NULL) {
+                return (false);
+            }
+            return (iter_ == other_real->iter_);
         }
 
     private:
index 29853e12bcb72ad1030d5013beed4f7598e8a33e..c7b66366c5a632c15213d147b301ea18ae2f612b 100644 (file)
@@ -18,6 +18,8 @@
 
 #include <gtest/gtest.h>
 
+#include <list>
+
 using namespace isc::dns;
 using namespace isc::dns::rdata;
 using namespace std;
@@ -178,4 +180,77 @@ TEST_F(RRsetCollectionTest, iteratorTest) {
     EXPECT_EQ(4, count);
 }
 
+// This is a dummy class which is used in iteratorCompareDifferent test
+// to compare iterators from different RRsetCollectionBase
+// implementations.
+class MyRRsetCollection : public RRsetCollectionBase {
+public:
+    MyRRsetCollection()
+    {}
+
+    virtual const isc::dns::AbstractRRset* find
+        (const isc::dns::Name&, const isc::dns::RRType&,
+         const isc::dns::RRClass&)
+        const
+    {
+        return (NULL);
+    }
+
+    typedef std::list<isc::dns::RRset> MyCollection;
+
+protected:
+    class MyIter : public RRsetCollectionBase::Iter {
+    public:
+        MyIter(MyCollection::iterator& iter) :
+            iter_(iter)
+        {}
+
+        virtual const isc::dns::AbstractRRset& getValue() {
+            return (*iter_);
+        }
+
+        virtual IterPtr getNext() {
+            MyCollection::iterator it = iter_;
+            it++;
+            return (RRsetCollectionBase::IterPtr(new MyIter(it)));
+        }
+
+        virtual bool equals(Iter& other) {
+            const MyIter* other_real = dynamic_cast<MyIter*>(&other);
+            if (other_real == NULL) {
+                return (false);
+            }
+            return (iter_ == other_real->iter_);
+        }
+
+    private:
+        MyCollection::iterator iter_;
+    };
+
+    virtual RRsetCollectionBase::IterPtr getBeginning() {
+        MyCollection::iterator it = dummy_list_.begin();
+        return (RRsetCollectionBase::IterPtr(new MyIter(it)));
+    }
+
+    virtual RRsetCollectionBase::IterPtr getEnd() {
+        MyCollection::iterator it = dummy_list_.end();
+        return (RRsetCollectionBase::IterPtr(new MyIter(it)));
+    }
+
+private:
+    MyCollection dummy_list_;
+};
+
+TEST_F(RRsetCollectionTest, iteratorCompareDifferent) {
+    // Create objects of two different RRsetCollectionBase
+    // implementations.
+    RRsetCollection cln1;
+    MyRRsetCollection cln2;
+
+    // Comparing two iterators from different RRsetCollectionBase
+    // implementations must not throw.
+    EXPECT_NE(cln2.begin(), cln1.begin());
+    EXPECT_NE(cln1.end(), cln2.end());
+}
+
 } // namespace