]> code.bitgloo.com Git - clyne/entityx.git/commitdiff
Add test for component destructor called when entity is destroyed.
authorAlec Thomas <alec@swapoff.org>
Tue, 21 Oct 2014 03:04:51 +0000 (14:04 +1100)
committerAlec Thomas <alec@swapoff.org>
Tue, 21 Oct 2014 03:04:51 +0000 (14:04 +1100)
entityx/Entity_test.cc

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