Browse Source

[2940] Added a unit test for Lease4 to check getClientIdVector function.

Marcin Siodelski 11 years ago
parent
commit
54910e664a

+ 1 - 0
src/lib/dhcpsrv/tests/Makefile.am

@@ -53,6 +53,7 @@ libdhcpsrv_unittests_SOURCES += alloc_engine_unittest.cc
 libdhcpsrv_unittests_SOURCES += callout_handle_store_unittest.cc
 libdhcpsrv_unittests_SOURCES += cfgmgr_unittest.cc
 libdhcpsrv_unittests_SOURCES += dbaccess_parser_unittest.cc
+libdhcpsrv_unittests_SOURCES += lease_unittest.cc
 libdhcpsrv_unittests_SOURCES += lease_mgr_factory_unittest.cc
 libdhcpsrv_unittests_SOURCES += lease_mgr_unittest.cc
 libdhcpsrv_unittests_SOURCES += memfile_lease_mgr_unittest.cc

+ 49 - 0
src/lib/dhcpsrv/tests/lease_unittest.cc

@@ -0,0 +1,49 @@
+// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <config.h>
+#include <dhcpsrv/lease.h>
+#include <gtest/gtest.h>
+#include <vector>
+
+using namespace isc;
+using namespace isc::dhcp;
+
+namespace {
+
+// @todo Currently this file contains a single test. Other tests for Lease
+// objects must be implemented. See http://bind10.isc.org/ticket/3240.
+
+// Verify that the client id can be returned as a vector object and if client
+// id is NULL the empty vector is returned.
+TEST(Lease4Test, getClientIdVector) {
+    // Create a lease.
+    Lease4 lease;
+    // By default, the lease should have client id set to NULL. If it doesn't,
+    // continuing the test makes no sense.
+    ASSERT_FALSE(lease.client_id_);
+    // When client id is NULL the vector returned should be empty.
+    EXPECT_TRUE(lease.getClientIdVector().empty());
+    // Now, let's set the non NULL client id. Fill it with the 8 bytes, each
+    // holding a value of 0x42.
+    std::vector<uint8_t> client_id_vec(8, 0x42);
+    lease.client_id_ = ClientIdPtr(new ClientId(client_id_vec));
+    // Check that the returned vector, encapsulating client id is equal to
+    // the one that has been used to set the client id for the lease.
+    std::vector<uint8_t> returned_vec = lease.getClientIdVector();
+    EXPECT_TRUE(returned_vec == client_id_vec);
+}
+
+
+}; // end of anonymous namespace

+ 1 - 21
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
@@ -237,24 +237,4 @@ TEST_F(MemfileLeaseMgrTest, getLease4ClientIdHWAddrSubnetId) {
     EXPECT_TRUE(lease == Lease4Ptr());
 }
 
-// This test verifies that the client id can be returned as a vector.
-// @todo This test should be moved to the Lease specific unit tests once
-// these tests are created.
-TEST_F(MemfileLeaseMgrTest, getLease4ClientIdVector) {
-    const LeaseMgr::ParameterMap pmap;
-    boost::scoped_ptr<Memfile_LeaseMgr> lease_mgr(new Memfile_LeaseMgr(pmap));
-
-    Lease4Ptr lease = initializeLease4(straddress4_[7]);
-    // Check that this lease has null client-id
-    ASSERT_TRUE(lease->client_id_ == ClientIdPtr());
-    // Check that this returns empty vector
-    ASSERT_TRUE(lease->getClientIdVector().empty());
-
-    // Let's take a lease with client-id not null
-    lease = initializeLease4(straddress4_[6]);
-    ASSERT_TRUE(lease->client_id_);
-    // Check that they return the same client-id value
-    ASSERT_TRUE(lease->client_id_->getClientId() == lease->getClientIdVector());
-}
-
 }; // end of anonymous namespace