1 | #include <gtest/gtest.h> |
---|
2 | #include "core/CoreIncludes.h" |
---|
3 | #include "core/class/Identifiable.h" |
---|
4 | #include "core/class/OrxonoxClass.h" |
---|
5 | #include "core/class/OrxonoxInterface.h" |
---|
6 | #include "core/module/ModuleInstance.h" |
---|
7 | |
---|
8 | namespace orxonox |
---|
9 | { |
---|
10 | // Tests the class hierarchy with classes that contain other classes as members. |
---|
11 | // |
---|
12 | // +------ Nested1 +------ Class1_notNested |
---|
13 | // +------ Nested2 +------ Class2_oneNested |
---|
14 | // OrxonoxClass <-----+------ BaseClass <-----+------ Class3_twoNested <----------- Class3_Child |
---|
15 | // +------ Class4_class1Nested |
---|
16 | // +------ Class5_class2Nested |
---|
17 | // +------ Class6_class3Nested <-------- Class6_Child |
---|
18 | |
---|
19 | namespace |
---|
20 | { |
---|
21 | class Nested1 : public OrxonoxClass |
---|
22 | { |
---|
23 | public: |
---|
24 | Nested1() { RegisterObject(Nested1); } |
---|
25 | }; |
---|
26 | |
---|
27 | class Nested2 : public OrxonoxClass |
---|
28 | { |
---|
29 | public: |
---|
30 | Nested2() { RegisterObject(Nested2); } |
---|
31 | }; |
---|
32 | |
---|
33 | class BaseClass : public OrxonoxClass |
---|
34 | { |
---|
35 | public: |
---|
36 | BaseClass() { RegisterObject(BaseClass); } |
---|
37 | }; |
---|
38 | |
---|
39 | class Class1_notNested : public BaseClass |
---|
40 | { |
---|
41 | public: |
---|
42 | Class1_notNested() { RegisterObject(Class1_notNested); } |
---|
43 | }; |
---|
44 | |
---|
45 | class Class2_oneNested : public BaseClass |
---|
46 | { |
---|
47 | public: |
---|
48 | Class2_oneNested() { RegisterObject(Class2_oneNested); } |
---|
49 | Nested1 nested1_; |
---|
50 | }; |
---|
51 | |
---|
52 | class Class3_twoNested : public BaseClass |
---|
53 | { |
---|
54 | public: |
---|
55 | Class3_twoNested() { RegisterObject(Class3_twoNested); } |
---|
56 | Nested1 nested1_; |
---|
57 | Nested2 nested2_; |
---|
58 | }; |
---|
59 | |
---|
60 | class Class4_class1Nested : public BaseClass |
---|
61 | { |
---|
62 | public: |
---|
63 | Class4_class1Nested() { RegisterObject(Class4_class1Nested); } |
---|
64 | Class1_notNested nested_; |
---|
65 | }; |
---|
66 | |
---|
67 | class Class5_class2Nested : public BaseClass |
---|
68 | { |
---|
69 | public: |
---|
70 | Class5_class2Nested() { RegisterObject(Class5_class2Nested); } |
---|
71 | Class2_oneNested nested_; |
---|
72 | }; |
---|
73 | |
---|
74 | class Class6_class3Nested : public BaseClass |
---|
75 | { |
---|
76 | public: |
---|
77 | Class6_class3Nested() { RegisterObject(Class6_class3Nested); } |
---|
78 | Class3_twoNested nested_; |
---|
79 | }; |
---|
80 | |
---|
81 | class Class3_Child : public Class3_twoNested |
---|
82 | { |
---|
83 | public: |
---|
84 | Class3_Child() { RegisterObject(Class3_Child); } |
---|
85 | }; |
---|
86 | |
---|
87 | class Class6_Child : public Class6_class3Nested |
---|
88 | { |
---|
89 | public: |
---|
90 | Class6_Child() { RegisterObject(Class6_Child); } |
---|
91 | }; |
---|
92 | |
---|
93 | RegisterClassNoArgs(Nested1); |
---|
94 | RegisterClassNoArgs(Nested2); |
---|
95 | RegisterClassNoArgs(BaseClass); |
---|
96 | RegisterClassNoArgs(Class1_notNested); |
---|
97 | RegisterClassNoArgs(Class2_oneNested); |
---|
98 | RegisterClassNoArgs(Class3_twoNested); |
---|
99 | RegisterClassNoArgs(Class4_class1Nested); |
---|
100 | RegisterClassNoArgs(Class5_class2Nested); |
---|
101 | RegisterClassNoArgs(Class6_class3Nested); |
---|
102 | RegisterClassNoArgs(Class3_Child); |
---|
103 | RegisterClassNoArgs(Class6_Child); |
---|
104 | |
---|
105 | // Fixture |
---|
106 | class IdentifierNestedClassHierarchyTest : public ::testing::Test |
---|
107 | { |
---|
108 | public: |
---|
109 | virtual void SetUp() |
---|
110 | { |
---|
111 | ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(); |
---|
112 | Identifier::initConfigValues_s = false; // TODO: hack! |
---|
113 | IdentifierManager::getInstance().createClassHierarchy(); |
---|
114 | } |
---|
115 | |
---|
116 | virtual void TearDown() |
---|
117 | { |
---|
118 | IdentifierManager::getInstance().destroyClassHierarchy(); |
---|
119 | ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(); |
---|
120 | } |
---|
121 | }; |
---|
122 | |
---|
123 | bool contains(const std::list<const Identifier*> identifiers, Identifier* identifier) |
---|
124 | { |
---|
125 | return std::find(identifiers.begin(), identifiers.end(), identifier) != identifiers.end(); |
---|
126 | } |
---|
127 | |
---|
128 | bool contains(const std::set<const Identifier*> identifiers, Identifier* identifier) |
---|
129 | { |
---|
130 | return identifiers.find(identifier) != identifiers.end(); |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | TEST_F(IdentifierNestedClassHierarchyTest, TestNested1) |
---|
135 | { |
---|
136 | Identifier* identifier = Class(Nested1); |
---|
137 | |
---|
138 | EXPECT_EQ(0u, identifier->getDirectChildren().size()); |
---|
139 | EXPECT_EQ(0u, identifier->getChildren().size()); |
---|
140 | |
---|
141 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
142 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(OrxonoxClass))); |
---|
143 | |
---|
144 | EXPECT_EQ(4u, identifier->getParents().size()); |
---|
145 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
146 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
147 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
148 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
149 | } |
---|
150 | |
---|
151 | TEST_F(IdentifierNestedClassHierarchyTest, TestNested2) |
---|
152 | { |
---|
153 | Identifier* identifier = Class(Nested2); |
---|
154 | |
---|
155 | EXPECT_EQ(0u, identifier->getDirectChildren().size()); |
---|
156 | EXPECT_EQ(0u, identifier->getChildren().size()); |
---|
157 | |
---|
158 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
159 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(OrxonoxClass))); |
---|
160 | |
---|
161 | EXPECT_EQ(4u, identifier->getParents().size()); |
---|
162 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
163 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
164 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
165 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
166 | } |
---|
167 | |
---|
168 | TEST_F(IdentifierNestedClassHierarchyTest, TestBaseClass) |
---|
169 | { |
---|
170 | Identifier* identifier = Class(BaseClass); |
---|
171 | |
---|
172 | EXPECT_EQ(6u, identifier->getDirectChildren().size()); |
---|
173 | EXPECT_TRUE(contains(identifier->getDirectChildren(), Class(Class1_notNested))); |
---|
174 | EXPECT_TRUE(contains(identifier->getDirectChildren(), Class(Class2_oneNested))); |
---|
175 | EXPECT_TRUE(contains(identifier->getDirectChildren(), Class(Class3_twoNested))); |
---|
176 | EXPECT_TRUE(contains(identifier->getDirectChildren(), Class(Class4_class1Nested))); |
---|
177 | EXPECT_TRUE(contains(identifier->getDirectChildren(), Class(Class5_class2Nested))); |
---|
178 | EXPECT_TRUE(contains(identifier->getDirectChildren(), Class(Class6_class3Nested))); |
---|
179 | |
---|
180 | EXPECT_EQ(8u, identifier->getChildren().size()); |
---|
181 | EXPECT_TRUE(contains(identifier->getChildren(), Class(Class1_notNested))); |
---|
182 | EXPECT_TRUE(contains(identifier->getChildren(), Class(Class2_oneNested))); |
---|
183 | EXPECT_TRUE(contains(identifier->getChildren(), Class(Class3_twoNested))); |
---|
184 | EXPECT_TRUE(contains(identifier->getChildren(), Class(Class4_class1Nested))); |
---|
185 | EXPECT_TRUE(contains(identifier->getChildren(), Class(Class5_class2Nested))); |
---|
186 | EXPECT_TRUE(contains(identifier->getChildren(), Class(Class6_class3Nested))); |
---|
187 | EXPECT_TRUE(contains(identifier->getChildren(), Class(Class3_Child))); |
---|
188 | EXPECT_TRUE(contains(identifier->getChildren(), Class(Class6_Child))); |
---|
189 | |
---|
190 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
191 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(OrxonoxClass))); |
---|
192 | |
---|
193 | EXPECT_EQ(4u, identifier->getParents().size()); |
---|
194 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
195 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
196 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
197 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
198 | } |
---|
199 | |
---|
200 | TEST_F(IdentifierNestedClassHierarchyTest, TestClass1_notNested) |
---|
201 | { |
---|
202 | Identifier* identifier = Class(Class1_notNested); |
---|
203 | |
---|
204 | EXPECT_EQ(0u, identifier->getDirectChildren().size()); |
---|
205 | EXPECT_EQ(0u, identifier->getChildren().size()); |
---|
206 | |
---|
207 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
208 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseClass))); |
---|
209 | |
---|
210 | EXPECT_EQ(5u, identifier->getParents().size()); |
---|
211 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
212 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
213 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
214 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
215 | EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); |
---|
216 | } |
---|
217 | |
---|
218 | TEST_F(IdentifierNestedClassHierarchyTest, TestClass2_oneNested) |
---|
219 | { |
---|
220 | Identifier* identifier = Class(Class2_oneNested); |
---|
221 | |
---|
222 | EXPECT_EQ(0u, identifier->getDirectChildren().size()); |
---|
223 | EXPECT_EQ(0u, identifier->getChildren().size()); |
---|
224 | |
---|
225 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
226 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseClass))); |
---|
227 | |
---|
228 | EXPECT_EQ(5u, identifier->getParents().size()); |
---|
229 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
230 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
231 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
232 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
233 | EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); |
---|
234 | } |
---|
235 | |
---|
236 | TEST_F(IdentifierNestedClassHierarchyTest, TestClass3_twoNested) |
---|
237 | { |
---|
238 | Identifier* identifier = Class(Class3_twoNested); |
---|
239 | |
---|
240 | EXPECT_EQ(1u, identifier->getDirectChildren().size()); |
---|
241 | EXPECT_TRUE(contains(identifier->getDirectChildren(), Class(Class3_Child))); |
---|
242 | |
---|
243 | EXPECT_EQ(1u, identifier->getChildren().size()); |
---|
244 | EXPECT_TRUE(contains(identifier->getChildren(), Class(Class3_Child))); |
---|
245 | |
---|
246 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
247 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseClass))); |
---|
248 | |
---|
249 | EXPECT_EQ(5u, identifier->getParents().size()); |
---|
250 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
251 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
252 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
253 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
254 | EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); |
---|
255 | } |
---|
256 | |
---|
257 | TEST_F(IdentifierNestedClassHierarchyTest, TestClass4_class1Nested) |
---|
258 | { |
---|
259 | Identifier* identifier = Class(Class4_class1Nested); |
---|
260 | |
---|
261 | EXPECT_EQ(0u, identifier->getDirectChildren().size()); |
---|
262 | EXPECT_EQ(0u, identifier->getChildren().size()); |
---|
263 | |
---|
264 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
265 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseClass))); |
---|
266 | |
---|
267 | EXPECT_EQ(5u, identifier->getParents().size()); |
---|
268 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
269 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
270 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
271 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
272 | EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); |
---|
273 | } |
---|
274 | |
---|
275 | TEST_F(IdentifierNestedClassHierarchyTest, TestClass5_class2Nested) |
---|
276 | { |
---|
277 | Identifier* identifier = Class(Class5_class2Nested); |
---|
278 | |
---|
279 | EXPECT_EQ(0u, identifier->getDirectChildren().size()); |
---|
280 | EXPECT_EQ(0u, identifier->getChildren().size()); |
---|
281 | |
---|
282 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
283 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseClass))); |
---|
284 | |
---|
285 | EXPECT_EQ(5u, identifier->getParents().size()); |
---|
286 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
287 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
288 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
289 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
290 | EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); |
---|
291 | } |
---|
292 | |
---|
293 | TEST_F(IdentifierNestedClassHierarchyTest, TestClass6_class3Nested) |
---|
294 | { |
---|
295 | Identifier* identifier = Class(Class6_class3Nested); |
---|
296 | |
---|
297 | EXPECT_EQ(1u, identifier->getDirectChildren().size()); |
---|
298 | EXPECT_TRUE(contains(identifier->getDirectChildren(), Class(Class6_Child))); |
---|
299 | |
---|
300 | EXPECT_EQ(1u, identifier->getChildren().size()); |
---|
301 | EXPECT_TRUE(contains(identifier->getChildren(), Class(Class6_Child))); |
---|
302 | |
---|
303 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
304 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseClass))); |
---|
305 | |
---|
306 | EXPECT_EQ(5u, identifier->getParents().size()); |
---|
307 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
308 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
309 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
310 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
311 | EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); |
---|
312 | } |
---|
313 | |
---|
314 | TEST_F(IdentifierNestedClassHierarchyTest, TestClass3_Child) |
---|
315 | { |
---|
316 | Identifier* identifier = Class(Class3_Child); |
---|
317 | |
---|
318 | EXPECT_EQ(0u, identifier->getDirectChildren().size()); |
---|
319 | EXPECT_EQ(0u, identifier->getChildren().size()); |
---|
320 | |
---|
321 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
322 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(Class3_twoNested))); |
---|
323 | |
---|
324 | EXPECT_EQ(6u, identifier->getParents().size()); |
---|
325 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
326 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
327 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
328 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
329 | EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); |
---|
330 | EXPECT_TRUE(contains(identifier->getParents(), Class(Class3_twoNested))); |
---|
331 | } |
---|
332 | |
---|
333 | TEST_F(IdentifierNestedClassHierarchyTest, TestClass6_Child) |
---|
334 | { |
---|
335 | Identifier* identifier = Class(Class6_Child); |
---|
336 | |
---|
337 | EXPECT_EQ(0u, identifier->getDirectChildren().size()); |
---|
338 | EXPECT_EQ(0u, identifier->getChildren().size()); |
---|
339 | |
---|
340 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
341 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(Class6_class3Nested))); |
---|
342 | |
---|
343 | EXPECT_EQ(6u, identifier->getParents().size()); |
---|
344 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
345 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
346 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
347 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
348 | EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); |
---|
349 | EXPECT_TRUE(contains(identifier->getParents(), Class(Class6_class3Nested))); |
---|
350 | } |
---|
351 | } |
---|