]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1748] Define AbstractRRset::isSameKind() and implement the default version
authorMukund Sivaraman <muks@isc.org>
Fri, 9 Mar 2012 06:59:23 +0000 (12:29 +0530)
committerMukund Sivaraman <muks@isc.org>
Wed, 14 Mar 2012 02:18:42 +0000 (07:48 +0530)
src/lib/dns/rrset.cc
src/lib/dns/rrset.h
src/lib/dns/tests/rrset_unittest.cc

index 776d49f6506eb91b8b52a112a5ba485c996f29de..40a8ac111588e8a9bf099dcc8d879dfa85061905 100644 (file)
@@ -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();
index 5042a98f55077a771c5d23123af5f81ddb33014d..4d8ca6549ca74e0e409555db3ee705bd69282a2a 100644 (file)
@@ -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);
+
     //@}
 };
 
index a6bfe5695b2d5644e2cbdfe3cdc74154a56dbfad..6570be678c3320ac13c37e11eb943cff88b487c3 100644 (file)
@@ -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());