[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 | |
---|
| 9 | namespace orxonox |
---|
| 10 | { |
---|
| 11 | namespace |
---|
| 12 | { |
---|
[9607] | 13 | class TestInterface : virtual public OrxonoxInterface |
---|
[9605] | 14 | { |
---|
| 15 | public: |
---|
[9659] | 16 | TestInterface() { RegisterObject(TestInterface); } |
---|
[9605] | 17 | }; |
---|
| 18 | |
---|
| 19 | class TestClass : public OrxonoxClass, public TestInterface |
---|
| 20 | { |
---|
| 21 | public: |
---|
[9659] | 22 | TestClass() { RegisterObject(TestClass); } |
---|
[9605] | 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 | } |
---|