From: Tomek Mrugalski Date: Thu, 15 Oct 2015 08:34:01 +0000 (+0200) Subject: [master] Unit-test fixes after trac3987 merge. X-Git-Tag: trac3874_base~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4753ad3c084061436c6abccacfcbe8b9aa790933;p=thirdparty%2Fkea.git [master] Unit-test fixes after trac3987 merge. --- diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index 83fdfa139f..1a46d7d221 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -274,6 +274,8 @@ Dhcpv4Srv::~Dhcpv4Srv() { IfaceMgr::instance().closeSockets(); + // The lease manager was instantiated during DHCPv4Srv configuration, + // so we should clean up after ourselves. LeaseMgrFactory::destroy(); } diff --git a/src/bin/dhcp4/tests/decline_unittest.cc b/src/bin/dhcp4/tests/decline_unittest.cc index 15194aec5a..d420749f20 100644 --- a/src/bin/dhcp4/tests/decline_unittest.cc +++ b/src/bin/dhcp4/tests/decline_unittest.cc @@ -89,7 +89,8 @@ Dhcpv4SrvTest::acquireLease(Dhcp4Client& client) { } void -Dhcpv4SrvTest::acquireAndDecline(const std::string& hw_address_1, +Dhcpv4SrvTest::acquireAndDecline(Dhcp4Client& client, + const std::string& hw_address_1, const std::string& client_id_1, const std::string& hw_address_2, const std::string& client_id_2, @@ -101,7 +102,7 @@ Dhcpv4SrvTest::acquireAndDecline(const std::string& hw_address_1, // Ok, do the normal lease aquisition. CfgMgr::instance().clear(); - Dhcp4Client client(Dhcp4Client::SELECTING); + // Configure DHCP server. configure(DECLINE_CONFIGS[0], *client.getServer()); // Explicitly set the client id. @@ -204,7 +205,8 @@ public: // This test checks that the client can acquire and decline the lease. TEST_F(DeclineTest, declineNoIdentifierChange) { - acquireAndDecline("01:02:03:04:05:06", "12:14", + Dhcp4Client client(Dhcp4Client::SELECTING); + acquireAndDecline(client, "01:02:03:04:05:06", "12:14", "01:02:03:04:05:06", "12:14", SHOULD_PASS); } @@ -215,7 +217,8 @@ TEST_F(DeclineTest, declineNoIdentifierChange) { // client identifier. // - The server successfully declines the lease. TEST_F(DeclineTest, declineHWAddressOnly) { - acquireAndDecline("01:02:03:04:05:06", "", + Dhcp4Client client(Dhcp4Client::SELECTING); + acquireAndDecline(client, "01:02:03:04:05:06", "", "01:02:03:04:05:06", "", SHOULD_PASS); } @@ -226,7 +229,8 @@ TEST_F(DeclineTest, declineHWAddressOnly) { // client identifier. // - The server successfully declines the lease. TEST_F(DeclineTest, declineNoClientId) { - acquireAndDecline("01:02:03:04:05:06", "12:14", + Dhcp4Client client(Dhcp4Client::SELECTING); + acquireAndDecline(client, "01:02:03:04:05:06", "12:14", "01:02:03:04:05:06", "", SHOULD_PASS); } @@ -238,7 +242,8 @@ TEST_F(DeclineTest, declineNoClientId) { // - The server identifies the lease using HW address and declines // this lease. TEST_F(DeclineTest, declineNoClientId2) { - acquireAndDecline("01:02:03:04:05:06", "", + Dhcp4Client client(Dhcp4Client::SELECTING); + acquireAndDecline(client, "01:02:03:04:05:06", "", "01:02:03:04:05:06", "12:14", SHOULD_PASS); } @@ -249,7 +254,8 @@ TEST_F(DeclineTest, declineNoClientId2) { // client identifier. // - The server should not remove the lease. TEST_F(DeclineTest, declineNonMatchingClientId) { - acquireAndDecline("01:02:03:04:05:06", "12:14", + Dhcp4Client client(Dhcp4Client::SELECTING); + acquireAndDecline(client, "01:02:03:04:05:06", "12:14", "01:02:03:04:05:06", "12:15:16", SHOULD_FAIL); } @@ -261,7 +267,8 @@ TEST_F(DeclineTest, declineNonMatchingClientId) { // - The server uses client identifier to find the client's lease and // declines it. TEST_F(DeclineTest, declineNonMatchingHWAddress) { - acquireAndDecline("01:02:03:04:05:06", "12:14", + Dhcp4Client client(Dhcp4Client::SELECTING); + acquireAndDecline(client, "01:02:03:04:05:06", "12:14", "06:06:06:06:06:06", "12:14", SHOULD_PASS); } diff --git a/src/bin/dhcp4/tests/dhcp4_test_utils.h b/src/bin/dhcp4/tests/dhcp4_test_utils.h index 13008b9f33..7864070c17 100644 --- a/src/bin/dhcp4/tests/dhcp4_test_utils.h +++ b/src/bin/dhcp4/tests/dhcp4_test_utils.h @@ -213,6 +213,11 @@ public: using Dhcpv4Srv::alloc_engine_; }; +// We need to pass one reference to the Dhcp4Client, which is defined in +// dhcp4_client.h. That header includes this file. To avoid circular +// dependencies, we use forward declaration here. +class Dhcp4Client; + class Dhcpv4SrvTest : public ::testing::Test { public: @@ -427,6 +432,7 @@ public: /// @brief Tests if the acquired lease is or is not declined. /// + /// @param client Dhcp4Client instance /// @param hw_address_1 HW Address to be used to acquire the lease. /// @param client_id_1 Client id to be used to acquire the lease. /// @param hw_address_2 HW Address to be used to decline the lease. @@ -434,7 +440,8 @@ public: /// @param expected_result SHOULD_PASS if the lease is expected to /// be successfully declined, or SHOULD_FAIL if the lease is expected /// to not be declined. - void acquireAndDecline(const std::string& hw_address_1, + void acquireAndDecline(Dhcp4Client& client, + const std::string& hw_address_1, const std::string& client_id_1, const std::string& hw_address_2, const std::string& client_id_2, diff --git a/src/bin/dhcp4/tests/hooks_unittest.cc b/src/bin/dhcp4/tests/hooks_unittest.cc index 1e05287d3a..f08bb9f5a1 100644 --- a/src/bin/dhcp4/tests/hooks_unittest.cc +++ b/src/bin/dhcp4/tests/hooks_unittest.cc @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -1485,7 +1486,8 @@ TEST_F(HooksDhcpv4SrvTest, HooksDecline) { "lease4_decline", lease4_decline_callout)); // Conduct the actual DORA + Decline. - acquireAndDecline("01:02:03:04:05:06", "12:14", + Dhcp4Client client(Dhcp4Client::SELECTING); + acquireAndDecline(client, "01:02:03:04:05:06", "12:14", "01:02:03:04:05:06", "12:14", SHOULD_PASS); @@ -1528,7 +1530,8 @@ TEST_F(HooksDhcpv4SrvTest, HooksDeclineDrop) { // Conduct the actual DORA + Decline. The DECLINE should fail, as the // hook will set the status to DROP. - acquireAndDecline("01:02:03:04:05:06", "12:14", + Dhcp4Client client(Dhcp4Client::SELECTING); + acquireAndDecline(client, "01:02:03:04:05:06", "12:14", "01:02:03:04:05:06", "12:14", SHOULD_FAIL);