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