blob: 876edd1d68390d797d1513e9efdba385a39e5a16 [file] [log] [blame]
Krzysztof Grobelnyb5645942020-09-29 11:52:45 +02001#include "utils/unique_call.hpp"
2
3#include <gmock/gmock.h>
4
5namespace utils
6{
7
8using namespace testing;
9
10class 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
31TEST_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
41TEST_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