Commit 8dedd713 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[2949] Another unit-tests improvement for inf-request

parent 4d23b59a
......@@ -621,5 +621,35 @@ NakedDhcpv6SrvTest::generateIA(uint16_t type, uint32_t iaid, uint32_t t1,
return (ia);
}
bool
Dhcpv6SrvTest::compareOptions(const isc::dhcp::OptionPtr& option1,
const isc::dhcp::OptionPtr& option2) {
if ((!option1 && option2) || (option1 && !option2)) {
return (false);
}
if (!option1 && !option2) {
return (true);
}
// We could start by comparing option codes and option lengths
// here, but it's just a waste of time. These are tests, so they
// don't have to be super performant. The pack+memcmp approach
// verifies all in one go.
isc::util::OutputBuffer buf1(0);
isc::util::OutputBuffer buf2(0);
option1->pack(buf1);
option2->pack(buf2);
if (buf1.getLength() != buf2.getLength()) {
return (false);
}
// memcmp returns 0 when equal.
return (!memcmp(buf1.getData(), buf2.getData(), buf1.getLength()));
}
}; // end of isc::test namespace
}; // end of isc namespace
......@@ -462,6 +462,22 @@ public:
const isc::asiolink::IOAddress& addr,
const uint8_t prefix_len, const uint32_t iaid);
/// @brief Compare options
///
/// This method compares whether options content is identical. It writes
/// both options to a buffer and then compares the buffers. Comparing
/// two different instances of an option that has identical content
/// will return true.
///
/// It is safe to pass NULL pointers. Two NULL pointers are equal.
/// NULL pointer and non-NULL pointers are obviously non-equal.
///
/// @param option1 pointer to the first option
/// @param option2
/// @return true, if content is identical
bool compareOptions(const isc::dhcp::OptionPtr& option1,
const isc::dhcp::OptionPtr& option2);
/// @brief Performs basic (positive) RENEW test
///
/// See renewBasic and pdRenewBasic tests for detailed explanation.
......
......@@ -148,12 +148,12 @@ TEST_F(InfRequestTest, infRequestBasic) {
// Check that it contains our client-id
OptionPtr client_id = response->getOption(D6O_CLIENTID);
ASSERT_TRUE(client_id);
EXPECT_EQ(client_id, client.getClientId());
EXPECT_TRUE(compareOptions(client_id, client.getClientId()));
// Check that it contains proper server-id
OptionPtr server_id = response->getOption(D6O_SERVERID);
ASSERT_TRUE(server_id);
EXPECT_EQ(server_id, client.getServer()->getServerID());
EXPECT_TRUE(compareOptions(server_id, client.getServer()->getServerID()));
// Check that we received requested DNS servers option
Option6AddrLstPtr dns = boost::dynamic_pointer_cast<Option6AddrLst>
......@@ -162,7 +162,7 @@ TEST_F(InfRequestTest, infRequestBasic) {
Option6AddrLst::AddressContainer addrs = dns->getAddresses();
ASSERT_EQ(2, addrs.size());
EXPECT_EQ("2001:db8::1", addrs[0].toText());
EXPECT_EQ("2001:db8::2", addrs[0].toText());
EXPECT_EQ("2001:db8::2", addrs[1].toText());
}
/// Check that server processes correctly an incoming inf-request
......@@ -194,7 +194,7 @@ TEST_F(InfRequestTest, infRequestAnonymous) {
Option6AddrLst::AddressContainer addrs = dns->getAddresses();
ASSERT_EQ(2, addrs.size());
EXPECT_EQ("2001:db8::1", addrs[0].toText());
EXPECT_EQ("2001:db8::2", addrs[0].toText());
EXPECT_EQ("2001:db8::2", addrs[1].toText());
}
/// Check that server processes correctly an incoming inf-request
......@@ -274,7 +274,7 @@ TEST_F(InfRequestTest, infRequestNoSubnets) {
// Make sure we ended-up having expected number of subnets configured.
const Subnet6Collection* subnets = CfgMgr::instance().getCurrentCfg()->
getCfgSubnets6()->getAll();
ASSERT_EQ(1, subnets->size());
ASSERT_EQ(0, subnets->size());
// Perform 2-way exchange (Inf-request/reply)
client.requestOption(D6O_NIS_SERVERS);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment