|
@@ -109,6 +109,7 @@ TEST_F(Lease4Test, constructor) {
|
|
|
EXPECT_TRUE(lease.fqdn_fwd_);
|
|
|
EXPECT_TRUE(lease.fqdn_rev_);
|
|
|
EXPECT_TRUE(lease.comments_.empty());
|
|
|
+ EXPECT_EQ(Lease::STATE_DEFAULT, lease.state_);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -126,6 +127,10 @@ TEST_F(Lease4Test, copyConstructor) {
|
|
|
Lease4 lease(0xffffffff, hwaddr_, clientid_, VALID_LIFETIME, 0, 0, current_time,
|
|
|
SUBNET_ID);
|
|
|
|
|
|
+ // Declined is a non-default state. We'll see if the state will be copied
|
|
|
+ // or the default state will be set for the copied lease.
|
|
|
+ lease.state_ = Lease::STATE_DECLINED;
|
|
|
+
|
|
|
// Use copy constructor to copy the lease.
|
|
|
Lease4 copied_lease(lease);
|
|
|
|
|
@@ -163,8 +168,14 @@ TEST_F(Lease4Test, operatorAssign) {
|
|
|
Lease4 lease(0xffffffff, hwaddr_, clientid_, VALID_LIFETIME, 0, 0, current_time,
|
|
|
SUBNET_ID);
|
|
|
|
|
|
- // Use assignment operator to assign the lease.
|
|
|
- Lease4 copied_lease = lease;
|
|
|
+ // Declined is a non-default state. We'll see if the state will be copied
|
|
|
+ // or the default state will be set for the copied lease.
|
|
|
+ lease.state_ = Lease::STATE_DECLINED;
|
|
|
+
|
|
|
+ // Create a default lease.
|
|
|
+ Lease4 copied_lease;
|
|
|
+ // Use assignment operator to assign new lease.
|
|
|
+ copied_lease = lease;
|
|
|
|
|
|
// Both leases should be now equal. When doing this check we assume that
|
|
|
// the equality operator works correctly.
|
|
@@ -377,6 +388,13 @@ TEST_F(Lease4Test, operatorEquals) {
|
|
|
lease1.comments_ = lease2.comments_;
|
|
|
EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
|
|
|
EXPECT_FALSE(lease1 != lease2); // ... leases equal
|
|
|
+
|
|
|
+ lease1.state_ += 1;
|
|
|
+ EXPECT_FALSE(lease1 == lease2);
|
|
|
+ EXPECT_TRUE(lease1 != lease2);
|
|
|
+ lease2.state_ += 1;
|
|
|
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
|
|
|
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
|
|
|
}
|
|
|
|
|
|
// Verify that the client id can be returned as a vector object and if client
|
|
@@ -430,7 +448,8 @@ TEST_F(Lease4Test, toText) {
|
|
|
<< "Cltt: 12345678\n"
|
|
|
<< "Hardware addr: " << hwaddr_->toText(false) << "\n"
|
|
|
<< "Client id: " << clientid_->toText() << "\n"
|
|
|
- << "Subnet ID: 789\n";
|
|
|
+ << "Subnet ID: 789\n"
|
|
|
+ << "State: default\n";
|
|
|
|
|
|
EXPECT_EQ(expected.str(), lease.toText());
|
|
|
|
|
@@ -445,10 +464,26 @@ TEST_F(Lease4Test, toText) {
|
|
|
<< "Cltt: 12345678\n"
|
|
|
<< "Hardware addr: (none)\n"
|
|
|
<< "Client id: (none)\n"
|
|
|
- << "Subnet ID: 789\n";
|
|
|
+ << "Subnet ID: 789\n"
|
|
|
+ << "State: default\n";
|
|
|
EXPECT_EQ(expected.str(), lease.toText());
|
|
|
}
|
|
|
|
|
|
+// Verify that the lease states are correctly returned in the textual format.
|
|
|
+TEST_F(Lease4Test, stateToText) {
|
|
|
+ EXPECT_EQ("default", Lease4::statesToText(Lease::STATE_DEFAULT));
|
|
|
+ EXPECT_EQ("declined", Lease4::statesToText(Lease::STATE_DECLINED));
|
|
|
+ EXPECT_EQ("expired-reclaimed", Lease4::statesToText(Lease::STATE_EXPIRED_RECLAIMED));
|
|
|
+
|
|
|
+ // Try multiple states.
|
|
|
+ EXPECT_EQ("default,declined,expired-reclaimed",
|
|
|
+ Lease4::statesToText(Lease::STATE_DEFAULT | Lease::STATE_DECLINED |
|
|
|
+ Lease::STATE_EXPIRED_RECLAIMED));
|
|
|
+
|
|
|
+ // Try undefined state.
|
|
|
+ EXPECT_EQ("(not set)", Lease4::statesToText(0));
|
|
|
+}
|
|
|
+
|
|
|
/// @brief Creates an instance of the lease with certain FQDN data.
|
|
|
///
|
|
|
/// @param hostname Hostname.
|
|
@@ -467,7 +502,7 @@ Lease6 createLease6(const std::string& hostname, const bool fqdn_fwd,
|
|
|
|
|
|
// Lease6 is also defined in lease_mgr.h, so is tested in this file as well.
|
|
|
// This test checks if the Lease6 structure can be instantiated correctly
|
|
|
-TEST(Lease6, Lease6ConstructorDefault) {
|
|
|
+TEST(Lease6Test, Lease6ConstructorDefault) {
|
|
|
|
|
|
// check a variety of addresses with different bits set.
|
|
|
const char* ADDRESS[] = {
|
|
@@ -514,7 +549,7 @@ TEST(Lease6, Lease6ConstructorDefault) {
|
|
|
|
|
|
// This test verifies that the Lease6 constructor which accepts FQDN data,
|
|
|
// sets the data correctly for the lease.
|
|
|
-TEST(Lease6, Lease6ConstructorWithFQDN) {
|
|
|
+TEST(Lease6Test, Lease6ConstructorWithFQDN) {
|
|
|
|
|
|
// check a variety of addresses with different bits set.
|
|
|
const char* ADDRESS[] = {
|
|
@@ -563,7 +598,7 @@ TEST(Lease6, Lease6ConstructorWithFQDN) {
|
|
|
/// Checks that the operator==() correctly compares two leases for equality.
|
|
|
/// As operator!=() is also defined for this class, every check on operator==()
|
|
|
/// is followed by the reverse check on operator!=().
|
|
|
-TEST(Lease6, OperatorEquals) {
|
|
|
+TEST(Lease6Test, OperatorEquals) {
|
|
|
|
|
|
// check a variety of addresses with different bits set.
|
|
|
const IOAddress addr("2001:db8:1::456");
|
|
@@ -699,10 +734,17 @@ TEST(Lease6, OperatorEquals) {
|
|
|
lease1.comments_ = lease2.comments_;
|
|
|
EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
|
|
|
EXPECT_FALSE(lease1 != lease2); // ... leases equal
|
|
|
+
|
|
|
+ lease1.state_ += 1;
|
|
|
+ EXPECT_FALSE(lease1 == lease2);
|
|
|
+ EXPECT_TRUE(lease1 != lease2);
|
|
|
+ lease2.state_ += 1;
|
|
|
+ EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
|
|
|
+ EXPECT_FALSE(lease1 != lease2); // ... leases equal
|
|
|
}
|
|
|
|
|
|
// Checks if lease expiration is calculated properly
|
|
|
-TEST(Lease6, Lease6Expired) {
|
|
|
+TEST(Lease6Test, Lease6Expired) {
|
|
|
const IOAddress addr("2001:db8:1::456");
|
|
|
const uint8_t duid_array[] = {0, 1, 2, 3, 4, 5, 6, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
|
|
|
const DuidPtr duid(new DUID(duid_array, sizeof(duid_array)));
|
|
@@ -727,7 +769,7 @@ TEST(Lease6, Lease6Expired) {
|
|
|
|
|
|
// Verify that the DUID can be returned as a vector object and if DUID is NULL
|
|
|
// the empty vector is returned.
|
|
|
-TEST(Lease6, getDuidVector) {
|
|
|
+TEST(Lease6Test, getDuidVector) {
|
|
|
// Create a lease.
|
|
|
Lease6 lease;
|
|
|
// By default, the lease should have client id set to NULL. If it doesn't,
|
|
@@ -746,7 +788,7 @@ TEST(Lease6, getDuidVector) {
|
|
|
}
|
|
|
|
|
|
// Verify the behavior of the function which checks FQDN data for equality.
|
|
|
-TEST(Lease6, hasIdenticalFqdn) {
|
|
|
+TEST(Lease6Test, hasIdenticalFqdn) {
|
|
|
Lease6 lease = createLease6("myhost.example.com.", true, true);
|
|
|
EXPECT_TRUE(lease.hasIdenticalFqdn(createLease6("myhost.example.com.",
|
|
|
true, true)));
|
|
@@ -763,7 +805,7 @@ TEST(Lease6, hasIdenticalFqdn) {
|
|
|
}
|
|
|
|
|
|
// Verify that toText() method reports Lease4 structure properly.
|
|
|
-TEST(Lease6, toText) {
|
|
|
+TEST(Lease6Test, toText) {
|
|
|
|
|
|
HWAddrPtr hwaddr(new HWAddr(HWADDR, sizeof(HWADDR), HTYPE_ETHER));
|
|
|
|
|
@@ -773,6 +815,7 @@ TEST(Lease6, toText) {
|
|
|
Lease6 lease(Lease::TYPE_NA, IOAddress("2001:db8::1"), duid, 123456,
|
|
|
400, 800, 100, 200, 5678, hwaddr, 128);
|
|
|
lease.cltt_ = 12345678;
|
|
|
+ lease.state_ = Lease::STATE_DECLINED;
|
|
|
|
|
|
std::stringstream expected;
|
|
|
expected << "Type: IA_NA(" << static_cast<int>(Lease::TYPE_NA) << ")\n"
|
|
@@ -783,7 +826,8 @@ TEST(Lease6, toText) {
|
|
|
<< "Valid life: 800\n"
|
|
|
<< "Cltt: 12345678\n"
|
|
|
<< "Hardware addr: " << hwaddr->toText(false) << "\n"
|
|
|
- << "Subnet ID: 5678\n";
|
|
|
+ << "Subnet ID: 5678\n"
|
|
|
+ << "State: declined\n";
|
|
|
|
|
|
EXPECT_EQ(expected.str(), lease.toText());
|
|
|
|
|
@@ -798,8 +842,25 @@ TEST(Lease6, toText) {
|
|
|
<< "Valid life: 800\n"
|
|
|
<< "Cltt: 12345678\n"
|
|
|
<< "Hardware addr: (none)\n"
|
|
|
- << "Subnet ID: 5678\n";
|
|
|
+ << "Subnet ID: 5678\n"
|
|
|
+ << "State: declined\n";
|
|
|
EXPECT_EQ(expected.str(), lease.toText());
|
|
|
}
|
|
|
|
|
|
+// Verify that the lease states are correctly returned in the textual format.
|
|
|
+TEST(Lease6Test, stateToText) {
|
|
|
+ EXPECT_EQ("default", Lease6::statesToText(Lease::STATE_DEFAULT));
|
|
|
+ EXPECT_EQ("declined", Lease6::statesToText(Lease::STATE_DECLINED));
|
|
|
+ EXPECT_EQ("expired-reclaimed", Lease6::statesToText(Lease::STATE_EXPIRED_RECLAIMED));
|
|
|
+
|
|
|
+ // Try multiple states.
|
|
|
+ EXPECT_EQ("default,declined,expired-reclaimed",
|
|
|
+ Lease6::statesToText(Lease::STATE_DEFAULT | Lease::STATE_DECLINED |
|
|
|
+ Lease::STATE_EXPIRED_RECLAIMED));
|
|
|
+
|
|
|
+ // Try undefined state.
|
|
|
+ EXPECT_EQ("(not set)", Lease6::statesToText(0));
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
}; // end of anonymous namespace
|