1 #include "src/processing.hpp"
2 #include "src/test/util/asio_server_class.hpp"
3 #include "src/test/util/association_objects.hpp"
4 #include "src/test/util/debug_output.hpp"
5 
6 #include <sdbusplus/asio/connection.hpp>
7 #include <sdbusplus/asio/object_server.hpp>
8 
9 #include <gtest/gtest.h>
10 
11 class TestInterfacesAdded : public AsioServerClassTest
12 {};
13 sdbusplus::asio::object_server*
14     TestInterfacesAdded::AsioServerClassTest::server = nullptr;
15 
16 // This is the data structure that comes in via the InterfacesAdded
17 // signal
18 InterfacesAdded createInterfacesAdded(const std::string& interface,
19                                       const std::string& property)
20 {
21     std::vector<Association> associations = {
22         {"inventory", "error",
23          "/xyz/openbmc_project/inventory/system/chassis"}};
24     std::variant<std::vector<Association>> sdbVecAssoc = {associations};
25     std::vector<std::pair<std::string, std::variant<std::vector<Association>>>>
26         vecMethToAssoc = {{property, sdbVecAssoc}};
27     InterfacesAdded intfAdded = {{interface, vecMethToAssoc}};
28     return intfAdded;
29 }
30 
31 // Verify good path of interfaces added function
32 TEST_F(TestInterfacesAdded, InterfacesAddedGoodPath)
33 {
34     auto interfaceMap = createDefaultInterfaceMap();
35     AssociationMaps assocMaps;
36 
37     auto intfAdded =
38         createInterfacesAdded(assocDefsInterface, assocDefsProperty);
39 
40     processInterfaceAdded(interfaceMap, defaultSourcePath, intfAdded,
41                           defaultDbusSvc, assocMaps, *server);
42 
43     // Interface map will get the following:
44     // /logging/entry/1 /logging/entry /logging/ / system/chassis
45     // dumpInterfaceMapType(interfaceMap);
46     EXPECT_EQ(interfaceMap.size(), 5);
47 
48     // New association ower created so ensure it now contains a single entry
49     // dumpAssociationOwnersType(assocOwners);
50     EXPECT_EQ(assocMaps.owners.size(), 1);
51 
52     // Ensure the 2 association interfaces were created
53     // dumpAssociationInterfaces(assocInterfaces);
54     EXPECT_EQ(assocMaps.ifaces.size(), 2);
55 
56     // No pending associations
57     EXPECT_EQ(assocMaps.pending.size(), 0);
58 }
59