TEST(EntityFilter, Record) { EntityManager entityManager; using TestFilter = EntityFilter< TestComponent<0> >; // Set up filter TestFilter filter(true); filter.setEntityManager(&entityManager); TestFilter::EntityMap filteredEntities = filter.entities(); // Add first component EntityId entityId = entityManager.generateNewId(); entityManager.addComponent( entityId, make_unique<TestComponent<0>>() ); // Check added entities EXPECT_EQ(1, filter.addedEntities().count(entityId)); // Remove component entityManager.removeComponent( entityId, TestComponent<0>::TYPE_ID ); entityManager.processRemovals(); // Check removed entities EXPECT_EQ(1, filter.removedEntities().count(entityId)); }
TEST(EntityFilter, Single) { EntityManager entityManager; // Set up filter EntityFilter<TestComponent<0>> filter; filter.setEntityManager(&entityManager); // Add component EntityId entityId = entityManager.generateNewId(); entityManager.addComponent( entityId, make_unique<TestComponent<0>>() ); // Check filter auto filteredEntities = filter.entities(); EXPECT_EQ(1, filteredEntities.count(entityId)); EXPECT_EQ(1, filteredEntities.size()); // Remove component entityManager.removeComponent( entityId, TestComponent<0>::TYPE_ID ); entityManager.processRemovals(); // Check filter filteredEntities = filter.entities(); EXPECT_EQ(0, filteredEntities.count(entityId)); EXPECT_EQ(0, filteredEntities.size()); }
TEST(EntityFilter, OptionalOnly) { EntityManager entityManager; using TestFilter = EntityFilter< Optional<TestComponent<0>> >; // Set up filter TestFilter filter; filter.setEntityManager(&entityManager); TestFilter::EntityMap filteredEntities = filter.entities(); // Add first component EntityId entityId = entityManager.generateNewId(); entityManager.addComponent( entityId, make_unique<TestComponent<0>>() ); // Check filter filteredEntities = filter.entities(); EXPECT_EQ(1, filteredEntities.count(entityId)); EXPECT_EQ(1, filteredEntities.size()); // Check group TestFilter::ComponentGroup group = filteredEntities[entityId]; EXPECT_TRUE(std::get<0>(group) != nullptr); // Remove component entityManager.removeComponent( entityId, TestComponent<0>::TYPE_ID ); entityManager.processRemovals(); // Check filter filteredEntities = filter.entities(); EXPECT_EQ(0, filteredEntities.count(entityId)); EXPECT_EQ(0, filteredEntities.size()); }