[9629] | 1 | #include <gtest/gtest.h> |
---|
| 2 | #include "core/object/Context.h" |
---|
| 3 | #include "core/class/OrxonoxClass.h" |
---|
| 4 | #include "core/CoreIncludes.h" |
---|
[10624] | 5 | #include "core/module/ModuleInstance.h" |
---|
[9629] | 6 | |
---|
| 7 | namespace orxonox |
---|
| 8 | { |
---|
| 9 | namespace |
---|
| 10 | { |
---|
| 11 | class SubclassContext : public OrxonoxClass, public Context |
---|
| 12 | { |
---|
| 13 | public: |
---|
[9659] | 14 | SubclassContext() : Context(NULL) { RegisterObject(SubclassContext); } |
---|
[9629] | 15 | }; |
---|
[9649] | 16 | |
---|
[10624] | 17 | RegisterClassNoArgs(SubclassContext); |
---|
| 18 | |
---|
[9649] | 19 | // Fixture |
---|
| 20 | class ContextTest : public ::testing::Test |
---|
| 21 | { |
---|
| 22 | public: |
---|
| 23 | virtual void SetUp() |
---|
| 24 | { |
---|
[10624] | 25 | new IdentifierManager(); |
---|
| 26 | ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); |
---|
[9649] | 27 | Context::setRootContext(new Context(NULL)); |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | virtual void TearDown() |
---|
| 31 | { |
---|
[10624] | 32 | Context::destroyRootContext(); |
---|
| 33 | ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); |
---|
| 34 | delete &IdentifierManager::getInstance(); |
---|
[9649] | 35 | } |
---|
| 36 | }; |
---|
[9629] | 37 | } |
---|
| 38 | |
---|
[9649] | 39 | TEST_F(ContextTest, CanCreateContext) |
---|
[9629] | 40 | { |
---|
| 41 | Context context(NULL); |
---|
| 42 | } |
---|
| 43 | |
---|
[9649] | 44 | TEST_F(ContextTest, CanCreateSubclassContext) |
---|
[9629] | 45 | { |
---|
| 46 | SubclassContext context; |
---|
| 47 | } |
---|
| 48 | |
---|
[9649] | 49 | TEST_F(ContextTest, ContextIsItsOwnContext) |
---|
[9629] | 50 | { |
---|
| 51 | Context context(NULL); |
---|
| 52 | EXPECT_EQ(&context, context.getContext()); |
---|
| 53 | } |
---|
| 54 | |
---|
[9649] | 55 | TEST_F(ContextTest, SubclassContextIsItsOwnContext) |
---|
[9629] | 56 | { |
---|
| 57 | SubclassContext context; |
---|
| 58 | EXPECT_EQ(&context, context.getContext()); |
---|
| 59 | } |
---|
| 60 | |
---|
[9649] | 61 | TEST_F(ContextTest, SubclassAddsToItsOwnObjectList) |
---|
[9629] | 62 | { |
---|
| 63 | SubclassContext context; |
---|
| 64 | EXPECT_EQ(&context, context.getContext()); |
---|
| 65 | EXPECT_EQ(1u, context.getObjectList<SubclassContext>()->size()); |
---|
| 66 | } |
---|
[9650] | 67 | |
---|
| 68 | TEST_F(ContextTest, ContextIsAddedToItsOwnObjectList) |
---|
| 69 | { |
---|
| 70 | Context context(NULL); |
---|
| 71 | ASSERT_EQ(1u, context.getObjectList<Context>()->size()); |
---|
| 72 | EXPECT_TRUE(context.getObjectList<Context>()->begin()->objectBase_ == static_cast<Listable*>(&context)); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | TEST_F(ContextTest, ContextIsAddedToObjectListOfBaseContext) |
---|
| 76 | { |
---|
| 77 | Context baseContext(NULL); |
---|
| 78 | Context subContext(&baseContext); |
---|
| 79 | |
---|
| 80 | ASSERT_EQ(1u, subContext.getObjectList<Context>()->size()); |
---|
| 81 | EXPECT_TRUE(subContext.getObjectList<Context>()->begin()->objectBase_ == static_cast<Listable*>(&subContext)); |
---|
| 82 | |
---|
| 83 | ASSERT_EQ(2u, baseContext.getObjectList<Context>()->size()); |
---|
| 84 | EXPECT_TRUE(baseContext.getObjectList<Context>()->begin()->objectBase_ == static_cast<Listable*>(&baseContext)); |
---|
| 85 | EXPECT_TRUE(baseContext.getObjectList<Context>()->begin()->next_->objectBase_ == static_cast<Listable*>(&subContext)); |
---|
| 86 | } |
---|
[9629] | 87 | } |
---|