From: Alec Thomas Date: Tue, 15 Sep 2015 01:19:36 +0000 (+1000) Subject: Test that receivers are only called once for each emit. X-Git-Url: https://code.bitgloo.com/?a=commitdiff_plain;h=6729c8341f15d046b87c0ac7f4f15e1c49c11440;p=clyne%2Fentityx.git Test that receivers are only called once for each emit. See #109. --- diff --git a/entityx/Event_test.cc b/entityx/Event_test.cc index c643ee9..c315051 100644 --- a/entityx/Event_test.cc +++ b/entityx/Event_test.cc @@ -35,12 +35,15 @@ struct Collision { struct ExplosionSystem : public Receiver { void receive(const Explosion &explosion) { damage_received += explosion.damage; + received_count++; } void receive(const Collision &collision) { damage_received += collision.damage; + received_count++; } + int received_count = 0; int damage_received = 0; }; @@ -51,9 +54,11 @@ TEST_CASE("TestEmitReceive") { em.subscribe(explosion_system); REQUIRE(0 == explosion_system.damage_received); em.emit(10); + REQUIRE(1 == explosion_system.received_count); REQUIRE(10 == explosion_system.damage_received); em.emit(10); REQUIRE(20 == explosion_system.damage_received); + REQUIRE(2 == explosion_system.received_count); } TEST_CASE("TestUntypedEmitReceive") { @@ -63,6 +68,7 @@ TEST_CASE("TestUntypedEmitReceive") { REQUIRE(0 == explosion_system.damage_received); Explosion explosion(10); em.emit(explosion); + REQUIRE(1 == explosion_system.received_count); REQUIRE(10 == explosion_system.damage_received); }