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 | #include "core/module/ModuleInstance.h" |
---|
7 | |
---|
8 | namespace orxonox |
---|
9 | { |
---|
10 | namespace |
---|
11 | { |
---|
12 | class TestClass : public OrxonoxClass |
---|
13 | { |
---|
14 | public: |
---|
15 | TestClass(Context* context = NULL) { RegisterObject(TestClass); } |
---|
16 | }; |
---|
17 | |
---|
18 | class TestSubclass : public TestClass |
---|
19 | { |
---|
20 | public: |
---|
21 | TestSubclass(Context* context = NULL) { RegisterObject(TestSubclass); } |
---|
22 | }; |
---|
23 | |
---|
24 | RegisterClass(TestClass); |
---|
25 | RegisterClass(TestSubclass); |
---|
26 | |
---|
27 | // Fixture |
---|
28 | class SubclassIdentifierTest : public ::testing::Test |
---|
29 | { |
---|
30 | public: |
---|
31 | virtual void SetUp() |
---|
32 | { |
---|
33 | ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(); |
---|
34 | Identifier::initConfigValues_s = false; // TODO: hack! |
---|
35 | IdentifierManager::getInstance().createClassHierarchy(); |
---|
36 | |
---|
37 | Context::setRootContext(new Context(NULL)); |
---|
38 | } |
---|
39 | |
---|
40 | virtual void TearDown() |
---|
41 | { |
---|
42 | Context::setRootContext(NULL); |
---|
43 | |
---|
44 | IdentifierManager::getInstance().destroyClassHierarchy(); |
---|
45 | ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(); |
---|
46 | } |
---|
47 | }; |
---|
48 | } |
---|
49 | |
---|
50 | TEST_F(SubclassIdentifierTest, CanCreateIdentifier) |
---|
51 | { |
---|
52 | TestSubclass test; |
---|
53 | |
---|
54 | SubclassIdentifier<TestClass> subclassIdentifier; |
---|
55 | } |
---|
56 | |
---|
57 | TEST_F(SubclassIdentifierTest, DefaultsToNormalIdentifier) |
---|
58 | { |
---|
59 | TestSubclass test; |
---|
60 | |
---|
61 | SubclassIdentifier<TestClass> subclassIdentifier; |
---|
62 | EXPECT_EQ(Class(TestClass), subclassIdentifier.getIdentifier()); |
---|
63 | } |
---|
64 | |
---|
65 | TEST_F(SubclassIdentifierTest, CanAssignIdentifierOfSubclass) |
---|
66 | { |
---|
67 | TestSubclass test; |
---|
68 | SubclassIdentifier<TestClass> subclassIdentifier; |
---|
69 | subclassIdentifier = Class(TestSubclass); |
---|
70 | EXPECT_EQ(Class(TestSubclass), subclassIdentifier.getIdentifier()); |
---|
71 | } |
---|
72 | |
---|
73 | TEST_F(SubclassIdentifierTest, CanCreateSubclass) |
---|
74 | { |
---|
75 | TestSubclass test; |
---|
76 | SubclassIdentifier<TestClass> subclassIdentifier; |
---|
77 | subclassIdentifier = Class(TestSubclass); |
---|
78 | |
---|
79 | TestClass* instance = subclassIdentifier.fabricate(NULL); |
---|
80 | ASSERT_TRUE(instance != NULL); |
---|
81 | EXPECT_EQ(Class(TestSubclass), instance->getIdentifier()); |
---|
82 | delete instance; |
---|
83 | } |
---|
84 | } |
---|