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