From bc70089822d281fca7050648760dfc5f7e68e51e Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Tue, 29 Aug 2017 15:27:58 +0900 Subject: [PATCH] Add a test to unit tests --- src/test/ECTest.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/test/ECTest.cpp b/src/test/ECTest.cpp index d8e6caa..e0c4c89 100644 --- a/src/test/ECTest.cpp +++ b/src/test/ECTest.cpp @@ -391,3 +391,41 @@ TEST(EC, FunctionStorage) } } +/* + This test demonstrates that while entity ids may change after cleanup, + pointers to their components do not. +*/ +TEST(EC, DataPointers) +{ + EC::Manager manager; + + auto first = manager.addEntity(); + auto second = manager.addEntity(); + + manager.addComponent(first, 5, 5); + manager.addComponent(second, 10, 10); + manager.addTag(second); + + auto* cptr = &manager.getEntityData(second); + + EXPECT_EQ(10, cptr->x); + EXPECT_EQ(10, cptr->y); + + manager.deleteEntity(first); + manager.cleanup(); + + auto newSecond = second; + manager.forMatchingSignature>( + [&newSecond] (auto eid) { + newSecond = eid; + }); + + EXPECT_NE(newSecond, second); + + auto* newcptr = &manager.getEntityData(newSecond); + EXPECT_EQ(newcptr, cptr); + + EXPECT_EQ(10, newcptr->x); + EXPECT_EQ(10, newcptr->y); +} +