From 0fb7a0e0b2b9e04ca414b1e47c69cc854c79831b Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 1 Dec 2020 23:20:01 +0800 Subject: ... --- test/common/HandlerRegistryTest.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test/common/HandlerRegistryTest.cpp (limited to 'test/common/HandlerRegistryTest.cpp') 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 +#include + +TEST(HandlerRegistry, Work) { + using namespace cru; + HandlerRegistry 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); +} -- cgit v1.2.3