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