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