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