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