From 1328552aaa908c3c81d1744f5a0b3fedf423217a Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Fri, 1 Sep 2017 14:52:38 +0200 Subject: [PATCH] [5305] Added unit test for shared network destruction. --- .../dhcpsrv/tests/shared_network_unittest.cc | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/lib/dhcpsrv/tests/shared_network_unittest.cc b/src/lib/dhcpsrv/tests/shared_network_unittest.cc index 054961a1fc..d2b6bff743 100644 --- a/src/lib/dhcpsrv/tests/shared_network_unittest.cc +++ b/src/lib/dhcpsrv/tests/shared_network_unittest.cc @@ -245,6 +245,32 @@ TEST(SharedNetwork4Test, unparse) { test::runToElementTest(expected, *network); } +// This test verifies that when the shared network object is destroyed, +// the subnets belonging to this shared network will not hold the pointer +// to the destroyed network. +TEST(SharedNetwork4Test, destructSharedNetwork) { + // Create a network and add a subnet to it. + SharedNetwork4Ptr network(new SharedNetwork4("frog")); + Subnet4Ptr subnet(new Subnet4(IOAddress("10.0.0.0"), 8, 10, 20, 30, + SubnetID(1))); + ASSERT_NO_THROW(network->add(subnet)); + + // Get the pointer to the network from subnet. + SharedNetwork4Ptr subnet_to_network; + subnet->getSharedNetwork(subnet_to_network); + ASSERT_TRUE(subnet_to_network); + + // Reset the pointer to not hold the reference to the shared network. + subnet_to_network.reset(); + + // Destroy the network object. + network.reset(); + + // The reference to the network from the subnet should be lost. + subnet->getSharedNetwork(subnet_to_network); + ASSERT_FALSE(subnet_to_network); +} + // This test verifies that shared network can be given a name and that // this name can be retrieved. TEST(SharedNetwork6Test, getName) { @@ -462,4 +488,31 @@ TEST(SharedNetwork6Test, unparse) { test::runToElementTest(expected, *network); } +// This test verifies that when the shared network object is destroyed, +// the subnets belonging to this shared network will not hold the pointer +// to the destroyed network. +TEST(SharedNetwork6Test, destructSharedNetwork) { + // Create a network and add a subnet to it. + SharedNetwork6Ptr network(new SharedNetwork6("frog")); + Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8:1::"), 64, 10, 20, 30, + 40, SubnetID(1))); + ASSERT_NO_THROW(network->add(subnet)); + + // Get the pointer to the network from subnet. + SharedNetwork6Ptr subnet_to_network; + subnet->getSharedNetwork(subnet_to_network); + ASSERT_TRUE(subnet_to_network); + + // Reset the pointer to not hold the reference to the shared network. + subnet_to_network.reset(); + + // Destroy the network object. + network.reset(); + + // The reference to the network from the subnet should be lost. + subnet->getSharedNetwork(subnet_to_network); + ASSERT_FALSE(subnet_to_network); +} + + } // end of anonymous namespace -- 2.47.2