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 | |
---|
9 | namespace 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 | // 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 | }; |
---|
40 | } |
---|
41 | |
---|
42 | TEST_F(IteratorTest, CanCreateIterator) |
---|
43 | { |
---|
44 | Iterator<TestInterface> it; |
---|
45 | } |
---|
46 | |
---|
47 | TEST_F(IteratorTest, CanAssignIterator) |
---|
48 | { |
---|
49 | Iterator<TestInterface> it = ObjectList<TestInterface>::begin(); |
---|
50 | } |
---|
51 | |
---|
52 | TEST_F(IteratorTest, CanIterateOverEmptyList) |
---|
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 | |
---|
60 | TEST_F(IteratorTest, CanCallObjects) |
---|
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 | } |
---|