// Copy the hardware address if it is defined.
if (other.hwaddr_) {
hwaddr_.reset(new HWAddr(*other.hwaddr_));
+ } else {
+ hwaddr_.reset();
}
if (other.client_id_) {
// Copy the hardware address if it is defined.
if (other.hwaddr_) {
hwaddr_.reset(new HWAddr(*other.hwaddr_));
+ } else {
+ hwaddr_.reset();
}
if (other.client_id_) {
Lease6::toText() const {
ostringstream stream;
+ /// @todo: print out DUID
stream << "Type: " << typeToText(type_) << "("
- << static_cast<int>(type_) << ") ";
+ << static_cast<int>(type_) << ")\n";
stream << "Address: " << addr_ << "\n"
<< "Prefix length: " << static_cast<int>(prefixlen_) << "\n"
<< "IAID: " << iaid_ << "\n"
<< "Pref life: " << preferred_lft_ << "\n"
<< "Valid life: " << valid_lft_ << "\n"
<< "Cltt: " << cltt_ << "\n"
- << "Hardware addr: " << (hwaddr_?hwaddr_->toText(false):"(none)")
+ << "Hardware addr: " << (hwaddr_?hwaddr_->toText(false):"(none)") << "\n"
<< "Subnet ID: " << subnet_id_ << "\n";
return (stream.str());
Lease4::toText() const {
ostringstream stream;
+ /// @todo: print out client-id (if present)
stream << "Address: " << addr_ << "\n"
<< "Valid life: " << valid_lft_ << "\n"
<< "T1: " << t1_ << "\n"
<< "T2: " << t2_ << "\n"
<< "Cltt: " << cltt_ << "\n"
- << "Hardware addr: " << (hwaddr_?hwaddr_->toText(false):"(none)")
+ << "Hardware addr: " << (hwaddr_?hwaddr_->toText(false):"(none)") << "\n"
<< "Subnet ID: " << subnet_id_ << "\n";
return (stream.str());
#include <dhcpsrv/lease.h>
#include <gtest/gtest.h>
#include <vector>
+#include <sstream>
using namespace isc;
using namespace isc::asiolink;
// ... 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:
+ lease.hwaddr_.reset();
+ Lease4 copied_lease2(lease);
+ EXPECT_TRUE(lease == copied_lease2);
}
// This test verfies that the assignment operator copies all Lease4 fields
// ... 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:
+ lease.hwaddr_.reset();
+ copied_lease = lease;
+ EXPECT_TRUE(lease == copied_lease);
}
// This test verifies that the matches() returns true if two leases differ
false, false)));
}
+// Verify that toText() method reports Lease4 structure properly.
+TEST_F(Lease4Test, toText) {
+
+ const time_t current_time = 12345678;
+ Lease4 lease(IOAddress("192.0.2.3"), hwaddr_, CLIENTID, sizeof(CLIENTID),
+ 3600, 123, 456, current_time, 789);
+
+ std::stringstream expected;
+ expected << "Address: 192.0.2.3\n"
+ << "Valid life: 3600\n"
+ << "T1: 123\n"
+ << "T2: 456\n"
+ << "Cltt: 12345678\n"
+ << "Hardware addr: " << hwaddr_->toText(false) << "\n"
+ << "Subnet ID: 789\n";
+
+ EXPECT_EQ(expected.str(), lease.toText());
+
+ // Now let's try with a lease without hardware address.
+ lease.hwaddr_.reset();
+ expected.str("");
+ expected << "Address: 192.0.2.3\n"
+ << "Valid life: 3600\n"
+ << "T1: 123\n"
+ << "T2: 456\n"
+ << "Cltt: 12345678\n"
+ << "Hardware addr: (none)\n"
+ << "Subnet ID: 789\n";
+ EXPECT_EQ(expected.str(), lease.toText());
+}
+
/// @brief Creates an instance of the lease with certain FQDN data.
///
/// @param hostname Hostname.
false, false)));
}
-/// @todo: Add tests for Lease4::toText()
-/// @todo: Add tests for Lease6::toText()
+// Verify that toText() method reports Lease4 structure properly.
+TEST(Lease6, toText) {
+
+ HWAddrPtr hwaddr(new HWAddr(HWADDR, sizeof(HWADDR), HTYPE_ETHER));
+
+ uint8_t llt[] = {0, 1, 2, 3, 4, 5, 6, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
+ DuidPtr duid(new DUID(llt, sizeof(llt)));
+
+ Lease6 lease(Lease::TYPE_NA, IOAddress("2001:db8::1"), duid, 123456,
+ 400, 800, 100, 200, 5678, hwaddr, 128);
+ lease.cltt_ = 12345678;
+
+ std::stringstream expected;
+ expected << "Type: IA_NA(" << static_cast<int>(Lease::TYPE_NA) << ")\n"
+ << "Address: 2001:db8::1\n"
+ << "Prefix length: 128\n"
+ << "IAID: 123456\n"
+ << "Pref life: 400\n"
+ << "Valid life: 800\n"
+ << "Cltt: 12345678\n"
+ << "Hardware addr: " << hwaddr->toText(false) << "\n"
+ << "Subnet ID: 5678\n";
+
+ EXPECT_EQ(expected.str(), lease.toText());
+
+ // Now let's try with a lease without hardware address.
+ lease.hwaddr_.reset();
+ expected.str("");
+ expected << "Type: IA_NA(" << static_cast<int>(Lease::TYPE_NA) << ")\n"
+ << "Address: 2001:db8::1\n"
+ << "Prefix length: 128\n"
+ << "IAID: 123456\n"
+ << "Pref life: 400\n"
+ << "Valid life: 800\n"
+ << "Cltt: 12345678\n"
+ << "Hardware addr: (none)\n"
+ << "Subnet ID: 5678\n";
+ EXPECT_EQ(expected.str(), lease.toText());
+}
}; // end of anonymous namespace