blob: 28eb921220f93d37704c709ed71ef84078050e02 [file] [log] [blame]
Andrew Geisslerb04f0332019-02-08 14:07:56 -06001#include "src/associations.hpp"
2
3#include <sdbusplus/asio/connection.hpp>
4#include <sdbusplus/asio/object_server.hpp>
5
Andrew Geissler5b2e7272019-02-11 19:56:57 -06006/* @brief Will contain path and name of test application */
7const char* appname = program_invocation_name;
8
Andrew Geisslerb04f0332019-02-08 14:07:56 -06009#include <gtest/gtest.h>
10/** @class AsioServerClassTest
11 *
12 * @brief Provide wrapper for creating asio::object_server for test suite
13 */
14class 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()
20 static void SetUpTestCase()
21 {
Brad Bishopefd58272021-08-03 12:35:20 -040022 static boost::asio::io_context io;
Andrew Geisslerb04f0332019-02-08 14:07:56 -060023 auto conn = std::make_shared<sdbusplus::asio::connection>(io);
24
Andrew Geissler5b2e7272019-02-11 19:56:57 -060025 // 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());
Andrew Geisslerb04f0332019-02-08 14:07:56 -060032 server = new sdbusplus::asio::object_server(conn);
33 }
34
35 // NOTE - latest googltest changed to TearDownTestSuite()
36 static void TearDownTestCase()
37 {
38 delete server;
39 server = nullptr;
40 }
41
42 static sdbusplus::asio::object_server* server;
43};