blob: f6fb59471a803a6f99c940a3f32ac99918321b6f [file] [log] [blame]
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +00001#include "helpers.hpp"
Krzysztof Grobelnyb5645942020-09-29 11:52:45 +02002#include "utils/unique_call.hpp"
3
4#include <gmock/gmock.h>
5
6namespace utils
7{
8
9using namespace testing;
10
11class 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
32TEST_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
42TEST_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