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) { 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 | } |
---|