aboutsummaryrefslogtreecommitdiff
path: root/test/common/HandlerRegistryTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/common/HandlerRegistryTest.cpp')
-rw-r--r--test/common/HandlerRegistryTest.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/common/HandlerRegistryTest.cpp b/test/common/HandlerRegistryTest.cpp
new file mode 100644
index 00000000..d1792c7c
--- /dev/null
+++ b/test/common/HandlerRegistryTest.cpp
@@ -0,0 +1,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);
+}