]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3359] getLease4HWAddr tests moved to common framework.
authorTomek Mrugalski <tomasz@isc.org>
Thu, 6 Mar 2014 10:28:46 +0000 (10:28 +0000)
committerTomek Mrugalski <tomasz@isc.org>
Thu, 6 Mar 2014 10:28:46 +0000 (10:28 +0000)
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/test_utils.cc
src/lib/dhcpsrv/tests/test_utils.h

index 7113b75d29ed766a1ccc99428c65d96c9d87b731..d68a272d9b23ceed7eb5ad6433884717df8b55b8 100644 (file)
@@ -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
index 621bbedd2966ee9003f0f3251af209a518ff10ca..dfb82669873575490447397d223699a2d514339b 100644 (file)
@@ -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<Lease6Ptr> 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<Lease4Ptr> 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<string> 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<uint8_t> 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)
index 06d10fcbd406dc27c762c2eea21a582d361775b6..52374d2abae8174f4aee0bc48f262aa524db5492 100644 (file)
@@ -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<Lease4Ptr> 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<string> 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<uint8_t> 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<Lease6Ptr> 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);
+}
+
+
 };
 };
 };
index d159c3251aa0eaeb94a13d45e86347612a4bcc50..935bbc8c07b0eb135af00b60514eb145d04c506f 100644 (file)
@@ -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