#include #include #include #include #include #include #include #include #include #include namespace sdeventplus { namespace { using testing::DoAll; using testing::Return; using testing::SetArgPointee; class ClockTest : public testing::Test { protected: testing::StrictMock mock; sd_event* const expected_event = reinterpret_cast(1234); }; TEST_F(ClockTest, CopyEvent) { Event event(expected_event, std::false_type(), &mock); EXPECT_CALL(mock, sd_event_ref(expected_event)) .WillOnce(Return(expected_event)); Clock clock(event); EXPECT_CALL(mock, sd_event_now(expected_event, CLOCK_REALTIME, testing::_)) .WillOnce(DoAll(SetArgPointee<2>(2000000), Return(0))); EXPECT_EQ(Clock::time_point(std::chrono::seconds{2}), clock.now()); EXPECT_CALL(mock, sd_event_unref(expected_event)) .Times(2) .WillRepeatedly(Return(nullptr)); } TEST_F(ClockTest, MoveEvent) { Event event(expected_event, std::false_type(), &mock); Clock clock(std::move(event)); EXPECT_CALL(mock, sd_event_now(expected_event, CLOCK_MONOTONIC, testing::_)) .WillOnce(Return(-EINVAL)); EXPECT_THROW(clock.now(), SdEventError); EXPECT_CALL(mock, sd_event_unref(expected_event)).WillOnce(Return(nullptr)); } } // namespace } // namespace sdeventplus