TEST(NAME, RemoveComponentEventDispatchesOnDestruction)
{
    World w;
    MockEntityManagerListener mock;
    EntityManager* em = new EntityManager(&w);
    em->event.addListener(&mock, "mock");

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

    // interesting calls
    EXPECT_CALL(mock, onAddComponentHelper(testing::_, testing::Pointee(TestComponent(336, 743))))
        .Times(1);
    EXPECT_CALL(mock, onRemoveComponentHelper(testing::_, testing::Pointee(TestComponent(336, 743))))
        .Times(1);

    Entity& e = em->createEntity("entity");
    e.addComponent<TestComponent>(336, 743);
    delete em;
}
Component* Component::getNextSiblingInNegY(void) const
{
    Component* TestComponent(NULL);
    if(getParentContainer() != NULL)
    {
        for(UInt32 i(0) ; getParentContainer()->getMFChildren()->size(); ++i)
        {
            if(getParentContainer()->getChildren(i)->getPosition().y() <= getPosition().y() &&
               (TestComponent == NULL ||
                getParentContainer()->getChildren(i)->getPosition().y() >= TestComponent->getPosition().y()))
            {
                TestComponent = getParentContainer()->getChildren(i);
            }
        }
    }

    if(TestComponent != this)
    {
        return TestComponent;
    }
    else
    {
        return NULL;
    }
}
TEST(NAME, AddingAndRemovingComponentsDispatchesEvents)
{
    World w;
    MockEntityManagerListener mock;
    EntityManager em(&w);
    em.event.addListener(&mock, "mock");

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

    // interesting calls
    EXPECT_CALL(mock, onAddComponentHelper(testing::_, testing::Pointee(testing::Eq(TestComponent(336, 743)))))
        .Times(1);
    EXPECT_CALL(mock, onRemoveComponentHelper(testing::_, testing::Pointee(testing::Eq(TestComponent(254, 8376)))))
        .Times(1);

    Entity& e = em.createEntity("entity");
    e.addComponent<TestComponent>(336, 743);
    e.getComponent<TestComponent>().x = 254;
    e.getComponent<TestComponent>().y = 8376;
    e.removeComponent<TestComponent>();
    em.event.removeListener("mock");
}
Exemple #4
0
void freettcn::TE::CModule::Disconnect(const TriPortId &fromPort, const TriPortId &toPort) const
{
  unsigned int count = 0;
  try {
    TestComponent(fromPort.compInst).Port(fromPort.portName, fromPort.portIndex).Disconnect(toPort);
    count++;
  }
  catch(ENotFound &) {
  }
  try {
    TestComponent(toPort.compInst).Port(toPort.portName, toPort.portIndex).Disconnect(fromPort);
    count++;
  }
  catch(ENotFound &) {
  }
  if (count < 1)
    throw ENotFound(E_DATA, "Ports to disconnect not found!!!");
}
Exemple #5
0
void freettcn::TE::CModule::Unmap(const TriPortId &fromPort, const TriPortId &toPort) const
{
  unsigned int count = 0;
  try {
    TestComponent(fromPort.compInst).Port(fromPort.portName, fromPort.portIndex).Unmap(toPort);
    count++;
  }
  catch(ENotFound &) {
  }
  try {
    TestComponent(toPort.compInst).Port(toPort.portName, toPort.portIndex).Unmap(fromPort);
    count++;
  }
  catch(ENotFound &) {
  }
  if (count < 1)
    throw ENotFound(E_DATA, "Ports to unmap not found!!!");
  
  if (triUnmap(&fromPort, &toPort) != TRI_OK)
    throw EOperationFailed(E_DATA, "Unmapping of ports failed!!!");
}
TEST(NAME, GettingNonExistingComponentsCausesDeath)
{
    MockEntityManager em;
    Entity entity("entity", &em);

    // uninteresting calls
    EXPECT_CALL(em, informRemoveComponentHelper(testing::_, testing::_)).Times(testing::AtLeast(0));
    EXPECT_CALL(em, informAddComponentHelper(testing::_, testing::_)).Times(testing::AtLeast(0));

    entity.addComponent<TestComponent>(2, 3);
    ASSERT_EQ(TestComponent(2, 3), entity.getComponent<TestComponent>());
    ASSERT_DEATH(entity.getComponent<NonExistingComponent>(), "");
}
Exemple #7
0
void freettcn::TE::CModule::TestComponentKill(const TriComponentId &componentId) const
{
  TestComponent(componentId).Kill();
//   CTestComponentType::CInstance &comp = TestComponent(componentId);
  
//   if (&comp == _ctrlComponent)
//     _ctrlComponent = 0;
//   delete &comp;
  
//   freettcn::TE::CTTCNExecutable &te = freettcn::TE::CTTCNExecutable::Instance();
//   if (te.Logging() && te.LogMask().Get(freettcn::CLogMask::CMD_TE_C_KILLED))
//     // log
//     tliCKilled(0, te.TimeStampMgr().Get(), 0, 0, componentId, 0);
}
TEST(NAME, AddingTwoComponentsOfTheSameTypeCausesDeath)
{
    MockEntityManager em;
    Entity entity("entity", &em);

    // uninteresting calls
    EXPECT_CALL(em, informRemoveComponentHelper(testing::_, testing::_)).Times(testing::AtLeast(0));

    // duplicate component should not be added, which means an addComponent event should not
    // be triggered
    EXPECT_CALL(em, informAddComponentHelper(testing::_, testing::Pointee(TestComponent(2, 3))))
        .Times(1);

    entity.addComponent<TestComponent>(2, 3);

    ASSERT_DEATH(entity.addComponent<TestComponent>(3, 4), "");
}
Exemple #9
0
void freettcn::TE::CModule::TestComponentStop(const TriComponentId &componentId) const
{
  TestComponent(componentId).Stop();
}
Exemple #10
0
void freettcn::TE::CModule::TestComponentStart(const TriComponentId &componentId,
                                               const TciBehaviourIdType &behaviorId,
                                               const TciParameterListType &parameterList) const
{
  TestComponent(componentId).Start(Behavior(behaviorId), parameterList);
}