[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 | { |
---|
[10544] | 36 | new IdentifierManager(); |
---|
| 37 | ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); |
---|
[9649] | 38 | Context::setRootContext(new Context(NULL)); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | virtual void TearDown() |
---|
| 42 | { |
---|
[10544] | 43 | Context::destroyRootContext(); |
---|
[10535] | 44 | ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); |
---|
[10544] | 45 | delete &IdentifierManager::getInstance(); |
---|
[9649] | 46 | } |
---|
| 47 | }; |
---|
[9605] | 48 | } |
---|
| 49 | |
---|
[9649] | 50 | TEST_F(IteratorTest, CanCreateIterator) |
---|
[9605] | 51 | { |
---|
| 52 | Iterator<TestInterface> it; |
---|
| 53 | } |
---|
| 54 | |
---|
[9649] | 55 | TEST_F(IteratorTest, CanAssignIterator) |
---|
[9605] | 56 | { |
---|
| 57 | Iterator<TestInterface> it = ObjectList<TestInterface>::begin(); |
---|
| 58 | } |
---|
| 59 | |
---|
[9649] | 60 | TEST_F(IteratorTest, CanIterateOverEmptyList) |
---|
[9605] | 61 | { |
---|
| 62 | size_t i = 0; |
---|
| 63 | for (Iterator<TestInterface> it = ObjectList<TestInterface>::begin(); it != ObjectList<TestInterface>::end(); ++it) |
---|
| 64 | ++i; |
---|
| 65 | EXPECT_EQ(0u, i); |
---|
| 66 | } |
---|
| 67 | |
---|
[9649] | 68 | TEST_F(IteratorTest, CanCallObjects) |
---|
[9605] | 69 | { |
---|
| 70 | TestClass test1; |
---|
| 71 | TestClass test2; |
---|
| 72 | TestClass test3; |
---|
| 73 | |
---|
| 74 | EXPECT_CALL(test1, test()); |
---|
| 75 | EXPECT_CALL(test2, test()); |
---|
| 76 | EXPECT_CALL(test3, test()); |
---|
| 77 | |
---|
| 78 | // iterate over interfaces but use a TestClass iterator - now we can call TestClass::test() |
---|
| 79 | for (Iterator<TestClass> it = ObjectList<TestInterface>::begin(); it != ObjectList<TestInterface>::end(); ++it) |
---|
| 80 | it->test(); |
---|
| 81 | } |
---|
| 82 | } |
---|