Krzysztof Grobelny | b564594 | 2020-09-29 11:52:45 +0200 | [diff] [blame] | 1 | #include "dbus_environment.hpp" |
| 2 | #include "utils/detached_timer.hpp" |
| 3 | |
| 4 | #include <gmock/gmock.h> |
| 5 | |
| 6 | namespace utils |
| 7 | { |
| 8 | |
| 9 | using namespace testing; |
| 10 | using namespace std::chrono_literals; |
| 11 | |
| 12 | class TestDetachedTimer : public Test |
| 13 | { |
| 14 | public: |
| 15 | uint32_t value = 0; |
| 16 | }; |
| 17 | |
| 18 | TEST_F(TestDetachedTimer, executesLambdaAfterTimeout) |
| 19 | { |
| 20 | auto setPromise = DbusEnvironment::setPromise("timer"); |
| 21 | |
| 22 | makeDetachedTimer(DbusEnvironment::getIoc(), 100ms, [this, &setPromise] { |
| 23 | ++value; |
| 24 | setPromise(); |
| 25 | }); |
| 26 | |
| 27 | auto elapsed = DbusEnvironment::measureTime( |
| 28 | [] { DbusEnvironment::waitForFuture("timer"); }); |
| 29 | |
| 30 | EXPECT_THAT(elapsed, AllOf(Ge(100ms), Lt(200ms))); |
| 31 | EXPECT_THAT(value, Eq(1u)); |
| 32 | } |
| 33 | |
| 34 | } // namespace utils |