Changeset 10624 for code/trunk/test/core/class
- Timestamp:
- Oct 4, 2015, 9:12:21 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 10 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
-
code/trunk/test/core/class/IdentifiableTest.cc
r9659 r10624 2 2 #include "core/CoreIncludes.h" 3 3 #include "core/class/Identifiable.h" 4 #include "core/module/ModuleInstance.h" 4 5 5 6 namespace orxonox … … 7 8 namespace 8 9 { 9 class Identifiable Test: public Identifiable10 class IdentifiableClass : public Identifiable 10 11 { 11 12 public: 12 IdentifiableTest() { RegisterObject(IdentifiableTest); } 13 IdentifiableClass() { RegisterObject(IdentifiableClass); } 14 }; 15 16 RegisterClassNoArgs(IdentifiableClass); 17 18 // Fixture 19 class IdentifiableTest : public ::testing::Test 20 { 21 public: 22 virtual void SetUp() 23 { 24 new IdentifierManager(); 25 ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); 26 } 27 28 virtual void TearDown() 29 { 30 ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); 31 delete &IdentifierManager::getInstance(); 32 } 13 33 }; 14 34 } 15 35 16 TEST (IdentifiableTest, CanCreate)36 TEST_F(IdentifiableTest, CanCreate) 17 37 { 18 Identifiable Test* test = new IdentifiableTest();38 IdentifiableClass* test = new IdentifiableClass(); 19 39 ASSERT_TRUE(test != NULL); 20 40 delete test; 21 41 } 22 42 23 TEST (IdentifiableTest, HasIdentifierAssigned)43 TEST_F(IdentifiableTest, HasIdentifierAssigned) 24 44 { 25 Identifiable Testtest;45 IdentifiableClass test; 26 46 EXPECT_TRUE(test.getIdentifier()); 27 47 } 28 48 29 TEST (IdentifiableTest, CanBeIdentified)49 TEST_F(IdentifiableTest, CanBeIdentified) 30 50 { 31 Identifiable Testtest;32 EXPECT_TRUE(test.isA(Class(Identifiable Test)));51 IdentifiableClass test; 52 EXPECT_TRUE(test.isA(Class(IdentifiableClass))); 33 53 } 34 54 } -
code/trunk/test/core/class/IdentifierClassHierarchyTest.cc
r9659 r10624 4 4 #include "core/class/OrxonoxClass.h" 5 5 #include "core/class/OrxonoxInterface.h" 6 #include "core/module/ModuleInstance.h" 6 7 7 8 namespace orxonox … … 19 20 namespace 20 21 { 21 class BaseInterface1 : public OrxonoxInterface22 class BaseInterface1 : virtual public OrxonoxInterface 22 23 { 23 24 public: … … 30 31 }; 31 32 32 class BaseInterface2 : public OrxonoxInterface33 class BaseInterface2 : virtual public OrxonoxInterface 33 34 { 34 35 public: … … 124 125 }; 125 126 127 RegisterAbstractClass(BaseInterface1).inheritsFrom<OrxonoxInterface>(); 128 RegisterAbstractClass(BaseInterface2).inheritsFrom<OrxonoxInterface>(); 129 RegisterAbstractClass(Interface1).inheritsFrom<BaseInterface1>(); 130 RegisterAbstractClass(Interface2).inheritsFrom<BaseInterface2>(); 131 RegisterClassNoArgs(BaseClass); 132 RegisterClassNoArgs(Class0); 133 RegisterClassNoArgs(Class1); 134 RegisterClassNoArgs(Class2a); 135 RegisterClassNoArgs(Class2b); 136 RegisterClassNoArgs(Class3); 137 126 138 // Fixture 127 139 class IdentifierClassHierarchyTest : public ::testing::Test … … 130 142 virtual void SetUp() 131 143 { 132 registerClass("Context", new ClassFactoryWithContext<Context>()); 133 registerClass("Listable", new ClassFactoryWithContext<Listable>()); 134 registerClass("Configurable", new ClassFactoryNoArgs<Configurable>()); 135 registerClass("OrxonoxInterface", new ClassFactoryNoArgs<OrxonoxInterface>()); 136 registerClass("OrxonoxClass", new ClassFactoryNoArgs<OrxonoxClass>()); 137 registerClass("BaseInterface1", static_cast<ClassFactory<BaseInterface1>*>(NULL), false).inheritsFrom(Class(OrxonoxInterface)); 138 registerClass("BaseInterface2", static_cast<ClassFactory<BaseInterface2>*>(NULL), false).inheritsFrom(Class(OrxonoxInterface)); 139 registerClass("Interface1", static_cast<ClassFactory<Interface1>*>(NULL), false).inheritsFrom(Class(BaseInterface1)); 140 registerClass("Interface2", static_cast<ClassFactory<Interface2>*>(NULL), false).inheritsFrom(Class(BaseInterface2)); 141 registerClass("BaseClass", new ClassFactoryNoArgs<BaseClass>()); 142 registerClass("Class0", new ClassFactoryNoArgs<Class0>()); 143 registerClass("Class1", new ClassFactoryNoArgs<Class1>()); 144 registerClass("Class2a", new ClassFactoryNoArgs<Class2a>()); 145 registerClass("Class2b", new ClassFactoryNoArgs<Class2b>()); 146 registerClass("Class3", new ClassFactoryNoArgs<Class3>()); 147 144 new IdentifierManager(); 145 ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); 146 Context::setRootContext(new Context(NULL)); 147 Identifier::initConfigValues_s = false; // TODO: hack! 148 148 IdentifierManager::getInstance().createClassHierarchy(); 149 149 } … … 151 151 virtual void TearDown() 152 152 { 153 IdentifierManager::getInstance().destroyAllIdentifiers(); 154 } 155 }; 153 IdentifierManager::getInstance().destroyClassHierarchy(); 154 Context::destroyRootContext(); 155 ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); 156 delete &IdentifierManager::getInstance(); 157 } 158 }; 159 160 bool contains(const std::list<const Identifier*> identifiers, Identifier* identifier) 161 { 162 return std::find(identifiers.begin(), identifiers.end(), identifier) != identifiers.end(); 163 } 156 164 157 165 bool contains(const std::set<const Identifier*> identifiers, Identifier* identifier) 158 166 { 159 167 return identifiers.find(identifier) != identifiers.end(); 160 }161 }162 163 TEST(IdentifierClassHierarchyTest_NoFixture, NoInitialization)164 {165 {166 Identifier* identifier = Class(BaseInterface1);167 EXPECT_EQ(0u, identifier->getChildren().size());168 EXPECT_EQ(0u, identifier->getParents().size());169 }170 {171 Identifier* identifier = Class(BaseInterface2);172 EXPECT_EQ(0u, identifier->getChildren().size());173 EXPECT_EQ(0u, identifier->getParents().size());174 }175 {176 Identifier* identifier = Class(Interface1);177 EXPECT_EQ(0u, identifier->getChildren().size());178 EXPECT_EQ(0u, identifier->getParents().size());179 }180 {181 Identifier* identifier = Class(Interface2);182 EXPECT_EQ(0u, identifier->getChildren().size());183 EXPECT_EQ(0u, identifier->getParents().size());184 }185 {186 Identifier* identifier = Class(BaseClass);187 EXPECT_EQ(0u, identifier->getChildren().size());188 EXPECT_EQ(0u, identifier->getParents().size());189 }190 {191 Identifier* identifier = Class(Class0);192 EXPECT_EQ(0u, identifier->getChildren().size());193 EXPECT_EQ(0u, identifier->getParents().size());194 }195 {196 Identifier* identifier = Class(Class1);197 EXPECT_EQ(0u, identifier->getChildren().size());198 EXPECT_EQ(0u, identifier->getParents().size());199 }200 {201 Identifier* identifier = Class(Class2a);202 EXPECT_EQ(0u, identifier->getChildren().size());203 EXPECT_EQ(0u, identifier->getParents().size());204 }205 {206 Identifier* identifier = Class(Class2b);207 EXPECT_EQ(0u, identifier->getChildren().size());208 EXPECT_EQ(0u, identifier->getParents().size());209 }210 {211 Identifier* identifier = Class(Class3);212 EXPECT_EQ(0u, identifier->getChildren().size());213 EXPECT_EQ(0u, identifier->getParents().size());214 168 } 215 169 } -
code/trunk/test/core/class/IdentifierExternalClassHierarchyTest.cc
r9659 r10624 2 2 #include "core/CoreIncludes.h" 3 3 #include "core/class/Identifiable.h" 4 #include "core/module/ModuleInstance.h" 4 5 5 6 namespace orxonox … … 38 39 }; 39 40 41 RegisterAbstractClass(Interface).inheritsFrom<Identifiable>(); 42 RegisterClassNoArgs(BaseClass); 43 RegisterClassNoArgs(RealClass); 44 40 45 // Fixture 41 46 class IdentifierExternalClassHierarchyTest : public ::testing::Test … … 44 49 virtual void SetUp() 45 50 { 46 registerClass("Context", new ClassFactoryWithContext<Context>()); 47 registerClass("Listable", new ClassFactoryWithContext<Listable>()); 48 registerClass("Interface", static_cast<ClassFactory<Interface>*>(NULL), false).inheritsFrom(Class(Identifiable)); 49 registerClass("BaseClass", new ClassFactoryNoArgs<BaseClass>()); 50 registerClass("RealClass", new ClassFactoryNoArgs<RealClass>()); 51 51 new IdentifierManager(); 52 ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); 53 Context::setRootContext(new Context(NULL)); 54 Identifier::initConfigValues_s = false; // TODO: hack! 52 55 IdentifierManager::getInstance().createClassHierarchy(); 53 56 } … … 55 58 virtual void TearDown() 56 59 { 57 IdentifierManager::getInstance().destroyAllIdentifiers(); 60 IdentifierManager::getInstance().destroyClassHierarchy(); 61 Context::destroyRootContext(); 62 ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); 63 delete &IdentifierManager::getInstance(); 58 64 } 59 65 }; 66 67 bool contains(const std::list<const Identifier*> identifiers, Identifier* identifier) 68 { 69 return std::find(identifiers.begin(), identifiers.end(), identifier) != identifiers.end(); 70 } 60 71 61 72 bool contains(const std::set<const Identifier*> identifiers, Identifier* identifier) 62 73 { 63 74 return identifiers.find(identifier) != identifiers.end(); 64 }65 }66 67 TEST(IdentifierExternalClassHierarchyTest_NoFixture, NoInitialization)68 {69 {70 Identifier* identifier = Class(Interface);71 EXPECT_EQ(0u, identifier->getChildren().size());72 EXPECT_EQ(0u, identifier->getParents().size());73 }74 {75 Identifier* identifier = Class(BaseClass);76 EXPECT_EQ(0u, identifier->getChildren().size());77 EXPECT_EQ(0u, identifier->getParents().size());78 }79 {80 Identifier* identifier = Class(RealClass);81 EXPECT_EQ(0u, identifier->getChildren().size());82 EXPECT_EQ(0u, identifier->getParents().size());83 75 } 84 76 } -
code/trunk/test/core/class/IdentifierSimpleClassHierarchyTest.cc
r9659 r10624 4 4 #include "core/class/OrxonoxClass.h" 5 5 #include "core/class/OrxonoxInterface.h" 6 #include "core/module/ModuleInstance.h" 6 7 7 8 namespace orxonox … … 9 10 namespace 10 11 { 11 class Interface : public OrxonoxInterface12 class Interface : virtual public OrxonoxInterface 12 13 { 13 14 public: … … 40 41 }; 41 42 43 RegisterAbstractClass(Interface).inheritsFrom<OrxonoxInterface>(); 44 RegisterClassNoArgs(BaseClass); 45 RegisterClassNoArgs(RealClass); 46 42 47 // Fixture 43 48 class IdentifierSimpleClassHierarchyTest : public ::testing::Test … … 46 51 virtual void SetUp() 47 52 { 48 registerClass("Context", new ClassFactoryWithContext<Context>()); 49 registerClass("Listable", new ClassFactoryWithContext<Listable>()); 50 registerClass("Configurable", new ClassFactoryNoArgs<Configurable>()); 51 registerClass("OrxonoxInterface", new ClassFactoryNoArgs<OrxonoxInterface>()); 52 registerClass("OrxonoxClass", new ClassFactoryNoArgs<OrxonoxClass>()); 53 registerClass("Interface", static_cast<ClassFactory<Interface>*>(NULL), false).inheritsFrom(Class(OrxonoxInterface)); 54 registerClass("BaseClass", new ClassFactoryNoArgs<BaseClass>()); 55 registerClass("RealClass", new ClassFactoryNoArgs<RealClass>()); 56 53 new IdentifierManager(); 54 ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); 55 Context::setRootContext(new Context(NULL)); 56 Identifier::initConfigValues_s = false; // TODO: hack! 57 57 IdentifierManager::getInstance().createClassHierarchy(); 58 58 } … … 60 60 virtual void TearDown() 61 61 { 62 IdentifierManager::getInstance().destroyAllIdentifiers(); 62 IdentifierManager::getInstance().destroyClassHierarchy(); 63 Context::destroyRootContext(); 64 ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); 65 delete &IdentifierManager::getInstance(); 63 66 } 64 67 }; 68 69 bool contains(const std::list<const Identifier*> identifiers, Identifier* identifier) 70 { 71 return std::find(identifiers.begin(), identifiers.end(), identifier) != identifiers.end(); 72 } 65 73 66 74 bool contains(const std::set<const Identifier*> identifiers, Identifier* identifier) 67 75 { 68 76 return identifiers.find(identifier) != identifiers.end(); 69 }70 }71 72 TEST(IdentifierSimpleClassHierarchyTest_NoFixture, NoInitialization)73 {74 {75 Identifier* identifier = Class(Interface);76 EXPECT_EQ(0u, identifier->getChildren().size());77 EXPECT_EQ(0u, identifier->getParents().size());78 }79 {80 Identifier* identifier = Class(BaseClass);81 EXPECT_EQ(0u, identifier->getChildren().size());82 EXPECT_EQ(0u, identifier->getParents().size());83 }84 {85 Identifier* identifier = Class(RealClass);86 EXPECT_EQ(0u, identifier->getChildren().size());87 EXPECT_EQ(0u, identifier->getParents().size());88 77 } 89 78 } -
code/trunk/test/core/class/IdentifierTest.cc
r9659 r10624 2 2 #include "core/CoreIncludes.h" 3 3 #include "core/class/Identifiable.h" 4 #include "core/module/ModuleInstance.h" 4 5 5 6 namespace orxonox … … 18 19 TestSubclass() { RegisterObject(TestSubclass); } 19 20 }; 21 22 RegisterClassNoArgs(TestClass); 23 RegisterClassNoArgs(TestSubclass); 24 25 // Fixture 26 class IdentifierTest : public ::testing::Test 27 { 28 public: 29 virtual void SetUp() 30 { 31 new IdentifierManager(); 32 ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); 33 } 34 35 virtual void TearDown() 36 { 37 ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); 38 delete &IdentifierManager::getInstance(); 39 } 40 }; 20 41 } 21 42 22 TEST (IdentifierTest, IdentifierExistsOfClass)43 TEST_F(IdentifierTest, IdentifierExistsOfClass) 23 44 { 24 45 TestClass test; … … 28 49 } 29 50 30 TEST (IdentifierTest, IdentifierExistsOfSubclass)51 TEST_F(IdentifierTest, IdentifierExistsOfSubclass) 31 52 { 32 53 TestSubclass test; … … 36 57 } 37 58 38 TEST (IdentifierTest, HasNameOfClass)59 TEST_F(IdentifierTest, HasNameOfClass) 39 60 { 40 61 TestClass test; … … 44 65 } 45 66 46 TEST (IdentifierTest, HasNameOfSubClass)67 TEST_F(IdentifierTest, HasNameOfSubClass) 47 68 { 48 69 TestSubclass test; -
code/trunk/test/core/class/OrxonoxClassTest.cc
r9649 r10624 1 1 #include <gtest/gtest.h> 2 2 #include "core/class/OrxonoxClass.h" 3 #include "core/class/IdentifierManager.h" 3 4 #include "core/object/Context.h" 4 5 … … 17 18 virtual void SetUp() 18 19 { 20 new IdentifierManager(); 19 21 Context::setRootContext(new Context(NULL)); 20 22 } … … 22 24 virtual void TearDown() 23 25 { 24 Context::setRootContext(NULL); 26 Context::destroyRootContext(); 27 delete &IdentifierManager::getInstance(); 25 28 } 26 29 }; -
code/trunk/test/core/class/OrxonoxInterfaceTest.cc
r9649 r10624 2 2 #include "core/class/OrxonoxInterface.h" 3 3 #include "core/class/OrxonoxClass.h" 4 #include "core/class/IdentifierManager.h" 4 5 #include "core/object/Context.h" 5 6 … … 32 33 virtual void SetUp() 33 34 { 35 new IdentifierManager(); 34 36 Context::setRootContext(new Context(NULL)); 35 37 } … … 37 39 virtual void TearDown() 38 40 { 39 Context::setRootContext(NULL); 41 Context::destroyRootContext(); 42 delete &IdentifierManager::getInstance(); 40 43 } 41 44 }; -
code/trunk/test/core/class/SubclassIdentifierTest.cc
r9659 r10624 4 4 #include "core/class/SubclassIdentifier.h" 5 5 #include "core/class/OrxonoxClass.h" 6 #include "core/module/ModuleInstance.h" 6 7 7 8 namespace orxonox … … 21 22 }; 22 23 24 RegisterClass(TestClass); 25 RegisterClass(TestSubclass); 26 23 27 // Fixture 24 28 class SubclassIdentifierTest : public ::testing::Test … … 27 31 virtual void SetUp() 28 32 { 29 registerClass("OrxonoxClass", new ClassFactoryNoArgs<OrxonoxClass>());30 registerClass("TestClass", new ClassFactoryWithContext<TestClass>());31 registerClass("TestSubclass", new ClassFactoryWithContext<TestSubclass>());32 33 new IdentifierManager(); 34 ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); 35 Context::setRootContext(new Context(NULL)); 36 Identifier::initConfigValues_s = false; // TODO: hack! 33 37 IdentifierManager::getInstance().createClassHierarchy(); 34 35 Context::setRootContext(new Context(NULL));36 38 } 37 39 38 40 virtual void TearDown() 39 41 { 40 Context::setRootContext(NULL); 41 42 IdentifierManager::getInstance().destroyAllIdentifiers(); 42 IdentifierManager::getInstance().destroyClassHierarchy(); 43 Context::destroyRootContext(); 44 ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); 45 delete &IdentifierManager::getInstance(); 43 46 } 44 47 }; -
code/trunk/test/core/class/SuperTest.cc
r9659 r10624 5 5 #include "core/BaseObject.h" 6 6 #include "core/class/Super.h" 7 #include "core/module/ModuleInstance.h" 7 8 8 9 namespace orxonox … … 62 63 }; 63 64 64 // Fixture 65 RegisterClass(TestClass); 66 RegisterClass(TestSubclass); 67 68 // Fixture 65 69 class SuperTest : public ::testing::Test 66 70 { … … 68 72 virtual void SetUp() 69 73 { 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 74 new IdentifierManager(); 75 ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); 76 Context::setRootContext(new Context(NULL)); 77 Identifier::initConfigValues_s = false; // TODO: hack! 77 78 IdentifierManager::getInstance().createClassHierarchy(); 78 79 Context::setRootContext(new Context(NULL));80 79 } 81 80 82 81 virtual void TearDown() 83 82 { 84 Context::setRootContext(NULL); 85 86 IdentifierManager::getInstance().destroyAllIdentifiers(); 83 IdentifierManager::getInstance().destroyClassHierarchy(); 84 Context::destroyRootContext(); 85 ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); 86 delete &IdentifierManager::getInstance(); 87 87 } 88 88 }; … … 97 97 98 98 EXPECT_EQ(1u, identifier->getDirectParents().size()); 99 EXPECT_TRUE( identifier->getDirectParents().find(Class(TestClass)) != identifier->getDirectParents().end());99 EXPECT_TRUE(std::find(identifier->getDirectParents().begin(), identifier->getDirectParents().end(), Class(TestClass)) != identifier->getDirectParents().end()); 100 100 } 101 101 { … … 106 106 107 107 EXPECT_EQ(1u, identifier->getDirectParents().size()); 108 EXPECT_TRUE( identifier->getDirectParents().find(Class(BaseObject)) != identifier->getDirectParents().end());108 EXPECT_TRUE(std::find(identifier->getDirectParents().begin(), identifier->getDirectParents().end(), Class(BaseObject)) != identifier->getDirectParents().end()); 109 109 } 110 110 }
Note: See TracChangeset
for help on using the changeset viewer.