aboutsummaryrefslogtreecommitdiff
path: root/test/common/Event2Test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/common/Event2Test.cpp')
-rw-r--r--test/common/Event2Test.cpp37
1 files changed, 30 insertions, 7 deletions
diff --git a/test/common/Event2Test.cpp b/test/common/Event2Test.cpp
index f63a5347..e14174cf 100644
--- a/test/common/Event2Test.cpp
+++ b/test/common/Event2Test.cpp
@@ -4,16 +4,39 @@
using cru::Event2;
-TEST_CASE("Event2 handlers should work.", "[event2]") {
+TEST_CASE("Event2", "[event2]") {
Event2 event;
int counter = 0;
auto handler = [&counter] { counter++; };
-
- event.AddHandler(handler);
-
- event.Raise();
-
- REQUIRE(counter == 1);
+ 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);
+ }
}