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 }; 14 sdbusplus::asio::object_server* 15 TestInterfacesAdded::AsioServerClassTest::server = nullptr; 16 17 // This is the data structure that comes in via the InterfacesAdded 18 // signal 19 InterfacesAdded createInterfacesAdded(const std::string& interface, 20 const std::string& property) 21 { 22 std::vector<Association> associations = { 23 {"inventory", "error", 24 "/xyz/openbmc_project/inventory/system/chassis"}}; 25 sdbusplus::message::variant<std::vector<Association>> sdbVecAssoc = { 26 associations}; 27 std::vector<std::pair< 28 std::string, sdbusplus::message::variant<std::vector<Association>>>> 29 vecMethToAssoc = {{property, sdbVecAssoc}}; 30 InterfacesAdded intfAdded = {{interface, vecMethToAssoc}}; 31 return intfAdded; 32 } 33 34 // Verify good path of interfaces added function 35 TEST_F(TestInterfacesAdded, InterfacesAddedGoodPath) 36 { 37 auto interfaceMap = createDefaultInterfaceMap(); 38 AssociationMaps assocMaps; 39 40 auto intfAdded = createInterfacesAdded( 41 assocDefsInterface, getAssocDefPropName(assocDefsInterface)); 42 43 processInterfaceAdded(interfaceMap, DEFAULT_SOURCE_PATH, intfAdded, 44 DEFAULT_DBUS_SVC, assocMaps, *server); 45 46 // Interface map will get the following: 47 // /logging/entry/1 /logging/entry /logging/ / system/chassis 48 // dump_InterfaceMapType(interfaceMap); 49 EXPECT_EQ(interfaceMap.size(), 5); 50 51 // New association ower created so ensure it now contains a single entry 52 // dump_AssociationOwnersType(assocOwners); 53 EXPECT_EQ(assocMaps.owners.size(), 1); 54 55 // Ensure the 2 association interfaces were created 56 // dump_AssociationInterfaces(assocInterfaces); 57 EXPECT_EQ(assocMaps.ifaces.size(), 2); 58 59 // No pending associations 60 EXPECT_EQ(assocMaps.pending.size(), 0); 61 } 62 63 TEST_F(TestInterfacesAdded, OrgOpenBmcInterfacesAddedGoodPath) 64 { 65 auto interfaceMap = createDefaultInterfaceMap(); 66 AssociationMaps assocMaps; 67 68 auto intfAdded = createInterfacesAdded( 69 orgOpenBMCAssocDefsInterface, 70 getAssocDefPropName(orgOpenBMCAssocDefsInterface)); 71 72 processInterfaceAdded(interfaceMap, DEFAULT_SOURCE_PATH, intfAdded, 73 DEFAULT_DBUS_SVC, assocMaps, *server); 74 75 // Interface map will get the following: 76 // /logging/entry/1 /logging/entry /logging/ / system/chassis 77 EXPECT_EQ(interfaceMap.size(), 5); 78 79 // New association ower created so ensure it now contains a single entry 80 // dump_AssociationOwnersType(assocOwners); 81 EXPECT_EQ(assocMaps.owners.size(), 1); 82 83 // Ensure the 2 association interfaces were created 84 // dump_AssociationInterfaces(assocInterfaces); 85 EXPECT_EQ(assocMaps.ifaces.size(), 2); 86 87 // No pending associations 88 EXPECT_EQ(assocMaps.pending.size(), 0); 89 } 90