[10363] | 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" |
---|
[10403] | 6 | #include "core/module/ModuleInstance.h" |
---|
[10363] | 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 | |
---|
[10400] | 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 | |
---|
[10363] | 105 | // Fixture |
---|
| 106 | class IdentifierNestedClassHierarchyTest : public ::testing::Test |
---|
| 107 | { |
---|
| 108 | public: |
---|
| 109 | virtual void SetUp() |
---|
| 110 | { |
---|
[10544] | 111 | new IdentifierManager(); |
---|
[10535] | 112 | ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); |
---|
[10544] | 113 | Context::setRootContext(new Context(NULL)); |
---|
[10403] | 114 | Identifier::initConfigValues_s = false; // TODO: hack! |
---|
| 115 | IdentifierManager::getInstance().createClassHierarchy(); |
---|
[10363] | 116 | } |
---|
| 117 | |
---|
| 118 | virtual void TearDown() |
---|
| 119 | { |
---|
[10403] | 120 | IdentifierManager::getInstance().destroyClassHierarchy(); |
---|
[10544] | 121 | Context::destroyRootContext(); |
---|
[10535] | 122 | ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); |
---|
[10544] | 123 | delete &IdentifierManager::getInstance(); |
---|
[10363] | 124 | } |
---|
| 125 | }; |
---|
| 126 | |
---|
[10372] | 127 | bool contains(const std::list<const Identifier*> identifiers, Identifier* identifier) |
---|
| 128 | { |
---|
| 129 | return std::find(identifiers.begin(), identifiers.end(), identifier) != identifiers.end(); |
---|
| 130 | } |
---|
| 131 | |
---|
[10363] | 132 | bool contains(const std::set<const Identifier*> identifiers, Identifier* identifier) |
---|
| 133 | { |
---|
| 134 | return identifiers.find(identifier) != identifiers.end(); |
---|
| 135 | } |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | TEST_F(IdentifierNestedClassHierarchyTest, TestNested1) |
---|
| 139 | { |
---|
| 140 | Identifier* identifier = Class(Nested1); |
---|
| 141 | |
---|
| 142 | EXPECT_EQ(0u, identifier->getDirectChildren().size()); |
---|
| 143 | EXPECT_EQ(0u, identifier->getChildren().size()); |
---|
| 144 | |
---|
| 145 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
| 146 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(OrxonoxClass))); |
---|
| 147 | |
---|
| 148 | EXPECT_EQ(4u, identifier->getParents().size()); |
---|
| 149 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
| 150 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
| 151 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
| 152 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | TEST_F(IdentifierNestedClassHierarchyTest, TestNested2) |
---|
| 156 | { |
---|
| 157 | Identifier* identifier = Class(Nested2); |
---|
| 158 | |
---|
| 159 | EXPECT_EQ(0u, identifier->getDirectChildren().size()); |
---|
| 160 | EXPECT_EQ(0u, identifier->getChildren().size()); |
---|
| 161 | |
---|
| 162 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
| 163 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(OrxonoxClass))); |
---|
| 164 | |
---|
| 165 | EXPECT_EQ(4u, identifier->getParents().size()); |
---|
| 166 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
| 167 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
| 168 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
| 169 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | TEST_F(IdentifierNestedClassHierarchyTest, TestBaseClass) |
---|
| 173 | { |
---|
| 174 | Identifier* identifier = Class(BaseClass); |
---|
| 175 | |
---|
| 176 | EXPECT_EQ(6u, identifier->getDirectChildren().size()); |
---|
| 177 | EXPECT_TRUE(contains(identifier->getDirectChildren(), Class(Class1_notNested))); |
---|
| 178 | EXPECT_TRUE(contains(identifier->getDirectChildren(), Class(Class2_oneNested))); |
---|
| 179 | EXPECT_TRUE(contains(identifier->getDirectChildren(), Class(Class3_twoNested))); |
---|
| 180 | EXPECT_TRUE(contains(identifier->getDirectChildren(), Class(Class4_class1Nested))); |
---|
| 181 | EXPECT_TRUE(contains(identifier->getDirectChildren(), Class(Class5_class2Nested))); |
---|
| 182 | EXPECT_TRUE(contains(identifier->getDirectChildren(), Class(Class6_class3Nested))); |
---|
| 183 | |
---|
| 184 | EXPECT_EQ(8u, identifier->getChildren().size()); |
---|
| 185 | EXPECT_TRUE(contains(identifier->getChildren(), Class(Class1_notNested))); |
---|
| 186 | EXPECT_TRUE(contains(identifier->getChildren(), Class(Class2_oneNested))); |
---|
| 187 | EXPECT_TRUE(contains(identifier->getChildren(), Class(Class3_twoNested))); |
---|
| 188 | EXPECT_TRUE(contains(identifier->getChildren(), Class(Class4_class1Nested))); |
---|
| 189 | EXPECT_TRUE(contains(identifier->getChildren(), Class(Class5_class2Nested))); |
---|
| 190 | EXPECT_TRUE(contains(identifier->getChildren(), Class(Class6_class3Nested))); |
---|
| 191 | EXPECT_TRUE(contains(identifier->getChildren(), Class(Class3_Child))); |
---|
| 192 | EXPECT_TRUE(contains(identifier->getChildren(), Class(Class6_Child))); |
---|
| 193 | |
---|
| 194 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
| 195 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(OrxonoxClass))); |
---|
| 196 | |
---|
| 197 | EXPECT_EQ(4u, identifier->getParents().size()); |
---|
| 198 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
| 199 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
| 200 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
| 201 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | TEST_F(IdentifierNestedClassHierarchyTest, TestClass1_notNested) |
---|
| 205 | { |
---|
| 206 | Identifier* identifier = Class(Class1_notNested); |
---|
| 207 | |
---|
| 208 | EXPECT_EQ(0u, identifier->getDirectChildren().size()); |
---|
| 209 | EXPECT_EQ(0u, identifier->getChildren().size()); |
---|
| 210 | |
---|
| 211 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
| 212 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseClass))); |
---|
| 213 | |
---|
| 214 | EXPECT_EQ(5u, identifier->getParents().size()); |
---|
| 215 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
| 216 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
| 217 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
| 218 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
| 219 | EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | TEST_F(IdentifierNestedClassHierarchyTest, TestClass2_oneNested) |
---|
| 223 | { |
---|
| 224 | Identifier* identifier = Class(Class2_oneNested); |
---|
| 225 | |
---|
| 226 | EXPECT_EQ(0u, identifier->getDirectChildren().size()); |
---|
| 227 | EXPECT_EQ(0u, identifier->getChildren().size()); |
---|
| 228 | |
---|
| 229 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
| 230 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseClass))); |
---|
| 231 | |
---|
| 232 | EXPECT_EQ(5u, identifier->getParents().size()); |
---|
| 233 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
| 234 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
| 235 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
| 236 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
| 237 | EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | TEST_F(IdentifierNestedClassHierarchyTest, TestClass3_twoNested) |
---|
| 241 | { |
---|
| 242 | Identifier* identifier = Class(Class3_twoNested); |
---|
| 243 | |
---|
| 244 | EXPECT_EQ(1u, identifier->getDirectChildren().size()); |
---|
| 245 | EXPECT_TRUE(contains(identifier->getDirectChildren(), Class(Class3_Child))); |
---|
| 246 | |
---|
| 247 | EXPECT_EQ(1u, identifier->getChildren().size()); |
---|
| 248 | EXPECT_TRUE(contains(identifier->getChildren(), Class(Class3_Child))); |
---|
| 249 | |
---|
| 250 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
| 251 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseClass))); |
---|
| 252 | |
---|
| 253 | EXPECT_EQ(5u, identifier->getParents().size()); |
---|
| 254 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
| 255 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
| 256 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
| 257 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
| 258 | EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); |
---|
| 259 | } |
---|
| 260 | |
---|
| 261 | TEST_F(IdentifierNestedClassHierarchyTest, TestClass4_class1Nested) |
---|
| 262 | { |
---|
| 263 | Identifier* identifier = Class(Class4_class1Nested); |
---|
| 264 | |
---|
| 265 | EXPECT_EQ(0u, identifier->getDirectChildren().size()); |
---|
| 266 | EXPECT_EQ(0u, identifier->getChildren().size()); |
---|
| 267 | |
---|
| 268 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
| 269 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseClass))); |
---|
| 270 | |
---|
| 271 | EXPECT_EQ(5u, identifier->getParents().size()); |
---|
| 272 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
| 273 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
| 274 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
| 275 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
| 276 | EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | TEST_F(IdentifierNestedClassHierarchyTest, TestClass5_class2Nested) |
---|
| 280 | { |
---|
| 281 | Identifier* identifier = Class(Class5_class2Nested); |
---|
| 282 | |
---|
| 283 | EXPECT_EQ(0u, identifier->getDirectChildren().size()); |
---|
| 284 | EXPECT_EQ(0u, identifier->getChildren().size()); |
---|
| 285 | |
---|
| 286 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
| 287 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseClass))); |
---|
| 288 | |
---|
| 289 | EXPECT_EQ(5u, identifier->getParents().size()); |
---|
| 290 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
| 291 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
| 292 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
| 293 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
| 294 | EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | TEST_F(IdentifierNestedClassHierarchyTest, TestClass6_class3Nested) |
---|
| 298 | { |
---|
| 299 | Identifier* identifier = Class(Class6_class3Nested); |
---|
| 300 | |
---|
| 301 | EXPECT_EQ(1u, identifier->getDirectChildren().size()); |
---|
| 302 | EXPECT_TRUE(contains(identifier->getDirectChildren(), Class(Class6_Child))); |
---|
| 303 | |
---|
| 304 | EXPECT_EQ(1u, identifier->getChildren().size()); |
---|
| 305 | EXPECT_TRUE(contains(identifier->getChildren(), Class(Class6_Child))); |
---|
| 306 | |
---|
| 307 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
| 308 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseClass))); |
---|
| 309 | |
---|
| 310 | EXPECT_EQ(5u, identifier->getParents().size()); |
---|
| 311 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
| 312 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
| 313 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
| 314 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
| 315 | EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | TEST_F(IdentifierNestedClassHierarchyTest, TestClass3_Child) |
---|
| 319 | { |
---|
| 320 | Identifier* identifier = Class(Class3_Child); |
---|
| 321 | |
---|
| 322 | EXPECT_EQ(0u, identifier->getDirectChildren().size()); |
---|
| 323 | EXPECT_EQ(0u, identifier->getChildren().size()); |
---|
| 324 | |
---|
| 325 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
| 326 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(Class3_twoNested))); |
---|
| 327 | |
---|
| 328 | EXPECT_EQ(6u, identifier->getParents().size()); |
---|
| 329 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
| 330 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
| 331 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
| 332 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
| 333 | EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); |
---|
| 334 | EXPECT_TRUE(contains(identifier->getParents(), Class(Class3_twoNested))); |
---|
| 335 | } |
---|
| 336 | |
---|
| 337 | TEST_F(IdentifierNestedClassHierarchyTest, TestClass6_Child) |
---|
| 338 | { |
---|
| 339 | Identifier* identifier = Class(Class6_Child); |
---|
| 340 | |
---|
| 341 | EXPECT_EQ(0u, identifier->getDirectChildren().size()); |
---|
| 342 | EXPECT_EQ(0u, identifier->getChildren().size()); |
---|
| 343 | |
---|
| 344 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
| 345 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(Class6_class3Nested))); |
---|
| 346 | |
---|
| 347 | EXPECT_EQ(6u, identifier->getParents().size()); |
---|
| 348 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
| 349 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
| 350 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
| 351 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
| 352 | EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); |
---|
| 353 | EXPECT_TRUE(contains(identifier->getParents(), Class(Class6_class3Nested))); |
---|
| 354 | } |
---|
| 355 | } |
---|