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     boost::asio::io_context io;
41 
42     processInterfaceAdded(io, interfaceMap, defaultSourcePath, intfAdded,
43                           defaultDbusSvc, assocMaps, *server);
44 
45     io.run();
46 
47     // Interface map will get the following:
48     // /logging/entry/1 /logging/entry /logging/ / system/chassis
49     // dumpInterfaceMapType(interfaceMap);
50     EXPECT_EQ(interfaceMap.size(), 5);
51 
52     // New association ower created so ensure it now contains a single entry
53     // dumpAssociationOwnersType(assocOwners);
54     EXPECT_EQ(assocMaps.owners.size(), 1);
55 
56     // Ensure the 2 association interfaces were created
57     // dumpAssociationInterfaces(assocInterfaces);
58     EXPECT_EQ(assocMaps.ifaces.size(), 2);
59 
60     // No pending associations
61     EXPECT_EQ(assocMaps.pending.size(), 0);
62 }
63