2020-07-18 20:16:57 +02:00
|
|
|
/**
|
2022-07-05 17:08:35 +02:00
|
|
|
* (C) 2016 - 2021 KISTLER INSTRUMENTE AG, Winterthur, Switzerland
|
|
|
|
|
* (C) 2016 - 2022 Stanislav Angelovic <stanislav.angelovic@protonmail.com>
|
2020-07-18 20:16:57 +02:00
|
|
|
*
|
|
|
|
|
* @file TestAdaptor.h
|
|
|
|
|
*
|
|
|
|
|
* Created on: Jan 2, 2017
|
|
|
|
|
* Project: sdbus-c++
|
|
|
|
|
* Description: High-level D-Bus IPC C++ library based on sd-bus
|
|
|
|
|
*
|
|
|
|
|
* This file is part of sdbus-c++.
|
|
|
|
|
*
|
|
|
|
|
* sdbus-c++ is free software; you can redistribute it and/or modify it
|
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2.1 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* sdbus-c++ is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
* along with sdbus-c++. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef SDBUS_CPP_INTEGRATIONTESTS_TESTFIXTURE_H_
|
|
|
|
|
#define SDBUS_CPP_INTEGRATIONTESTS_TESTFIXTURE_H_
|
|
|
|
|
|
|
|
|
|
#include "TestAdaptor.h"
|
|
|
|
|
#include "TestProxy.h"
|
|
|
|
|
#include "Defs.h"
|
|
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
|
|
|
|
|
|
#include <thread>
|
|
|
|
|
#include <chrono>
|
|
|
|
|
#include <atomic>
|
|
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
|
|
namespace sdbus { namespace test {
|
|
|
|
|
|
|
|
|
|
class TestFixture : public ::testing::Test
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static void SetUpTestCase()
|
|
|
|
|
{
|
2021-10-14 15:53:51 +02:00
|
|
|
s_proxyConnection->enterEventLoopAsync();
|
2021-10-14 16:08:38 +02:00
|
|
|
s_adaptorConnection->requestName(BUS_NAME);
|
2021-10-14 15:53:51 +02:00
|
|
|
s_adaptorConnection->enterEventLoopAsync();
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(50)); // Give time for the proxy connection to start listening to signals
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void TearDownTestCase()
|
|
|
|
|
{
|
2021-10-14 16:08:38 +02:00
|
|
|
s_adaptorConnection->releaseName(BUS_NAME);
|
2021-10-14 15:53:51 +02:00
|
|
|
s_adaptorConnection->leaveEventLoop();
|
|
|
|
|
s_proxyConnection->leaveEventLoop();
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename _Fnc>
|
|
|
|
|
static bool waitUntil(_Fnc&& fnc, std::chrono::milliseconds timeout = std::chrono::seconds(5))
|
|
|
|
|
{
|
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
|
|
|
|
|
|
std::chrono::milliseconds elapsed{};
|
|
|
|
|
std::chrono::milliseconds step{5ms};
|
|
|
|
|
do {
|
|
|
|
|
std::this_thread::sleep_for(step);
|
|
|
|
|
elapsed += step;
|
|
|
|
|
if (elapsed > timeout)
|
|
|
|
|
return false;
|
|
|
|
|
} while (!fnc());
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool waitUntil(std::atomic<bool>& flag, std::chrono::milliseconds timeout = std::chrono::seconds(5))
|
|
|
|
|
{
|
|
|
|
|
return waitUntil([&flag]() -> bool { return flag; }, timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void SetUp() override
|
|
|
|
|
{
|
2021-10-14 16:08:38 +02:00
|
|
|
m_objectManagerProxy = std::make_unique<ObjectManagerTestProxy>(*s_proxyConnection, BUS_NAME, MANAGER_PATH);
|
|
|
|
|
m_proxy = std::make_unique<TestProxy>(*s_proxyConnection, BUS_NAME, OBJECT_PATH);
|
2021-10-14 15:53:51 +02:00
|
|
|
|
|
|
|
|
m_objectManagerAdaptor = std::make_unique<ObjectManagerTestAdaptor>(*s_adaptorConnection, MANAGER_PATH);
|
|
|
|
|
m_adaptor = std::make_unique<TestAdaptor>(*s_adaptorConnection, OBJECT_PATH);
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TearDown() override
|
|
|
|
|
{
|
|
|
|
|
m_proxy.reset();
|
|
|
|
|
m_adaptor.reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
2021-10-14 15:53:51 +02:00
|
|
|
static std::unique_ptr<sdbus::IConnection> s_adaptorConnection;
|
|
|
|
|
static std::unique_ptr<sdbus::IConnection> s_proxyConnection;
|
|
|
|
|
std::unique_ptr<ObjectManagerTestAdaptor> m_objectManagerAdaptor;
|
|
|
|
|
std::unique_ptr<ObjectManagerTestProxy> m_objectManagerProxy;
|
2020-07-18 20:16:57 +02:00
|
|
|
std::unique_ptr<TestAdaptor> m_adaptor;
|
|
|
|
|
std::unique_ptr<TestProxy> m_proxy;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
|
|
#endif /* SDBUS_CPP_INTEGRATIONTESTS_TESTFIXTURE_H_ */
|