Browse Source

[master] Merge branch 'master' of ssh://git.bind10.isc.org/var/bind10/git/bind10

JINMEI Tatuya 12 years ago
parent
commit
aa9c2bbcf4

+ 8 - 5
src/lib/dhcp/tests/option6_int_unittest.cc

@@ -303,7 +303,9 @@ TEST_F(Option6IntTest, setValueint32) {
 }
 }
 
 
 TEST_F(Option6IntTest, packSuboptions) {
 TEST_F(Option6IntTest, packSuboptions) {
-    uint16_t opt_code = 80;
+    // option code is really uint16_t, but using uint8_t
+    // for easier conversion to uint8_t array.
+    uint8_t opt_code = 80;
 
 
     boost::shared_ptr<Option6Int<uint32_t> > opt(new Option6Int<uint32_t>(opt_code, 0x01020304));
     boost::shared_ptr<Option6Int<uint32_t> > opt(new Option6Int<uint32_t>(opt_code, 0x01020304));
     OptionPtr sub1(new Option(Option::V6, 0xcafe));
     OptionPtr sub1(new Option(Option::V6, 0xcafe));
@@ -319,7 +321,7 @@ TEST_F(Option6IntTest, packSuboptions) {
     ASSERT_EQ(40, opt->len());
     ASSERT_EQ(40, opt->len());
 
 
     uint8_t expected[] = {
     uint8_t expected[] = {
-        opt_code / 256, opt_code % 256, // type
+        0, opt_code, // type
         0, 36, // length
         0, 36, // length
         0x01, 0x02, 0x03, 0x04, // uint32_t value
         0x01, 0x02, 0x03, 0x04, // uint32_t value
 
 
@@ -345,11 +347,12 @@ TEST_F(Option6IntTest, packSuboptions) {
 
 
 
 
 TEST_F(Option6IntTest, unpackSuboptions) {
 TEST_F(Option6IntTest, unpackSuboptions) {
-    // Create some dummy option.
-    const uint16_t opt_code = 80;
+    // option code is really uint16_t, but using uint8_t
+    // for easier conversion to uint8_t array.
+    const uint8_t opt_code = 80;
     // Prepare reference data.
     // Prepare reference data.
     uint8_t expected[] = {
     uint8_t expected[] = {
-        opt_code / 256, opt_code % 256, // type
+        0, opt_code, // type
         0, 34, // length
         0, 34, // length
         0x01, 0x02, // uint16_t value
         0x01, 0x02, // uint16_t value
 
 

+ 19 - 18
src/lib/dhcp/tests/option_definition_unittest.cc

@@ -163,11 +163,13 @@ TEST_F(OptionDefinitionTest, factoryAddrList6) {
     addrs.push_back(asiolink::IOAddress("::2"));
     addrs.push_back(asiolink::IOAddress("::2"));
 
 
     // Write addresses to the buffer.
     // Write addresses to the buffer.
-    OptionBuffer buf;
+    OptionBuffer buf(addrs.size() * asiolink::V6ADDRESS_LEN);
     for (int i = 0; i < addrs.size(); ++i) {
     for (int i = 0; i < addrs.size(); ++i) {
-        unsigned char* data = addrs[i].getAddress().to_v6().to_bytes().data();
-        // @todo Are there any sanity checks needed here on this raw pointer?
-        buf.insert(buf.end(), data, data + asiolink::V6ADDRESS_LEN);
+        asio::ip::address_v6::bytes_type addr_bytes =
+            addrs[i].getAddress().to_v6().to_bytes();
+        ASSERT_EQ(asiolink::V6ADDRESS_LEN, addr_bytes.size());
+        std::copy(addr_bytes.begin(), addr_bytes.end(),
+                  buf.begin() + i * asiolink::V6ADDRESS_LEN);
     }
     }
     // Create DHCPv6 option from this buffer. Once option is created it is
     // Create DHCPv6 option from this buffer. Once option is created it is
     // supposed to have internal list of addresses that it parses out from
     // supposed to have internal list of addresses that it parses out from
@@ -213,11 +215,13 @@ TEST_F(OptionDefinitionTest, factoryAddrList4) {
     addrs.push_back(asiolink::IOAddress("213.41.23.12"));
     addrs.push_back(asiolink::IOAddress("213.41.23.12"));
 
 
     // Write addresses to the buffer.
     // Write addresses to the buffer.
-    OptionBuffer buf;
+    OptionBuffer buf(addrs.size() * asiolink::V4ADDRESS_LEN);
     for (int i = 0; i < addrs.size(); ++i) {
     for (int i = 0; i < addrs.size(); ++i) {
-        unsigned char* data = addrs[i].getAddress().to_v4().to_bytes().data();
-        // @todo Are there any sanity checks needed here on this raw pointer?
-        buf.insert(buf.end(), data, data + asiolink::V4ADDRESS_LEN);
+        asio::ip::address_v4::bytes_type addr_bytes =
+            addrs[i].getAddress().to_v4().to_bytes();
+        ASSERT_EQ(asiolink::V4ADDRESS_LEN, addr_bytes.size());
+        std::copy(addr_bytes.begin(), addr_bytes.end(),
+                  buf.begin() + i * asiolink::V4ADDRESS_LEN);
     }
     }
     // Create DHCPv6 option from this buffer. Once option is created it is
     // Create DHCPv6 option from this buffer. Once option is created it is
     // supposed to have internal list of addresses that it parses out from
     // supposed to have internal list of addresses that it parses out from
@@ -339,20 +343,17 @@ TEST_F(OptionDefinitionTest, factoryIAAddr6) {
     // Check the positive scenario.
     // Check the positive scenario.
     OptionPtr option_v6;
     OptionPtr option_v6;
     asiolink::IOAddress addr_v6("2001:0db8::ff00:0042:8329");
     asiolink::IOAddress addr_v6("2001:0db8::ff00:0042:8329");
+    OptionBuffer buf(asiolink::V6ADDRESS_LEN);
     ASSERT_TRUE(addr_v6.getAddress().is_v6());
     ASSERT_TRUE(addr_v6.getAddress().is_v6());
-    unsigned char* addr_bytes_v6 = addr_v6.getAddress().to_v6().to_bytes().data();
-    ASSERT_TRUE(addr_bytes_v6 != NULL);
-    OptionBuffer buf;
-    buf.insert(buf.end(), addr_bytes_v6, addr_bytes_v6 + asiolink::V6ADDRESS_LEN);
+    asio::ip::address_v6::bytes_type addr_bytes =
+        addr_v6.getAddress().to_v6().to_bytes();
+    ASSERT_EQ(asiolink::V6ADDRESS_LEN, addr_bytes.size());
+    std::copy(addr_bytes.begin(), addr_bytes.end(), buf.begin());
+
     for (int i = 0; i < option6_iaaddr_len - asiolink::V6ADDRESS_LEN; ++i) {
     for (int i = 0; i < option6_iaaddr_len - asiolink::V6ADDRESS_LEN; ++i) {
         buf.push_back(i);
         buf.push_back(i);
     }
     }
-    //    ASSERT_NO_THROW(option_v6 = factory(Option::V6, D6O_IAADDR, buf));
-    try {
-        option_v6 = factory(Option::V6, D6O_IAADDR, buf);
-    } catch (const Exception& e) {
-        std::cout << e.what() << std::endl;
-    }
+    ASSERT_NO_THROW(option_v6 = factory(Option::V6, D6O_IAADDR, buf));
     ASSERT_TRUE(typeid(*option_v6) == typeid(Option6IAAddr));
     ASSERT_TRUE(typeid(*option_v6) == typeid(Option6IAAddr));
     boost::shared_ptr<Option6IAAddr> option_cast_v6 =
     boost::shared_ptr<Option6IAAddr> option_cast_v6 =
         boost::static_pointer_cast<Option6IAAddr>(option_v6);
         boost::static_pointer_cast<Option6IAAddr>(option_v6);