blob: 95d02af00c469ef13eb5f8f16576d7c544aaf0d7 [file] [log] [blame]
Andrew Geissler20679262019-02-11 20:20:40 -06001#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
7class TestNameChange : public AsioServerClassTest
8{
9};
10sdbusplus::asio::object_server* TestNameChange::AsioServerClassTest::server =
11 nullptr;
12
13// Verify unique name is removed from nameOwners
14TEST_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;
Matt Spinlere2359fb2019-04-05 14:11:33 -050021 AssociationMaps assocMaps;
Andrew Geissler20679262019-02-11 20:20:40 -060022
23 processNameChangeDelete(nameOwners, wellKnown, oldOwner, interfaceMap,
Matt Spinlere2359fb2019-04-05 14:11:33 -050024 assocMaps, *server);
Andrew Geissler20679262019-02-11 20:20:40 -060025 EXPECT_EQ(nameOwners.size(), 0);
26}
27
28// Verify path removed from interface map and association objects
29TEST_F(TestNameChange, UniqueNameAssociationsAndInterface)
30{
31 boost::container::flat_map<std::string, std::string> nameOwners = {
32 {":1.99", DEFAULT_DBUS_SVC}};
33 std::string oldOwner = {":1.99"};
34 boost::container::flat_set<std::string> assocInterfacesSet = {
Matt Spinler8f876a52019-04-15 13:22:50 -050035 assocDefsInterface};
Andrew Geissler20679262019-02-11 20:20:40 -060036
37 // Build up these objects so that an associated interface will match
38 // with the associated owner being removed
Matt Spinlere2359fb2019-04-05 14:11:33 -050039 AssociationMaps assocMaps;
40 assocMaps.owners = createDefaultOwnerAssociation();
41 assocMaps.ifaces = createDefaultInterfaceAssociation(server);
Andrew Geissler20679262019-02-11 20:20:40 -060042 auto interfaceMap = createInterfaceMap(
43 DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, assocInterfacesSet);
44
45 processNameChangeDelete(nameOwners, DEFAULT_DBUS_SVC, oldOwner,
Matt Spinlere2359fb2019-04-05 14:11:33 -050046 interfaceMap, assocMaps, *server);
Andrew Geissler20679262019-02-11 20:20:40 -060047 EXPECT_EQ(nameOwners.size(), 0);
48
49 // Verify owner association was deleted
Matt Spinlere2359fb2019-04-05 14:11:33 -050050 EXPECT_TRUE(assocMaps.owners.empty());
Andrew Geissler20679262019-02-11 20:20:40 -060051
52 // Verify endpoint was deleted from interface association
53 auto intfEndpoints =
Matt Spinlere2359fb2019-04-05 14:11:33 -050054 std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]);
Andrew Geissler20679262019-02-11 20:20:40 -060055 EXPECT_EQ(intfEndpoints.size(), 0);
Matt Spinlere2359fb2019-04-05 14:11:33 -050056 intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]);
Andrew Geissler20679262019-02-11 20:20:40 -060057 EXPECT_EQ(intfEndpoints.size(), 0);
58
59 // Verify interface map was deleted
60 EXPECT_TRUE(interfaceMap.empty());
61}