Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/test/core/class/IdentifierSimpleClassHierarchyTest.cc @ 12184

Last change on this file since 12184 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 5.3 KB
RevLine 
[9637]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"
[10624]6#include "core/module/ModuleInstance.h"
[9637]7
8namespace orxonox
9{
10    namespace
11    {
[10624]12        class Interface : virtual public OrxonoxInterface
[9646]13        {
14            public:
15                Interface()
16                {
[9659]17                    RegisterObject(Interface);
[9646]18                }
[9637]19
[9646]20                virtual void test() = 0;
21        };
22
[9637]23        class BaseClass : public OrxonoxClass
[9646]24        {
25            public:
26                BaseClass()
27                {
[9659]28                    RegisterObject(BaseClass);
[9646]29                }
30        };
[9637]31
32        class RealClass : public BaseClass, public Interface
[9646]33        {
34            public:
35                RealClass()
36                {
37                    RegisterObject(RealClass);
38                }
[9637]39
[11071]40                virtual void test() override {}
[9646]41        };
42
[10624]43        RegisterAbstractClass(Interface).inheritsFrom<OrxonoxInterface>();
44        RegisterClassNoArgs(BaseClass);
45        RegisterClassNoArgs(RealClass);
46
[9637]47        // Fixture
48        class IdentifierSimpleClassHierarchyTest : public ::testing::Test
49        {
50            public:
[11071]51                virtual void SetUp() override
[9637]52                {
[10624]53                    new IdentifierManager();
54                    ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
[11071]55                    Context::setRootContext(new Context(nullptr));
[10624]56                    Identifier::initConfigValues_s = false; // TODO: hack!
[9640]57                    IdentifierManager::getInstance().createClassHierarchy();
[9637]58                }
59
[11071]60                virtual void TearDown() override
[9637]61                {
[10624]62                    IdentifierManager::getInstance().destroyClassHierarchy();
63                    Context::destroyRootContext();
64                    ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
65                    delete &IdentifierManager::getInstance();
[9637]66                }
67        };
[9646]68
[10624]69        bool contains(const std::list<const Identifier*> identifiers, Identifier* identifier)
[9646]70        {
[10624]71            return std::find(identifiers.begin(), identifiers.end(), identifier) != identifiers.end();
[9646]72        }
[9637]73
[10624]74        bool contains(const std::set<const Identifier*> identifiers, Identifier* identifier)
[9637]75        {
[10624]76            return identifiers.find(identifier) != identifiers.end();
[9637]77        }
78    }
79
80    TEST_F(IdentifierSimpleClassHierarchyTest, TestInterface)
81    {
82        Identifier* identifier = Class(Interface);
83
[9646]84        EXPECT_EQ(1u, identifier->getDirectChildren().size());
85        EXPECT_TRUE(contains(identifier->getDirectChildren(), Class(RealClass)));
86
[9637]87        EXPECT_EQ(1u, identifier->getChildren().size());
[9646]88        EXPECT_TRUE(contains(identifier->getChildren(), Class(RealClass)));
89
90        EXPECT_EQ(1u, identifier->getDirectParents().size());
91        EXPECT_TRUE(contains(identifier->getDirectParents(), Class(OrxonoxInterface)));
92
[9653]93        EXPECT_EQ(4u, identifier->getParents().size());
[9646]94        EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
[9651]95        EXPECT_TRUE(contains(identifier->getParents(), Class(Listable)));
[9653]96        EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable)));
[9646]97        EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxInterface)));
[9637]98    }
99
100    TEST_F(IdentifierSimpleClassHierarchyTest, BaseClass)
101    {
102        Identifier* identifier = Class(BaseClass);
103
[9646]104        EXPECT_EQ(1u, identifier->getDirectChildren().size());
105        EXPECT_TRUE(contains(identifier->getDirectChildren(), Class(RealClass)));
106
[9637]107        EXPECT_EQ(1u, identifier->getChildren().size());
[9646]108        EXPECT_TRUE(contains(identifier->getChildren(), Class(RealClass)));
109
110        EXPECT_EQ(1u, identifier->getDirectParents().size());
111        EXPECT_TRUE(contains(identifier->getDirectParents(), Class(OrxonoxClass)));
112
[9653]113        EXPECT_EQ(4u, identifier->getParents().size());
[9646]114        EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
[9651]115        EXPECT_TRUE(contains(identifier->getParents(), Class(Listable)));
[9653]116        EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable)));
[9646]117        EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass)));
[9637]118    }
119
120    TEST_F(IdentifierSimpleClassHierarchyTest, RealClass)
121    {
122        Identifier* identifier = Class(RealClass);
123
[9646]124        EXPECT_EQ(0u, identifier->getDirectChildren().size());
125
[9637]126        EXPECT_EQ(0u, identifier->getChildren().size());
[9646]127
128        EXPECT_EQ(2u, identifier->getDirectParents().size());
129        EXPECT_TRUE(contains(identifier->getDirectParents(), Class(Interface)));
130        EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseClass)));
131
[9653]132        EXPECT_EQ(7u, identifier->getParents().size());
[9646]133        EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
[9651]134        EXPECT_TRUE(contains(identifier->getParents(), Class(Listable)));
[9653]135        EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable)));
[9646]136        EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxInterface)));
137        EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass)));
138        EXPECT_TRUE(contains(identifier->getParents(), Class(Interface)));
139        EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass)));
[9637]140    }
141}
Note: See TracBrowser for help on using the repository browser.