BIND 10 trac2312, updated. 47e1dfee342b4b1fc269109d130bea5eeeff743f [2312] Added the method to return number of option data field.
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Nov 27 13:34:56 UTC 2012
The branch, trac2312 has been updated
via 47e1dfee342b4b1fc269109d130bea5eeeff743f (commit)
via deaf3af3f2b12e34dee77b31ff28748cbaef3778 (commit)
from 276a08d3371eef268c0e0b738d0c8583c3d8641d (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 47e1dfee342b4b1fc269109d130bea5eeeff743f
Author: Marcin Siodelski <marcin at isc.org>
Date: Tue Nov 27 14:32:34 2012 +0100
[2312] Added the method to return number of option data field.
commit deaf3af3f2b12e34dee77b31ff28748cbaef3778
Author: Marcin Siodelski <marcin at isc.org>
Date: Tue Nov 27 14:21:03 2012 +0100
[2312] Constructor unit test.
-----------------------------------------------------------------------
Summary of changes:
src/lib/dhcp/option_custom.h | 5 ++
src/lib/dhcp/tests/option_custom_unittest.cc | 98 ++++++++++++++++++++++++--
2 files changed, 99 insertions(+), 4 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dhcp/option_custom.h b/src/lib/dhcp/option_custom.h
index 5c792cb..10b2b79 100644
--- a/src/lib/dhcp/option_custom.h
+++ b/src/lib/dhcp/option_custom.h
@@ -64,6 +64,11 @@ public:
OptionCustom(const OptionDefinition& def, Universe u,
OptionBufferConstIter first, OptionBufferConstIter last);
+ /// @brief Return a number of the data fields.
+ ///
+ /// @return number of data fields held by the option.
+ uint32_t getDataFieldsNum() const { return (buffers_.size()); }
+
/// @brief Read a buffer as IP address.
///
/// @param index buffer index.
diff --git a/src/lib/dhcp/tests/option_custom_unittest.cc b/src/lib/dhcp/tests/option_custom_unittest.cc
index bdb0322..bfde9e4 100644
--- a/src/lib/dhcp/tests/option_custom_unittest.cc
+++ b/src/lib/dhcp/tests/option_custom_unittest.cc
@@ -32,6 +32,10 @@ public:
/// @brief Constructor.
OptionCustomTest() { }
+ /// @brief Write IP address into a buffer.
+ ///
+ /// @param address address to be written.
+ /// @param [out] buf output buffer.
void writeAddress(const asiolink::IOAddress& address,
std::vector<uint8_t>& buf) {
short family = address.getFamily();
@@ -46,6 +50,11 @@ public:
}
}
+ /// @brief Write integer (signed or unsiged) into a buffer.
+ ///
+ /// @param value integer value.
+ /// @param [out] buf output buffer.
+ /// @tparam integer type.
template<typename T>
void writeInt(T value, std::vector<uint8_t>& buf) {
for (int i = 0; i < sizeof(T); ++i) {
@@ -53,6 +62,10 @@ public:
}
}
+ /// @brief Write a string into a buffer.
+ ///
+ /// @param value string to be written into a buffer.
+ /// @param buf output buffer.
void writeString(const std::string& value,
std::vector<uint8_t>& buf) {
buf.resize(buf.size() + value.size());
@@ -61,9 +74,38 @@ public:
}
};
+// The purpose of this test is to check that parameters passed to
+// a custom option's constructor are used to initialize class
+// members.
TEST_F(OptionCustomTest, constructor) {
- /* OptionDefinition opt_def1("OPTION_FOO", 1000, "string", true);
- ASSERT_THROW(opt_def1.validate(), isc::Exception); */
+ // Create option definition for a DHCPv6 option.
+ OptionDefinition opt_def1("OPTION_FOO", 1000, "boolean", true);
+
+ // Initialize some dummy buffer that holds single boolean value.
+ OptionBuffer buf;
+ buf.push_back(1);
+
+ // Create DHCPv6 option.
+ boost::scoped_ptr<OptionCustom> option;
+ ASSERT_NO_THROW(
+ option.reset(new OptionCustom(opt_def1, Option::V6, buf));
+ );
+ ASSERT_TRUE(option);
+
+ // Check if constructor initialized the universe and type correctly.
+ EXPECT_EQ(Option::V6, option->getUniverse());
+ EXPECT_EQ(1000, option->getType());
+
+ // Do another round of testing for DHCPv4 option.
+ OptionDefinition opt_def2("OPTION_FOO", 232, "boolean");
+
+ ASSERT_NO_THROW(
+ option.reset(new OptionCustom(opt_def2, Option::V4, buf.begin(), buf.end()));
+ );
+ ASSERT_TRUE(option);
+
+ EXPECT_EQ(Option::V4, option->getUniverse());
+ EXPECT_EQ(232, option->getType());
}
// The purpose of this test is to verify that 'empty' option definition can
@@ -76,6 +118,9 @@ TEST_F(OptionCustomTest, emptyData) {
option.reset(new OptionCustom(opt_def, Option::V4, OptionBuffer()));
);
ASSERT_TRUE(option);
+
+ // Option is 'empty' so no data fields are expected.
+ EXPECT_EQ(0, option->getDataFieldsNum());
}
// The purpose of this test is to verify that the option definition comprising
@@ -100,6 +145,9 @@ TEST_F(OptionCustomTest, binaryData) {
);
ASSERT_TRUE(option);
+ // We should have just one data field.
+ ASSERT_EQ(1, option->getDataFieldsNum());
+
// The custom option should hold just one buffer that can be
// accessed using index 0.
OptionBuffer buf_out;
@@ -130,6 +178,9 @@ TEST_F(OptionCustomTest, booleanData) {
);
ASSERT_TRUE(option);
+ // We should have just one data field.
+ ASSERT_EQ(1, option->getDataFieldsNum());
+
// Initialize the value to true because we want to make sure
// that it is modified to 'false' by readBoolean below.
bool value = true;
@@ -156,6 +207,9 @@ TEST_F(OptionCustomTest, int16Data) {
);
ASSERT_TRUE(option);
+ // We should have just one data field.
+ ASSERT_EQ(1, option->getDataFieldsNum());
+
// Initialize value to 0 explicitely to make sure that is
// modified by readInteger function to expected -234.
int16_t value = 0;
@@ -179,6 +233,9 @@ TEST_F(OptionCustomTest, ipv4AddressData) {
);
ASSERT_TRUE(option);
+ // We should have just one data field.
+ ASSERT_EQ(1, option->getDataFieldsNum());
+
IOAddress address("127.0.0.1");
// Read IPv4 address from using index 0.
ASSERT_NO_THROW(option->readAddress(0, address));
@@ -202,6 +259,9 @@ TEST_F(OptionCustomTest, ipv6AddressData) {
);
ASSERT_TRUE(option);
+ // We should have just one data field.
+ ASSERT_EQ(1, option->getDataFieldsNum());
+
// Custom option should comprise exactly one buffer that represents
// IPv6 address.
IOAddress address("::1");
@@ -227,6 +287,9 @@ TEST_F(OptionCustomTest, stringData) {
);
ASSERT_TRUE(option);
+ // We should have just one data field.
+ ASSERT_EQ(1, option->getDataFieldsNum());
+
// Custom option should now comprise single string value that
// can be accessed using index 0.
std::string value;
@@ -256,6 +319,9 @@ TEST_F(OptionCustomTest, booleanDataArray) {
);
ASSERT_TRUE(option);
+ // We should have 5 data fields.
+ ASSERT_EQ(5, option->getDataFieldsNum());
+
// Read values from custom option using indexes 0..4 and
// check that they are valid.
bool value0 = false;
@@ -308,6 +374,9 @@ TEST_F(OptionCustomTest, uint32DataArray) {
);
ASSERT_TRUE(option);
+ // We should have 3 data fields.
+ ASSERT_EQ(3, option->getDataFieldsNum());
+
// Expect only 3 values.
for (int i = 0; i < 3; ++i) {
uint32_t value = 0;
@@ -340,6 +409,9 @@ TEST_F(OptionCustomTest, ipv4AddressDataArray) {
);
ASSERT_TRUE(option);
+ // We should have 3 data fields.
+ ASSERT_EQ(3, option->getDataFieldsNum());
+
// We expect 3 IPv4 addresses being stored in the option.
for (int i = 0; i < 3; ++i) {
IOAddress address("10.10.10.10");
@@ -368,10 +440,13 @@ TEST_F(OptionCustomTest, ipv6AddressDataArray) {
// Use the input buffer to create custom option.
boost::scoped_ptr<OptionCustom> option;
ASSERT_NO_THROW(
- option.reset(new OptionCustom(opt_def, Option::V6, buf.begin(), buf.begin() + 70));
+ option.reset(new OptionCustom(opt_def, Option::V6, buf.begin(), buf.begin() + 50));
);
ASSERT_TRUE(option);
+ // We should have 3 data fields.
+ ASSERT_EQ(3, option->getDataFieldsNum());
+
// We expect 3 IPv6 addresses being stored in the option.
for (int i = 0; i < 3; ++i) {
IOAddress address("fe80::4");
@@ -411,6 +486,9 @@ TEST_F(OptionCustomTest, recordData) {
);
ASSERT_TRUE(option);
+ // We should have 5 data fields.
+ ASSERT_EQ(5, option->getDataFieldsNum());
+
// Verify value in the field 0.
uint16_t value0 = 0;
ASSERT_NO_THROW(value0 = option->readInteger<uint16_t>(0));
@@ -529,6 +607,9 @@ TEST_F(OptionCustomTest, unpack) {
);
ASSERT_TRUE(option);
+ // We should have 3 data fields.
+ ASSERT_EQ(3, option->getDataFieldsNum());
+
// We expect 3 IPv4 addresses being stored in the option.
for (int i = 0; i < 3; ++i) {
IOAddress address("10.10.10.10");
@@ -553,6 +634,9 @@ TEST_F(OptionCustomTest, unpack) {
// Perform 'unpack'.
ASSERT_NO_THROW(option->unpack(buf.begin(), buf.end()));
+ // Now we should have only 2 data fields.
+ ASSERT_EQ(2, option->getDataFieldsNum());
+
// Verify that the addresses have been overwritten.
for (int i = 0; i < 2; ++i) {
IOAddress address("10.10.10.10");
@@ -582,10 +666,13 @@ TEST_F(OptionCustomTest, setData)
// Use the input buffer to create custom option.
boost::scoped_ptr<OptionCustom> option;
ASSERT_NO_THROW(
- option.reset(new OptionCustom(opt_def, Option::V6, buf.begin(), buf.begin() + 70));
+ option.reset(new OptionCustom(opt_def, Option::V6, buf.begin(), buf.begin() + 50));
);
ASSERT_TRUE(option);
+ // We should have 3 data fields.
+ ASSERT_EQ(3, option->getDataFieldsNum());
+
// We expect 3 IPv6 addresses being stored in the option.
for (int i = 0; i < 3; ++i) {
IOAddress address("fe80::4");
@@ -609,6 +696,9 @@ TEST_F(OptionCustomTest, setData)
// Replace the option data.
ASSERT_NO_THROW(option->setData(buf.begin(), buf.end()));
+ // Now we should have only 2 data fields.
+ ASSERT_EQ(2, option->getDataFieldsNum());
+
// Check that it has been replaced.
for (int i = 0; i < 2; ++i) {
IOAddress address("10.10.10.10");
More information about the bind10-changes
mailing list