summaryrefslogtreecommitdiffstats
path: root/src/test/name_change.cpp
diff options
context:
space:
mode:
authorAndrew Geissler <geissonator@yahoo.com>2019-02-11 20:20:40 -0600
committerMatt Spinler <spinler@us.ibm.com>2019-04-05 15:05:32 +0000
commit2067926a03284fae98203c99f8a5d9acda0d2a47 (patch)
treebc606ebd4988ec57b67e15abc5d83c22c964d849 /src/test/name_change.cpp
parent5b2e72765e4f547dd74a139f703c957c41a9078a (diff)
downloadphosphor-objmgr-2067926a03284fae98203c99f8a5d9acda0d2a47.tar.gz
phosphor-objmgr-2067926a03284fae98203c99f8a5d9acda0d2a47.zip
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>
Diffstat (limited to 'src/test/name_change.cpp')
-rw-r--r--src/test/name_change.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/test/name_change.cpp b/src/test/name_change.cpp
new file mode 100644
index 0000000..f4a9662
--- /dev/null
+++ b/src/test/name_change.cpp
@@ -0,0 +1,62 @@
+#include "src/processing.hpp"
+#include "src/test/util/asio_server_class.hpp"
+#include "src/test/util/association_objects.hpp"
+
+#include <gtest/gtest.h>
+
+class TestNameChange : public AsioServerClassTest
+{
+};
+sdbusplus::asio::object_server* TestNameChange::AsioServerClassTest::server =
+ nullptr;
+
+// Verify unique name is removed from nameOwners
+TEST_F(TestNameChange, UniqueNameNoInterfaces)
+{
+ boost::container::flat_map<std::string, std::string> nameOwners = {
+ {":1.99", "test-name"}};
+ std::string wellKnown = {"test-name"};
+ std::string oldOwner = {":1.99"};
+ interface_map_type interfaceMap;
+ AssociationOwnersType assocOwners;
+ AssociationInterfaces assocInterfaces;
+
+ processNameChangeDelete(nameOwners, wellKnown, oldOwner, interfaceMap,
+ assocOwners, assocInterfaces, *server);
+ EXPECT_EQ(nameOwners.size(), 0);
+}
+
+// Verify path removed from interface map and association objects
+TEST_F(TestNameChange, UniqueNameAssociationsAndInterface)
+{
+ boost::container::flat_map<std::string, std::string> nameOwners = {
+ {":1.99", DEFAULT_DBUS_SVC}};
+ std::string oldOwner = {":1.99"};
+ boost::container::flat_set<std::string> assocInterfacesSet = {
+ ASSOCIATIONS_INTERFACE};
+
+ // Build up these objects so that an associated interface will match
+ // with the associated owner being removed
+ auto assocOwners = createDefaultOwnerAssociation();
+ auto assocInterfaces = createDefaultInterfaceAssociation(server);
+ auto interfaceMap = createInterfaceMap(
+ DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, assocInterfacesSet);
+
+ processNameChangeDelete(nameOwners, DEFAULT_DBUS_SVC, oldOwner,
+ interfaceMap, assocOwners, assocInterfaces,
+ *server);
+ EXPECT_EQ(nameOwners.size(), 0);
+
+ // Verify owner association was deleted
+ EXPECT_TRUE(assocOwners.empty());
+
+ // Verify endpoint was deleted from interface association
+ auto intfEndpoints =
+ std::get<endpointsPos>(assocInterfaces[DEFAULT_FWD_PATH]);
+ EXPECT_EQ(intfEndpoints.size(), 0);
+ intfEndpoints = std::get<endpointsPos>(assocInterfaces[DEFAULT_REV_PATH]);
+ EXPECT_EQ(intfEndpoints.size(), 0);
+
+ // Verify interface map was deleted
+ EXPECT_TRUE(interfaceMap.empty());
+}
OpenPOWER on IntegriCloud