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 sdbusplus::asio::object_server* TestNameChange::AsioServerClassTest::server =
10     nullptr;
11 
12 // Verify unique name is removed from nameOwners
13 TEST_F(TestNameChange, UniqueNameNoInterfaces)
14 {
15     boost::container::flat_map<std::string, std::string> nameOwners = {
16         {":1.99", "test-name"}};
17     std::string wellKnown = {"test-name"};
18     std::string oldOwner = {":1.99"};
19     InterfaceMapType interfaceMap;
20     AssociationMaps assocMaps;
21 
22     processNameChangeDelete(nameOwners, wellKnown, oldOwner, interfaceMap,
23                             assocMaps, *server);
24     EXPECT_EQ(nameOwners.size(), 0);
25 }
26 
27 // Verify path removed from interface map and association objects
28 TEST_F(TestNameChange, UniqueNameAssociationsAndInterface)
29 {
30     boost::container::flat_map<std::string, std::string> nameOwners = {
31         {":1.99", defaultDbusSvc}};
32     std::string oldOwner = {":1.99"};
33     InterfaceNames assocInterfacesSet = {assocDefsInterface};
34 
35     // Build up these objects so that an associated interface will match
36     // with the associated owner being removed
37     AssociationMaps assocMaps;
38     assocMaps.owners = createDefaultOwnerAssociation();
39     assocMaps.ifaces = createDefaultInterfaceAssociation(server);
40     auto interfaceMap = createInterfaceMap(defaultSourcePath, defaultDbusSvc,
41                                            assocInterfacesSet);
42 
43     processNameChangeDelete(nameOwners, defaultDbusSvc, oldOwner, interfaceMap,
44                             assocMaps, *server);
45     EXPECT_EQ(nameOwners.size(), 0);
46 
47     // Verify owner association was deleted
48     EXPECT_TRUE(assocMaps.owners.empty());
49 
50     // Verify endpoint was deleted from interface association
51     auto intfEndpoints =
52         std::get<endpointsPos>(assocMaps.ifaces[defaultFwdPath]);
53     EXPECT_EQ(intfEndpoints.size(), 0);
54     intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[defaultRevPath]);
55     EXPECT_EQ(intfEndpoints.size(), 0);
56 
57     // Verify interface map was deleted
58     EXPECT_TRUE(interfaceMap.empty());
59 }
60