aboutsummaryrefslogtreecommitdiff
path: root/test/common/HandlerRegistryTest.cpp
blob: cf64ef4d2bf06b73b46e1d300ed784d7a14184e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "cru/common/HandlerRegistry.h"

#include <gtest/gtest.h>
#include <algorithm>

TEST(HandlerRegistry, Work) {
  using namespace cru;
  HandlerRegistry<void()> registry;

  int counter = 1;

  auto tag1 = registry.AddHandler([&counter] { counter++; });
  auto tag2 = registry.AddHandler([&counter] { counter++; });

  for (const auto& handler : registry) {
    handler();
  }

  ASSERT_EQ(counter, 3);

  registry.RemoveHandler(tag1);

  for (const auto& handler : registry) {
    handler();
  }

  ASSERT_EQ(counter, 4);

  registry.RemoveHandler(tag2);

  for (const auto& handler : registry) {
    handler();
  }

  ASSERT_EQ(counter, 4);
}