aboutsummaryrefslogtreecommitdiff
path: root/test/common/HandlerRegistryTest.cpp
blob: 03e190e3652cb1366592a5d2109eb355be6d16fe (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
37
#include "cru/common/HandlerRegistry.h"

#include <catch2/catch_test_macros.hpp>

#include <algorithm>

TEST_CASE("HandlerRegistry", "[handler_registry]") {
  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();
  }

  REQUIRE(counter == 3);

  registry.RemoveHandler(tag1);

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

  REQUIRE(counter == 4);

  registry.RemoveHandler(tag2);

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

  REQUIRE(counter == 4);
}