Skip to content

Commit

Permalink
Add test case for component destruction.
Browse files Browse the repository at this point in the history
  • Loading branch information
alecthomas committed Oct 20, 2014
1 parent d1c9572 commit b25ba8b
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion entityx/Entity_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

0 comments on commit b25ba8b

Please sign in to comment.