Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/test/core/object/ObjectListIteratorTest.cc @ 11071

Last change on this file since 11071 was 11071, checked in by landauf, 8 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 3.5 KB
RevLine 
[9605]1#include <gtest/gtest.h>
2#include <gmock/gmock.h>
3
4#include "core/object/ObjectListIterator.h"
[11071]5#include "core/class/OrxonoxClass.h"
6#include "core/class/OrxonoxInterface.h"
[9605]7#include "core/CoreIncludes.h"
[10624]8#include "core/module/ModuleInstance.h"
[9605]9
10namespace orxonox
11{
12    namespace
13    {
[11071]14        class TestInterface : virtual public OrxonoxInterface
[9605]15        {
16            public:
[11071]17                TestInterface() { RegisterObject(TestInterface); }
18        };
19
20        class TestClass : public OrxonoxClass, public TestInterface
21        {
22            public:
23                TestClass() { RegisterObject(TestClass); }
[9605]24                MOCK_METHOD0(test, void());
25        };
[9649]26
[11071]27        RegisterClassNoArgs(TestInterface);
28        RegisterClassNoArgs(TestClass);
[10624]29
[9649]30        // Fixture
31        class ObjectListIteratorTest : public ::testing::Test
32        {
33            public:
[11071]34                virtual void SetUp() override
[9649]35                {
[10624]36                    new IdentifierManager();
37                    ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
[11071]38                    Context::setRootContext(new Context(nullptr));
[9649]39                }
40
[11071]41                virtual void TearDown() override
[9649]42                {
[10624]43                    Context::destroyRootContext();
44                    ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
45                    delete &IdentifierManager::getInstance();
[9649]46                }
47        };
[9605]48    }
49
[9649]50    TEST_F(ObjectListIteratorTest, CanCreateIterator)
[9605]51    {
[11071]52        ObjectListIterator<TestClass> it;
[9605]53    }
54
[9649]55    TEST_F(ObjectListIteratorTest, CanAssignIterator)
[9605]56    {
[11071]57        ObjectList<TestClass> list;
58        ObjectListIterator<TestClass> it = list.begin();
[9605]59    }
60
[9649]61    TEST_F(ObjectListIteratorTest, CanIterateOverEmptyList)
[9605]62    {
63        size_t i = 0;
[11071]64        ObjectList<TestClass> list;
65        for (ObjectListIterator<TestClass> it = list.begin(); it != list.end(); ++it)
[9605]66            ++i;
67        EXPECT_EQ(0u, i);
68    }
69
[9649]70    TEST_F(ObjectListIteratorTest, CanIterateOverFullList)
[9605]71    {
[11071]72        TestClass test1;
73        TestClass test2;
74        TestClass test3;
75        TestInterface interface;
[9605]76
77        size_t i = 0;
[11071]78        ObjectList<TestClass> list;
79        for (ObjectListIterator<TestClass> it = list.begin(); it != list.end(); ++it)
[9605]80        {
81            ++i;
82            if (i == 1u) EXPECT_EQ(&test1, *it);
83            if (i == 2u) EXPECT_EQ(&test2, *it);
84            if (i == 3u) EXPECT_EQ(&test3, *it);
85        }
86        EXPECT_EQ(3u, i);
87    }
88
[9649]89    TEST_F(ObjectListIteratorTest, CanIterateReverseOverFullList)
[9605]90    {
[11071]91        TestClass test1;
92        TestClass test2;
93        TestClass test3;
94        TestInterface interface;
[9605]95
96        size_t i = 0;
[11071]97        ObjectList<TestClass> list;
98        for (ObjectListIterator<TestClass> it = list.rbegin(); it != list.rend(); --it)
[9605]99        {
100            ++i;
101            if (i == 1u) EXPECT_EQ(&test3, *it);
102            if (i == 2u) EXPECT_EQ(&test2, *it);
103            if (i == 3u) EXPECT_EQ(&test1, *it);
104        }
105        EXPECT_EQ(3u, i);
106    }
107
[9649]108    TEST_F(ObjectListIteratorTest, CanCallObjects)
[9605]109    {
[11071]110        TestClass test1;
111        TestClass test2;
112        TestClass test3;
113        TestInterface interface;
[9605]114
115        EXPECT_CALL(test1, test());
116        EXPECT_CALL(test2, test());
117        EXPECT_CALL(test3, test());
118
[11071]119        ObjectList<TestClass> list;
120        for (ObjectListIterator<TestClass> it = list.begin(); it != list.end(); ++it)
[9605]121            it->test();
122    }
123}
Note: See TracBrowser for help on using the repository browser.