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