ifw-daq  2.1.0-pre1
IFW Data Acquisition modules
mockAsyncOperations.hpp
Go to the documentation of this file.
1 // GCOVR_EXCL_START
2 #ifndef OCM_DAQ_TEST_MOCK_ASYNC_OPERATIONS_HPP_
3 #define OCM_DAQ_TEST_MOCK_ASYNC_OPERATIONS_HPP_
4 #include <daq/config.hpp>
5 #include <gmock/gmock.h>
6 
7 #include <daq/daqController.hpp>
9 /**
10  * Simple class that facilitates mocking of the freestanding asynchronous operations in
11  * daq::op:
12  * - `daq::op::StartAsync`
13  * - `daq::op::StopAsync`
14  * - `daq::op::AbortAsync`
15  *
16  * where each method matches the interface of the operations.
17  */
18 struct MockAbort {
19  MOCK_METHOD0(Abort, bool());
20 };
21 
23  MOCK_METHOD1(Start, boost::future<void>(daq::op::AsyncOpParams));
24  MOCK_METHOD2(Abort,
29  // Mocks the await function only, not the abort to simplify usage
31 
32  // Helper that simplifies the mocking by setting up the abort mock automatically
34  return {AwaitPrim(params), [&]() -> bool { return mock_abort.Abort(); }};
35  }
37 };
38 
39 std::tuple<std::unique_ptr<MockAsyncOperations>, daq::OcmAsyncOperations>
41  std::tuple<std::unique_ptr<MockAsyncOperations>, daq::OcmAsyncOperations> res(
42  std::make_unique<MockAsyncOperations>(), daq::OcmAsyncOperations());
43 
44  auto& ops = std::get<daq::OcmAsyncOperations>(res);
45  auto* mock_ptr = std::get<std::unique_ptr<MockAsyncOperations>>(res).get();
46 
47  ops.start = [mock_ptr](daq::op::AsyncOpParams params) { return mock_ptr->Start(params); };
48  ops.abort = [mock_ptr](daq::ErrorPolicy policy, daq::op::AsyncOpParams params) {
49  return mock_ptr->Abort(policy, params);
50  };
51  ops.stop = [mock_ptr](daq::ErrorPolicy policy, daq::op::AsyncOpParams params) {
52  return mock_ptr->Stop(policy, params);
53  };
54  ops.await_prim = [mock_ptr](daq::op::AwaitOpParams params) {
55  return mock_ptr->AwaitPrimHelper(params);
56  };
57  return res;
58 }
59 #endif // #define OCM_DAQ_TEST_MOCK_ASYNC_OPERATIONS_HPP_
60 // GCOVR_EXCL_STOP
MockAbort::MOCK_METHOD0
MOCK_METHOD0(Abort, bool())
CreateMockAsyncOperations
std::tuple< std::unique_ptr< MockAsyncOperations >, daq::OcmAsyncOperations > CreateMockAsyncOperations()
Definition: mockAsyncOperations.hpp:40
MockAsyncOperations::MOCK_METHOD1
MOCK_METHOD1(AwaitPrim, boost::future< daq::Result< daq::DpParts >>(daq::op::AwaitOpParams))
asyncOpParams.hpp
MockAsyncOperations::MOCK_METHOD2
MOCK_METHOD2(Abort, boost::future< daq::Result< void >>(daq::ErrorPolicy, daq::op::AsyncOpParams))
daq::op::AwaitOpParams
Await specific parameters that is not provided with AsyncOpParams.
Definition: asyncOpParams.hpp:114
config.hpp
daq::OcmAsyncOperations
OCM Async operations.
Definition: daqController.hpp:49
MockAsyncOperations::mock_abort
MockAbort mock_abort
Definition: mockAsyncOperations.hpp:36
daq::OcmAsyncOperations::AwaitReturnType
std::pair< boost::future< Result< DpParts > >, std::function< bool()> > AwaitReturnType
Definition: daqController.hpp:51
daq::Result
Utility class that represents a result and an error.
Definition: utility.hpp:17
daqController.hpp
Contains declaration for for DaqController.
daq::Result< void >
Definition: utility.hpp:23
MockAsyncOperations::MOCK_METHOD2
MOCK_METHOD2(Stop, boost::future< daq::Result< daq::DpParts >>(daq::ErrorPolicy, daq::op::AsyncOpParams))
MockAsyncOperations::AwaitPrimHelper
daq::OcmAsyncOperations::AwaitReturnType AwaitPrimHelper(daq::op::AwaitOpParams params)
Definition: mockAsyncOperations.hpp:33
daq::op::AsyncOpParams
Parameters required for each async operation.
Definition: asyncOpParams.hpp:67
daq::ErrorPolicy
ErrorPolicy
Error policy supported by certain operations.
Definition: error.hpp:25
MockAsyncOperations
Definition: mockAsyncOperations.hpp:22
MockAbort
Simple class that facilitates mocking of the freestanding asynchronous operations in daq::op:
Definition: mockAsyncOperations.hpp:18
MockAsyncOperations::MOCK_METHOD1
MOCK_METHOD1(Start, boost::future< void >(daq::op::AsyncOpParams))