ifw-daq  3.0.0-pre2
IFW Data Acquisition modules
mockAsyncProcess.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup daq_common_libdpm
4  * @copyright (c) Copyright ESO 2022
5  * All Rights Reserved
6  * ESO (eso.org) is an Intergovernmental Organisation, and therefore special legal conditions apply.
7  *
8  * @brief Mocks for daq::RsyncAsyncProcessIf
9  */
10 #ifndef DAQ_DPM_MOCK_MOCKASYNCPROCESS_HPP
11 #define DAQ_DPM_MOCK_MOCKASYNCPROCESS_HPP
12 
13 #include <gmock/gmock.h>
14 
16 
17 namespace daq {
18 /**
19  * Combined fake/mock
20  */
21 struct MockAsyncProcess : virtual AsyncProcessIf {
22  virtual boost::future<int> Initiate() override {
23  return promise.get_future();
24  }
25  MOCK_METHOD(std::optional<pid_t>, GetPid, (), (const, noexcept, override));
26 
27  MOCK_METHOD(std::error_code, Abort, (), (noexcept, override));
28  MOCK_METHOD(std::error_code, Signal, (int), (override, noexcept));
29  MOCK_METHOD(std::vector<std::string> const&, GetArguments, (), (const, override, noexcept));
30  MOCK_METHOD(bool, IsRunning, (), (const, noexcept, override));
31 
33  boost::signals2::connection ConnectStdout(SigOutStream::slot_type const& slot) override {
34  return stdout.connect(slot);
35  }
36  boost::signals2::connection ConnectStderr(SigOutStream::slot_type const& slot) override {
37  return stderr.connect(slot);
38  }
39 
42  boost::promise<int> promise;
43 };
44 
47  boost::signals2::connection ConnectProgress(SigProgress::slot_type const& slot) override {
48  return progress.connect(slot);
49  }
51 };
52 } // namespace daq
53 #endif // #ifndef DAQ_DPM_MOCK_MOCKASYNCPROCESS_HPP
Interface to asynchronous process.
virtual std::error_code Abort() noexcept=0
Aborts the operation by terminating process which completes the operation.
virtual std::vector< std::string > const & GetArguments() const noexcept=0
boost::signals2::signal< void(pid_t, std::string const &)> SigOutStream
Signal type for stdout/stderr signals.
virtual std::error_code Signal(int sig) noexcept=0
Send signal to process.
virtual bool IsRunning() const noexcept=0
virtual std::optional< pid_t > GetPid() const noexcept=0
Get PID.
More specialized version for rsync which also monitors transfer progress.
boost::signals2::signal< void(pid_t, RsyncProgress const &)> SigProgress
Progress update signal.
daq::RsyncAsyncProcess and related class declarations.
Combined fake/mock.
boost::signals2::connection ConnectStderr(SigOutStream::slot_type const &slot) override
Connect slot to line-buffered stderr signal.
MOCK_METHOD(std::optional< pid_t >, GetPid,(),(const, noexcept, override))
MOCK_METHOD(std::error_code, Abort,(),(noexcept, override))
boost::promise< int > promise
virtual boost::future< int > Initiate() override
Initiates async operation by executing the specified process.
MOCK_METHOD(std::error_code, Signal,(int),(override, noexcept))
MOCK_METHOD(std::vector< std::string > const &, GetArguments,(),(const, override, noexcept))
boost::signals2::connection ConnectStdout(SigOutStream::slot_type const &slot) override
Connect slot to line-buffered stdout signal.
MOCK_METHOD(bool, IsRunning,(),(const, noexcept, override))
boost::signals2::connection ConnectProgress(SigProgress::slot_type const &slot) override
Connect to progress signal.