From: Tomek Mrugalski Date: Thu, 6 Mar 2014 10:28:46 +0000 (+0000) Subject: [3359] getLease4HWAddr tests moved to common framework. X-Git-Tag: kea-eng-20140313~17^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ae241216b7a9764e00835ffbde13011102db3983;p=thirdparty%2Fkea.git [3359] getLease4HWAddr tests moved to common framework. --- diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc index 7113b75d29..d68a272d9b 100644 --- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc @@ -99,8 +99,16 @@ TEST_F(MemfileLeaseMgrTest, getLease4NullClientId) { } // Checks lease4 retrieval through HWAddr -TEST_F(MemfileLeaseMgrTest, getLease4HWAddr) { - testGetLease4HWAddr(); +TEST_F(MemfileLeaseMgrTest, getLease4HWAddr1) { + testGetLease4HWAddr1(); +} + +/// @brief Check GetLease4 methods - access by Hardware Address +/// +/// Adds leases to the database and checks that they can be accessed via +/// a combination of DUID and IAID. +TEST_F(MemfileLeaseMgrTest, getLease4HWAddr2) { + testGetLease4HWAddr2(); } // Checks lease4 retrieval with clientId, HWAddr and subnet_id diff --git a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc index 621bbedd29..dfb8266987 100644 --- a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc @@ -370,45 +370,7 @@ TEST_F(MySqlLeaseMgrTest, lease4InvalidHostname) { /// Checks that the addLease, getLease6 (by address) and deleteLease (with an /// IPv6 address) works. TEST_F(MySqlLeaseMgrTest, basicLease6) { - // Get the leases to be used for the test. - vector leases = createLeases6(); - - // Start the tests. Add three leases to the database, read them back and - // check they are what we think they are. - EXPECT_TRUE(lmptr_->addLease(leases[1])); - EXPECT_TRUE(lmptr_->addLease(leases[2])); - EXPECT_TRUE(lmptr_->addLease(leases[3])); - lmptr_->commit(); - - // Reopen the database to ensure that they actually got stored. - reopen(); - - Lease6Ptr l_returned = lmptr_->getLease6(leasetype6_[1], ioaddress6_[1]); - ASSERT_TRUE(l_returned); - detailCompareLease(leases[1], l_returned); - - l_returned = lmptr_->getLease6(leasetype6_[2], ioaddress6_[2]); - ASSERT_TRUE(l_returned); - detailCompareLease(leases[2], l_returned); - - l_returned = lmptr_->getLease6(leasetype6_[3], ioaddress6_[3]); - ASSERT_TRUE(l_returned); - detailCompareLease(leases[3], l_returned); - - // Check that we can't add a second lease with the same address - EXPECT_FALSE(lmptr_->addLease(leases[1])); - - // Delete a lease, check that it's gone, and that we can't delete it - // a second time. - EXPECT_TRUE(lmptr_->deleteLease(ioaddress6_[1])); - l_returned = lmptr_->getLease6(leasetype6_[1], ioaddress6_[1]); - EXPECT_FALSE(l_returned); - EXPECT_FALSE(lmptr_->deleteLease(ioaddress6_[1])); - - // Check that the second address is still there. - l_returned = lmptr_->getLease6(leasetype6_[2], ioaddress6_[2]); - ASSERT_TRUE(l_returned); - detailCompareLease(leases[2], l_returned); + testBasicLease6(); } /// @brief Verify that too long hostname for Lease6 is not accepted. @@ -437,52 +399,13 @@ TEST_F(MySqlLeaseMgrTest, lease6InvalidHostname) { } /// @brief Check GetLease4 methods - access by Hardware Address -/// -/// Adds leases to the database and checks that they can be accessed via -/// a combination of DIUID and IAID. -TEST_F(MySqlLeaseMgrTest, getLease4Hwaddr) { - // Get the leases to be used for the test and add to the database - vector leases = createLeases4(); - for (int i = 0; i < leases.size(); ++i) { - EXPECT_TRUE(lmptr_->addLease(leases[i])); - } - - // Get the leases matching the hardware address of lease 1 - /// @todo: Simply use HWAddr directly once 2589 is implemented - HWAddr tmp(leases[1]->hwaddr_, HTYPE_ETHER); - Lease4Collection returned = lmptr_->getLease4(tmp); - - // Should be three leases, matching leases[1], [3] and [5]. - ASSERT_EQ(3, returned.size()); - - // Easiest way to check is to look at the addresses. - vector addresses; - for (Lease4Collection::const_iterator i = returned.begin(); - i != returned.end(); ++i) { - addresses.push_back((*i)->addr_.toText()); - } - sort(addresses.begin(), addresses.end()); - EXPECT_EQ(straddress4_[1], addresses[0]); - EXPECT_EQ(straddress4_[3], addresses[1]); - EXPECT_EQ(straddress4_[5], addresses[2]); - - // Repeat test with just one expected match - /// @todo: Simply use HWAddr directly once 2589 is implemented - returned = lmptr_->getLease4(HWAddr(leases[2]->hwaddr_, HTYPE_ETHER)); - ASSERT_EQ(1, returned.size()); - detailCompareLease(leases[2], *returned.begin()); - - // Check that an empty vector is valid - EXPECT_TRUE(leases[7]->hwaddr_.empty()); - /// @todo: Simply use HWAddr directly once 2589 is implemented - returned = lmptr_->getLease4(HWAddr(leases[7]->hwaddr_, HTYPE_ETHER)); - ASSERT_EQ(1, returned.size()); - detailCompareLease(leases[7], *returned.begin()); +TEST_F(MySqlLeaseMgrTest, getLease4HWAddr1) { + testGetLease4HWAddr1(); +} - // Try to get something with invalid hardware address - vector invalid(6, 0); - returned = lmptr_->getLease4(invalid); - EXPECT_EQ(0, returned.size()); +/// @brief Check GetLease4 methods - access by Hardware Address +TEST_F(MySqlLeaseMgrTest, getLease4HWAddr2) { + testGetLease4HWAddr2(); } // @brief Get lease4 by hardware address (2) diff --git a/src/lib/dhcpsrv/tests/test_utils.cc b/src/lib/dhcpsrv/tests/test_utils.cc index 06d10fcbd4..52374d2aba 100644 --- a/src/lib/dhcpsrv/tests/test_utils.cc +++ b/src/lib/dhcpsrv/tests/test_utils.cc @@ -595,7 +595,7 @@ GenericLeaseMgrTest::testLease4NullClientId() { } void -GenericLeaseMgrTest::testGetLease4HWAddr() { +GenericLeaseMgrTest::testGetLease4HWAddr1() { // Let's initialize two different leases 4 and just add the first ... Lease4Ptr leaseA = initializeLease4(straddress4_[5]); HWAddr hwaddrA(leaseA->hwaddr_, HTYPE_ETHER); @@ -612,6 +612,52 @@ GenericLeaseMgrTest::testGetLease4HWAddr() { ASSERT_EQ(1, returned.size()); } +void +GenericLeaseMgrTest::testGetLease4HWAddr2() { + // Get the leases to be used for the test and add to the database + vector leases = createLeases4(); + for (int i = 0; i < leases.size(); ++i) { + EXPECT_TRUE(lmptr_->addLease(leases[i])); + } + + // Get the leases matching the hardware address of lease 1 + /// @todo: Simply use HWAddr directly once 2589 is implemented + HWAddr tmp(leases[1]->hwaddr_, HTYPE_ETHER); + Lease4Collection returned = lmptr_->getLease4(tmp); + + // Should be three leases, matching leases[1], [3] and [5]. + ASSERT_EQ(3, returned.size()); + + // Easiest way to check is to look at the addresses. + vector addresses; + for (Lease4Collection::const_iterator i = returned.begin(); + i != returned.end(); ++i) { + addresses.push_back((*i)->addr_.toText()); + } + sort(addresses.begin(), addresses.end()); + EXPECT_EQ(straddress4_[1], addresses[0]); + EXPECT_EQ(straddress4_[3], addresses[1]); + EXPECT_EQ(straddress4_[5], addresses[2]); + + // Repeat test with just one expected match + /// @todo: Simply use HWAddr directly once 2589 is implemented + returned = lmptr_->getLease4(HWAddr(leases[2]->hwaddr_, HTYPE_ETHER)); + ASSERT_EQ(1, returned.size()); + detailCompareLease(leases[2], *returned.begin()); + + // Check that an empty vector is valid + EXPECT_TRUE(leases[7]->hwaddr_.empty()); + /// @todo: Simply use HWAddr directly once 2589 is implemented + returned = lmptr_->getLease4(HWAddr(leases[7]->hwaddr_, HTYPE_ETHER)); + ASSERT_EQ(1, returned.size()); + detailCompareLease(leases[7], *returned.begin()); + + // Try to get something with invalid hardware address + vector invalid(6, 0); + returned = lmptr_->getLease4(invalid); + EXPECT_EQ(0, returned.size()); +} + void GenericLeaseMgrTest::testGetLease4ClientIdHWAddrSubnetId() { Lease4Ptr leaseA = initializeLease4(straddress4_[4]); @@ -771,6 +817,50 @@ GenericLeaseMgrTest::testBasicLease4() { } +void +GenericLeaseMgrTest::testBasicLease6() { + // Get the leases to be used for the test. + vector leases = createLeases6(); + + // Start the tests. Add three leases to the database, read them back and + // check they are what we think they are. + EXPECT_TRUE(lmptr_->addLease(leases[1])); + EXPECT_TRUE(lmptr_->addLease(leases[2])); + EXPECT_TRUE(lmptr_->addLease(leases[3])); + lmptr_->commit(); + + // Reopen the database to ensure that they actually got stored. + reopen(); + + Lease6Ptr l_returned = lmptr_->getLease6(leasetype6_[1], ioaddress6_[1]); + ASSERT_TRUE(l_returned); + detailCompareLease(leases[1], l_returned); + + l_returned = lmptr_->getLease6(leasetype6_[2], ioaddress6_[2]); + ASSERT_TRUE(l_returned); + detailCompareLease(leases[2], l_returned); + + l_returned = lmptr_->getLease6(leasetype6_[3], ioaddress6_[3]); + ASSERT_TRUE(l_returned); + detailCompareLease(leases[3], l_returned); + + // Check that we can't add a second lease with the same address + EXPECT_FALSE(lmptr_->addLease(leases[1])); + + // Delete a lease, check that it's gone, and that we can't delete it + // a second time. + EXPECT_TRUE(lmptr_->deleteLease(ioaddress6_[1])); + l_returned = lmptr_->getLease6(leasetype6_[1], ioaddress6_[1]); + EXPECT_FALSE(l_returned); + EXPECT_FALSE(lmptr_->deleteLease(ioaddress6_[1])); + + // Check that the second address is still there. + l_returned = lmptr_->getLease6(leasetype6_[2], ioaddress6_[2]); + ASSERT_TRUE(l_returned); + detailCompareLease(leases[2], l_returned); +} + + }; }; }; diff --git a/src/lib/dhcpsrv/tests/test_utils.h b/src/lib/dhcpsrv/tests/test_utils.h index d159c3251a..935bbc8c07 100644 --- a/src/lib/dhcpsrv/tests/test_utils.h +++ b/src/lib/dhcpsrv/tests/test_utils.h @@ -122,7 +122,13 @@ public: void testGetLease4NullClientId(); /// @brief Test lease retrieval using HW address. - void testGetLease4HWAddr(); + void testGetLease4HWAddr1(); + + /// @brief Check GetLease4 methods - access by Hardware Address + /// + /// Adds leases to the database and checks that they can be accessed using + /// HWAddr information. + void testGetLease4HWAddr2(); /// @brief Test lease retrieval using client id, HW address and subnet id. void testGetLease4ClientIdHWAddrSubnetId(); @@ -136,6 +142,12 @@ public: /// @todo: check if it does overlap with @ref testGetLease4NullClientId() void testLease4NullClientId(); + /// @brief Basic Lease6 Checks + /// + /// Checks that the addLease, getLease6 (by address) and deleteLease (with an + /// IPv6 address) works. + void testBasicLease6(); + /// @brief Test that IPv6 lease can be added, retrieved and deleted. /// /// This method checks basic IPv6 lease operations. There's check_t1_t2