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