aboutsummaryrefslogtreecommitdiff
path: root/test/common
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-12-01 23:20:01 +0800
committercrupest <crupest@outlook.com>2020-12-01 23:20:01 +0800
commit0fb7a0e0b2b9e04ca414b1e47c69cc854c79831b (patch)
tree46d7f93e96bca49b0ec114c5595567b9bbcec6e3 /test/common
parent4fcf336d15fe246259ee18ccc99808d80e69c455 (diff)
downloadcru-0fb7a0e0b2b9e04ca414b1e47c69cc854c79831b.tar.gz
cru-0fb7a0e0b2b9e04ca414b1e47c69cc854c79831b.tar.bz2
cru-0fb7a0e0b2b9e04ca414b1e47c69cc854c79831b.zip
...
Diffstat (limited to 'test/common')
-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);
+}