From 67e5a420756d7ae96be91721138054be9d897a7b Mon Sep 17 00:00:00 2001 From: Andrew Geissler Date: Mon, 4 Feb 2019 13:00:59 -0600 Subject: unit-test: Add all required parameters to removeAssociation Testing is easier when all required parameters are input (vs. global references) Change-Id: I0c6c45c79a6095eaa6d702150cc346ac4f8e0e0d Signed-off-by: Andrew Geissler --- src/main.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index dea80f8..801d910 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,10 +36,11 @@ using Association = std::tuple; static constexpr auto ifacePos = 0; static constexpr auto endpointsPos = 1; using Endpoints = std::vector; -boost::container::flat_map< +using AssociationInterfaces = boost::container::flat_map< std::string, - std::tuple, Endpoints>> - associationInterfaces; + std::tuple, Endpoints>>; + +AssociationInterfaces associationInterfaces; // The associationOwners map contains information about creators of // associations, so that when a org.openbmc.Association interface is @@ -365,7 +366,9 @@ void associationChanged(sdbusplus::asio::object_server& objectServer, } void removeAssociation(const std::string& sourcePath, const std::string& owner, - sdbusplus::asio::object_server& server) + sdbusplus::asio::object_server& server, + AssociationOwnersType& assocOwners, + AssociationInterfaces& assocInterfaces) { // Use associationOwners to find the association paths and endpoints // that the passed in object path and service own. Remove all of @@ -377,8 +380,8 @@ void removeAssociation(const std::string& sourcePath, const std::string& owner, // association path itself. // Find the services that have associations for this object path - auto owners = associationOwners.find(sourcePath); - if (owners == associationOwners.end()) + auto owners = assocOwners.find(sourcePath); + if (owners == assocOwners.end()) { return; } @@ -394,8 +397,8 @@ void removeAssociation(const std::string& sourcePath, const std::string& owner, for (const auto& [assocPath, endpointsToRemove] : assocs->second) { // Get the association D-Bus object for this assocPath - auto target = associationInterfaces.find(assocPath); - if (target == associationInterfaces.end()) + auto target = assocInterfaces.find(assocPath); + if (target == assocInterfaces.end()) { continue; } @@ -796,7 +799,9 @@ int main(int argc, char** argv) if (assoc != ifaces->second.end()) { - removeAssociation(path_it->first, name, server); + removeAssociation(path_it->first, name, server, + associationOwners, + associationInterfaces); } } @@ -968,7 +973,8 @@ int main(int argc, char** argv) if (interface == ASSOCIATIONS_INTERFACE) { - removeAssociation(obj_path.str, sender, server); + removeAssociation(obj_path.str, sender, server, + associationOwners, associationInterfaces); } interface_set->second.erase(interface); -- cgit v1.2.1