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     boost::container::flat_set<std::string> assocInterfacesSet = {
34         assocDefsInterface};
35 
36     // Build up these objects so that an associated interface will match
37     // with the associated owner being removed
38     AssociationMaps assocMaps;
39     assocMaps.owners = createDefaultOwnerAssociation();
40     assocMaps.ifaces = createDefaultInterfaceAssociation(server);
41     auto interfaceMap = createInterfaceMap(defaultSourcePath, defaultDbusSvc,
42                                            assocInterfacesSet);
43 
44     processNameChangeDelete(nameOwners, defaultDbusSvc, oldOwner, interfaceMap,
45                             assocMaps, *server);
46     EXPECT_EQ(nameOwners.size(), 0);
47 
48     // Verify owner association was deleted
49     EXPECT_TRUE(assocMaps.owners.empty());
50 
51     // Verify endpoint was deleted from interface association
52     auto intfEndpoints =
53         std::get<endpointsPos>(assocMaps.ifaces[defaultFwdPath]);
54     EXPECT_EQ(intfEndpoints.size(), 0);
55     intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[defaultRevPath]);
56     EXPECT_EQ(intfEndpoints.size(), 0);
57 
58     // Verify interface map was deleted
59     EXPECT_TRUE(interfaceMap.empty());
60 }
61