BIND 10 trac2325, updated. 54663a3c7bda67a6813d2478ff44c8a07d9c48b8 [2325] Option::equal() method implemented.
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Nov 29 15:54:02 UTC 2012
The branch, trac2325 has been updated
via 54663a3c7bda67a6813d2478ff44c8a07d9c48b8 (commit)
from 00eee13bde95c741890ad3ca52967c11076c5087 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 54663a3c7bda67a6813d2478ff44c8a07d9c48b8
Author: Tomek Mrugalski <tomasz at isc.org>
Date: Thu Nov 29 16:53:37 2012 +0100
[2325] Option::equal() method implemented.
-----------------------------------------------------------------------
Summary of changes:
src/lib/dhcp/option.cc | 4 ++++
src/lib/dhcp/option.h | 17 +++++++++++++++--
src/lib/dhcp/tests/option_unittest.cc | 23 +++++++++++++++++++++++
3 files changed, 42 insertions(+), 2 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dhcp/option.cc b/src/lib/dhcp/option.cc
index 4638025..2a53f0f 100644
--- a/src/lib/dhcp/option.cc
+++ b/src/lib/dhcp/option.cc
@@ -314,6 +314,10 @@ void Option::setData(const OptionBufferConstIter first,
std::copy(first, last, data_.begin());
}
+bool Option::equal(const OptionPtr& other) const {
+ return ( (getType() == other->getType()) &&
+ (getData() == other->getData()) );
+}
Option::~Option() {
diff --git a/src/lib/dhcp/option.h b/src/lib/dhcp/option.h
index a6b0622..29f0f01 100644
--- a/src/lib/dhcp/option.h
+++ b/src/lib/dhcp/option.h
@@ -197,7 +197,7 @@ public:
/// Returns option type (0-255 for DHCPv4, 0-65535 for DHCPv6)
///
/// @return option type
- uint16_t getType() { return (type_); }
+ uint16_t getType() const { return (type_); }
/// Returns length of the complete option (data length + DHCPv4/DHCPv6
/// option header)
@@ -219,7 +219,7 @@ public:
///
/// @return pointer to actual data (or reference to an empty vector
/// if there is no data)
- virtual const OptionBuffer& getData() { return (data_); }
+ virtual const OptionBuffer& getData() const { return (data_); }
/// Adds a sub-option.
///
@@ -303,6 +303,19 @@ public:
/// just to force that every option has virtual dtor
virtual ~Option();
+ /// @brief Checks if two options are equal
+ ///
+ /// Equality verifies option type and option content. Care should
+ /// be taken when using this method. Implementation for derived
+ /// classes should be provided when this method is expected to be
+ /// used. It is safe in general, as the first check (different types)
+ /// will detect differences between base Option and derived
+ /// objects.
+ ///
+ /// @param other the other option
+ /// @return true if both options are equal
+ virtual bool equal(const OptionPtr& other) const;
+
protected:
/// Builds raw (over-wire) buffer of this option, including all
/// defined suboptions. Version for building DHCPv4 options.
diff --git a/src/lib/dhcp/tests/option_unittest.cc b/src/lib/dhcp/tests/option_unittest.cc
index 50d143f..afa64d5 100644
--- a/src/lib/dhcp/tests/option_unittest.cc
+++ b/src/lib/dhcp/tests/option_unittest.cc
@@ -524,4 +524,27 @@ TEST_F(OptionTest, setData) {
EXPECT_TRUE(0 == memcmp(&buf_[0], test_data + opt1->getHeaderLen(),
buf_.size()));
}
+
+// This test verifies that options can be compared using equal() method.
+TEST_F(OptionTest, equal) {
+
+ // five options with varying lengths
+ OptionPtr opt1(new Option(Option::V6, 258, buf_.begin(), buf_.begin() + 1));
+ OptionPtr opt2(new Option(Option::V6, 258, buf_.begin(), buf_.begin() + 2));
+ OptionPtr opt3(new Option(Option::V6, 258, buf_.begin(), buf_.begin() + 3));
+
+ // the same content as opt2, but different type
+ OptionPtr opt4(new Option(Option::V6, 1, buf_.begin(), buf_.begin() + 2));
+
+ // another instance with the same type and content as opt2
+ OptionPtr opt5(new Option(Option::V6, 258, buf_.begin(), buf_.begin() + 2));
+
+ EXPECT_TRUE(opt1->equal(opt1));
+
+ EXPECT_FALSE(opt1->equal(opt2));
+ EXPECT_FALSE(opt1->equal(opt3));
+ EXPECT_FALSE(opt1->equal(opt4));
+
+ EXPECT_TRUE(opt2->equal(opt5));
+}
}
More information about the bind10-changes
mailing list