Browse Source

[1749] Implement a specialized RBNodeRRset::isSameKind()

Mukund Sivaraman 13 years ago
parent
commit
216b2e18c9
2 changed files with 28 additions and 0 deletions
  1. 11 0
      src/lib/datasrc/rbnode_rrset.h
  2. 17 0
      src/lib/datasrc/tests/rbnode_rrset_unittest.cc

+ 11 - 0
src/lib/datasrc/rbnode_rrset.h

@@ -127,6 +127,17 @@ public:
 
     virtual std::string toText() const;
 
+    virtual bool isSameKind(const AbstractRRset& other) {
+        const AbstractRRset* t = &other;
+        const RBNodeRRset* rb;
+
+        rb = dynamic_cast<const RBNodeRRset*>(t);
+        if (rb)
+          return (this == rb);
+        else
+          return AbstractRRset::isSameKind(other);
+    }
+
     virtual unsigned int toWire(
         isc::dns::AbstractMessageRenderer& renderer) const;
 

+ 17 - 0
src/lib/datasrc/tests/rbnode_rrset_unittest.cc

@@ -138,6 +138,23 @@ TEST_F(RBNodeRRsetTest, toText) {
     EXPECT_THROW(rrset_a_empty.toText(), EmptyRRset);
 }
 
+TEST_F(RBNodeRRsetTest, isSameKind) {
+    RBNodeRRset rrset_p(ConstRRsetPtr(new RRset(test_name, RRClass::IN(), RRType::A(), RRTTL(3600))));
+    RBNodeRRset rrset_q(ConstRRsetPtr(new RRset(test_name, RRClass::IN(), RRType::A(), RRTTL(3600))));
+    RRset rrset_w(test_name, RRClass::IN(), RRType::A(), RRTTL(3600));
+    RRset rrset_x(test_name, RRClass::IN(), RRType::A(), RRTTL(3600));
+    RRset rrset_y(test_name, RRClass::IN(), RRType::NS(), RRTTL(3600));
+    RRset rrset_z(test_name, RRClass::CH(), RRType::A(), RRTTL(3600));
+
+    EXPECT_TRUE(rrset_p.isSameKind(rrset_p));
+    EXPECT_FALSE(rrset_p.isSameKind(rrset_q));
+
+    EXPECT_TRUE(rrset_p.isSameKind(rrset_w));
+    EXPECT_TRUE(rrset_p.isSameKind(rrset_x));
+    EXPECT_FALSE(rrset_p.isSameKind(rrset_y));
+    EXPECT_FALSE(rrset_p.isSameKind(rrset_z));
+}
+
 // Note: although the next two tests are essentially the same and used common
 // test code, they use different test data: the MessageRenderer produces
 // compressed wire data whereas the OutputBuffer does not.