1 #include "helpers.hpp"
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:
uniqueCallIncrementCounter()14     void uniqueCallIncrementCounter()
15     {
16         uniqueCall1([this](auto context) { ++counter; });
17     }
18 
uniqueCallWhileUniqueCallIsActiveIncrementCounter()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 
TEST_F(TestUniqueCall,shouldExecuteNormally)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 
TEST_F(TestUniqueCall,shouldNotExecuteWhenPreviousExecutionIsStillActive)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
53