Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core6/test/core/object/IteratorTest.cc @ 9649

Last change on this file since 9649 was 9649, checked in by landauf, 11 years ago

added ability to set the root-context explicitly (and also to destroy it before the class-hierarchy is destroyed).
currently it's not possible to set the root context explicitly during startup of the game because it is already used by static initialization

  • Property svn:eol-style set to native
File size: 1.9 KB
RevLine 
[9605]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
9namespace orxonox
10{
11    namespace
12    {
[9607]13        class TestInterface : virtual public OrxonoxInterface
[9605]14        {
15            public:
16            TestInterface() { RegisterRootObject(TestInterface); }
17        };
18
19        class TestClass : public OrxonoxClass, public TestInterface
20        {
21            public:
22                TestClass() { RegisterRootObject(TestClass); }
23                MOCK_METHOD0(test, void());
24        };
[9649]25
26        // Fixture
27        class IteratorTest : public ::testing::Test
28        {
29            public:
30                virtual void SetUp()
31                {
32                    Context::setRootContext(new Context(NULL));
33                }
34
35                virtual void TearDown()
36                {
37                    Context::setRootContext(NULL);
38                }
39        };
[9605]40    }
41
[9649]42    TEST_F(IteratorTest, CanCreateIterator)
[9605]43    {
44        Iterator<TestInterface> it;
45    }
46
[9649]47    TEST_F(IteratorTest, CanAssignIterator)
[9605]48    {
49        Iterator<TestInterface> it = ObjectList<TestInterface>::begin();
50    }
51
[9649]52    TEST_F(IteratorTest, CanIterateOverEmptyList)
[9605]53    {
54        size_t i = 0;
55        for (Iterator<TestInterface> it = ObjectList<TestInterface>::begin(); it != ObjectList<TestInterface>::end(); ++it)
56            ++i;
57        EXPECT_EQ(0u, i);
58    }
59
[9649]60    TEST_F(IteratorTest, CanCallObjects)
[9605]61    {
62        TestClass test1;
63        TestClass test2;
64        TestClass test3;
65
66        EXPECT_CALL(test1, test());
67        EXPECT_CALL(test2, test());
68        EXPECT_CALL(test3, test());
69
70        // iterate over interfaces but use a TestClass iterator - now we can call TestClass::test()
71        for (Iterator<TestClass> it = ObjectList<TestInterface>::begin(); it != ObjectList<TestInterface>::end(); ++it)
72            it->test();
73    }
74}
Note: See TracBrowser for help on using the repository browser.