Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

no need to inherit virtually from OrxonoxClass anymore

  • Property svn:eol-style set to native
File size: 1.5 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() { RegisterRootObject(TestInterface); }
17        };
18
19        class TestClass : public OrxonoxClass, public TestInterface
20        {
21            public:
22                TestClass() { RegisterRootObject(TestClass); }
23                MOCK_METHOD0(test, void());
24        };
25    }
26
27    TEST(IteratorTest, CanCreateIterator)
28    {
29        Iterator<TestInterface> it;
30    }
31
32    TEST(IteratorTest, CanAssignIterator)
33    {
34        Iterator<TestInterface> it = ObjectList<TestInterface>::begin();
35    }
36
37    TEST(IteratorTest, CanIterateOverEmptyList)
38    {
39        size_t i = 0;
40        for (Iterator<TestInterface> it = ObjectList<TestInterface>::begin(); it != ObjectList<TestInterface>::end(); ++it)
41            ++i;
42        EXPECT_EQ(0u, i);
43    }
44
45    TEST(IteratorTest, CanCallObjects)
46    {
47        TestClass test1;
48        TestClass test2;
49        TestClass test3;
50
51        EXPECT_CALL(test1, test());
52        EXPECT_CALL(test2, test());
53        EXPECT_CALL(test3, test());
54
55        // iterate over interfaces but use a TestClass iterator - now we can call TestClass::test()
56        for (Iterator<TestClass> it = ObjectList<TestInterface>::begin(); it != ObjectList<TestInterface>::end(); ++it)
57            it->test();
58    }
59}
Note: See TracBrowser for help on using the repository browser.