1 | #include <gtest/gtest.h> |
---|
2 | #include "core/CoreIncludes.h" |
---|
3 | #include "core/class/Identifiable.h" |
---|
4 | #include "core/class/OrxonoxClass.h" |
---|
5 | #include "core/class/OrxonoxInterface.h" |
---|
6 | #include "core/module/ModuleInstance.h" |
---|
7 | |
---|
8 | namespace orxonox |
---|
9 | { |
---|
10 | namespace |
---|
11 | { |
---|
12 | class Interface : virtual public OrxonoxInterface |
---|
13 | { |
---|
14 | public: |
---|
15 | Interface() |
---|
16 | { |
---|
17 | RegisterObject(Interface); |
---|
18 | } |
---|
19 | |
---|
20 | virtual void test() = 0; |
---|
21 | }; |
---|
22 | |
---|
23 | class BaseClass : public OrxonoxClass |
---|
24 | { |
---|
25 | public: |
---|
26 | BaseClass() |
---|
27 | { |
---|
28 | RegisterObject(BaseClass); |
---|
29 | } |
---|
30 | }; |
---|
31 | |
---|
32 | class RealClass : public BaseClass, public Interface |
---|
33 | { |
---|
34 | public: |
---|
35 | RealClass() |
---|
36 | { |
---|
37 | RegisterObject(RealClass); |
---|
38 | } |
---|
39 | |
---|
40 | virtual void test() {} |
---|
41 | }; |
---|
42 | |
---|
43 | RegisterAbstractClass(Interface).inheritsFrom<OrxonoxInterface>(); |
---|
44 | RegisterClassNoArgs(BaseClass); |
---|
45 | RegisterClassNoArgs(RealClass); |
---|
46 | |
---|
47 | // Fixture |
---|
48 | class IdentifierSimpleClassHierarchyTest : public ::testing::Test |
---|
49 | { |
---|
50 | public: |
---|
51 | virtual void SetUp() |
---|
52 | { |
---|
53 | ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(); |
---|
54 | Identifier::initConfigValues_s = false; // TODO: hack! |
---|
55 | IdentifierManager::getInstance().createClassHierarchy(); |
---|
56 | } |
---|
57 | |
---|
58 | virtual void TearDown() |
---|
59 | { |
---|
60 | IdentifierManager::getInstance().destroyClassHierarchy(); |
---|
61 | ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(); |
---|
62 | } |
---|
63 | }; |
---|
64 | |
---|
65 | bool contains(const std::list<const Identifier*> identifiers, Identifier* identifier) |
---|
66 | { |
---|
67 | return std::find(identifiers.begin(), identifiers.end(), identifier) != identifiers.end(); |
---|
68 | } |
---|
69 | |
---|
70 | bool contains(const std::set<const Identifier*> identifiers, Identifier* identifier) |
---|
71 | { |
---|
72 | return identifiers.find(identifier) != identifiers.end(); |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | TEST(IdentifierSimpleClassHierarchyTest_NoFixture, NoInitialization) |
---|
77 | { |
---|
78 | { |
---|
79 | Identifier* identifier = Class(Interface); |
---|
80 | EXPECT_EQ(0u, identifier->getChildren().size()); |
---|
81 | EXPECT_EQ(0u, identifier->getParents().size()); |
---|
82 | } |
---|
83 | { |
---|
84 | Identifier* identifier = Class(BaseClass); |
---|
85 | EXPECT_EQ(0u, identifier->getChildren().size()); |
---|
86 | EXPECT_EQ(0u, identifier->getParents().size()); |
---|
87 | } |
---|
88 | { |
---|
89 | Identifier* identifier = Class(RealClass); |
---|
90 | EXPECT_EQ(0u, identifier->getChildren().size()); |
---|
91 | EXPECT_EQ(0u, identifier->getParents().size()); |
---|
92 | } |
---|
93 | } |
---|
94 | |
---|
95 | TEST_F(IdentifierSimpleClassHierarchyTest, TestInterface) |
---|
96 | { |
---|
97 | Identifier* identifier = Class(Interface); |
---|
98 | |
---|
99 | EXPECT_EQ(1u, identifier->getDirectChildren().size()); |
---|
100 | EXPECT_TRUE(contains(identifier->getDirectChildren(), Class(RealClass))); |
---|
101 | |
---|
102 | EXPECT_EQ(1u, identifier->getChildren().size()); |
---|
103 | EXPECT_TRUE(contains(identifier->getChildren(), Class(RealClass))); |
---|
104 | |
---|
105 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
106 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(OrxonoxInterface))); |
---|
107 | |
---|
108 | EXPECT_EQ(4u, identifier->getParents().size()); |
---|
109 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
110 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
111 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
112 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxInterface))); |
---|
113 | } |
---|
114 | |
---|
115 | TEST_F(IdentifierSimpleClassHierarchyTest, BaseClass) |
---|
116 | { |
---|
117 | Identifier* identifier = Class(BaseClass); |
---|
118 | |
---|
119 | EXPECT_EQ(1u, identifier->getDirectChildren().size()); |
---|
120 | EXPECT_TRUE(contains(identifier->getDirectChildren(), Class(RealClass))); |
---|
121 | |
---|
122 | EXPECT_EQ(1u, identifier->getChildren().size()); |
---|
123 | EXPECT_TRUE(contains(identifier->getChildren(), Class(RealClass))); |
---|
124 | |
---|
125 | EXPECT_EQ(1u, identifier->getDirectParents().size()); |
---|
126 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(OrxonoxClass))); |
---|
127 | |
---|
128 | EXPECT_EQ(4u, identifier->getParents().size()); |
---|
129 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
130 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
131 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
132 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
133 | } |
---|
134 | |
---|
135 | TEST_F(IdentifierSimpleClassHierarchyTest, RealClass) |
---|
136 | { |
---|
137 | Identifier* identifier = Class(RealClass); |
---|
138 | |
---|
139 | EXPECT_EQ(0u, identifier->getDirectChildren().size()); |
---|
140 | |
---|
141 | EXPECT_EQ(0u, identifier->getChildren().size()); |
---|
142 | |
---|
143 | EXPECT_EQ(2u, identifier->getDirectParents().size()); |
---|
144 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(Interface))); |
---|
145 | EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseClass))); |
---|
146 | |
---|
147 | EXPECT_EQ(7u, identifier->getParents().size()); |
---|
148 | EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); |
---|
149 | EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); |
---|
150 | EXPECT_TRUE(contains(identifier->getParents(), Class(Configurable))); |
---|
151 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxInterface))); |
---|
152 | EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); |
---|
153 | EXPECT_TRUE(contains(identifier->getParents(), Class(Interface))); |
---|
154 | EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); |
---|
155 | } |
---|
156 | } |
---|