Browse Source

clang compilation fix (now using C++ cast in option.cc, also added test)

Tomek Mrugalski 13 years ago
parent
commit
937b5a6f47
2 changed files with 14 additions and 2 deletions
  1. 2 2
      src/lib/dhcp/option.cc
  2. 12 0
      src/lib/dhcp/tests/option_unittest.cc

+ 2 - 2
src/lib/dhcp/option.cc

@@ -213,14 +213,14 @@ std::string Option::toText(int indent /* =0 */ ) {
     for (int i=0; i<indent; i++)
     for (int i=0; i<indent; i++)
         tmp << " ";
         tmp << " ";
 
 
-    tmp << "type=" << type_ << ", len=" << data_len_ << ":";
+    tmp << "type=" << type_ << ", len=" << data_len_ << ": ";
 
 
     for (unsigned int i=0; i<data_len_; i++) {
     for (unsigned int i=0; i<data_len_; i++) {
         if (i) {
         if (i) {
             tmp << ":";
             tmp << ":";
         }
         }
         tmp << setfill('0') << setw(2) << hex
         tmp << setfill('0') << setw(2) << hex
-            << (unsigned short)(unsigned uint8_t)data_[offset_+i];
+            << static_cast<unsigned short>(data_[offset_+i]);
     }
     }
 
 
     // print suboptions
     // print suboptions

+ 12 - 0
src/lib/dhcp/tests/option_unittest.cc

@@ -265,3 +265,15 @@ TEST_F(OptionTest, addgetdel) {
 }
 }
 
 
 }
 }
+
+TEST_F(OptionTest, toText) {
+    boost::shared_array<uint8_t> buf(new uint8_t[3]);
+    buf[0] = 0;
+    buf[1] = 0xf;
+    buf[2] = 0xff;
+
+    boost::shared_ptr<Option> opt(new Option(Option::V6, 258,
+                                             buf, 0, 3));
+
+    EXPECT_EQ("type=258, len=3: 00:0f:ff", opt->toText());
+}