[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 | |
---|
[10395] | 26 | RegisterClassNoArgs(TestInterface); |
---|
| 27 | RegisterClassNoArgs(TestClass); |
---|
| 28 | |
---|
[9649] | 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 | }; |
---|
[9605] | 43 | } |
---|
| 44 | |
---|
[9649] | 45 | TEST_F(IteratorTest, CanCreateIterator) |
---|
[9605] | 46 | { |
---|
| 47 | Iterator<TestInterface> it; |
---|
| 48 | } |
---|
| 49 | |
---|
[9649] | 50 | TEST_F(IteratorTest, CanAssignIterator) |
---|
[9605] | 51 | { |
---|
| 52 | Iterator<TestInterface> it = ObjectList<TestInterface>::begin(); |
---|
| 53 | } |
---|
| 54 | |
---|
[9649] | 55 | TEST_F(IteratorTest, CanIterateOverEmptyList) |
---|
[9605] | 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 | |
---|
[9649] | 63 | TEST_F(IteratorTest, CanCallObjects) |
---|
[9605] | 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 | } |
---|