1 #include "src/associations.hpp" 2 3 #include "src/test/util/asio_server_class.hpp" 4 #include "src/test/util/association_objects.hpp" 5 6 #include <sdbusplus/asio/connection.hpp> 7 #include <sdbusplus/asio/object_server.hpp> 8 9 #include <gtest/gtest.h> 10 11 class TestAssociations : public AsioServerClassTest 12 { 13 }; 14 sdbusplus::asio::object_server* TestAssociations::AsioServerClassTest::server = 15 nullptr; 16 17 // Verify call when path is not in associated owners 18 TEST_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 30 TEST_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 41 TEST_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 54 TEST_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 76 TEST_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 } 99