BIND 10 trac2491, updated. 1dc0f0871d7045e8fb57bb0767fc31a2f7e3fe80 [2491] Add a function to set binary data for a data field.

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Nov 30 17:06:42 UTC 2012


The branch, trac2491 has been updated
       via  1dc0f0871d7045e8fb57bb0767fc31a2f7e3fe80 (commit)
      from  1bbe13152cea9e759bb0423750f244be58eff578 (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 1dc0f0871d7045e8fb57bb0767fc31a2f7e3fe80
Author: Marcin Siodelski <marcin at isc.org>
Date:   Fri Nov 30 18:06:26 2012 +0100

    [2491] Add a function to set binary data for a data field.

-----------------------------------------------------------------------

Summary of changes:
 src/lib/dhcp/option_custom.cc                |    7 ++++++
 src/lib/dhcp/option_custom.h                 |    6 +++++
 src/lib/dhcp/tests/option_custom_unittest.cc |   34 ++++++++++++++++++++++++++
 3 files changed, 47 insertions(+)

-----------------------------------------------------------------------
diff --git a/src/lib/dhcp/option_custom.cc b/src/lib/dhcp/option_custom.cc
index ba84519..11e124c 100644
--- a/src/lib/dhcp/option_custom.cc
+++ b/src/lib/dhcp/option_custom.cc
@@ -390,6 +390,13 @@ OptionCustom::readBinary(const uint32_t index) const {
     return (buffers_[index]);
 }
 
+void
+OptionCustom::writeBinary(const OptionBuffer& buf,
+                          const uint32_t index) {
+    checkIndex(index);
+    buffers_[index] = buf;
+}
+
 bool
 OptionCustom::readBoolean(const uint32_t index) const {
     checkIndex(index);
diff --git a/src/lib/dhcp/option_custom.h b/src/lib/dhcp/option_custom.h
index 64d9886..7be9ab5 100644
--- a/src/lib/dhcp/option_custom.h
+++ b/src/lib/dhcp/option_custom.h
@@ -118,6 +118,12 @@ public:
     /// @return read buffer holding binary data.
     const OptionBuffer& readBinary(const uint32_t index = 0) const;
 
+    /// @brief Write binary data into a buffer.
+    ///
+    /// @param buf buffer holding binary data to be written.
+    /// @param index buffer index.
+    void writeBinary(const OptionBuffer& buf, const uint32_t index = 0);
+
     /// @brief Read a buffer as boolean value.
     ///
     /// @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 da5903f..16148ee 100644
--- a/src/lib/dhcp/tests/option_custom_unittest.cc
+++ b/src/lib/dhcp/tests/option_custom_unittest.cc
@@ -789,6 +789,40 @@ TEST_F(OptionCustomTest, recordDataTruncated) {
 }
 
 // The purpose of this test is to verify that an option comprising
+// single data field with binary data can be used and that this
+// binary data is properly initialized to a default value. This
+// test also checks that it is possible to override this default
+// value.
+TEST_F(OptionCustomTest, setBinaryData) {
+    OptionDefinition opt_def("OPTION_FOO", 1000, "binary");
+
+    // Create an option and let the data field be initialized
+    // to default value (do not provide any data buffer).
+    boost::scoped_ptr<OptionCustom> option;
+    ASSERT_NO_THROW(
+        option.reset(new OptionCustom(opt_def, Option::V6));
+    );
+    ASSERT_TRUE(option);
+
+    // Get the default binary value.
+    OptionBuffer buf;
+    ASSERT_NO_THROW(option->readBinary());
+    // The buffer is by default empty.
+    EXPECT_TRUE(buf.empty());
+    // Prepare input buffer with some dummy data.
+    OptionBuffer buf_in(10);
+    for (int i = 0; i < buf_in.size(); ++i) {
+        buf_in[i] = i;
+    }
+    // Try to override the default binary buffer.
+    ASSERT_NO_THROW(option->writeBinary(buf_in));
+    // And check that it has been actually overriden.
+    ASSERT_NO_THROW(buf = option->readBinary());
+    ASSERT_EQ(buf_in.size(), buf.size());
+    EXPECT_TRUE(std::equal(buf_in.begin(), buf_in.end(), buf.begin()));
+}
+
+// The purpose of this test is to verify that an option comprising
 // single boolean data field can be created and that its default
 // value can be overriden by a new value.
 TEST_F(OptionCustomTest, setBooleanData) {



More information about the bind10-changes mailing list