Exemplo n.º 1
0
TEST(NAME, DestroyingEntitiesDispatchesReallocationEvent)
{
    World w;
    MockEntityManagerListener mock;
    EntityManager* em = new EntityManager(&w);
    em->event.addListener(&mock, "mock");

    // uninteresting calls
    EXPECT_CALL(mock, onCreateEntityHelper(testing::_))
        .Times(testing::AtLeast(0));
    EXPECT_CALL(mock, onDestroyEntityHelper(testing::_))
        .Times(testing::AtLeast(0));

    EXPECT_CALL(mock, onEntitiesReallocatedHelper(testing::_)).Times(testing::AtLeast(0)); // ignore this call during entity creation - not important
    em->createEntity("entity1");             // will be destroyed via destroyEntities()
    em->createEntity("entity2");             // will be via destroyAllEntities

    // expect 4 calls, since 4 entities are being destroyed
    EXPECT_CALL(mock, onEntitiesReallocatedHelper(testing::_))
        .Times(4);  // 4 entities were created...

    em->destroyEntities("entity1");
    em->destroyAllEntities();
    Entity& e = em->createEntity("entity3");
    em->destroyEntity(e);
    em->createEntity("entity4"); // destroyed by destructor
    delete em;
}