Skip to content

Commit b25ba8b

Browse files
committed
Add test case for component destruction.
1 parent d1c9572 commit b25ba8b

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

entityx/Entity_test.cc

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <set>
1919
#include <map>
2020
#include "entityx/3rdparty/catch.hpp"
21-
#include "entityx/Entity.h"
21+
#include "entityx/entityx.h"
2222

2323
// using namespace std;
2424
using namespace entityx;
@@ -519,3 +519,26 @@ TEST_CASE_METHOD(EntityManagerFixture, "TestEntityInStdMap") {
519519
REQUIRE(entityMap[b] == 2);
520520
REQUIRE(entityMap[c] == 3);
521521
}
522+
523+
TEST_CASE("TestComponentDestructorCalledWhenManagerDestroyed") {
524+
struct Freed {
525+
explicit Freed(bool &yes) : yes(yes) {}
526+
~Freed() { yes = true; }
527+
528+
bool &yes;
529+
};
530+
531+
struct Test : Component<Test> {
532+
Test(bool &yes) : freed(yes) {}
533+
534+
Freed freed;
535+
};
536+
537+
bool freed = false;
538+
{
539+
EntityX e;
540+
auto test = e.entities.create();
541+
test.assign<Test>(freed);
542+
}
543+
REQUIRE(freed == true);
544+
}

0 commit comments

Comments
 (0)