10 #include <gmock/gmock.h>
11 #include <gtest/gtest.h>
12 #include <log4cplus/logger.h>
23 using namespace ::testing;
34 boost::promise<std::shared_ptr<metadaqif::DaqReply>> reply_promise;
35 auto reply_mock = std::make_shared<DaqReplyMock>();
36 boost::promise<std::shared_ptr<metadaqif::DaqReply>> reply_promise2;
37 auto reply_mock2 = std::make_shared<DaqReplyMock>();
39 EXPECT_CALL(*m_meta_rr_client, StartDaq(
"id"))
40 .WillOnce(Return(ByMove(reply_promise.get_future())));
41 EXPECT_CALL(*m_meta_rr_client2, StartDaq(
"id"))
42 .WillOnce(Return(ByMove(reply_promise2.get_future())));
44 boost::promise<std::shared_ptr<recif::RecStatus>> prim_promise_1;
45 boost::promise<std::shared_ptr<recif::RecStatus>> prim_promise_2;
46 auto prim_reply_mock_1 = std::make_shared<RecStatusMock>();
47 EXPECT_CALL(*m_prim_rr_client, RecStart(RecPropertyIdEq(
"id")))
48 .WillOnce(Return(ByMove(prim_promise_1.get_future())));
49 EXPECT_CALL(*m_prim_rr_client2, RecStart(RecPropertyIdEq(
"id")))
50 .WillOnce(Return(ByMove(prim_promise_2.get_future())));
53 boost::future<void> fut = op::InitiateOperation<op::StartAsync>(MakeParams());
54 EXPECT_FALSE(fut.is_ready());
57 reply_promise.set_value(reply_mock);
58 reply_promise2.set_value(reply_mock2);
59 prim_promise_1.set_value(prim_reply_mock_1);
60 prim_promise_2.set_value(prim_reply_mock_1);
65 ASSERT_TRUE(fut.is_ready());
66 ASSERT_FALSE(fut.has_exception());
73 EXPECT_CALL(*m_meta_rr_client, StartDaq(_))
74 .WillOnce(Throw(std::runtime_error(
"Fake test failure")));
77 EXPECT_CALL(*m_meta_rr_client2, StartDaq(_)).Times(0);
80 boost::future<void> fut = op::InitiateOperation<op::StartAsync>(MakeParams());
81 EXPECT_FALSE(fut.is_ready());
87 ASSERT_TRUE(fut.is_ready());
88 EXPECT_TRUE(fut.has_exception()) <<
"Expected future to contain exception";
89 EXPECT_THROW(fut.get(), std::exception) <<
"Expected exception to derive from std::exception";
95 boost::promise<std::shared_ptr<metadaqif::DaqReply>> reply_promise;
96 auto reply_mock = std::make_shared<DaqReplyMock>();
97 EXPECT_CALL(*reply_mock, getMessage()).WillRepeatedly(Return(std::string(
"some message")));
99 boost::promise<std::shared_ptr<metadaqif::DaqReply>> reply_promise2;
100 auto reply_mock2 = std::make_shared<DaqReplyMock>();
101 EXPECT_CALL(*reply_mock2, getMessage()).WillRepeatedly(Return(std::string(
"some message")));
104 EXPECT_CALL(*m_meta_rr_client, StartDaq(_))
105 .WillOnce(Return(ByMove(reply_promise.get_future())));
107 EXPECT_CALL(*m_meta_rr_client2, StartDaq(_))
108 .WillOnce(Return(ByMove(reply_promise2.get_future())));
111 boost::future<void> fut = op::InitiateOperation<op::StartAsync>(MakeParams());
112 EXPECT_FALSE(fut.is_ready());
115 reply_promise.set_exception(metadaqif::DaqException(
"foo",
"baz"));
116 reply_promise2.set_value(reply_mock2);
121 ASSERT_TRUE(fut.is_ready());