Andrew Geissler | b04f033 | 2019-02-08 14:07:56 -0600 | [diff] [blame] | 1 | #include "src/associations.hpp" |
| 2 | |
| 3 | #include <sdbusplus/asio/connection.hpp> |
| 4 | #include <sdbusplus/asio/object_server.hpp> |
| 5 | |
Andrew Geissler | 5b2e727 | 2019-02-11 19:56:57 -0600 | [diff] [blame] | 6 | /* @brief Will contain path and name of test application */ |
| 7 | const char* appname = program_invocation_name; |
| 8 | |
Andrew Geissler | b04f033 | 2019-02-08 14:07:56 -0600 | [diff] [blame] | 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() |
| 20 | static void SetUpTestCase() |
| 21 | { |
Brad Bishop | efd5827 | 2021-08-03 12:35:20 -0400 | [diff] [blame] | 22 | static boost::asio::io_context io; |
Andrew Geissler | b04f033 | 2019-02-08 14:07:56 -0600 | [diff] [blame] | 23 | auto conn = std::make_shared<sdbusplus::asio::connection>(io); |
| 24 | |
Andrew Geissler | 5b2e727 | 2019-02-11 19:56:57 -0600 | [diff] [blame] | 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()); |
Andrew Geissler | b04f033 | 2019-02-08 14:07:56 -0600 | [diff] [blame] | 32 | 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 | }; |