Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

create and initialize Identifiers explicitly via registerClass(). registerClass() must be called before using an Identifier of this type.
(some tests will currently fail)

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