1 #include "src/processing.hpp"
2 #include "src/test/util/asio_server_class.hpp"
3 #include "src/test/util/association_objects.hpp"
4 
5 #include <gtest/gtest.h>
6 
7 class TestNameChange : public AsioServerClassTest
8 {
9 };
10 sdbusplus::asio::object_server* TestNameChange::AsioServerClassTest::server =
11     nullptr;
12 
13 // Verify unique name is removed from nameOwners
14 TEST_F(TestNameChange, UniqueNameNoInterfaces)
15 {
16     boost::container::flat_map<std::string, std::string> nameOwners = {
17         {":1.99", "test-name"}};
18     std::string wellKnown = {"test-name"};
19     std::string oldOwner = {":1.99"};
20     interface_map_type interfaceMap;
21     AssociationMaps assocMaps;
22 
23     processNameChangeDelete(nameOwners, wellKnown, oldOwner, interfaceMap,
24                             assocMaps, *server);
25     EXPECT_EQ(nameOwners.size(), 0);
26 }
27 
28 // Verify path removed from interface map and association objects
29 TEST_F(TestNameChange, UniqueNameAssociationsAndInterface)
30 {
31     boost::container::flat_map<std::string, std::string> nameOwners = {
32         {":1.99", DEFAULT_DBUS_SVC}};
33     std::string oldOwner = {":1.99"};
34     boost::container::flat_set<std::string> assocInterfacesSet = {
35         assocDefsInterface};
36 
37     // Build up these objects so that an associated interface will match
38     // with the associated owner being removed
39     AssociationMaps assocMaps;
40     assocMaps.owners = createDefaultOwnerAssociation();
41     assocMaps.ifaces = createDefaultInterfaceAssociation(server);
42     auto interfaceMap = createInterfaceMap(
43         DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, assocInterfacesSet);
44 
45     processNameChangeDelete(nameOwners, DEFAULT_DBUS_SVC, oldOwner,
46                             interfaceMap, assocMaps, *server);
47     EXPECT_EQ(nameOwners.size(), 0);
48 
49     // Verify owner association was deleted
50     EXPECT_TRUE(assocMaps.owners.empty());
51 
52     // Verify endpoint was deleted from interface association
53     auto intfEndpoints =
54         std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]);
55     EXPECT_EQ(intfEndpoints.size(), 0);
56     intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]);
57     EXPECT_EQ(intfEndpoints.size(), 0);
58 
59     // Verify interface map was deleted
60     EXPECT_TRUE(interfaceMap.empty());
61 }
62