blob: d1792c7c5630f76e2f5e1ef71d9fef28003a2146 (
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.hpp"
#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);
}
|