Andrew Geissler | 2067926 | 2019-02-11 20:20:40 -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 | |
| 5 | #include <gtest/gtest.h> |
| 6 | |
| 7 | class TestNameChange : public AsioServerClassTest |
| 8 | { |
| 9 | }; |
| 10 | sdbusplus::asio::object_server* TestNameChange::AsioServerClassTest::server = |
| 11 | nullptr; |
| 12 | |
| 13 | // Verify unique name is removed from nameOwners |
| 14 | TEST_F(TestNameChange, UniqueNameNoInterfaces) |
| 15 | { |
| 16 | boost::container::flat_map<std::string, std::string> nameOwners = { |
| 17 | {":1.99", "test-name"}}; |
| 18 | std::string wellKnown = {"test-name"}; |
| 19 | std::string oldOwner = {":1.99"}; |
| 20 | interface_map_type interfaceMap; |
| 21 | AssociationOwnersType assocOwners; |
| 22 | AssociationInterfaces assocInterfaces; |
| 23 | |
| 24 | processNameChangeDelete(nameOwners, wellKnown, oldOwner, interfaceMap, |
| 25 | assocOwners, assocInterfaces, *server); |
| 26 | EXPECT_EQ(nameOwners.size(), 0); |
| 27 | } |
| 28 | |
| 29 | // Verify path removed from interface map and association objects |
| 30 | TEST_F(TestNameChange, UniqueNameAssociationsAndInterface) |
| 31 | { |
| 32 | boost::container::flat_map<std::string, std::string> nameOwners = { |
| 33 | {":1.99", DEFAULT_DBUS_SVC}}; |
| 34 | std::string oldOwner = {":1.99"}; |
| 35 | boost::container::flat_set<std::string> assocInterfacesSet = { |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame^] | 36 | assocDefsInterface}; |
Andrew Geissler | 2067926 | 2019-02-11 20:20:40 -0600 | [diff] [blame] | 37 | |
| 38 | // Build up these objects so that an associated interface will match |
| 39 | // with the associated owner being removed |
| 40 | auto assocOwners = createDefaultOwnerAssociation(); |
| 41 | auto assocInterfaces = createDefaultInterfaceAssociation(server); |
| 42 | auto interfaceMap = createInterfaceMap( |
| 43 | DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, assocInterfacesSet); |
| 44 | |
| 45 | processNameChangeDelete(nameOwners, DEFAULT_DBUS_SVC, oldOwner, |
| 46 | interfaceMap, assocOwners, assocInterfaces, |
| 47 | *server); |
| 48 | EXPECT_EQ(nameOwners.size(), 0); |
| 49 | |
| 50 | // Verify owner association was deleted |
| 51 | EXPECT_TRUE(assocOwners.empty()); |
| 52 | |
| 53 | // Verify endpoint was deleted from interface association |
| 54 | auto intfEndpoints = |
| 55 | std::get<endpointsPos>(assocInterfaces[DEFAULT_FWD_PATH]); |
| 56 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 57 | intfEndpoints = std::get<endpointsPos>(assocInterfaces[DEFAULT_REV_PATH]); |
| 58 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 59 | |
| 60 | // Verify interface map was deleted |
| 61 | EXPECT_TRUE(interfaceMap.empty()); |
| 62 | } |