From: Francis Dupont Date: Sat, 28 Jan 2023 10:25:13 +0000 (+0100) Subject: [#2738] Checkpoint: did some UTs X-Git-Tag: Kea-2.3.5~64 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b10fec5c8575afa3cfda6e5bc78415e91a8f781d;p=thirdparty%2Fkea.git [#2738] Checkpoint: did some UTs --- diff --git a/src/hooks/dhcp/lease_cmds/tests/lease_cmds4_unittest.cc b/src/hooks/dhcp/lease_cmds/tests/lease_cmds4_unittest.cc index 85b3c8a045..d177b3a497 100644 --- a/src/hooks/dhcp/lease_cmds/tests/lease_cmds4_unittest.cc +++ b/src/hooks/dhcp/lease_cmds/tests/lease_cmds4_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2017-2022 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2017-2023 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -171,6 +171,10 @@ public: /// @brief Check that a well formed lease4 with a comment can be added. void testLease4AddComment(); + /// @brief Check that a well formed lease4 with relay and remote ids + /// can be added. + void testLease4AddExtendedInfo(); + /// @brief Check that lease4-get can handle a situation when the query is /// broken (some required parameters are missing). void testLease4GetMissingParams(); @@ -325,6 +329,10 @@ public: /// user context. void testLease4UpdateComment(); + /// @brief Check that a lease4 can be updated. We're adding relay and + /// remote ids. + void testLease4UpdateExtendedInfo(); + /// @brief Check that lease4-del can handle a situation when the query is /// broken (some required parameters are missing). void testLease4DelMissingParams(); @@ -908,7 +916,7 @@ void Lease4CmdsTest::testLease4AddComment() { " \"hw-address\": \"1a:1b:1c:1d:1e:1f\",\n" " \"comment\": \"a comment\"\n" " }\n" - "}"; + "}"; string exp_rsp = "Lease for address 192.0.2.202, subnet-id 44 added."; testCommand(txt, CONTROL_RESULT_SUCCESS, exp_rsp); @@ -927,6 +935,56 @@ void Lease4CmdsTest::testLease4AddComment() { EXPECT_EQ("{ \"comment\": \"a comment\" }", l->getContext()->str()); } +void Lease4CmdsTest::testLease4AddExtendedInfo() { + // Initialize lease manager (false = v4, false = don't add leases) + initLeaseMgr(false, false); + + checkLease4Stats(44, 0, 0); + + checkLease4Stats(88, 0, 0); + + // Now send the command. + string txt = + "{\n" + " \"command\": \"lease4-add\",\n" + " \"arguments\": {" + " \"subnet-id\": 44,\n" + " \"ip-address\": \"192.0.2.202\",\n" + " \"hw-address\": \"1a:1b:1c:1d:1e:1f\",\n" + " \"user-context\": { \"ISC\": { \"relay-agent-info\": {\n" + " \"sub-options\": \"0x02030102030C03AABBCC\",\n" + " \"remote-id\": \"010203\",\n" + " \"relay-id\": \"AABBCC\"\n" + " } } }\n" + " }\n" + "}"; + string exp_rsp = "Lease for address 192.0.2.202, subnet-id 44 added."; + testCommand(txt, CONTROL_RESULT_SUCCESS, exp_rsp); + + checkLease4Stats(44, 1, 0); + + checkLease4Stats(88, 0, 0); + + // Now check that the lease is really there. + Lease4Ptr l = lmptr_->getLease4(IOAddress("192.0.2.202")); + ASSERT_TRUE(l); + + // Make sure the lease have proper value set. + ASSERT_TRUE(l->hwaddr_); + EXPECT_EQ("1a:1b:1c:1d:1e:1f", l->hwaddr_->toText(false)); + ConstElementPtr ctx = l->getContext(); + ASSERT_TRUE(ctx); + string expected = "{ \"ISC\": { \"relay-agent-info\": "; + expected += "{ \"relay-id\": \"AABBCC\", "; + expected += "\"remote-id\": \"010203\", "; + expected += "\"sub-options\": \"0x02030102030C03AABBCC\" } } }"; + EXPECT_EQ(expected, ctx->str()); + const vector relay_id = { 0xaa, 0xbb, 0xcc }; + EXPECT_EQ(relay_id, l->relay_id_); + const vector remote_id = { 1, 2, 3 }; + EXPECT_EQ(remote_id, l->remote_id_); +} + void Lease4CmdsTest::testLease4GetMissingParams() { // No parameters whatsoever. You want just a lease, any lease? string cmd = @@ -2243,6 +2301,58 @@ void Lease4CmdsTest::testLease4UpdateComment() { EXPECT_EQ("true", ctx->get("foobar")->str()); } +void Lease4CmdsTest::testLease4UpdateExtendedInfo() { + // Initialize lease manager (false = v4, true = add leases) + initLeaseMgr(false, true); + + checkLease4Stats(44, 2, 0); + + checkLease4Stats(88, 2, 0); + + // Now send the command. + string txt = + "{\n" + " \"command\": \"lease4-update\",\n" + " \"arguments\": {" + " \"subnet-id\": 44,\n" + " \"ip-address\": \"192.0.2.1\",\n" + " \"hw-address\": \"42:42:42:42:42:42:42:42\",\n" + " \"user-context\": { \"ISC\": { \"relay-agent-info\": {\n" + " \"sub-options\": \"0x02030102030C03AABBCC\",\n" + " \"remote-id\": \"010203\",\n" + " \"relay-id\": \"AABBCC\"\n" + " } } }\n" + " }\n" + "}"; + string exp_rsp = "IPv4 lease updated."; + testCommand(txt, CONTROL_RESULT_SUCCESS, exp_rsp); + + checkLease4Stats(44, 2, 0); + + checkLease4Stats(88, 2, 0); + + // Now check that the lease is still there. + Lease4Ptr l = lmptr_->getLease4(IOAddress("192.0.2.1")); + ASSERT_TRUE(l); + + // Make sure it's been updated. + ASSERT_TRUE(l->hwaddr_); + EXPECT_EQ("42:42:42:42:42:42:42:42", l->hwaddr_->toText(false)); + + // Check user context. + ConstElementPtr ctx = l->getContext(); + ASSERT_TRUE(ctx); + string expected = "{ \"ISC\": { \"relay-agent-info\": "; + expected += "{ \"relay-id\": \"AABBCC\", "; + expected += "\"remote-id\": \"010203\", "; + expected += "\"sub-options\": \"0x02030102030C03AABBCC\" } } }"; + EXPECT_EQ(expected, ctx->str()); + const vector relay_id = { 0xaa, 0xbb, 0xcc }; + EXPECT_EQ(relay_id, l->relay_id_); + const vector remote_id = { 1, 2, 3 }; + EXPECT_EQ(remote_id, l->remote_id_); +} + void Lease4CmdsTest::testLease4DelMissingParams() { // No parameters whatsoever. You want just a lease, any lease? string cmd = @@ -3286,6 +3396,15 @@ TEST_F(Lease4CmdsTest, lease4AddCommentMultiThreading) { testLease4AddComment(); } +TEST_F(Lease4CmdsTest, lease4AddExtendedInfo) { + testLease4AddExtendedInfo(); +} + +TEST_F(Lease4CmdsTest, lease4AddExtendedInfoMultiThreading) { + MultiThreadingTest mt(true); + testLease4AddExtendedInfo(); +} + TEST_F(Lease4CmdsTest, lease4GetMissingParams) { testLease4GetMissingParams(); } @@ -3655,6 +3774,15 @@ TEST_F(Lease4CmdsTest, lease4UpdateCommentMultiThreading) { testLease4UpdateComment(); } +TEST_F(Lease4CmdsTest, lease4UpdateExtendedInfo) { + testLease4UpdateExtendedInfo(); +} + +TEST_F(Lease4CmdsTest, lease4UpdateExtendedInfoMultiThreading) { + MultiThreadingTest mt(true); + testLease4UpdateExtendedInfo(); +} + TEST_F(Lease4CmdsTest, lease4DelMissingParams) { testLease4DelMissingParams(); } diff --git a/src/lib/dhcpsrv/lease.cc b/src/lib/dhcpsrv/lease.cc index 061f823ba1..db806e7e02 100644 --- a/src/lib/dhcpsrv/lease.cc +++ b/src/lib/dhcpsrv/lease.cc @@ -318,6 +318,8 @@ Lease4::Lease4(const Lease4& other) if (other.getContext()) { setContext(other.getContext()); + relay_id_ = other.relay_id_; + remote_id_ = other.remote_id_; } } @@ -419,6 +421,8 @@ Lease4::operator=(const Lease4& other) { if (other.getContext()) { setContext(other.getContext()); + relay_id_ = other.relay_id_; + remote_id_ = other.remote_id_; } } return (*this); diff --git a/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc index 950420a345..b74bb9d10a 100644 --- a/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2022 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2012-2023 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -11,8 +11,7 @@ #include #include #include - -#include +#include #include #include @@ -873,6 +872,202 @@ TEST(Lease4ExtendedInfoTest, upgradeLease4ExtendedInfo) { } } +// Verify Lease4 user context extract basic operations. +TEST(Lease4ExtendedInfoTest, extract) { + Lease4Ptr lease; + + // No Lease. + ASSERT_FALSE(lease); + EXPECT_NO_THROW(LeaseMgr::extractLease4ExtendedInfo(lease)); + EXPECT_NO_THROW(LeaseMgr::extractLease4ExtendedInfo(lease, false)); + + // No user context. + lease.reset(new Lease4()); + ASSERT_TRUE(lease); + ASSERT_FALSE(lease->getContext()); + EXPECT_NO_THROW(LeaseMgr::extractLease4ExtendedInfo(lease)); + EXPECT_NO_THROW(LeaseMgr::extractLease4ExtendedInfo(lease, false)); + + // Not map user context. + ElementPtr user_context = Element::createList(); + lease->setContext(user_context); + EXPECT_NO_THROW(LeaseMgr::extractLease4ExtendedInfo(lease)); + + // No ISC. + user_context = Element::createMap(); + user_context->set("foo", Element::create(string("bar"))); + lease->setContext(user_context); + EXPECT_NO_THROW(LeaseMgr::extractLease4ExtendedInfo(lease)); + EXPECT_NO_THROW(LeaseMgr::extractLease4ExtendedInfo(lease, false)); + + // Not a map ISC. + user_context = Element::createMap(); + lease->setContext(user_context); + ElementPtr isc = Element::create(string("...")); + user_context->set("ISC", isc); + EXPECT_NO_THROW(LeaseMgr::extractLease4ExtendedInfo(lease)); + + // No relay agent info. + user_context = Element::createMap(); + lease->setContext(user_context); + isc = Element::createMap(); + user_context->set("ISC", isc); + isc->set("foo", Element::create(string("bar"))); + EXPECT_NO_THROW(LeaseMgr::extractLease4ExtendedInfo(lease)); + EXPECT_NO_THROW(LeaseMgr::extractLease4ExtendedInfo(lease, false)); + + // Not a map relay agent info. + user_context = Element::createMap(); + lease->setContext(user_context); + isc = Element::createMap(); + user_context->set("ISC", isc); + ElementPtr rai = Element::createMap(); + rai->set("foo", Element::create(string("bar"))); + isc->set("relay-agent-info", rai); + EXPECT_NO_THROW(LeaseMgr::extractLease4ExtendedInfo(lease)); + + // No upgraded. + user_context = Element::createMap(); + lease->setContext(user_context); + isc = Element::createMap(); + user_context->set("ISC", isc); + rai = Element::create(string("0x02030102030C03AABBCC")); + isc->set("relay-agent-info", rai); + EXPECT_NO_THROW(LeaseMgr::extractLease4ExtendedInfo(lease)); + EXPECT_TRUE(lease->relay_id_.empty()); + EXPECT_TRUE(lease->remote_id_.empty()); + + // Upgraded. + EXPECT_TRUE(LeaseMgr::upgradeLease4ExtendedInfo(lease)); + EXPECT_NO_THROW(LeaseMgr::extractLease4ExtendedInfo(lease, false)); + const vector relay_id = { 0xaa, 0xbb, 0xcc }; + EXPECT_EQ(relay_id, lease->relay_id_); + const vector remote_id = { 1, 2, 3 }; + EXPECT_EQ(remote_id, lease->remote_id_); +} + +// Verify Lease4 user context extract complex operations. +TEST(Lease4ExtendedInfoTest, extractLease4ExtendedInfo) { + struct Scenario { + string description_; // test description. + string context_; // user context. + string msg_; // error message. + }; + + // Test scenarios. + vector scenarios { + { + "no user context", + "", + "" + }, + { + "user context is not a map", + "[ ]", + "user context is not a map" + }, + { + "no ISC entry", + "{ }", + "" + }, + { + "no ISC entry but not empty", + "{ \"foo\": true }", + "" + }, + { + "ISC entry is not a map", + "{ \"ISC\": true }", + "ISC entry is not a map" + }, + { + "ISC entry is not a map, user context not empty", + "{ \"foo\": true, \"ISC\": true }", + "ISC entry is not a map" + }, + { + "no relay agent info", + "{ \"ISC\": { } }", + "" + }, + { + "no relay agent info, ISC not empty", + "{ \"ISC\": { \"foo\": true } }", + "" + }, + { + "relay agent info is not a string or a map", + "{ \"ISC\": { \"relay-agent-info\": false } }", + "relay-agent-info is not a map" + }, + { + "relay agent info is not a string or a map, ISC not empty", + "{ \"ISC\": { \"foo\": true, \"relay-agent-info\": false } }", + "relay-agent-info is not a map" + }, + { + "relay agent info has a junk value", + "{ \"ISC\": { \"relay-agent-info\": \"foobar\" } }", + "relay-agent-info is not a map" + }, + { + "relay agent info has a junk value, ISC not empty", + "{ \"ISC\": { \"foo\": true, \"relay-agent-info\": \"foobar\" } }", + "relay-agent-info is not a map" + }, + { + "relay agent info has a rai without ids", + "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" + " \"0x0104AABBCCDD\" } } }", + "" + }, + { + "relay agent info with other entries", + "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" + " \"0x0104AABBCCDD\" }, \"bar\": 456 }, \"foo\": 123 }", + "" + }, + { + "relay agent info has a rai with ids", + "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" + " \"0x02030102030C03AABBCC\", \"remote-id\": \"010203\"," + " \"relay-id\": \"AABBCC\" } } }", + "" + } + }; + + Lease4Ptr lease(new Lease4()); + ElementPtr user_context; + for (auto scenario : scenarios) { + SCOPED_TRACE(scenario.description_); + + // Create the original user context from JSON. + if (scenario.context_.empty()) { + user_context.reset(); + } else { + ASSERT_NO_THROW(user_context = Element::fromJSON(scenario.context_)) + << "invalid user context, test " << scenario.description_ + << " is broken"; + } + + // Perform the test. + lease->setContext(user_context); + if (scenario.msg_.empty()) { + EXPECT_NO_THROW(LeaseMgr::extractLease4ExtendedInfo(lease, false)); + } else { + EXPECT_NO_THROW(LeaseMgr::extractLease4ExtendedInfo(lease)); + EXPECT_THROW_MSG(LeaseMgr::extractLease4ExtendedInfo(lease, false), + BadValue, scenario.msg_); + } + } + // Last scenario sets relay and remote ids. + const vector relay_id = { 0xaa, 0xbb, 0xcc }; + EXPECT_EQ(relay_id, lease->relay_id_); + const vector remote_id = { 1, 2, 3 }; + EXPECT_EQ(remote_id, lease->remote_id_); +} + // Verify Lease6 user context upgrade basic operations. TEST(Lease6ExtendedInfoTest, basic) { Lease6Ptr lease; diff --git a/src/lib/dhcpsrv/tests/lease_unittest.cc b/src/lib/dhcpsrv/tests/lease_unittest.cc index 9fae66dd09..07e1cc8101 100644 --- a/src/lib/dhcpsrv/tests/lease_unittest.cc +++ b/src/lib/dhcpsrv/tests/lease_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2022 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2013-2023 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -113,7 +113,7 @@ public: // This test checks if the Lease4 structure can be instantiated correctly. TEST_F(Lease4Test, constructor) { // Get current time for the use in Lease. - const time_t current_time = time(NULL); + const time_t current_time = time(0); // We want to check that various addresses work, so let's iterate over // these. @@ -146,7 +146,7 @@ TEST_F(Lease4Test, constructor) { TEST_F(Lease4Test, copyConstructor) { // Get current time for the use in Lease4. - const time_t current_time = time(NULL); + const time_t current_time = time(0); // Create the lease Lease4 lease(0xffffffff, hwaddr_, clientid_, VALID_LIFETIME, current_time, @@ -159,6 +159,12 @@ TEST_F(Lease4Test, copyConstructor) { // Set an user context. lease.setContext(Element::fromJSON("{ \"foobar\": 1234 }")); + // Set relay and remote id. + const std::vector relay_id = { 0xaa, 0xbb, 0xcc }; + lease.relay_id_ = relay_id; + const std::vector remote_id = { 1, 2, 3 }; + lease.remote_id_ = remote_id; + // Use copy constructor to copy the lease. Lease4 copied_lease(lease); @@ -173,6 +179,10 @@ TEST_F(Lease4Test, copyConstructor) { EXPECT_TRUE(lease.getContext() == copied_lease.getContext()); EXPECT_TRUE(*lease.getContext() == *copied_lease.getContext()); + // Relay and remote ids are equal. + EXPECT_TRUE(lease.relay_id_ == copied_lease.relay_id_); + EXPECT_TRUE(lease.remote_id_ == copied_lease.remote_id_); + // Hardware addresses are equal, but they should point to two objects, // each holding the same data. The content should be equal... EXPECT_TRUE(*lease.hwaddr_ == *copied_lease.hwaddr_); @@ -180,7 +190,7 @@ TEST_F(Lease4Test, copyConstructor) { // ... but it should point to different objects. EXPECT_FALSE(lease.hwaddr_ == copied_lease.hwaddr_); - // Now let's check that the hwaddr pointer is copied even if it's NULL: + // Now let's check that the hwaddr pointer is copied even if it's null: lease.hwaddr_.reset(); Lease4 copied_lease2(lease); EXPECT_TRUE(lease == copied_lease2); @@ -191,7 +201,7 @@ TEST_F(Lease4Test, copyConstructor) { TEST_F(Lease4Test, operatorAssign) { // Get the current time for the use in Lease4. - const time_t current_time = time(NULL); + const time_t current_time = time(0); // Create the lease Lease4 lease(0xffffffff, hwaddr_, clientid_, VALID_LIFETIME, current_time, @@ -204,33 +214,44 @@ TEST_F(Lease4Test, operatorAssign) { // Set an user context. lease.setContext(Element::fromJSON("{ \"foobar\": 1234 }")); + // Set relay and remote id. + const std::vector relay_id = { 0xaa, 0xbb, 0xcc }; + lease.relay_id_ = relay_id; + const std::vector remote_id = { 1, 2, 3 }; + lease.remote_id_ = remote_id; + // Create a default lease. - Lease4 copied_lease; + Lease4 assigned_lease; // Use assignment operator to assign new lease. - copied_lease = lease; + assigned_lease = lease; // Both leases should be now equal. When doing this check we assume that // the equality operator works correctly. - EXPECT_TRUE(lease == copied_lease); + EXPECT_TRUE(lease == assigned_lease); // Client IDs are equal, but they should be in two distinct pointers. - EXPECT_FALSE(lease.client_id_ == copied_lease.client_id_); + EXPECT_FALSE(lease.client_id_ == assigned_lease.client_id_); // User context are equal and point to the same object. - ASSERT_TRUE(copied_lease.getContext()); - EXPECT_TRUE(lease.getContext() == copied_lease.getContext()); - EXPECT_TRUE(*lease.getContext() == *copied_lease.getContext()); + ASSERT_TRUE(assigned_lease.getContext()); + EXPECT_TRUE(lease.getContext() == assigned_lease.getContext()); + EXPECT_TRUE(*lease.getContext() == *assigned_lease.getContext()); + + // User context are equal and point to the same object. + ASSERT_TRUE(assigned_lease.getContext()); + EXPECT_TRUE(lease.getContext() == assigned_lease.getContext()); + EXPECT_TRUE(*lease.getContext() == *assigned_lease.getContext()); // Hardware addresses are equal, but they should point to two objects, // each holding the same data. The content should be equal... - EXPECT_TRUE(*lease.hwaddr_ == *copied_lease.hwaddr_); + EXPECT_TRUE(*lease.hwaddr_ == *assigned_lease.hwaddr_); // ... but it should point to different objects. - EXPECT_FALSE(lease.hwaddr_ == copied_lease.hwaddr_); + EXPECT_FALSE(lease.hwaddr_ == assigned_lease.hwaddr_); - // Now let's check that the hwaddr pointer is copied even if it's NULL: + // Now let's check that the hwaddr pointer is copied even if it's null: lease.hwaddr_.reset(); - copied_lease = lease; - EXPECT_TRUE(lease == copied_lease); + assigned_lease = lease; + EXPECT_TRUE(lease == assigned_lease); } // This test verifies that it is correctly determined when the lease @@ -255,7 +276,7 @@ TEST_F(Lease4Test, leaseBelongsToClient) { // Create the lease with MAC address and Client Identifier. Lease4 lease(IOAddress("192.0.2.1"), matching_hw, matching_client_id, - 60, time(NULL), 0, 0, 1); + 60, time(0), 0, 0, 1); // Verify cases for lease that has both hw address and client identifier. EXPECT_TRUE(lease.belongsToClient(matching_hw, matching_client_id)); @@ -304,7 +325,7 @@ TEST_F(Lease4Test, operatorEquals) { // Random values for the tests const uint32_t ADDRESS = 0x01020304; - const time_t current_time = time(NULL); + const time_t current_time = time(0); // Check when the leases are equal. Lease4 lease1(ADDRESS, hwaddr_, clientid_, VALID_LIFETIME, current_time, @@ -414,14 +435,14 @@ TEST_F(Lease4Test, operatorEquals) { } // Verify that the client id can be returned as a vector object and if client -// id is NULL the empty vector is returned. +// id is null the empty vector is returned. TEST_F(Lease4Test, getClientIdVector) { // Create a lease. Lease4 lease; - // By default, the lease should have client id set to NULL. If it doesn't, + // 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. + // When client id is null the vector returned should be empty. EXPECT_TRUE(lease.getClientIdVector().empty()); // Initialize client identifier to non-null value. @@ -641,7 +662,7 @@ TEST_F(Lease4Test, decline) { lease.fqdn_fwd_ = true; lease.fqdn_rev_ = true; - time_t now = time(NULL); + time_t now = time(0); // Move lease to declined state and set its valid-lifetime to 123 seconds lease.decline(123); @@ -719,7 +740,7 @@ TEST(Lease6Test, Lease6ConstructorDefault) { EXPECT_FALSE(lease->getContext()); } - // Lease6 must be instantiated with a DUID, not with NULL pointer + // Lease6 must be instantiated with a DUID, not with null pointer IOAddress addr(ADDRESS[0]); Lease6Ptr lease2; EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_NA, addr, @@ -763,7 +784,7 @@ TEST(Lease6Test, Lease6ConstructorWithFQDN) { EXPECT_EQ("host.example.com.", lease->hostname_); } - // Lease6 must be instantiated with a DUID, not with NULL pointer + // Lease6 must be instantiated with a DUID, not with null pointer IOAddress addr(ADDRESS[0]); Lease6Ptr lease2; EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_NA, addr, @@ -792,7 +813,7 @@ TEST(Lease6Test, operatorEquals) { lease1.setContext(Element::fromJSON("{ \"foobar\": 1234 }")); lease2.setContext(Element::fromJSON("{ \"foobar\": 1234 }")); - // cltt_ constructs with time(NULL), make sure they are always equal + // cltt_ constructs with time(0), make sure they are always equal lease1.cltt_ = lease2.cltt_; EXPECT_TRUE(lease1 == lease2); @@ -918,16 +939,16 @@ TEST(Lease6Test, Lease6Expired) { Lease6 lease(Lease::TYPE_NA, addr, duid, iaid, 100, 200, subnet_id); // Case 1: a second before expiration - lease.cltt_ = time(NULL) - 100; + lease.cltt_ = time(0) - 100; lease.valid_lft_ = 101; EXPECT_FALSE(lease.expired()); // Case 2: the lease will expire after this second is concluded - lease.cltt_ = time(NULL) - 101; + lease.cltt_ = time(0) - 101; EXPECT_FALSE(lease.expired()); // Case 3: the lease is expired - lease.cltt_ = time(NULL) - 102; + lease.cltt_ = time(0) - 102; EXPECT_TRUE(lease.expired()); // Case 4: the lease is static @@ -936,17 +957,17 @@ TEST(Lease6Test, Lease6Expired) { EXPECT_FALSE(lease.expired()); } -// Verify that the DUID can be returned as a vector object and if DUID is NULL +// Verify that the DUID can be returned as a vector object and if DUID is null // the empty vector is returned. TEST(Lease6Test, getDuidVector) { // Create a lease. Lease6 lease; - // By default, the lease should have client id set to NULL. If it doesn't, + // By default, the lease should have client id set to null. If it doesn't, // continuing the test makes no sense. ASSERT_FALSE(lease.duid_); - // When client id is NULL the vector returned should be empty. + // When client id is null the vector returned should be empty. EXPECT_TRUE(lease.getDuidVector().empty()); - // Now, let's set the non NULL DUID. Fill it with the 8 bytes, each + // Now, let's set the non null DUID. Fill it with the 8 bytes, each // holding a value of 0x42. std::vector duid_vec(8, 0x42); lease.duid_ = DuidPtr(new DUID(duid_vec)); @@ -973,7 +994,7 @@ TEST(Lease6Test, decline) { lease.fqdn_fwd_ = true; lease.fqdn_rev_ = true; - time_t now = time(NULL); + time_t now = time(0); // Move the lease to declined state and set probation-period to 123 seconds lease.decline(123); @@ -1381,5 +1402,4 @@ TEST(Lease6Test, stateToText) { EXPECT_EQ("expired-reclaimed", Lease6::statesToText(Lease::STATE_EXPIRED_RECLAIMED)); } - -}; // end of anonymous namespace +} // end of anonymous namespace