diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-09-03 12:42:10 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-09-03 12:42:10 +0800 |
commit | efa1266f10e90c0c46f47cc06645422142cb2d9f (patch) | |
tree | 3d8cfefb81ce4645d150c08fc52ad646b6da80e2 /test/base/HandlerRegistryTest.cpp | |
parent | 5e59a8e38c9f8992e6ffd9dbbde11e1f873780e1 (diff) | |
download | cru-efa1266f10e90c0c46f47cc06645422142cb2d9f.tar.gz cru-efa1266f10e90c0c46f47cc06645422142cb2d9f.tar.bz2 cru-efa1266f10e90c0c46f47cc06645422142cb2d9f.zip |
common -> base in test dir.
Diffstat (limited to 'test/base/HandlerRegistryTest.cpp')
-rw-r--r-- | test/base/HandlerRegistryTest.cpp | 37 |
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); +} |