Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/test/core/class/SubclassIdentifierTest.cc @ 11283

Last change on this file since 11283 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: 2.7 KB
RevLine 
[9601]1#include <gtest/gtest.h>
2#include "core/CoreIncludes.h"
3#include "core/class/Identifiable.h"
4#include "core/class/SubclassIdentifier.h"
5#include "core/class/OrxonoxClass.h"
[10624]6#include "core/module/ModuleInstance.h"
[9601]7
8namespace orxonox
9{
10    namespace
11    {
12        class TestClass : public OrxonoxClass
13        {
14            public:
[11071]15                TestClass(Context* context = nullptr) { RegisterObject(TestClass); }
[9601]16        };
17
18        class TestSubclass : public TestClass
19        {
20            public:
[11071]21                TestSubclass(Context* context = nullptr) { RegisterObject(TestSubclass); }
[9601]22        };
23
[10624]24        RegisterClass(TestClass);
25        RegisterClass(TestSubclass);
26
[9647]27        // Fixture
28        class SubclassIdentifierTest : public ::testing::Test
29        {
30            public:
[11071]31                virtual void SetUp() override
[9647]32                {
[10624]33                    new IdentifierManager();
34                    ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
[11071]35                    Context::setRootContext(new Context(nullptr));
[10624]36                    Identifier::initConfigValues_s = false; // TODO: hack!
[9647]37                    IdentifierManager::getInstance().createClassHierarchy();
38                }
39
[11071]40                virtual void TearDown() override
[9647]41                {
[10624]42                    IdentifierManager::getInstance().destroyClassHierarchy();
43                    Context::destroyRootContext();
44                    ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
45                    delete &IdentifierManager::getInstance();
[9647]46                }
47        };
[9601]48    }
49
[9647]50    TEST_F(SubclassIdentifierTest, CanCreateIdentifier)
[9601]51    {
52        TestSubclass test;
53
54        SubclassIdentifier<TestClass> subclassIdentifier;
55    }
56
[9647]57    TEST_F(SubclassIdentifierTest, DefaultsToNormalIdentifier)
[9601]58    {
59        TestSubclass test;
60
61        SubclassIdentifier<TestClass> subclassIdentifier;
62        EXPECT_EQ(Class(TestClass), subclassIdentifier.getIdentifier());
63    }
64
[9647]65    TEST_F(SubclassIdentifierTest, CanAssignIdentifierOfSubclass)
[9601]66    {
67        TestSubclass test;
68        SubclassIdentifier<TestClass> subclassIdentifier;
69        subclassIdentifier = Class(TestSubclass);
70        EXPECT_EQ(Class(TestSubclass), subclassIdentifier.getIdentifier());
71    }
72
[9647]73    TEST_F(SubclassIdentifierTest, CanCreateSubclass)
[9601]74    {
75        TestSubclass test;
76        SubclassIdentifier<TestClass> subclassIdentifier;
77        subclassIdentifier = Class(TestSubclass);
78
[11071]79        TestClass* instance = subclassIdentifier.fabricate(nullptr);
80        ASSERT_TRUE(instance != nullptr);
[9601]81        EXPECT_EQ(Class(TestSubclass), instance->getIdentifier());
82        delete instance;
83    }
84}
Note: See TracBrowser for help on using the repository browser.