From: Thomas Markwalder Date: Mon, 22 Aug 2016 15:34:15 +0000 (-0400) Subject: [4279] Addressed review comments X-Git-Tag: trac4631_base~19^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=44c9306060af6e705f28dd6b8d5fa0889fd20128;p=thirdparty%2Fkea.git [4279] Addressed review comments src/lib/dhcpsrv/tests/generic_host_data_source_unittest.cc GenericHostDataSourceTest::compareClientClasses() - now uses std::equal() GenericHostDataSourceTest::testMultipleClientClasses4() GenericHostDataSourceTest::testMultipleClientClasses6() - added steps for each of the host getters defined in BaseHostDataSource src/lib/dhcpsrv/tests/generic_host_data_source_unittest.h src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc - fixed typo --- diff --git a/src/lib/dhcpsrv/tests/generic_host_data_source_unittest.cc b/src/lib/dhcpsrv/tests/generic_host_data_source_unittest.cc index 7b3ac2162d..86d34fdd7f 100644 --- a/src/lib/dhcpsrv/tests/generic_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/tests/generic_host_data_source_unittest.cc @@ -329,9 +329,7 @@ GenericHostDataSourceTest::compareReservations6(IPv6ResrvRange resrv1, void GenericHostDataSourceTest::compareClientClasses(const ClientClasses& classes1, const ClientClasses& classes2) { - // Currently simple comparison works as ClientClasses derives from - // std::set. - EXPECT_EQ(classes1, classes2); + EXPECT_TRUE(std::equal(classes1.begin(), classes1.end(), classes2.begin())); } void @@ -1155,10 +1153,7 @@ void GenericHostDataSourceTest::testOptionsReservations46(const bool formatted) void GenericHostDataSourceTest::testMultipleClientClasses4() { - /// Add host reservation with a multiple v4 client-classes, retrieve it and - /// make sure that all client classes are retrieved properly. ASSERT_TRUE(hdsptr_); - uint8_t len = 128; // Create the Host object. HostPtr host = initializeHost4("192.0.2.5", Host::IDENT_HWADDR); @@ -1176,18 +1171,50 @@ GenericHostDataSourceTest::testMultipleClientClasses4() { // Subnet id will be used in quries to the database. SubnetID subnet_id = host->getIPv4SubnetID(); - // Fetch the host from the source. - ConstHostPtr from_hds = hdsptr_->get4(subnet_id, IOAddress("192.0.2.5")); + // Fetch the host via: + // getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid = DuidPtr()) const; + ConstHostCollection hosts_by_id = hdsptr_->getAll(host->getHWAddress()); + ASSERT_EQ(1, hosts_by_id.size()); + ASSERT_NO_FATAL_FAILURE(compareHosts(host, *hosts_by_id.begin())); + + // Fetch the host via: + // getAll(const Host::IdentifierType, const uint8_t* identifier_begin, + // const size_t identifier_len) const; + hosts_by_id = hdsptr_->getAll(host->getIdentifierType(), &host->getIdentifier()[0], + host->getIdentifier().size()); + ASSERT_EQ(1, hosts_by_id.size()); + ASSERT_NO_FATAL_FAILURE(compareHosts(host, *hosts_by_id.begin())); + + // Fetch the host via + // getAll4(const asiolink::IOAddress& address) const; + hosts_by_id = hdsptr_->getAll4(IOAddress("192.0.2.5")); + ASSERT_EQ(1, hosts_by_id.size()); + ASSERT_NO_FATAL_FAILURE(compareHosts(host, *hosts_by_id.begin())); + + // Fetch the host via + // get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr, + // const DuidPtr& duid = DuidPtr()) const; + ConstHostPtr from_hds = hdsptr_->get4(subnet_id, host->getHWAddress()); ASSERT_TRUE(from_hds); + ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds)); - // Verify they match. + // Fetch the host via + // get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type, + // const uint8_t* identifier_begin, const size_t identifier_len) const; + from_hds = hdsptr_->get4(subnet_id, host->getIdentifierType(), &host->getIdentifier()[0], + host->getIdentifier().size()); + ASSERT_TRUE(from_hds); + ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds)); + + // Fetch the host via: + // get4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const; + from_hds = hdsptr_->get4(subnet_id, IOAddress("192.0.2.5")); + ASSERT_TRUE(from_hds); ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds)); } void GenericHostDataSourceTest::testMultipleClientClasses6() { - /// Add host reservation with a multiple v6 client-classes, retrieve it and - /// make sure that all client classes are retrieved properly. ASSERT_TRUE(hdsptr_); // Create the Host object. @@ -1206,13 +1233,39 @@ GenericHostDataSourceTest::testMultipleClientClasses6() { // Subnet id will be used in quries to the database. SubnetID subnet_id = host->getIPv6SubnetID(); - // Fetch the host from the source. - ConstHostPtr from_hds = hdsptr_->get6(subnet_id, Host::IDENT_HWADDR, + // Fetch the host via: + // getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid = DuidPtr()) const; + ConstHostCollection hosts_by_id = hdsptr_->getAll(host->getHWAddress()); + ASSERT_EQ(1, hosts_by_id.size()); + ASSERT_NO_FATAL_FAILURE(compareHosts(host, *hosts_by_id.begin())); + + //getAll(const Host::IdentifierType& identifier_type, + // const uint8_t* identifier_begin, + // const size_t identifier_len) const; + hosts_by_id = hdsptr_->getAll(host->getIdentifierType(), &host->getIdentifier()[0], + host->getIdentifier().size()); + ASSERT_EQ(1, hosts_by_id.size()); + ASSERT_NO_FATAL_FAILURE(compareHosts(host, *hosts_by_id.begin())); + + //get6(const SubnetID& subnet_id, const DuidPtr& duid, + // const HWAddrPtr& hwaddr = HWAddrPtr()) const; + ConstHostPtr from_hds = hdsptr_->get6(subnet_id, DuidPtr(), host->getHWAddress()); + ASSERT_TRUE(from_hds); + ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds)); + + // Fetch the host via: + // get6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type, + // const uint8_t* identifier_begin, const size_t identifier_len) const; + from_hds = hdsptr_->get6(subnet_id, Host::IDENT_HWADDR, &host->getIdentifier()[0], host->getIdentifier().size()); ASSERT_TRUE(from_hds); + ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds)); - // Verify they match. + // Fetch the host via: + // get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const; + from_hds = hdsptr_->get6(IOAddress("2001:db8::1"), 128); + ASSERT_TRUE(from_hds); ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds)); } diff --git a/src/lib/dhcpsrv/tests/generic_host_data_source_unittest.h b/src/lib/dhcpsrv/tests/generic_host_data_source_unittest.h index 5b6f4e4b82..b0ed22c2a7 100644 --- a/src/lib/dhcpsrv/tests/generic_host_data_source_unittest.h +++ b/src/lib/dhcpsrv/tests/generic_host_data_source_unittest.h @@ -489,7 +489,7 @@ public: /// void testMultipleClientClasses6(); - /// @brief Test that multiple client classes for both IPv5 and IPv6 can + /// @brief Test that multiple client classes for both IPv4 and IPv6 can /// be inserted and retrieved for a given host reservation. /// /// Uses gtest macros to report failures. diff --git a/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc b/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc index 4efdc0f988..1ef01548c1 100644 --- a/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc @@ -363,7 +363,7 @@ TEST_F(MySqlHostDataSourceTest, multipleClientClasses6) { testMultipleClientClasses6(); } -// Test that multiple client classes for both IPv5 and IPv6 can +// Test that multiple client classes for both IPv4 and IPv6 can // be inserted and retrieved for a given host reservation. TEST_F(MySqlHostDataSourceTest, multipleClientClassesBoth) { testMultipleClientClassesBoth(); diff --git a/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc b/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc index 9b8d45c06b..8d58637c5f 100644 --- a/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc @@ -323,7 +323,7 @@ TEST_F(PgSqlHostDataSourceTest, multipleClientClasses6) { testMultipleClientClasses6(); } -// Test that multiple client classes for both IPv5 and IPv6 can +// Test that multiple client classes for both IPv4 and IPv6 can // be inserted and retrieved for a given host reservation. TEST_F(PgSqlHostDataSourceTest, multipleClientClassesBoth) { testMultipleClientClassesBoth();