From e4ab6c90baf1e32df55a729055d9a5838905ad0d Mon Sep 17 00:00:00 2001 From: Andrew Geissler Date: Thu, 21 Feb 2019 15:07:27 -0600 Subject: unit-test: Test checkAssociationEndpointRemoves() Testing: 100% coverage of associations.cpp Change-Id: I311af1c868416e8e898a25e593d399cd8297ccf9 Signed-off-by: Andrew Geissler --- src/test/associations.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/test/associations.cpp b/src/test/associations.cpp index 8edb0de..8b2fadf 100644 --- a/src/test/associations.cpp +++ b/src/test/associations.cpp @@ -96,3 +96,69 @@ TEST_F(TestAssociations, PathIsInAssociatedInterfacesExtraEndpoints) intfEndpoints = std::get(assocInterfaces[DEFAULT_REV_PATH]); EXPECT_EQ(intfEndpoints.size(), 0); } + +// Verify no associations or endpoints removed when the change is identical +TEST_F(TestAssociations, checkAssociationEndpointRemovesNoEpRemove) +{ + + AssociationPaths newAssocPaths = { + {DEFAULT_FWD_PATH, {DEFAULT_ENDPOINT}}, + {DEFAULT_REV_PATH, {DEFAULT_SOURCE_PATH}}}; + + auto assocOwners = createDefaultOwnerAssociation(); + auto assocInterfaces = createDefaultInterfaceAssociation(server); + + checkAssociationEndpointRemoves(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, + newAssocPaths, *server, assocOwners, + assocInterfaces); + + // Verify endpoints were not deleted because they matche with what was + // in the original + auto intfEndpoints = + std::get(assocInterfaces[DEFAULT_FWD_PATH]); + EXPECT_EQ(intfEndpoints.size(), 1); + intfEndpoints = std::get(assocInterfaces[DEFAULT_REV_PATH]); + EXPECT_EQ(intfEndpoints.size(), 1); +} + +// Verify endpoint is removed when assoc path is different +TEST_F(TestAssociations, checkAssociationEndpointRemovesEpRemoveApDiff) +{ + AssociationPaths newAssocPaths = {{"/different/path", {DEFAULT_ENDPOINT}}}; + + auto assocOwners = createDefaultOwnerAssociation(); + auto assocInterfaces = createDefaultInterfaceAssociation(server); + + checkAssociationEndpointRemoves(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, + newAssocPaths, *server, assocOwners, + assocInterfaces); + + // Verify initial endpoints were deleted because the new path + auto intfEndpoints = + std::get(assocInterfaces[DEFAULT_FWD_PATH]); + EXPECT_EQ(intfEndpoints.size(), 0); + intfEndpoints = std::get(assocInterfaces[DEFAULT_REV_PATH]); + EXPECT_EQ(intfEndpoints.size(), 0); +} + +// Verify endpoint is removed when endpoint is different +TEST_F(TestAssociations, checkAssociationEndpointRemovesEpRemoveEpChanged) +{ + AssociationPaths newAssocPaths = { + {DEFAULT_FWD_PATH, {DEFAULT_ENDPOINT + "/different"}}, + {DEFAULT_REV_PATH, {DEFAULT_SOURCE_PATH + "/different"}}}; + + auto assocOwners = createDefaultOwnerAssociation(); + auto assocInterfaces = createDefaultInterfaceAssociation(server); + + checkAssociationEndpointRemoves(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, + newAssocPaths, *server, assocOwners, + assocInterfaces); + + // Verify initial endpoints were deleted because of different endpoints + auto intfEndpoints = + std::get(assocInterfaces[DEFAULT_FWD_PATH]); + EXPECT_EQ(intfEndpoints.size(), 0); + intfEndpoints = std::get(assocInterfaces[DEFAULT_REV_PATH]); + EXPECT_EQ(intfEndpoints.size(), 0); +} -- cgit v1.2.1