Commit 9095ca3d authored by Francis Dupont's avatar Francis Dupont
Browse files

[5532] Updated tests using add to check return

parent d2932074
......@@ -572,7 +572,9 @@ GenericHostDataSourceTest::testReadOnlyDatabase(const char* valid_db_type) {
// insert some data to the database.
HostPtr host = initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
ASSERT_TRUE(host);
ASSERT_NO_THROW(hdsptr_->add(host));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host));
EXPECT_TRUE(added);
// Subnet id will be used in queries to the database.
SubnetID subnet_id = host->getIPv6SubnetID();
......@@ -621,7 +623,9 @@ GenericHostDataSourceTest::testBasic4(const Host::IdentifierType& id) {
SubnetID subnet = host->getIPv4SubnetID();
// Try to add it to the host data source.
ASSERT_NO_THROW(hdsptr_->add(host));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host));
EXPECT_TRUE(added);
// This should not return anything
ConstHostPtr from_hds = hdsptr_->get4(subnet, IOAddress("10.10.10.10"));
......@@ -647,10 +651,15 @@ GenericHostDataSourceTest::testGetByIPv4(const Host::IdentifierType& id) {
HostPtr host4 = initializeHost4("192.0.2.4", id);
// ... and add them to the data source.
ASSERT_NO_THROW(hdsptr_->add(host1));
ASSERT_NO_THROW(hdsptr_->add(host2));
ASSERT_NO_THROW(hdsptr_->add(host3));
ASSERT_NO_THROW(hdsptr_->add(host4));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host1));
EXPECT_TRUE(added);
ASSERT_NO_THROW(added = hdsptr_->add(host2));
EXPECT_TRUE(added);
ASSERT_NO_THROW(added = hdsptr_->add(host3));
EXPECT_TRUE(added);
ASSERT_NO_THROW(added = hdsptr_->add(host4));
EXPECT_TRUE(added);
SubnetID subnet1 = host1->getIPv4SubnetID();
SubnetID subnet2 = host2->getIPv4SubnetID();
......@@ -693,8 +702,11 @@ GenericHostDataSourceTest::testGet4ByIdentifier(
ASSERT_FALSE(host1->getIdentifier() == host2->getIdentifier());
// Try to add both of them to the host data source.
ASSERT_NO_THROW(hdsptr_->add(host1));
ASSERT_NO_THROW(hdsptr_->add(host2));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host1));
EXPECT_TRUE(added);
ASSERT_NO_THROW(added = hdsptr_->add(host2));
EXPECT_TRUE(added);
SubnetID subnet1 = host1->getIPv4SubnetID();
SubnetID subnet2 = host2->getIPv4SubnetID();
......@@ -725,7 +737,9 @@ GenericHostDataSourceTest::testHWAddrNotClientId() {
ASSERT_FALSE(host->getDuid());
// Try to add it to the host data source.
ASSERT_NO_THROW(hdsptr_->add(host));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host));
EXPECT_TRUE(added);
SubnetID subnet = host->getIPv4SubnetID();
......@@ -757,7 +771,9 @@ GenericHostDataSourceTest::testClientIdNotHWAddr() {
ASSERT_TRUE(host->getDuid());
// Try to add it to the host data source.
ASSERT_NO_THROW(hdsptr_->add(host));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host));
EXPECT_TRUE(added);
SubnetID subnet = host->getIPv4SubnetID();
......@@ -810,7 +826,9 @@ GenericHostDataSourceTest::testHostname(std::string name, int num) {
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));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(*it));
EXPECT_TRUE(added);
}
// And finally retrieve them one by one and check
......@@ -839,7 +857,9 @@ GenericHostDataSourceTest::testUserContext(ConstElementPtr user_context) {
SubnetID subnet = host->getIPv4SubnetID();
// Try to add it to the host data source.
ASSERT_NO_THROW(hdsptr_->add(host));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host));
EXPECT_TRUE(added);
// Retrieve it.
ConstHostPtr from_hds = hdsptr_->get4(subnet, IOAddress("192.0.2.1"));
......@@ -856,7 +876,8 @@ GenericHostDataSourceTest::testUserContext(ConstElementPtr user_context) {
host->setHostname("foo.example.com");
subnet = host->getIPv6SubnetID();
ASSERT_NO_THROW(hdsptr_->add(host));
ASSERT_NO_THROW(added = hdsptr_->add(host));
EXPECT_TRUE(added);
from_hds = hdsptr_->get6(subnet, Host::IDENT_HWADDR,
&host->getIdentifier()[0],
......@@ -879,7 +900,9 @@ GenericHostDataSourceTest::testMultipleSubnets(int subnets,
host->setIPv4SubnetID(i + 1000);
// Check that the same host can have reservations in multiple subnets.
EXPECT_NO_THROW(hdsptr_->add(host));
bool added = false;
EXPECT_NO_THROW(added = hdsptr_->add(host));
EXPECT_TRUE(added);
}
// Now check that the reservations can be retrieved by IPv4 address from
......@@ -953,8 +976,11 @@ GenericHostDataSourceTest::testGet6ByHWAddr() {
compareHwaddrs(host1, host2, false);
// Try to add both of them to the host data source.
ASSERT_NO_THROW(hdsptr_->add(host1));
ASSERT_NO_THROW(hdsptr_->add(host2));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host1));
EXPECT_TRUE(added);
ASSERT_NO_THROW(added = hdsptr_->add(host2));
EXPECT_TRUE(added);
SubnetID subnet1 = host1->getIPv6SubnetID();
SubnetID subnet2 = host2->getIPv6SubnetID();
......@@ -990,8 +1016,11 @@ GenericHostDataSourceTest::testGet6ByClientId() {
compareDuids(host1, host2, false);
// Try to add both of them to the host data source.
ASSERT_NO_THROW(hdsptr_->add(host1));
ASSERT_NO_THROW(hdsptr_->add(host2));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host1));
EXPECT_TRUE(added);
ASSERT_NO_THROW(added = hdsptr_->add(host2));
EXPECT_TRUE(added);
SubnetID subnet1 = host1->getIPv6SubnetID();
SubnetID subnet2 = host2->getIPv6SubnetID();
......@@ -1027,7 +1056,9 @@ GenericHostDataSourceTest::testSubnetId6(int subnets, Host::IdentifierType id) {
host->setIPv6SubnetID(i + 1000);
// Check that the same host can have reservations in multiple subnets.
EXPECT_NO_THROW(hdsptr_->add(host));
bool added = false;
EXPECT_NO_THROW(added = hdsptr_->add(host));
EXPECT_TRUE(added);
// Increase address to make sure we don't assign the same address
// in different subnets.
......@@ -1075,10 +1106,15 @@ GenericHostDataSourceTest::testGetByIPv6(Host::IdentifierType id, bool prefix) {
HostPtr host4 = initializeHost6("2001:db8::4", id, prefix);
// ... and add them to the data source.
ASSERT_NO_THROW(hdsptr_->add(host1));
ASSERT_NO_THROW(hdsptr_->add(host2));
ASSERT_NO_THROW(hdsptr_->add(host3));
ASSERT_NO_THROW(hdsptr_->add(host4));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host1));
EXPECT_TRUE(added);
ASSERT_NO_THROW(added = hdsptr_->add(host2));
EXPECT_TRUE(added);
ASSERT_NO_THROW(added = hdsptr_->add(host3));
EXPECT_TRUE(added);
ASSERT_NO_THROW(added = hdsptr_->add(host4));
EXPECT_TRUE(added);
// Are we talking about addresses or prefixes?
uint8_t len = prefix ? 64 : 128;
......@@ -1118,10 +1154,15 @@ GenericHostDataSourceTest::testGetBySubnetIPv6() {
HostPtr host4 = initializeHost6("2001:db8:4::", Host::IDENT_DUID, true);
// ... and add them to the data source.
ASSERT_NO_THROW(hdsptr_->add(host1));
ASSERT_NO_THROW(hdsptr_->add(host2));
ASSERT_NO_THROW(hdsptr_->add(host3));
ASSERT_NO_THROW(hdsptr_->add(host4));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host1));
EXPECT_TRUE(added);
ASSERT_NO_THROW(added = hdsptr_->add(host2));
EXPECT_TRUE(added);
ASSERT_NO_THROW(added = hdsptr_->add(host3));
EXPECT_TRUE(added);
ASSERT_NO_THROW(added = hdsptr_->add(host4));
EXPECT_TRUE(added);
// And then try to retrieve them back.
ConstHostPtr from_hds1 = hdsptr_->get6(host1->getIPv6SubnetID(), IOAddress("2001:db8:1::"));
......@@ -1151,7 +1192,9 @@ GenericHostDataSourceTest::testAddDuplicate6WithSameDUID() {
HostPtr host = initializeHost6("2001:db8::1", Host::IDENT_DUID, true);
// Add this reservation once.
ASSERT_NO_THROW(hdsptr_->add(host));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host));
EXPECT_TRUE(added);
// Then try to add it again, it should throw an exception.
ASSERT_THROW(hdsptr_->add(host), DuplicateEntry);
......@@ -1166,7 +1209,9 @@ GenericHostDataSourceTest::testAddDuplicate6WithSameHWAddr() {
HostPtr host = initializeHost6("2001:db8::1", Host::IDENT_HWADDR, true);
// Add this reservation once.
ASSERT_NO_THROW(hdsptr_->add(host));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host));
EXPECT_TRUE(added);
// Then try to add it again, it should throw an exception.
ASSERT_THROW(hdsptr_->add(host), DuplicateEntry);
......@@ -1181,7 +1226,9 @@ GenericHostDataSourceTest::testAddDuplicate4() {
HostPtr host = initializeHost4("192.0.2.1", Host::IDENT_DUID);
// Add this reservation once.
ASSERT_NO_THROW(hdsptr_->add(host));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host));
EXPECT_TRUE(added);
// Then try to add it again, it should throw an exception.
ASSERT_THROW(hdsptr_->add(host), DuplicateEntry);
......@@ -1195,7 +1242,8 @@ GenericHostDataSourceTest::testAddDuplicate4() {
// Modify address to avoid its duplication and make sure
// we can now add the host.
ASSERT_NO_THROW(host->setIPv4Reservation(IOAddress("192.0.2.3")));
EXPECT_NO_THROW(hdsptr_->add(host));
EXPECT_NO_THROW(added = hdsptr_->add(host));
EXPECT_TRUE(added);
}
void
......@@ -1211,7 +1259,9 @@ GenericHostDataSourceTest::testAddr6AndPrefix() {
host->addReservation(resv);
// Add this reservation
ASSERT_NO_THROW(hdsptr_->add(host));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host));
EXPECT_TRUE(added);
// Get this host by DUID
ConstHostPtr from_hds =
......@@ -1245,7 +1295,9 @@ GenericHostDataSourceTest::testMultipleReservations() {
host->addReservation(resv3);
host->addReservation(resv4);
ASSERT_NO_THROW(hdsptr_->add(host));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host));
EXPECT_TRUE(added);
ConstHostPtr from_hds = hdsptr_->get6(IOAddress("2001:db8::1"), len);
......@@ -1292,7 +1344,9 @@ void GenericHostDataSourceTest::testOptionsReservations4(const bool formatted,
// Add a bunch of DHCPv4 and DHCPv6 options for the host.
ASSERT_NO_THROW(addTestOptions(host, formatted, DHCP4_ONLY, user_context));
// Insert host and the options into respective tables.
ASSERT_NO_THROW(hdsptr_->add(host));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host));
EXPECT_TRUE(added);
// Subnet id will be used in queries to the database.
SubnetID subnet_id = host->getIPv4SubnetID();
......@@ -1320,7 +1374,9 @@ void GenericHostDataSourceTest::testOptionsReservations6(const bool formatted,
// Add a bunch of DHCPv4 and DHCPv6 options for the host.
ASSERT_NO_THROW(addTestOptions(host, formatted, DHCP6_ONLY, user_context));
// Insert host, options and IPv6 reservations into respective tables.
ASSERT_NO_THROW(hdsptr_->add(host));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host));
EXPECT_TRUE(added);
// Subnet id will be used in queries to the database.
SubnetID subnet_id = host->getIPv6SubnetID();
......@@ -1342,7 +1398,9 @@ GenericHostDataSourceTest::testOptionsReservations46(const bool formatted) {
// Add a bunch of DHCPv4 and DHCPv6 options for the host.
ASSERT_NO_THROW(addTestOptions(host, formatted, DHCP4_AND_DHCP6));
// Insert host, options and IPv6 reservations into respective tables.
ASSERT_NO_THROW(hdsptr_->add(host));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host));
EXPECT_TRUE(added);
// getAll(identifier_type, identifier, identifier_size)
ConstHostCollection hosts_by_id =
......@@ -1367,7 +1425,9 @@ GenericHostDataSourceTest::testMultipleClientClasses4() {
}
// Add the host.
ASSERT_NO_THROW(hdsptr_->add(host));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host));
EXPECT_TRUE(added);
// Subnet id will be used in queries to the database.
SubnetID subnet_id = host->getIPv4SubnetID();
......@@ -1432,7 +1492,9 @@ GenericHostDataSourceTest::testMultipleClientClasses6() {
}
// Add the host.
ASSERT_NO_THROW(hdsptr_->add(host));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host));
EXPECT_TRUE(added);
// Subnet id will be used in queries to the database.
SubnetID subnet_id = host->getIPv6SubnetID();
......@@ -1501,7 +1563,9 @@ GenericHostDataSourceTest::testMultipleClientClassesBoth() {
}
// Add the host.
ASSERT_NO_THROW(hdsptr_->add(host));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host));
EXPECT_TRUE(added);
// Subnet id will be used in queries to the database.
SubnetID subnet_id = host->getIPv6SubnetID();
......@@ -1530,7 +1594,9 @@ GenericHostDataSourceTest::testMessageFields4() {
});
// Add the host.
ASSERT_NO_THROW(hdsptr_->add(host));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host));
EXPECT_TRUE(added);
// Subnet id will be used in queries to the database.
SubnetID subnet_id = host->getIPv4SubnetID();
......@@ -1589,7 +1655,9 @@ void GenericHostDataSourceTest::testDeleteByAddr4() {
SubnetID subnet1 = host1->getIPv4SubnetID();
// ... and add it to the data source.
ASSERT_NO_THROW(hdsptr_->add(host1));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host1));
EXPECT_TRUE(added);
// And then try to retrieve it back.
ConstHostPtr before = hdsptr_->get4(subnet1, IOAddress("192.0.2.1"));
......@@ -1616,7 +1684,9 @@ void GenericHostDataSourceTest::testDeleteById4() {
SubnetID subnet1 = host1->getIPv4SubnetID();
// ... and add it to the data source.
ASSERT_NO_THROW(hdsptr_->add(host1));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host1));
EXPECT_TRUE(added);
// And then try to retrieve it back.
ConstHostPtr before = hdsptr_->get4(subnet1,
......@@ -1657,7 +1727,9 @@ void GenericHostDataSourceTest::testDeleteById4Options() {
SubnetID subnet1 = host1->getIPv4SubnetID();
// ... and add it to the data source.
ASSERT_NO_THROW(hdsptr_->add(host1));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host1));
EXPECT_TRUE(added);
// There must be some options
EXPECT_NE(0, countDBOptions4());
......@@ -1698,7 +1770,9 @@ void GenericHostDataSourceTest::testDeleteById6() {
SubnetID subnet1 = host1->getIPv6SubnetID();
// ... and add it to the data source.
ASSERT_NO_THROW(hdsptr_->add(host1));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host1));
EXPECT_TRUE(added);
// And then try to retrieve it back.
ConstHostPtr before = hdsptr_->get6(subnet1,
......@@ -1734,7 +1808,9 @@ void GenericHostDataSourceTest::testDeleteById6Options() {
ASSERT_NO_THROW(addTestOptions(host1, true, DHCP6_ONLY));
// ... and add it to the data source.
ASSERT_NO_THROW(hdsptr_->add(host1));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host1));
EXPECT_TRUE(added);
// Check that the options are stored...
EXPECT_NE(0, countDBOptions6());
......@@ -1782,7 +1858,9 @@ GenericHostDataSourceTest::testMultipleHostsNoAddress4() {
host1->setIPv4SubnetID(1);
host1->setIPv6SubnetID(0);
// Add the host to the database.
ASSERT_NO_THROW(hdsptr_->add(host1));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host1));
EXPECT_TRUE(added);
// An attempt to add this host again should fail due to client identifier
// duplication.
......@@ -1794,7 +1872,8 @@ GenericHostDataSourceTest::testMultipleHostsNoAddress4() {
HostPtr host2 = initializeHost4("0.0.0.0", Host::IDENT_HWADDR);
host2->setIPv4SubnetID(1);
host2->setIPv6SubnetID(0);
ASSERT_NO_THROW(hdsptr_->add(host2));
ASSERT_NO_THROW(added = hdsptr_->add(host2));
EXPECT_TRUE(added);
}
void
......@@ -1807,7 +1886,9 @@ GenericHostDataSourceTest::testMultipleHosts6() {
host1->setIPv4SubnetID(0);
host1->setIPv6SubnetID(1);
// Add the host to the database.
ASSERT_NO_THROW(hdsptr_->add(host1));
bool added = false;
ASSERT_NO_THROW(added = hdsptr_->add(host1));
EXPECT_TRUE(added);
// An attempt to add this host again should fail due to client identifier
// duplication.
......@@ -1817,7 +1898,8 @@ GenericHostDataSourceTest::testMultipleHosts6() {
host2->setIPv4SubnetID(0);
host2->setIPv6SubnetID(1);
// Add the host to the database.
ASSERT_NO_THROW(hdsptr_->add(host2));
ASSERT_NO_THROW(added = hdsptr_->add(host2));
EXPECT_TRUE(added);
}
} // namespace test
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment