1 | #include <gtest/gtest.h> |
---|
2 | #include "core/object/Context.h" |
---|
3 | #include "core/class/OrxonoxClass.h" |
---|
4 | #include "core/CoreIncludes.h" |
---|
5 | #include "core/module/ModuleInstance.h" |
---|
6 | |
---|
7 | namespace orxonox |
---|
8 | { |
---|
9 | namespace |
---|
10 | { |
---|
11 | class SubclassContext : public OrxonoxClass, public Context |
---|
12 | { |
---|
13 | public: |
---|
14 | SubclassContext() : Context(nullptr) { RegisterObject(SubclassContext); } |
---|
15 | }; |
---|
16 | |
---|
17 | RegisterClassNoArgs(SubclassContext); |
---|
18 | |
---|
19 | // Fixture |
---|
20 | class ContextTest : public ::testing::Test |
---|
21 | { |
---|
22 | public: |
---|
23 | virtual void SetUp() override |
---|
24 | { |
---|
25 | new IdentifierManager(); |
---|
26 | ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); |
---|
27 | Context::setRootContext(new Context(nullptr)); |
---|
28 | } |
---|
29 | |
---|
30 | virtual void TearDown() override |
---|
31 | { |
---|
32 | Context::destroyRootContext(); |
---|
33 | ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); |
---|
34 | delete &IdentifierManager::getInstance(); |
---|
35 | } |
---|
36 | }; |
---|
37 | } |
---|
38 | |
---|
39 | TEST_F(ContextTest, CanCreateContext) |
---|
40 | { |
---|
41 | Context context(nullptr); |
---|
42 | } |
---|
43 | |
---|
44 | TEST_F(ContextTest, CanCreateSubclassContext) |
---|
45 | { |
---|
46 | SubclassContext context; |
---|
47 | } |
---|
48 | |
---|
49 | TEST_F(ContextTest, ContextIsItsOwnContext) |
---|
50 | { |
---|
51 | Context context(nullptr); |
---|
52 | EXPECT_EQ(&context, context.getContext()); |
---|
53 | } |
---|
54 | |
---|
55 | TEST_F(ContextTest, SubclassContextIsItsOwnContext) |
---|
56 | { |
---|
57 | SubclassContext context; |
---|
58 | EXPECT_EQ(&context, context.getContext()); |
---|
59 | } |
---|
60 | |
---|
61 | TEST_F(ContextTest, SubclassAddsToItsOwnObjectList) |
---|
62 | { |
---|
63 | SubclassContext context; |
---|
64 | EXPECT_EQ(&context, context.getContext()); |
---|
65 | EXPECT_EQ(1u, context.getObjectList<SubclassContext>()->size()); |
---|
66 | } |
---|
67 | |
---|
68 | TEST_F(ContextTest, ContextIsAddedToItsOwnObjectList) |
---|
69 | { |
---|
70 | Context context(nullptr); |
---|
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(nullptr); |
---|
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 | } |
---|
87 | } |
---|