Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 30, 2013, 10:40:48 PM (12 years ago)
Author:
landauf
Message:

implemented method to change the context of a Listable. the object will then be added to the object lists of the new context

Location:
code/branches/core6/test/core/object
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core6/test/core/object/ListableTest.cc

    r9606 r9608  
    2020
    2121        template <class T>
    22         bool objectListContains(T* element)
     22        bool objectListContains(T* element, Context* context = Context::getRootContext())
    2323        {
    24             for (typename ObjectList<T>::iterator it = ObjectList<T>::begin(); it != ObjectList<T>::end(); ++it)
     24            for (typename ObjectList<T>::iterator it = static_cast<ObjectListElement<T>*>(context->getObjectList<T>()->begin());
     25                    it != static_cast<ObjectListElement<T>*>(context->getObjectList<T>()->end()); ++it)
    2526                if (*it == element)
    2627                    return true;
     
    7778        EXPECT_EQ(0u, ObjectList<ListableSubclassTest>::size());
    7879    }
     80
     81    TEST(ListableTest, CanChangeContext)
     82    {
     83        Context* rootContext = Context::getRootContext();
     84        Context newContext;
     85        ListableSubclassTest test;
     86
     87        EXPECT_EQ(1u, rootContext->getObjectList<ListableTest>()->size());
     88        EXPECT_TRUE(objectListContains<ListableTest>(&test, rootContext));
     89        EXPECT_EQ(1u, rootContext->getObjectList<ListableSubclassTest>()->size());
     90        EXPECT_TRUE(objectListContains<ListableSubclassTest>(&test, rootContext));
     91
     92        EXPECT_EQ(0u, newContext.getObjectList<ListableTest>()->size());
     93        EXPECT_FALSE(objectListContains<ListableTest>(&test, &newContext));
     94        EXPECT_EQ(0u, newContext.getObjectList<ListableSubclassTest>()->size());
     95        EXPECT_FALSE(objectListContains<ListableSubclassTest>(&test, &newContext));
     96
     97        test.setContext(&newContext);
     98
     99        EXPECT_EQ(0u, rootContext->getObjectList<ListableTest>()->size());
     100        EXPECT_FALSE(objectListContains<ListableTest>(&test, rootContext));
     101        EXPECT_EQ(0u, rootContext->getObjectList<ListableSubclassTest>()->size());
     102        EXPECT_FALSE(objectListContains<ListableSubclassTest>(&test, rootContext));
     103
     104        EXPECT_EQ(1u, newContext.getObjectList<ListableTest>()->size());
     105        EXPECT_TRUE(objectListContains<ListableTest>(&test, &newContext));
     106        EXPECT_EQ(1u, newContext.getObjectList<ListableSubclassTest>()->size());
     107        EXPECT_TRUE(objectListContains<ListableSubclassTest>(&test, &newContext));
     108    }
    79109}
  • code/branches/core6/test/core/object/ObjectListBaseTest.cc

    r9605 r9608  
    22#include <gmock/gmock.h>
    33#include "core/object/ObjectListBase.h"
     4#include "core/class/Identifier.h"
    45
    56namespace orxonox
     
    2324    {
    2425        ObjectListBase list;
    25         ObjectListBaseElement* element = new ObjectListBaseElement(NULL);
     26        ObjectListBaseElement* element = new ObjectListElement<Listable>(NULL);
    2627        list.addElement(element);
    2728        EXPECT_EQ(1u, list.size());
     
    3132    {
    3233        ObjectListBase list;
    33         ObjectListBaseElement* element = new ObjectListBaseElement(NULL);
     34        ObjectListBaseElement* element = new ObjectListElement<Listable>(NULL);
    3435        list.addElement(element);
    3536        EXPECT_EQ(1u, list.size());
     
    5152        EXPECT_EQ(0u, list.size());
    5253        {
    53             ObjectListBaseElement element1(NULL);
     54            ObjectListElement<Listable> element1(NULL);
    5455            list.addElement(&element1);
    5556            EXPECT_EQ(1u, list.size());
    5657            {
    57                 ObjectListBaseElement element1(NULL);
     58                ObjectListElement<Listable> element1(NULL);
    5859                list.addElement(&element1);
    5960                EXPECT_EQ(2u, list.size());
    6061                {
    61                     ObjectListBaseElement element1(NULL);
     62                    ObjectListElement<Listable> element1(NULL);
    6263                    list.addElement(&element1);
    6364                    EXPECT_EQ(3u, list.size());
     
    7576        ObjectListElementRemovalListenerMock listener;
    7677        list.registerRemovalListener(&listener);
    77         ObjectListBaseElement* element = new ObjectListBaseElement(NULL);
     78        ObjectListBaseElement* element = new ObjectListElement<Listable>(NULL);
    7879        list.addElement(element);
    7980        EXPECT_CALL(listener, removedElement(element));
Note: See TracChangeset for help on using the changeset viewer.