]> code.bitgloo.com Git - clyne/entityx.git/commitdiff
Add test case for component destruction.
authorAlec Thomas <alec@swapoff.org>
Mon, 20 Oct 2014 23:46:38 +0000 (10:46 +1100)
committerAlec Thomas <alec@swapoff.org>
Mon, 20 Oct 2014 23:46:38 +0000 (10:46 +1100)
entityx/Entity_test.cc

index 2b4ed6b891136460803b4567ee25b09b3e44849c..a928e9ba318dc7b5fc65d7c9638f0d0166010712 100644 (file)
@@ -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);
+}