Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 1 | #include "helpers.hpp" |
Krzysztof Grobelny | b564594 | 2020-09-29 11:52:45 +0200 | [diff] [blame] | 2 | #include "utils/unique_call.hpp" |
| 3 | |
| 4 | #include <gmock/gmock.h> |
| 5 | |
| 6 | namespace utils |
| 7 | { |
| 8 | |
| 9 | using namespace testing; |
| 10 | |
| 11 | class TestUniqueCall : public Test |
| 12 | { |
| 13 | public: |
| 14 | void uniqueCallIncrementCounter() |
| 15 | { |
| 16 | uniqueCall1([this](auto context) { ++counter; }); |
| 17 | } |
| 18 | |
| 19 | void uniqueCallWhileUniqueCallIsActiveIncrementCounter() |
| 20 | { |
| 21 | uniqueCall2([this](auto context) { |
| 22 | ++counter; |
| 23 | uniqueCallWhileUniqueCallIsActiveIncrementCounter(); |
| 24 | }); |
| 25 | } |
| 26 | |
| 27 | UniqueCall uniqueCall1; |
| 28 | UniqueCall uniqueCall2; |
| 29 | uint32_t counter = 0u; |
| 30 | }; |
| 31 | |
| 32 | TEST_F(TestUniqueCall, shouldExecuteNormally) |
| 33 | { |
| 34 | for (size_t i = 0; i < 3u; ++i) |
| 35 | { |
| 36 | uniqueCallIncrementCounter(); |
| 37 | } |
| 38 | |
| 39 | ASSERT_THAT(counter, Eq(3u)); |
| 40 | } |
| 41 | |
| 42 | TEST_F(TestUniqueCall, shouldNotExecuteWhenPreviousExecutionIsStillActive) |
| 43 | { |
| 44 | for (size_t i = 0; i < 3u; ++i) |
| 45 | { |
| 46 | uniqueCallWhileUniqueCallIsActiveIncrementCounter(); |
| 47 | } |
| 48 | |
| 49 | ASSERT_THAT(counter, Eq(3u)); |
| 50 | } |
| 51 | |
| 52 | } // namespace utils |