diff options
author | Alec Thomas <alec@swapoff.org> | 2014-10-21 10:46:38 +1100 |
---|---|---|
committer | Alec Thomas <alec@swapoff.org> | 2014-10-21 10:46:38 +1100 |
commit | b25ba8bd4be4b3d734ffcaa876cbf0f53ad3e7c1 (patch) | |
tree | 001c3aca801eefbe7b6aee9f5244b89b494b1a7e | |
parent | d1c9572526291a16db73e53edfb378af7c50c784 (diff) |
Add test case for component destruction.
-rw-r--r-- | entityx/Entity_test.cc | 25 |
1 files changed, 24 insertions, 1 deletions
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 <set> #include <map> #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> { + Test(bool &yes) : freed(yes) {} + + Freed freed; + }; + + bool freed = false; + { + EntityX e; + auto test = e.entities.create(); + test.assign<Test>(freed); + } + REQUIRE(freed == true); +} |