EXPECT_FALSE(by_hwaddr);
}
+void
+GenericHostDataSourceTest::testHostname(std::string name, int num) {
+
+ // Make sure we have a pointer to the host data source.
+ ASSERT_TRUE(hdsptr_);
+
+ // Initialize the address to 192.0.2.0 (this will be bumped
+ // up to 192.0.2.1 in the first iteration)
+ IOAddress addr("192.0.2.0");
+
+ vector<HostPtr> hosts;
+
+ // Prepare a vector of hosts with unique hostnames
+ for (int i = 0; i < num; ++i) {
+
+ addr = IOAddress::increase(addr);
+
+ HostPtr host = initializeHost4(addr.toText(), false);
+
+ stringstream hostname;
+ hostname.str("");
+ if (num > 1) {
+ hostname << i;
+ }
+ hostname << name;
+ host->setHostname(hostname.str());
+
+ hosts.push_back(host);
+ }
+
+ // Now add them all to the host data source.
+ for (vector<HostPtr>::const_iterator it = hosts.begin();
+ it != hosts.end(); ++it) {
+ // Try to add both of the to the host data source.
+ ASSERT_NO_THROW(hdsptr_->add(*it));
+ }
+
+ // And finally retrieve them one by one and check
+ // if the hostname was preserved.
+ for (vector<HostPtr>::const_iterator it = hosts.begin();
+ it != hosts.end(); ++it) {
+
+ ConstHostPtr from_hds;
+ ASSERT_NO_THROW(from_hds = hdsptr_->get4(
+ (*it)->getIPv4SubnetID(),
+ (*it)->getIPv4Reservation()));
+ ASSERT_TRUE(from_hds);
+
+ EXPECT_EQ((*it)->getHostname(), from_hds->getHostname());
+ }
+}
}; // namespace test
}; // namespace dhcp
/// @brief Test that clients with stored HW address can't be retrieved
/// by DUID with the same value.
///
+ /// Test procedure: add host reservation with hardware address X, try to retrieve
+ /// host by client-identifier X, verify that the reservation is not returned.
+ ///
/// Uses gtest macros to report failures.
void testHWAddrNotClientId();
/// @brief Test that clients with stored DUID can't be retrieved
/// by HW address of the same value.
///
+ /// Test procedure: add host reservation with client identifier X, try to
+ /// retrieve host by hardware address X, verify that the reservation is not
+ /// returned.
+ ///
/// Uses gtest macros to report failures.
void testClientIdNotHWAddr();
+ /// @brief Test adds specified number of hosts with unique hostnames, then
+ /// retrives them and checks that the hostnames are set properly.
+ ///
+ /// Uses gtest macros to report failures.
+ ///
+ /// @param name hostname to be used (if n>1, numbers will be appended)
+ /// @param num number of hostnames to be added.
+ void testHostname(std::string name, int num);
+
/// @brief Returns DUID with identical content as specified HW address
///
/// This method does not have any sense in real life and is only useful
// Test verifies if hardware address and client identifier are not confused.
TEST_F(MySqlHostDataSourceTest, hwaddrNotClientId1) {
testHWAddrNotClientId();
- /// @todo: add host reservation with hardware address X, try to retrieve
- /// host by client-identifier X, verify that the reservation is not returned.
}
// Test verifies if hardware address and client identifier are not confused.
TEST_F(MySqlHostDataSourceTest, hwaddrNotClientId2) {
testClientIdNotHWAddr();
- /// @todo: add host reservation with client identifier X, try to retrieve host
- /// by hardware address X, verify that the reservation is not returned.
+}
+
+// Test verifies if a host with FQDN hostname can be stored and later retrieved.
+TEST_F(MySqlHostDataSourceTest, hostnameFQDN) {
+ testHostname("foo.example.org", 1);
+}
+
+// Test verifies if 100 hosts with unique FQDN hostnames can be stored and later
+// retrieved.
+TEST_F(MySqlHostDataSourceTest, hostnameFQDN100) {
+ testHostname("foo.example.org", 1);
+}
+
+// Test verifies if a host without any hostname specified can be stored and later
+// retrieved.
+TEST_F(MySqlHostDataSourceTest, noHostname) {
+ testHostname("", 1);
}
// Test verifies if the hardware or client-id query can match hardware address.
-TEST_F(MySqlHostDataSourceTest, hwaddrOrClientId1) {
+TEST_F(MySqlHostDataSourceTest, DISABLED_hwaddrOrClientId1) {
+ /// @todo: The logic behind ::get4(subnet_id, hwaddr, duid) call needs to
+ /// be discussed.
+ ///
/// @todo: Add host reservation with hardware address X, try to retrieve
/// host for hardware address X or client identifier Y, verify that the
/// reservation is returned.
}
// Test verifies if the hardware or client-id query can match client-id.
-TEST_F(MySqlHostDataSourceTest, hwaddrOrClientId2) {
+TEST_F(MySqlHostDataSourceTest, DISABLED_hwaddrOrClientId2) {
+ /// @todo: The logic behind ::get4(subnet_id, hwaddr, duid) call needs to
+ /// be discussed.
+ ///
/// @todo: Add host reservation with client identifier Y, try to retrieve
/// host for hardware address X or client identifier Y, verify that the
/// reservation is returned.