ifw-daq  2.1.0-pre1
IFW Data Acquisition modules
testAsyncOpBase.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup daq_ocm_libdaq_test
4  * @copyright 2022 ESO - European Southern Observatory
5  *
6  * @brief Contains declaration for async operations shared base class
7  */
8 #ifndef OCM_DAQ_TEST_ASYNC_OP_BASE_HPP_
9 #define OCM_DAQ_TEST_ASYNC_OP_BASE_HPP_
10 #include <daq/config.hpp>
11 
12 #include <gmock/gmock.h>
13 #include <gtest/gtest.h>
14 #include <log4cplus/logger.h>
15 #include <boost/asio/io_context.hpp>
16 
17 #include <daq/status.hpp>
18 #include <daq/source.hpp>
19 #include <daq/pendingReplies.hpp>
20 #include <daq/op/asyncOpParams.hpp>
21 #include <rad/ioExecutor.hpp>
22 
23 #include "mock/recifMock.hpp"
24 #include "mock/metadaqifMock.hpp"
25 #include "statusObserver.hpp"
26 #include "utils.hpp"
27 
28 MATCHER_P(RecPropertyIdEq, id, "") {
29  *result_listener << "where the id is" << (arg->getId());
30  return arg && arg->getId() == id;
31 }
32 
33 /**
34  * Base fixture for async operation tests.
35  *
36  * @ingroup daq_ocm_libdaq_test
37  */
38 struct TestAsyncOpBase : ::testing::Test {
39  std::shared_ptr<daq::RecCmdsAsyncMock> m_prim_rr_client;
40  std::shared_ptr<daq::RecCmdsAsyncMock> m_prim_rr_client2;
41  std::shared_ptr<daq::MetaDaqAsyncMock> m_meta_rr_client;
42  std::shared_ptr<daq::MetaDaqAsyncMock> m_meta_rr_client2;
43 
44 
45  boost::asio::io_context m_io_ctx;
47  log4cplus::Logger m_logger;
48  std::string m_id;
50  std::shared_ptr<daq::ObservableStatus> m_status;
51  std::shared_ptr<daq::ObservableEventLog> m_event_log;
53  std::shared_ptr<daq::PendingReplies> m_pending_replies;
54  std::vector<daq::Source<daq::PrimSource>> m_prim_sources;
55  std::vector<daq::Source<daq::MetaSource>> m_meta_sources;
56 
57  // Used in tests
58  boost::promise<std::shared_ptr<recif::RecStatus>> m_recstatus_promise1;
59  boost::promise<std::shared_ptr<recif::RecStatus>> m_recstatus_promise2;
60  boost::promise<std::string> m_string_promise1;
61  boost::promise<std::string> m_string_promise2;
62 
64  void SetUp() override;
65  void TearDown() override;
66 
67  template<class SourceType>
68  std::vector<daq::Source<SourceType>>
69  MakeSources(std::vector<SourceType> sources) {
70  std::vector<daq::Source<SourceType>> dest;
71  dest.reserve(sources.size());
72  std::transform(std::make_move_iterator(sources.begin()), std::make_move_iterator(sources.end()),
73  std::back_inserter(dest), [](SourceType&& s) -> daq::Source<SourceType> {
74  return daq::Source<SourceType>{std::move(s)};
75  });
76  return dest;
77  }
78 
79  daq::op::AsyncOpParams MakeParams();
80 };
81 
82 #endif // #ifndef OCM_DAQ_TEST_ASYNC_OP_BASE_HPP_
TestAsyncOpBase::m_meta_sources
std::vector< daq::Source< daq::MetaSource > > m_meta_sources
Definition: testAsyncOpBase.hpp:55
pendingReplies.hpp
Contains declaration for classes related to pending replies.
source.hpp
Declarations for daq::Source and related classes.
ioExecutor.hpp
TestAsyncOpBase::m_meta_rr_client
std::shared_ptr< daq::MetaDaqAsyncMock > m_meta_rr_client
Definition: testAsyncOpBase.hpp:41
TestAsyncOpBase::m_observer
StatusObserverMock m_observer
Definition: testAsyncOpBase.hpp:49
utils.hpp
Defines shared test utilities.
TestAsyncOpBase::SetUp
void SetUp() override
Definition: testAsyncOpBase.cpp:23
metadaqifMock.hpp
Mockup of metadaqif classes.
TestAsyncOpBase::m_logger
log4cplus::Logger m_logger
Definition: testAsyncOpBase.hpp:47
TestAsyncOpBase::m_prim_rr_client2
std::shared_ptr< daq::RecCmdsAsyncMock > m_prim_rr_client2
Definition: testAsyncOpBase.hpp:40
TestAsyncOpBase::m_event_log
std::shared_ptr< daq::ObservableEventLog > m_event_log
Definition: testAsyncOpBase.hpp:51
rad::IoExecutor
Adapts boost::asio::io_context into a compatible boost::thread Executor type.
Definition: ioExecutor.hpp:12
TestAsyncOpBase::m_meta_rr_client2
std::shared_ptr< daq::MetaDaqAsyncMock > m_meta_rr_client2
Definition: testAsyncOpBase.hpp:42
daq::Source
Simple class that holds the source and associated state.
Definition: source.hpp:29
daq::op::AlertState
Definition: asyncOpParams.hpp:18
recifMock.hpp
Mockup of metadaqif classes.
asyncOpParams.hpp
config.hpp
TestAsyncOpBase::m_prim_sources
std::vector< daq::Source< daq::PrimSource > > m_prim_sources
Definition: testAsyncOpBase.hpp:54
TestAsyncOpBase::m_id
std::string m_id
Definition: testAsyncOpBase.hpp:48
TestAsyncOpBase::m_string_promise2
boost::promise< std::string > m_string_promise2
Definition: testAsyncOpBase.hpp:61
TestAsyncOpBase::m_executor
rad::IoExecutor m_executor
Definition: testAsyncOpBase.hpp:46
TestAsyncOpBase::m_recstatus_promise1
boost::promise< std::shared_ptr< recif::RecStatus > > m_recstatus_promise1
Definition: testAsyncOpBase.hpp:58
TestAsyncOpBase::TestAsyncOpBase
TestAsyncOpBase()
Definition: testAsyncOpBase.cpp:13
TestAsyncOpBase
Base fixture for async operation tests.
Definition: testAsyncOpBase.hpp:38
statusObserver.hpp
status.hpp
Contains declaration for Status and ObservableStatus.
MATCHER_P
MATCHER_P(RecPropertyIdEq, id, "")
Definition: testAsyncOpBase.hpp:28
TestAsyncOpBase::m_alerts
daq::op::AlertState m_alerts
Definition: testAsyncOpBase.hpp:52
StatusObserverMock
Simple observer used for testing.
Definition: statusObserver.hpp:22
TestAsyncOpBase::m_io_ctx
boost::asio::io_context m_io_ctx
Definition: testAsyncOpBase.hpp:45
TestAsyncOpBase::m_prim_rr_client
std::shared_ptr< daq::RecCmdsAsyncMock > m_prim_rr_client
Definition: testAsyncOpBase.hpp:39
TestAsyncOpBase::m_recstatus_promise2
boost::promise< std::shared_ptr< recif::RecStatus > > m_recstatus_promise2
Definition: testAsyncOpBase.hpp:59
TestAsyncOpBase::TearDown
void TearDown() override
Definition: testAsyncOpBase.cpp:43
TestAsyncOpBase::MakeSources
std::vector< daq::Source< SourceType > > MakeSources(std::vector< SourceType > sources)
Definition: testAsyncOpBase.hpp:69
daq::op::AsyncOpParams
Parameters required for each async operation.
Definition: asyncOpParams.hpp:67
TestAsyncOpBase::m_pending_replies
std::shared_ptr< daq::PendingReplies > m_pending_replies
Definition: testAsyncOpBase.hpp:53
TestAsyncOpBase::m_status
std::shared_ptr< daq::ObservableStatus > m_status
Definition: testAsyncOpBase.hpp:50
TestAsyncOpBase::m_string_promise1
boost::promise< std::string > m_string_promise1
Definition: testAsyncOpBase.hpp:60