aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlec Thomas <alec@swapoff.org>2014-10-21 10:46:38 +1100
committerAlec Thomas <alec@swapoff.org>2014-10-21 10:46:38 +1100
commitb25ba8bd4be4b3d734ffcaa876cbf0f53ad3e7c1 (patch)
tree001c3aca801eefbe7b6aee9f5244b89b494b1a7e
parentd1c9572526291a16db73e53edfb378af7c50c784 (diff)
Add test case for component destruction.
-rw-r--r--entityx/Entity_test.cc25
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);
+}