Browse Source

[1748] Define AbstractRRset::isSameKind() and implement the default version

Mukund Sivaraman 13 years ago
parent
commit
64eef65d27
3 changed files with 32 additions and 0 deletions
  1. 11 0
      src/lib/dns/rrset.cc
  2. 8 0
      src/lib/dns/rrset.h
  3. 13 0
      src/lib/dns/tests/rrset_unittest.cc

+ 11 - 0
src/lib/dns/rrset.cc

@@ -113,6 +113,17 @@ AbstractRRset::toWire(AbstractMessageRenderer& renderer) const {
     return (rrs_written);
 }
 
+bool
+AbstractRRset::isSameKind(const AbstractRRset& other) {
+    if (getType() != other.getType())
+        return false;
+    if (getClass() != other.getClass())
+        return false;
+    if (getName() != other.getName())
+        return false;
+    return true;
+}
+
 ostream&
 operator<<(ostream& os, const AbstractRRset& rrset) {
     os << rrset.toText();

+ 8 - 0
src/lib/dns/rrset.h

@@ -475,6 +475,14 @@ public:
     /// \brief Clear the RRSIGs for this RRset
     virtual void removeRRsig() = 0;
 
+    /// \brief Check whether two RRsets are of the same kind
+    ///
+    /// Checks if two RRsets have the same name, RR type, and RR class.
+    ///
+    /// \param other Pointer to another AbstractRRset to compare
+    ///              against.
+    virtual bool isSameKind(const AbstractRRset& other);
+
     //@}
 };
 

+ 13 - 0
src/lib/dns/tests/rrset_unittest.cc

@@ -112,6 +112,19 @@ TEST_F(RRsetTest, setName) {
     EXPECT_EQ(test_nsname, rrset_a.getName());
 }
 
+TEST_F(RRsetTest, isSameKind) {
+    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));
+    RRset rrset_p(test_nsname, RRClass::IN(), RRType::A(), RRTTL(3600));
+
+    EXPECT_TRUE(rrset_w.isSameKind(rrset_x));
+    EXPECT_FALSE(rrset_w.isSameKind(rrset_y));
+    EXPECT_FALSE(rrset_w.isSameKind(rrset_z));
+    EXPECT_FALSE(rrset_w.isSameKind(rrset_p));
+}
+
 void
 addRdataTestCommon(const RRset& rrset) {
     EXPECT_EQ(2, rrset.getRdataCount());