Browse Source

[2940] Extend null client id unit test.

Marcin Siodelski 11 years ago
parent
commit
ad2132e568
1 changed files with 20 additions and 5 deletions
  1. 20 5
      src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc

+ 20 - 5
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc

@@ -222,19 +222,34 @@ TEST_F(MemfileLeaseMgrTest, getLease4ClientIdHWAddrSubnetId) {
 
     Lease4Ptr leaseA = initializeLease4(straddress4_[4]);
     Lease4Ptr leaseB = initializeLease4(straddress4_[5]);
+    Lease4Ptr leaseC = initializeLease4(straddress4_[6]);
+    // Set NULL client id for one of the leases. This is to make sure that such
+    // a lease may coexist with other leases with non NULL client id.
+    leaseC->client_id_.reset();
+
     HWAddr hwaddrA(leaseA->hwaddr_, HTYPE_ETHER);
     HWAddr hwaddrB(leaseB->hwaddr_, HTYPE_ETHER);
+    HWAddr hwaddrC(leaseC->hwaddr_, HTYPE_ETHER);
     EXPECT_TRUE(lease_mgr->addLease(leaseA));
+    EXPECT_TRUE(lease_mgr->addLease(leaseB));
+    EXPECT_TRUE(lease_mgr->addLease(leaseC));
     // First case we should retrieve our lease
     Lease4Ptr lease = lease_mgr->getLease4(*leaseA->client_id_, hwaddrA, leaseA->subnet_id_);
     detailCompareLease(lease, leaseA);
-    lease = lease_mgr->getLease4(*leaseB->client_id_, hwaddrA, leaseA->subnet_id_);
-    detailCompareLease(lease, leaseA);
-    // But not the folowing, with different  hwaddr and subnet
+    // Retrieve the other lease.
+    lease = lease_mgr->getLease4(*leaseB->client_id_, hwaddrB, leaseB->subnet_id_);
+    detailCompareLease(lease, leaseB);
+    // The last lease has NULL client id so we will use a different getLease4 function
+    // which doesn't require client id (just a hwaddr and subnet id).
+    lease = lease_mgr->getLease4(hwaddrC, leaseC->subnet_id_);
+    detailCompareLease(lease, leaseC);
+
+    // An attempt to retrieve the lease with non matching lease parameters should
+    // result in NULL pointer being returned.
     lease = lease_mgr->getLease4(*leaseA->client_id_, hwaddrB, leaseA->subnet_id_);
-    EXPECT_TRUE(lease == Lease4Ptr());
+    EXPECT_FALSE(lease);
     lease = lease_mgr->getLease4(*leaseA->client_id_, hwaddrA, leaseB->subnet_id_);
-    EXPECT_TRUE(lease == Lease4Ptr());
+    EXPECT_FALSE(lease);
 }
 
 }; // end of anonymous namespace