diff options
author | Alec Thomas <alec@swapoff.org> | 2014-10-21 14:04:51 +1100 |
---|---|---|
committer | Alec Thomas <alec@swapoff.org> | 2014-10-21 14:04:51 +1100 |
commit | 04fdec9b2284517233471691bc887a51c77149b7 (patch) | |
tree | 95f220c41ff29eedf412bf86e262ffe68a805dc2 | |
parent | b25ba8bd4be4b3d734ffcaa876cbf0f53ad3e7c1 (diff) |
Add test for component destructor called when entity is destroyed.
-rw-r--r-- | entityx/Entity_test.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/entityx/Entity_test.cc b/entityx/Entity_test.cc index a928e9b..cd7b2a1 100644 --- a/entityx/Entity_test.cc +++ b/entityx/Entity_test.cc @@ -542,3 +542,26 @@ TEST_CASE("TestComponentDestructorCalledWhenManagerDestroyed") { } REQUIRE(freed == true); } + +TEST_CASE("TestComponentDestructorCalledWhenEntityDestroyed") { + 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 == false); + test.destroy(); + REQUIRE(freed == true); +} |