From: Mukund Sivaraman Date: Fri, 9 Mar 2012 06:59:23 +0000 (+0530) Subject: [1748] Define AbstractRRset::isSameKind() and implement the default version X-Git-Tag: trac2351_base~226^2~116^2~127^2~1^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=64eef65d27bf5310afa53cac418c18bc8a989b31;p=thirdparty%2Fkea.git [1748] Define AbstractRRset::isSameKind() and implement the default version --- diff --git a/src/lib/dns/rrset.cc b/src/lib/dns/rrset.cc index 776d49f650..40a8ac1115 100644 --- a/src/lib/dns/rrset.cc +++ b/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(); diff --git a/src/lib/dns/rrset.h b/src/lib/dns/rrset.h index 5042a98f55..4d8ca6549c 100644 --- a/src/lib/dns/rrset.h +++ b/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); + //@} }; diff --git a/src/lib/dns/tests/rrset_unittest.cc b/src/lib/dns/tests/rrset_unittest.cc index a6bfe5695b..6570be678c 100644 --- a/src/lib/dns/tests/rrset_unittest.cc +++ b/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());