mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 16:46:47 +00:00
68 lines
1.9 KiB
C++
68 lines
1.9 KiB
C++
/********************************************************************************
|
|
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
|
* *
|
|
* This software is distributed under the terms of the *
|
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
|
* copied verbatim in the file "LICENSE" *
|
|
********************************************************************************/
|
|
|
|
#ifndef FAIR_MQ_TEST_FIXTURE
|
|
#define FAIR_MQ_TEST_FIXTURE
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <fairmq/PluginServices.h>
|
|
#include <FairMQDevice.h>
|
|
#include <options/FairMQProgOptions.h>
|
|
#include <memory>
|
|
#include <thread>
|
|
|
|
namespace fair
|
|
{
|
|
namespace mq
|
|
{
|
|
namespace test
|
|
{
|
|
|
|
inline auto control(FairMQDevice& device) -> void
|
|
{
|
|
for (const auto event : {
|
|
FairMQDevice::INIT_DEVICE,
|
|
FairMQDevice::RESET_DEVICE,
|
|
FairMQDevice::END,
|
|
}) {
|
|
device.ChangeState(event);
|
|
if (event != FairMQDevice::END) device.WaitForEndOfState(event);
|
|
}
|
|
}
|
|
|
|
struct PluginServices : ::testing::Test {
|
|
PluginServices()
|
|
: mConfig()
|
|
, mDevice()
|
|
, mServices(mConfig, mDevice)
|
|
, fRunStateMachineThread()
|
|
{
|
|
fRunStateMachineThread = std::thread(&FairMQDevice::RunStateMachine, &mDevice);
|
|
mDevice.SetTransport("zeromq");
|
|
}
|
|
|
|
~PluginServices()
|
|
{
|
|
if (mDevice.GetCurrentState() == FairMQDevice::IDLE) control(mDevice);
|
|
if (fRunStateMachineThread.joinable()) {
|
|
fRunStateMachineThread.join();
|
|
}
|
|
}
|
|
|
|
FairMQProgOptions mConfig;
|
|
FairMQDevice mDevice;
|
|
fair::mq::PluginServices mServices;
|
|
std::thread fRunStateMachineThread;
|
|
};
|
|
|
|
} /* namespace test */
|
|
} /* namespace mq */
|
|
} /* namespace fair */
|
|
|
|
#endif /* FAIR_MQ_TEST_FIXTURE */
|