1 #include "src/associations.hpp"
2 
3 #include <sdbusplus/asio/connection.hpp>
4 #include <sdbusplus/asio/object_server.hpp>
5 
6 /* @brief Will contain path and name of test application */
7 const char* appname = program_invocation_name;
8 
9 #include <gtest/gtest.h>
10 /** @class AsioServerClassTest
11  *
12  *  @brief Provide wrapper for creating asio::object_server for test suite
13  */
14 class AsioServerClassTest : public testing::Test
15 {
16   protected:
17     // Make this global to the whole test suite since we want to share
18     // the asio::object_server accross the test cases
19     // NOTE - latest googltest changed to SetUpTestSuite()
SetUpTestCase()20     static void SetUpTestCase()
21     {
22         static boost::asio::io_context io;
23         auto conn = std::make_shared<sdbusplus::asio::connection>(io);
24 
25         // Need a distinct name for the bus since multiple test applications
26         // will be running at same time
27         std::string dbusName = {"xyz.openbmc_project.ObjMgr.Test."};
28         std::string fullAppPath = {appname};
29         std::size_t fileNameLoc = fullAppPath.find_last_of("/\\");
30         dbusName += fullAppPath.substr(fileNameLoc + 1);
31         conn->request_name(dbusName.c_str());
32         server = new sdbusplus::asio::object_server(conn);
33     }
34 
35     // NOTE - latest googltest changed to TearDownTestSuite()
TearDownTestCase()36     static void TearDownTestCase()
37     {
38         delete server;
39         server = nullptr;
40     }
41 
42     static sdbusplus::asio::object_server* server;
43 };
44