BIND 10 trac1955, updated. 0235da81624be30ea2aeadaf1c93fde1ba1bd057 [1955] Corrections to timestamp unit tests in dhcp::PktN.

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Jun 11 11:32:18 UTC 2012


The branch, trac1955 has been updated
       via  0235da81624be30ea2aeadaf1c93fde1ba1bd057 (commit)
       via  8cecc1ec807f782e4fde4f5a21463c304bd07223 (commit)
      from  ce911b68e171ddced13c91ced5e7a1d417ad62ca (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 0235da81624be30ea2aeadaf1c93fde1ba1bd057
Author: Marcin Siodelski <marcin at isc.org>
Date:   Mon Jun 11 13:30:36 2012 +0200

    [1955] Corrections to timestamp unit tests in dhcp::PktN.

commit 8cecc1ec807f782e4fde4f5a21463c304bd07223
Author: Marcin Siodelski <marcin at isc.org>
Date:   Mon Jun 11 13:23:31 2012 +0200

    [1955] Added setData() unit test for dhcp::Option.

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

Summary of changes:
 src/lib/dhcp/option.cc                |    8 ++------
 src/lib/dhcp/tests/option_unittest.cc |   29 ++++++++++++++++++++++++++++-
 src/lib/dhcp/tests/pkt4_unittest.cc   |    7 ++++---
 src/lib/dhcp/tests/pkt6_unittest.cc   |    8 +++++---
 4 files changed, 39 insertions(+), 13 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/dhcp/option.cc b/src/lib/dhcp/option.cc
index ed3f9dd..0c71606 100644
--- a/src/lib/dhcp/option.cc
+++ b/src/lib/dhcp/option.cc
@@ -273,12 +273,8 @@ void Option::setUint32(uint32_t value) {
 void Option::setData(const OptionBufferConstIter first,
                      const OptionBufferConstIter last) {
     // We will copy entire option buffer, so we have to resize data_.
-    data_.resize(last - first);
-    OptionBufferConstIter x = first;
-    while (x != last) {
-        data_[x - first] = *x;
-        ++x;
-    }
+    data_.resize(std::distance(first, last));
+    std::copy(first, last, data_.begin());
 }
 
 
diff --git a/src/lib/dhcp/tests/option_unittest.cc b/src/lib/dhcp/tests/option_unittest.cc
index 5daf75d..9b046f0 100644
--- a/src/lib/dhcp/tests/option_unittest.cc
+++ b/src/lib/dhcp/tests/option_unittest.cc
@@ -485,7 +485,7 @@ TEST_F(OptionTest, setUintX) {
     uint8_t exp2[] = {125, 2, 12345/256, 12345%256};
     EXPECT_TRUE(0 == memcmp(exp2, outBuf_.getData(), 4));
 
-    // verity getUint32
+    // verify getUint32
     outBuf_.clear();
     opt4->setUint32(0x12345678);
     opt4->pack4(outBuf_);
@@ -495,4 +495,31 @@ TEST_F(OptionTest, setUintX) {
     uint8_t exp4[] = {125, 4, 0x12, 0x34, 0x56, 0x78};
     EXPECT_TRUE(0 == memcmp(exp4, outBuf_.getData(), 6));
 }
+
+TEST_F(OptionTest, setData) {
+    // verify data override with new buffer larger than
+    // initial option buffer size
+    OptionPtr opt1(new Option(Option::V4, 125,
+                              buf_.begin(), buf_.begin() + 10));
+    buf_.resize(20, 1);
+    opt1->setData(buf_.begin(), buf_.end());
+    opt1->pack4(outBuf_);
+    ASSERT_EQ(outBuf_.getLength() - opt1->getHeaderLen(), buf_.size());
+    const uint8_t* test_data = static_cast<const uint8_t*>(outBuf_.getData());
+    EXPECT_TRUE(0 == memcmp(&buf_[0], test_data + opt1->getHeaderLen(),
+                            buf_.size()));
+
+    // verify data override with new buffer shorter than
+    // initial option buffer size
+    OptionPtr opt2(new Option(Option::V4, 125,
+                              buf_.begin(), buf_.begin() + 10));
+    outBuf_.clear();
+    buf_.resize(5, 1);
+    opt2->setData(buf_.begin(), buf_.end());
+    opt2->pack4(outBuf_);
+    ASSERT_EQ(outBuf_.getLength() - opt1->getHeaderLen(), buf_.size());
+    test_data = static_cast<const uint8_t*>(outBuf_.getData());
+    EXPECT_TRUE(0 == memcmp(&buf_[0], test_data + opt1->getHeaderLen(),
+                            buf_.size()));
+}
 }
diff --git a/src/lib/dhcp/tests/pkt4_unittest.cc b/src/lib/dhcp/tests/pkt4_unittest.cc
index 1ac8477..e443b65 100644
--- a/src/lib/dhcp/tests/pkt4_unittest.cc
+++ b/src/lib/dhcp/tests/pkt4_unittest.cc
@@ -599,7 +599,10 @@ TEST(Pkt4Test, metaFields) {
 }
 
 TEST(Pkt4Test, Timestamp) {
-    Pkt4* pkt = new Pkt4(DHCPOFFER, 1234);
+    scoped_ptr<Pkt4> pkt(new Pkt4(DHCPOFFER, 1234));
+
+    // Just after construction timestamp is invalid
+    ASSERT_TRUE(pkt->getTimestamp().is_not_a_date_time());
 
     // Update packet time.
     pkt->updateTimestamp();
@@ -619,8 +622,6 @@ TEST(Pkt4Test, Timestamp) {
 
     // Duration should be positive or zero.
     EXPECT_TRUE(ts_period.length().total_microseconds() >= 0);
-
-    delete pkt;
 }
 
 
diff --git a/src/lib/dhcp/tests/pkt6_unittest.cc b/src/lib/dhcp/tests/pkt6_unittest.cc
index fdc9733..d6ca9b1 100644
--- a/src/lib/dhcp/tests/pkt6_unittest.cc
+++ b/src/lib/dhcp/tests/pkt6_unittest.cc
@@ -206,7 +206,11 @@ TEST_F(Pkt6Test, addGetDelOptions) {
 }
 
 TEST_F(Pkt6Test, Timestamp) {
-    Pkt6* pkt = new Pkt6(DHCPV6_SOLICIT, 0x020304);
+    boost::scoped_ptr<Pkt6> pkt(new Pkt6(DHCPV6_SOLICIT, 0x020304));
+
+    // Just after construction timestamp is invalid
+    ASSERT_TRUE(pkt->getTimestamp().is_not_a_date_time());
+
     // Update packet time.
     pkt->updateTimestamp();
 
@@ -225,8 +229,6 @@ TEST_F(Pkt6Test, Timestamp) {
 
     // Duration should be positive or zero.
     EXPECT_TRUE(ts_period.length().total_microseconds() >= 0);
-
-    delete pkt;
 }
 
 }



More information about the bind10-changes mailing list