Andrew Geissler | 7f83837 | 2019-02-27 10:14:31 -0600 | [diff] [blame] | 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 |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame] | 19 | InterfacesAdded createInterfacesAdded(const std::string& interface, |
| 20 | const std::string& property) |
Andrew Geissler | 7f83837 | 2019-02-27 10:14:31 -0600 | [diff] [blame] | 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>>>> |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame] | 29 | vecMethToAssoc = {{property, sdbVecAssoc}}; |
| 30 | InterfacesAdded intfAdded = {{interface, vecMethToAssoc}}; |
Andrew Geissler | 7f83837 | 2019-02-27 10:14:31 -0600 | [diff] [blame] | 31 | return intfAdded; |
| 32 | } |
| 33 | |
| 34 | // Verify good path of interfaces added function |
| 35 | TEST_F(TestInterfacesAdded, InterfacesAddedGoodPath) |
| 36 | { |
| 37 | interface_map_type interfaceMap; |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 38 | AssociationMaps assocMaps; |
| 39 | |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame] | 40 | auto intfAdded = createInterfacesAdded( |
| 41 | assocDefsInterface, getAssocDefPropName(assocDefsInterface)); |
| 42 | |
| 43 | processInterfaceAdded(interfaceMap, DEFAULT_SOURCE_PATH, intfAdded, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 44 | DEFAULT_DBUS_SVC, assocMaps, *server); |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame] | 45 | |
| 46 | // Interface map will get the following: |
| 47 | // /logging/entry/1 /logging/entry /logging/ / |
| 48 | // dump_InterfaceMapType(interfaceMap); |
| 49 | EXPECT_EQ(interfaceMap.size(), 4); |
| 50 | |
| 51 | // New association ower created so ensure it now contains a single entry |
| 52 | // dump_AssociationOwnersType(assocOwners); |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 53 | EXPECT_EQ(assocMaps.owners.size(), 1); |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame] | 54 | |
| 55 | // Ensure the 2 association interfaces were created |
| 56 | // dump_AssociationInterfaces(assocInterfaces); |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 57 | EXPECT_EQ(assocMaps.ifaces.size(), 2); |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | TEST_F(TestInterfacesAdded, OrgOpenBmcInterfacesAddedGoodPath) |
| 61 | { |
| 62 | interface_map_type interfaceMap; |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 63 | AssociationMaps assocMaps; |
| 64 | |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame] | 65 | auto intfAdded = createInterfacesAdded( |
| 66 | orgOpenBMCAssocDefsInterface, |
| 67 | getAssocDefPropName(orgOpenBMCAssocDefsInterface)); |
Andrew Geissler | 7f83837 | 2019-02-27 10:14:31 -0600 | [diff] [blame] | 68 | |
| 69 | processInterfaceAdded(interfaceMap, DEFAULT_SOURCE_PATH, intfAdded, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 70 | DEFAULT_DBUS_SVC, assocMaps, *server); |
Andrew Geissler | 7f83837 | 2019-02-27 10:14:31 -0600 | [diff] [blame] | 71 | |
| 72 | // Interface map will get the following: |
| 73 | // /logging/entry/1 /logging/entry /logging/ / |
| 74 | // dump_InterfaceMapType(interfaceMap); |
| 75 | EXPECT_EQ(interfaceMap.size(), 4); |
| 76 | |
| 77 | // New association ower created so ensure it now contains a single entry |
| 78 | // dump_AssociationOwnersType(assocOwners); |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 79 | EXPECT_EQ(assocMaps.owners.size(), 1); |
Andrew Geissler | 7f83837 | 2019-02-27 10:14:31 -0600 | [diff] [blame] | 80 | |
| 81 | // Ensure the 2 association interfaces were created |
| 82 | // dump_AssociationInterfaces(assocInterfaces); |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 83 | EXPECT_EQ(assocMaps.ifaces.size(), 2); |
Andrew Geissler | 7f83837 | 2019-02-27 10:14:31 -0600 | [diff] [blame] | 84 | } |