5 #include <condition_variable>
12 #include <gtest/gtest.h>
13 #include <gmock/gmock.h>
61 EXPECT_CALL(sn, tick()).WillOnce(testing::Invoke([&]() {
62 std::this_thread::sleep_for(std::chrono::milliseconds(10));
67 ASSERT_EQ(sn.spinUntilDone(), state);
75 ASSERT_TRUE(sn.isHaltRequested());
79 EXPECT_CALL(sn, tick()).WillOnce(testing::Return(state));
82 ASSERT_EQ(sn.spinUntilDone(), state);
83 ASSERT_FALSE(sn.isHaltRequested());
91 std::condition_variable cv;
94 EXPECT_CALL(sn, tick()).WillOnce(testing::Invoke([&]() {
96 std::unique_lock<std::mutex> l(m);
107 std::future<void> halted = std::async(std::launch::async, [&]() { sn.halt(); });
108 ASSERT_EQ(halted.wait_for(std::chrono::milliseconds(10)), std::future_status::timeout);
113 std::unique_lock<std::mutex> l(m);
120 ASSERT_EQ(sn.status(), state);
129 EXPECT_CALL(sn, tick()).WillOnce(testing::Invoke([&]() {
130 throw std::runtime_error(
"This is not good!");
134 ASSERT_ANY_THROW(sn.spinUntilDone());
135 testing::Mock::VerifyAndClearExpectations(&sn);
140 EXPECT_CALL(sn, tick()).WillOnce(testing::Return(state));
141 ASSERT_EQ(sn.spinUntilDone(), state);