From b25ba8bd4be4b3d734ffcaa876cbf0f53ad3e7c1 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Tue, 21 Oct 2014 10:46:38 +1100 Subject: Add test case for component destruction. --- entityx/Entity_test.cc | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/entityx/Entity_test.cc b/entityx/Entity_test.cc index 2b4ed6b..a928e9b 100644 --- a/entityx/Entity_test.cc +++ b/entityx/Entity_test.cc @@ -18,7 +18,7 @@ #include #include #include "entityx/3rdparty/catch.hpp" -#include "entityx/Entity.h" +#include "entityx/entityx.h" // using namespace std; using namespace entityx; @@ -519,3 +519,26 @@ TEST_CASE_METHOD(EntityManagerFixture, "TestEntityInStdMap") { REQUIRE(entityMap[b] == 2); REQUIRE(entityMap[c] == 3); } + +TEST_CASE("TestComponentDestructorCalledWhenManagerDestroyed") { + struct Freed { + explicit Freed(bool &yes) : yes(yes) {} + ~Freed() { yes = true; } + + bool &yes; + }; + + struct Test : Component { + Test(bool &yes) : freed(yes) {} + + Freed freed; + }; + + bool freed = false; + { + EntityX e; + auto test = e.entities.create(); + test.assign(freed); + } + REQUIRE(freed == true); +} -- cgit v1.2.3