1 | #include <gtest/gtest.h> |
---|
2 | #include <tinyxml/tinyxml.h> |
---|
3 | |
---|
4 | #include "core/CoreIncludes.h" |
---|
5 | #include "core/BaseObject.h" |
---|
6 | #include "core/class/Super.h" |
---|
7 | |
---|
8 | namespace orxonox |
---|
9 | { |
---|
10 | namespace |
---|
11 | { |
---|
12 | class TestClass : public BaseObject |
---|
13 | { |
---|
14 | public: |
---|
15 | TestClass(Context* context = NULL) : BaseObject(context), changedNameBase_(false), xmlPortBase_(false), modeBase_(XMLPort::NOP) |
---|
16 | { |
---|
17 | RegisterRootObject(TestClass); |
---|
18 | } |
---|
19 | |
---|
20 | virtual void changedName() |
---|
21 | { |
---|
22 | this->changedNameBase_ = true; |
---|
23 | } |
---|
24 | |
---|
25 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
26 | { |
---|
27 | this->xmlPortBase_ = true; |
---|
28 | this->modeBase_ = mode; |
---|
29 | } |
---|
30 | |
---|
31 | bool changedNameBase_; |
---|
32 | bool xmlPortBase_; |
---|
33 | XMLPort::Mode modeBase_; |
---|
34 | }; |
---|
35 | |
---|
36 | class TestSubclass : public TestClass |
---|
37 | { |
---|
38 | public: |
---|
39 | TestSubclass(Context* context = NULL) : TestClass(context), changedNameSubclass_(false), xmlPortSubclass_(false), modeSubclass_(XMLPort::NOP) |
---|
40 | { |
---|
41 | RegisterObject(TestSubclass); |
---|
42 | } |
---|
43 | |
---|
44 | virtual void changedName() |
---|
45 | { |
---|
46 | this->changedNameSubclass_ = true; |
---|
47 | |
---|
48 | SUPER(TestSubclass, changedName); |
---|
49 | } |
---|
50 | |
---|
51 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
52 | { |
---|
53 | this->xmlPortSubclass_ = true; |
---|
54 | this->modeSubclass_ = mode; |
---|
55 | |
---|
56 | SUPER(TestSubclass, XMLPort, xmlelement, mode); |
---|
57 | } |
---|
58 | |
---|
59 | bool changedNameSubclass_; |
---|
60 | bool xmlPortSubclass_; |
---|
61 | XMLPort::Mode modeSubclass_; |
---|
62 | }; |
---|
63 | |
---|
64 | // Fixture |
---|
65 | class SuperTest : public ::testing::Test |
---|
66 | { |
---|
67 | public: |
---|
68 | virtual void SetUp() |
---|
69 | { |
---|
70 | IdentifierManager::getInstance().destroyAllIdentifiers(); |
---|
71 | |
---|
72 | registerClass("OrxonoxClass", new ClassFactoryNoArgs<OrxonoxClass>()); |
---|
73 | registerClass("BaseObject", new ClassFactoryWithContext<BaseObject>()); |
---|
74 | registerClass("TestClass", new ClassFactoryWithContext<TestClass>()); |
---|
75 | registerClass("TestSubclass", new ClassFactoryWithContext<TestSubclass>()); |
---|
76 | |
---|
77 | IdentifierManager::getInstance().createClassHierarchy(); |
---|
78 | } |
---|
79 | |
---|
80 | virtual void TearDown() |
---|
81 | { |
---|
82 | IdentifierManager::getInstance().destroyAllIdentifiers(); |
---|
83 | } |
---|
84 | }; |
---|
85 | } |
---|
86 | |
---|
87 | TEST_F(SuperTest, ClassHierarchyIsCorrect) |
---|
88 | { |
---|
89 | { |
---|
90 | Identifier* identifier = Class(TestSubclass); |
---|
91 | |
---|
92 | EXPECT_EQ(0u, identifier->getDirectChildren().size()); |
---|
93 | |
---|
94 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
95 | EXPECT_TRUE(identifier->getDirectParents().find(Class(TestClass)) != identifier->getDirectParents().end()); |
---|
96 | } |
---|
97 | { |
---|
98 | Identifier* identifier = Class(TestClass); |
---|
99 | |
---|
100 | EXPECT_EQ(1u, identifier->getDirectChildren().size()); |
---|
101 | EXPECT_TRUE(identifier->getDirectChildren().find(Class(TestSubclass)) != identifier->getDirectChildren().end()); |
---|
102 | |
---|
103 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
104 | EXPECT_TRUE(identifier->getDirectParents().find(Class(BaseObject)) != identifier->getDirectParents().end()); |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | TEST_F(SuperTest, SuperCallWithoutArguments) |
---|
109 | { |
---|
110 | TestSubclass test; |
---|
111 | |
---|
112 | EXPECT_FALSE(test.changedNameBase_); |
---|
113 | EXPECT_FALSE(test.changedNameSubclass_); |
---|
114 | |
---|
115 | test.changedName(); |
---|
116 | |
---|
117 | EXPECT_TRUE(test.changedNameBase_); |
---|
118 | EXPECT_TRUE(test.changedNameSubclass_); |
---|
119 | } |
---|
120 | |
---|
121 | TEST_F(SuperTest, SuperCallWithArguments) |
---|
122 | { |
---|
123 | TestSubclass test; |
---|
124 | |
---|
125 | EXPECT_FALSE(test.xmlPortBase_); |
---|
126 | EXPECT_FALSE(test.xmlPortSubclass_); |
---|
127 | EXPECT_EQ(XMLPort::NOP, test.modeBase_); |
---|
128 | EXPECT_EQ(XMLPort::NOP, test.modeSubclass_); |
---|
129 | |
---|
130 | Element* element = NULL; |
---|
131 | test.XMLPort(*element, XMLPort::SaveObject); |
---|
132 | |
---|
133 | EXPECT_TRUE(test.xmlPortBase_); |
---|
134 | EXPECT_TRUE(test.xmlPortSubclass_); |
---|
135 | EXPECT_EQ(XMLPort::SaveObject, test.modeBase_); |
---|
136 | EXPECT_EQ(XMLPort::SaveObject, test.modeSubclass_); |
---|
137 | } |
---|
138 | } |
---|