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