Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core6/test/core/class/SubclassIdentifierTest.cc @ 9630

Last change on this file since 9630 was 9629, checked in by landauf, 11 years ago

BaseObject now requires a Context instead of a creator (BaseObject*) in its constructor.
Namespace, Level, and Scene inherit from Context

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
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"
6
7namespace orxonox
8{
9    namespace
10    {
11        class TestClass : public OrxonoxClass
12        {
13            public:
14                TestClass(Context* context = NULL) { RegisterRootObject(TestClass); }
15        };
16
17        class TestSubclass : public TestClass
18        {
19            public:
20                TestSubclass(Context* context = NULL) { RegisterObject(TestSubclass); }
21        };
22
23        CreateFactory(TestClass);
24        CreateFactory(TestSubclass);
25    }
26
27    TEST(SubclassIdentifierTest, CanCreateIdentifier)
28    {
29        TestSubclass test;
30
31        SubclassIdentifier<TestClass> subclassIdentifier;
32    }
33
34    TEST(SubclassIdentifierTest, DefaultsToNormalIdentifier)
35    {
36        TestSubclass test;
37
38        SubclassIdentifier<TestClass> subclassIdentifier;
39        EXPECT_EQ(Class(TestClass), subclassIdentifier.getIdentifier());
40    }
41
42    TEST(SubclassIdentifierTest, CanAssignIdentifierOfSubclass)
43    {
44        TestSubclass test;
45        IdentifierManager::createClassHierarchy();
46
47        SubclassIdentifier<TestClass> subclassIdentifier;
48        subclassIdentifier = Class(TestSubclass);
49        EXPECT_EQ(Class(TestSubclass), subclassIdentifier.getIdentifier());
50    }
51
52    TEST(SubclassIdentifierTest, CanCreateSubclass)
53    {
54        TestSubclass test;
55        IdentifierManager::createClassHierarchy();
56
57        SubclassIdentifier<TestClass> subclassIdentifier;
58        subclassIdentifier = Class(TestSubclass);
59
60        TestClass* instance = subclassIdentifier.fabricate(NULL);
61        ASSERT_TRUE(instance != NULL);
62        EXPECT_EQ(Class(TestSubclass), instance->getIdentifier());
63        delete instance;
64    }
65}
Note: See TracBrowser for help on using the repository browser.