unit-test: Test deleting entry on name change

Breaking off into a separate function enables easier unit testing of the
specific function

Testing: 97% coverage of processing.cpp

Change-Id: I08f229657a8f44230b711fabbae20fb403792637
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
diff --git a/src/processing.cpp b/src/processing.cpp
index be7bf12..3cd348b 100644
--- a/src/processing.cpp
+++ b/src/processing.cpp
@@ -37,3 +37,48 @@
 
     return inWhitelist && !inBlacklist;
 }
+
+void processNameChangeDelete(
+    boost::container::flat_map<std::string, std::string>& nameOwners,
+    const std::string& wellKnown, const std::string& oldOwner,
+    interface_map_type& interfaceMap, AssociationOwnersType& assocOwners,
+    AssociationInterfaces& assocInterfaces,
+    sdbusplus::asio::object_server& server)
+{
+    if (boost::starts_with(oldOwner, ":"))
+    {
+        auto it = nameOwners.find(oldOwner);
+        if (it != nameOwners.end())
+        {
+            nameOwners.erase(it);
+        }
+    }
+    // Connection removed
+    interface_map_type::iterator pathIt = interfaceMap.begin();
+    while (pathIt != interfaceMap.end())
+    {
+        // If an associations interface is being removed,
+        // also need to remove the corresponding associations
+        // objects and properties.
+        auto ifaces = pathIt->second.find(wellKnown);
+        if (ifaces != pathIt->second.end())
+        {
+            auto assoc = std::find(ifaces->second.begin(), ifaces->second.end(),
+                                   ASSOCIATIONS_INTERFACE);
+            if (assoc != ifaces->second.end())
+            {
+                removeAssociation(pathIt->first, wellKnown, server, assocOwners,
+                                  assocInterfaces);
+            }
+        }
+        pathIt->second.erase(wellKnown);
+        if (pathIt->second.empty())
+        {
+            // If the last connection to the object is gone,
+            // delete the top level object
+            pathIt = interfaceMap.erase(pathIt);
+            continue;
+        }
+        pathIt++;
+    }
+}