aboutsummaryrefslogtreecommitdiff
path: root/test/base/HandlerRegistryTest.cpp
blob: aacef70f4ff8f7b5c4de84c84a8f8f26188f1747 (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/base/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);
}