aboutsummaryrefslogtreecommitdiff
path: root/test/common/Event2Test.cpp
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-09-03 12:42:10 +0800
committerYuqian Yang <crupest@crupest.life>2025-09-03 12:42:10 +0800
commitefa1266f10e90c0c46f47cc06645422142cb2d9f (patch)
tree3d8cfefb81ce4645d150c08fc52ad646b6da80e2 /test/common/Event2Test.cpp
parent5e59a8e38c9f8992e6ffd9dbbde11e1f873780e1 (diff)
downloadcru-efa1266f10e90c0c46f47cc06645422142cb2d9f.tar.gz
cru-efa1266f10e90c0c46f47cc06645422142cb2d9f.tar.bz2
cru-efa1266f10e90c0c46f47cc06645422142cb2d9f.zip
common -> base in test dir.
Diffstat (limited to 'test/common/Event2Test.cpp')
-rw-r--r--test/common/Event2Test.cpp54
1 files changed, 0 insertions, 54 deletions
diff --git a/test/common/Event2Test.cpp b/test/common/Event2Test.cpp
deleted file mode 100644
index 0c67f28e..00000000
--- a/test/common/Event2Test.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-#include "cru/base/Event2.h"
-
-#include <catch2/catch_test_macros.hpp>
-
-using cru::Event2;
-
-TEST_CASE("Event2", "[event2]") {
- Event2 event;
-
- int counter = 0;
-
- auto handler = [&counter] { counter++; };
- auto token = event.AddHandler(handler);
-
- auto handler2 = [&counter](decltype(event)::Context* context) { counter++; };
-
- SECTION("two handlers should work.") {
- event.Raise();
- REQUIRE(counter == 1);
- event.Raise();
- REQUIRE(counter == 2);
-
- event.AddHandler(handler2);
- event.Raise();
- REQUIRE(counter == 4);
- }
-
- SECTION("handler revoker should work.") {
- token.RevokeHandler();
- event.Raise();
- REQUIRE(counter == 0);
-
- token = event.AddHandler(handler);
- event.AddHandler(handler2);
- event.Raise();
- REQUIRE(counter == 2);
-
- token.RevokeHandler();
- event.Raise();
- REQUIRE(counter == 3);
- }
-
- SECTION("stop handling should work.") {
- auto short_circuit_handler = [&counter](decltype(event)::Context* context) {
- context->SetStopHandling();
- };
-
- event.AddHandler(short_circuit_handler);
- event.AddHandler(handler2);
-
- event.Raise();
- REQUIRE(counter == 1);
- }
-}