diff options
author | Andrew Geissler <geissonator@yahoo.com> | 2019-02-08 14:07:56 -0600 |
---|---|---|
committer | Matt Spinler <spinler@us.ibm.com> | 2019-04-05 15:05:32 +0000 |
commit | b04f0335379773c87ed0f8cb259ea37cef80981b (patch) | |
tree | 3ff42b768f01ba0914c57eed3e689bf7550f127c /src | |
parent | 271b7dd00648c8a0d004e57b2c53ca642a6d3a42 (diff) | |
download | phosphor-objmgr-b04f0335379773c87ed0f8cb259ea37cef80981b.tar.gz phosphor-objmgr-b04f0335379773c87ed0f8cb259ea37cef80981b.zip |
unit-test: Move asio server to its own class
Other test suites will need this object so move to a utility directory
and inherit from.
Change-Id: Ia34c8149fc0df02c510717a6efd21f51086e97e6
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/test/associations.cpp | 29 | ||||
-rw-r--r-- | src/test/util/asio_server_class.hpp | 34 |
2 files changed, 39 insertions, 24 deletions
diff --git a/src/test/associations.cpp b/src/test/associations.cpp index d5f86f4..acfa884 100644 --- a/src/test/associations.cpp +++ b/src/test/associations.cpp @@ -1,36 +1,17 @@ #include "src/associations.hpp" +#include "src/test/util/asio_server_class.hpp" + #include <sdbusplus/asio/connection.hpp> #include <sdbusplus/asio/object_server.hpp> #include <gtest/gtest.h> -class TestAssociations : public testing::Test +class TestAssociations : public AsioServerClassTest { - protected: - // Make this global to the whole test suite since we want to share - // the asio::object_server accross the test cases - // NOTE - latest googltest changed to SetUpTestSuite() - static void SetUpTestCase() - { - boost::asio::io_context io; - auto conn = std::make_shared<sdbusplus::asio::connection>(io); - - conn->request_name("xyz.openbmc_project.ObjMgr.Test"); - server = new sdbusplus::asio::object_server(conn); - } - - // NOTE - latest googltest changed to TearDownTestSuite() - static void TearDownTestCase() - { - delete server; - server = nullptr; - } - - static sdbusplus::asio::object_server* server; }; - -sdbusplus::asio::object_server* TestAssociations::server = nullptr; +sdbusplus::asio::object_server* TestAssociations::AsioServerClassTest::server = + nullptr; const std::string DEFAULT_SOURCE_PATH = "/logging/entry/1"; const std::string DEFAULT_DBUS_SVC = "xyz.openbmc_project.New.Interface"; diff --git a/src/test/util/asio_server_class.hpp b/src/test/util/asio_server_class.hpp new file mode 100644 index 0000000..34b2095 --- /dev/null +++ b/src/test/util/asio_server_class.hpp @@ -0,0 +1,34 @@ +#include "src/associations.hpp" + +#include <sdbusplus/asio/connection.hpp> +#include <sdbusplus/asio/object_server.hpp> + +#include <gtest/gtest.h> +/** @class AsioServerClassTest + * + * @brief Provide wrapper for creating asio::object_server for test suite + */ +class AsioServerClassTest : public testing::Test +{ + protected: + // Make this global to the whole test suite since we want to share + // the asio::object_server accross the test cases + // NOTE - latest googltest changed to SetUpTestSuite() + static void SetUpTestCase() + { + boost::asio::io_context io; + auto conn = std::make_shared<sdbusplus::asio::connection>(io); + + conn->request_name("xyz.openbmc_project.ObjMgr.Test"); + server = new sdbusplus::asio::object_server(conn); + } + + // NOTE - latest googltest changed to TearDownTestSuite() + static void TearDownTestCase() + { + delete server; + server = nullptr; + } + + static sdbusplus::asio::object_server* server; +}; |