blob: 8edb0de22183ffa593d5235881c2ffb9632a5329 [file] [log] [blame]
Andrew Geissler271b7dd2019-02-05 11:23:30 -06001#include "src/associations.hpp"
2
Andrew Geisslerb04f0332019-02-08 14:07:56 -06003#include "src/test/util/asio_server_class.hpp"
Andrew Geisslerbb7b5922019-02-08 14:16:48 -06004#include "src/test/util/association_objects.hpp"
Andrew Geisslerb04f0332019-02-08 14:07:56 -06005
Andrew Geissler271b7dd2019-02-05 11:23:30 -06006#include <sdbusplus/asio/connection.hpp>
7#include <sdbusplus/asio/object_server.hpp>
8
9#include <gtest/gtest.h>
10
Andrew Geisslerb04f0332019-02-08 14:07:56 -060011class TestAssociations : public AsioServerClassTest
Andrew Geissler271b7dd2019-02-05 11:23:30 -060012{
Andrew Geissler271b7dd2019-02-05 11:23:30 -060013};
Andrew Geisslerb04f0332019-02-08 14:07:56 -060014sdbusplus::asio::object_server* TestAssociations::AsioServerClassTest::server =
15 nullptr;
Andrew Geissler271b7dd2019-02-05 11:23:30 -060016
Andrew Geissler271b7dd2019-02-05 11:23:30 -060017// Verify call when path is not in associated owners
18TEST_F(TestAssociations, SourcePathNotInAssociations)
19{
20 EXPECT_NE(nullptr, server);
21 std::string sourcePath = "/xyz/openbmc_project/no/association";
22 AssociationOwnersType assocOwners;
23 AssociationInterfaces assocInterfaces;
24
25 removeAssociation(sourcePath, DEFAULT_DBUS_SVC, *server, assocOwners,
26 assocInterfaces);
27}
28
29// Verify call when owner is not in associated owners
30TEST_F(TestAssociations, OwnerNotInAssociations)
31{
32 AssociationInterfaces assocInterfaces;
33
34 auto assocOwners = createDefaultOwnerAssociation();
35
36 removeAssociation(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, *server,
37 assocOwners, assocInterfaces);
38}
39
40// Verify call when path is not in associated interfaces
41TEST_F(TestAssociations, PathNotInAssocInterfaces)
42{
43 AssociationInterfaces assocInterfaces;
44
45 auto assocOwners = createDefaultOwnerAssociation();
46
47 removeAssociation(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, *server,
48 assocOwners, assocInterfaces);
49
50 EXPECT_TRUE(assocOwners.empty());
51}
52
53// Verify call when path is in associated interfaces
54TEST_F(TestAssociations, PathIsInAssociatedInterfaces)
55{
56 // Build up these objects so that an associated interface will match
57 // with the associated owner being removed
58 auto assocOwners = createDefaultOwnerAssociation();
59 auto assocInterfaces = createDefaultInterfaceAssociation(server);
60
61 removeAssociation(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, *server,
62 assocOwners, assocInterfaces);
63
64 // Verify owner association was deleted
65 EXPECT_TRUE(assocOwners.empty());
66
67 // Verify endpoint was deleted from interface association
68 auto intfEndpoints =
69 std::get<endpointsPos>(assocInterfaces[DEFAULT_FWD_PATH]);
70 EXPECT_EQ(intfEndpoints.size(), 0);
71 intfEndpoints = std::get<endpointsPos>(assocInterfaces[DEFAULT_REV_PATH]);
72 EXPECT_EQ(intfEndpoints.size(), 0);
73}
74
75// Verify call when path is in associated interfaces, with extra endpoints
76TEST_F(TestAssociations, PathIsInAssociatedInterfacesExtraEndpoints)
77{
78 // Build up these objects so that an associated interface will match
79 // with the associated owner being removed
80 auto assocOwners = createDefaultOwnerAssociation();
81 auto assocInterfaces = createDefaultInterfaceAssociation(server);
82
83 // Add another endpoint to the assoc interfaces
84 addEndpointToInterfaceAssociation(assocInterfaces);
85
86 removeAssociation(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, *server,
87 assocOwners, assocInterfaces);
88
89 // Verify owner association was deleted
90 EXPECT_TRUE(assocOwners.empty());
91
92 // Verify all endpoints are deleted since source path was deleted
93 auto intfEndpoints =
94 std::get<endpointsPos>(assocInterfaces[DEFAULT_FWD_PATH]);
95 EXPECT_EQ(intfEndpoints.size(), 0);
96 intfEndpoints = std::get<endpointsPos>(assocInterfaces[DEFAULT_REV_PATH]);
97 EXPECT_EQ(intfEndpoints.size(), 0);
98}