Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core7/test/core/object/IteratorTest.cc @ 10535

Last change on this file since 10535 was 10535, checked in by landauf, 9 years ago

statically initialized instances are now registered with a type. CoreStaticInitializationHandler initializes all instances in core, NetworkStaticInitializationHandler initializes all instances in network.

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1#include <gtest/gtest.h>
2#include <gmock/gmock.h>
3
4#include "core/object/Iterator.h"
5#include "core/class/OrxonoxClass.h"
6#include "core/class/OrxonoxInterface.h"
7#include "core/CoreIncludes.h"
8#include "core/module/ModuleInstance.h"
9
10namespace orxonox
11{
12    namespace
13    {
14        class TestInterface : virtual public OrxonoxInterface
15        {
16            public:
17            TestInterface() { RegisterObject(TestInterface); }
18        };
19
20        class TestClass : public OrxonoxClass, public TestInterface
21        {
22            public:
23                TestClass() { RegisterObject(TestClass); }
24                MOCK_METHOD0(test, void());
25        };
26
27        RegisterClassNoArgs(TestInterface);
28        RegisterClassNoArgs(TestClass);
29
30        // Fixture
31        class IteratorTest : public ::testing::Test
32        {
33            public:
34                virtual void SetUp()
35                {
36                    Context::setRootContext(new Context(NULL));
37                    ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
38                }
39
40                virtual void TearDown()
41                {
42                    ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
43                    Context::setRootContext(NULL);
44                }
45        };
46    }
47
48    TEST_F(IteratorTest, CanCreateIterator)
49    {
50        Iterator<TestInterface> it;
51    }
52
53    TEST_F(IteratorTest, CanAssignIterator)
54    {
55        Iterator<TestInterface> it = ObjectList<TestInterface>::begin();
56    }
57
58    TEST_F(IteratorTest, CanIterateOverEmptyList)
59    {
60        size_t i = 0;
61        for (Iterator<TestInterface> it = ObjectList<TestInterface>::begin(); it != ObjectList<TestInterface>::end(); ++it)
62            ++i;
63        EXPECT_EQ(0u, i);
64    }
65
66    TEST_F(IteratorTest, CanCallObjects)
67    {
68        TestClass test1;
69        TestClass test2;
70        TestClass test3;
71
72        EXPECT_CALL(test1, test());
73        EXPECT_CALL(test2, test());
74        EXPECT_CALL(test3, test());
75
76        // iterate over interfaces but use a TestClass iterator - now we can call TestClass::test()
77        for (Iterator<TestClass> it = ObjectList<TestInterface>::begin(); it != ObjectList<TestInterface>::end(); ++it)
78            it->test();
79    }
80}
Note: See TracBrowser for help on using the repository browser.