From a2360caf9d69594b375a162928bbf13e02f9e163 Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Fri, 23 May 2014 08:55:29 +0200 Subject: [PATCH] [master] Unit tests for IAPREFIX compare IOAddress objects. The unit tests used to compare the addresses in the textual formats. Since IPv6 addresses may be presented in various ways, it led to false positives on some OSes. --- src/lib/dhcp/tests/option6_iaprefix_unittest.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/lib/dhcp/tests/option6_iaprefix_unittest.cc b/src/lib/dhcp/tests/option6_iaprefix_unittest.cc index 892f40b2fb..2861c478ee 100644 --- a/src/lib/dhcp/tests/option6_iaprefix_unittest.cc +++ b/src/lib/dhcp/tests/option6_iaprefix_unittest.cc @@ -85,15 +85,15 @@ public: /// @param opt IAPREFIX option being tested /// @param expected_type expected option type /// @param expected_length Expected length of the prefix. - /// @param expected_address Expected prefix value in the textual format. + /// @param expected_address Expected prefix value. void checkOption(Option6IAPrefix& opt, const uint16_t expected_type, const uint8_t expected_length, - const std::string& expected_address) { + const IOAddress& expected_address) { // Check if all fields have expected values EXPECT_EQ(Option::V6, opt.getUniverse()); EXPECT_EQ(expected_type, opt.getType()); - EXPECT_EQ(expected_address, opt.getAddress().toText()); + EXPECT_EQ(expected_address, opt.getAddress()); EXPECT_EQ(1000, opt.getPreferred()); EXPECT_EQ(3000000000U, opt.getValid()); // uint8_t is often represented as a character type (char). Convert it @@ -148,7 +148,7 @@ TEST_F(Option6IAPrefixTest, parseShort) { // The non-significant bits (above 77) of the received prefix should be // set to zero. - checkOption(*opt, D6O_IAPREFIX, 77, "2001:db8:1:0:afa8::"); + checkOption(*opt, D6O_IAPREFIX, 77, IOAddress("2001:db8:1:0:afa8::")); // Set non-significant bits in the reference buffer to 0, so as the buffer // can be directly compared with the option buffer. @@ -160,7 +160,7 @@ TEST_F(Option6IAPrefixTest, parseShort) { EXPECT_NO_THROW(opt.reset()); } -// Tests if a received option holding prefix of 128 bits is parsed correctly. +// Tests if a received option holding prefix of 128 bits is parsed correctly. TEST_F(Option6IAPrefixTest, parseLong) { setExampleBuffer(); @@ -177,7 +177,8 @@ TEST_F(Option6IAPrefixTest, parseLong) { opt->pack(out_buf_); EXPECT_EQ(29, out_buf_.getLength()); - checkOption(*opt, D6O_IAPREFIX, 128, "2001:db8:1:0:afaf:0:dead:beef"); + checkOption(*opt, D6O_IAPREFIX, 128, + IOAddress("2001:db8:1:0:afaf:0:dead:beef")); checkOutputBuffer(D6O_IAPREFIX); @@ -201,7 +202,7 @@ TEST_F(Option6IAPrefixTest, parseZero) { opt->pack(out_buf_); EXPECT_EQ(29, out_buf_.getLength()); - checkOption(*opt, D6O_IAPREFIX, 0, "::"); + checkOption(*opt, D6O_IAPREFIX, 0, IOAddress("::")); // Fill the address in the reference buffer with zeros. buf_.insert(buf_.begin() + 9, 16, 0); @@ -223,7 +224,7 @@ TEST_F(Option6IAPrefixTest, build) { 1000, 3000000000u))); ASSERT_TRUE(opt); - checkOption(*opt, 12345, 77, "2001:db8:1:0:afaf:0:dead:beef"); + checkOption(*opt, 12345, 77, IOAddress("2001:db8:1:0:afaf:0:dead:beef")); // Check if we can build it properly EXPECT_NO_THROW(opt->pack(out_buf_)); -- GitLab