[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" |
---|
[10481] | 8 | #include "core/module/ModuleInstance.h" |
---|
[9605] | 9 | |
---|
| 10 | namespace orxonox |
---|
| 11 | { |
---|
| 12 | namespace |
---|
| 13 | { |
---|
[9607] | 14 | class TestInterface : virtual public OrxonoxInterface |
---|
[9605] | 15 | { |
---|
| 16 | public: |
---|
[9659] | 17 | TestInterface() { RegisterObject(TestInterface); } |
---|
[9605] | 18 | }; |
---|
| 19 | |
---|
| 20 | class TestClass : public OrxonoxClass, public TestInterface |
---|
| 21 | { |
---|
| 22 | public: |
---|
[9659] | 23 | TestClass() { RegisterObject(TestClass); } |
---|
[9605] | 24 | MOCK_METHOD0(test, void()); |
---|
| 25 | }; |
---|
[9649] | 26 | |
---|
[10395] | 27 | RegisterClassNoArgs(TestInterface); |
---|
| 28 | RegisterClassNoArgs(TestClass); |
---|
| 29 | |
---|
[9649] | 30 | // Fixture |
---|
| 31 | class IteratorTest : public ::testing::Test |
---|
| 32 | { |
---|
| 33 | public: |
---|
| 34 | virtual void SetUp() |
---|
| 35 | { |
---|
| 36 | Context::setRootContext(new Context(NULL)); |
---|
[10535] | 37 | ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); |
---|
[9649] | 38 | } |
---|
| 39 | |
---|
| 40 | virtual void TearDown() |
---|
| 41 | { |
---|
[10535] | 42 | ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); |
---|
[9649] | 43 | Context::setRootContext(NULL); |
---|
| 44 | } |
---|
| 45 | }; |
---|
[9605] | 46 | } |
---|
| 47 | |
---|
[9649] | 48 | TEST_F(IteratorTest, CanCreateIterator) |
---|
[9605] | 49 | { |
---|
| 50 | Iterator<TestInterface> it; |
---|
| 51 | } |
---|
| 52 | |
---|
[9649] | 53 | TEST_F(IteratorTest, CanAssignIterator) |
---|
[9605] | 54 | { |
---|
| 55 | Iterator<TestInterface> it = ObjectList<TestInterface>::begin(); |
---|
| 56 | } |
---|
| 57 | |
---|
[9649] | 58 | TEST_F(IteratorTest, CanIterateOverEmptyList) |
---|
[9605] | 59 | { |
---|
| 60 | size_t i = 0; |
---|
| 61 | for (Iterator<TestInterface> it = ObjectList<TestInterface>::begin(); it != ObjectList<TestInterface>::end(); ++it) |
---|
| 62 | ++i; |
---|
| 63 | EXPECT_EQ(0u, i); |
---|
| 64 | } |
---|
| 65 | |
---|
[9649] | 66 | TEST_F(IteratorTest, CanCallObjects) |
---|
[9605] | 67 | { |
---|
| 68 | TestClass test1; |
---|
| 69 | TestClass test2; |
---|
| 70 | TestClass test3; |
---|
| 71 | |
---|
| 72 | EXPECT_CALL(test1, test()); |
---|
| 73 | EXPECT_CALL(test2, test()); |
---|
| 74 | EXPECT_CALL(test3, test()); |
---|
| 75 | |
---|
| 76 | // iterate over interfaces but use a TestClass iterator - now we can call TestClass::test() |
---|
| 77 | for (Iterator<TestClass> it = ObjectList<TestInterface>::begin(); it != ObjectList<TestInterface>::end(); ++it) |
---|
| 78 | it->test(); |
---|
| 79 | } |
---|
| 80 | } |
---|