aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/test/reflection_tut.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/test/reflection_tut.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r--linden/indra/test/reflection_tut.cpp223
1 files changed, 223 insertions, 0 deletions
diff --git a/linden/indra/test/reflection_tut.cpp b/linden/indra/test/reflection_tut.cpp
new file mode 100644
index 0000000..a7b46d4
--- /dev/null
+++ b/linden/indra/test/reflection_tut.cpp
@@ -0,0 +1,223 @@
1/**
2 * @file reflection_tut.cpp
3 * @date May 2006
4 * @brief Reflection unit tests.
5 *
6 * Copyright (c) 2006-2007, Linden Research, Inc.
7 *
8 * The source code in this file ("Source Code") is provided by Linden Lab
9 * to you under the terms of the GNU General Public License, version 2.0
10 * ("GPL"), unless you have obtained a separate licensing agreement
11 * ("Other License"), formally executed by you and Linden Lab. Terms of
12 * the GPL can be found in doc/GPL-license.txt in this distribution, or
13 * online at http://secondlife.com/developers/opensource/gplv2
14 *
15 * There are special exceptions to the terms and conditions of the GPL as
16 * it is applied to this Source Code. View the full text of the exception
17 * in the file doc/FLOSS-exception.txt in this software distribution, or
18 * online at http://secondlife.com/developers/opensource/flossexception
19 *
20 * By copying, modifying or distributing this software, you acknowledge
21 * that you have read and understood your obligations described above,
22 * and agree to abide by those obligations.
23 *
24 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
25 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
26 * COMPLETENESS OR PERFORMANCE.
27 */
28
29#include <tut/tut.h>
30
31#include "lltut.h"
32#include "reflective.h"
33#include "metaclasst.h"
34#include "metapropertyt.h"
35//#include "referencemetaproperty.h"
36#include "stdtypes.h"
37//#include "reflectivemetapropertyt.h"
38
39namespace tut
40{
41 class TestAggregatedData : public LLReflective
42 {
43 public:
44 TestAggregatedData() {;}
45 virtual const LLMetaClass& getMetaClass() const;
46
47 private:
48 };
49
50 class TestReflectionData : public LLReflective
51 {
52 public:
53 TestReflectionData() : mInt(42), mString("foo"), mNullPtr(NULL), mPtr(new TestAggregatedData()), mRef(*(new TestAggregatedData)) {;}
54 virtual ~TestReflectionData() {delete mPtr;}
55 virtual const LLMetaClass& getMetaClass() const;
56
57 static U32 getPropertyCount() {return 5;}
58
59 private:
60
61 friend class LLMetaClassT<TestReflectionData>;
62 S32 mInt;
63 std::string mString;
64 TestAggregatedData* mNullPtr;
65 TestAggregatedData* mPtr;
66 TestAggregatedData mObj;
67 TestAggregatedData& mRef;
68 };
69}
70
71template <>
72void LLMetaClassT<tut::TestReflectionData>::reflectProperties(LLMetaClass& meta_class)
73{
74 reflectProperty(meta_class, "mInt", &tut::TestReflectionData::mInt);
75 reflectProperty(meta_class, "mString", &tut::TestReflectionData::mString);
76 reflectPtrProperty(meta_class, "mNullPtr", &tut::TestReflectionData::mNullPtr);
77 reflectPtrProperty(meta_class, "mPtr", &tut::TestReflectionData::mPtr);
78 reflectProperty(meta_class, "mObj", &tut::TestReflectionData::mObj);
79 //reflectProperty(meta_class, "mRef", &tut::TestReflectionData::mRef); // AARGH!
80}
81
82namespace tut
83{
84 // virtual
85 const LLMetaClass& TestReflectionData::getMetaClass() const
86 {
87 return LLMetaClassT<TestReflectionData>::instance();
88 }
89
90 const LLMetaClass& TestAggregatedData::getMetaClass() const
91 {
92 return LLMetaClassT<TestAggregatedData>::instance();
93 }
94}
95
96namespace tut
97{
98 typedef tut::test_group<TestReflectionData> TestReflectionGroup;
99 typedef TestReflectionGroup::object TestReflectionObject;
100 TestReflectionGroup gTestReflectionGroup("reflection");
101
102 template<> template<>
103 void TestReflectionObject::test<1>()
104 {
105 // Check properties can be found.
106 const LLMetaClass& meta_class = LLMetaClassT<TestReflectionData>::instance();
107 const LLMetaProperty* null = NULL;
108 ensure_not_equals(meta_class.findProperty("mInt"), null);
109 ensure_not_equals(meta_class.findProperty("mString"), null);
110 }
111
112 template<> template<>
113 void TestReflectionObject::test<2>()
114 {
115 // Check non-existent property cannot be found.
116 const LLMetaClass& meta_class = LLMetaClassT<TestReflectionData>::instance();
117 const LLMetaProperty* null = NULL;
118 ensure_equals(meta_class.findProperty("foo"), null);
119 }
120
121 template<> template<>
122 void TestReflectionObject::test<3>()
123 {
124 // Check integer property has correct value.
125 const LLMetaClass& meta_class = LLMetaClassT<TestReflectionData>::instance();
126 ensure_equals(meta_class.findProperty("mInt")->getLLSD(this).asInteger(), 42);
127 }
128
129 template<> template<>
130 void TestReflectionObject::test<4>()
131 {
132 // Check string property has correct value.
133 const LLMetaClass& meta_class = LLMetaClassT<TestReflectionData>::instance();
134 ensure_equals(meta_class.findProperty("mString")->getLLSD(this).asString(), std::string("foo"));
135 }
136
137 template<> template<>
138 void TestReflectionObject::test<5>()
139 {
140 // Check NULL reference property has correct value.
141 const LLMetaClass& meta_class = LLMetaClassT<TestReflectionData>::instance();
142 const LLReflective* null = NULL;
143 ensure_equals(meta_class.findProperty("mNullPtr")->get(this), null);
144 }
145
146 template<> template<>
147 void TestReflectionObject::test<6>()
148 {
149 // Check reference property has correct value.
150 const LLMetaClass& meta_class = LLMetaClassT<TestReflectionData>::instance();
151 const LLReflective* null = NULL;
152 const LLReflective* ref = meta_class.findProperty("mPtr")->get(this);
153 ensure_not_equals(ref, null);
154 }
155
156 template<> template<>
157 void TestReflectionObject::test<7>()
158 {
159 // Check reflective property has correct value.
160 const LLMetaClass& meta_class = LLMetaClassT<TestReflectionData>::instance();
161 const LLReflective* null = NULL;
162 const LLReflective* ref = meta_class.findProperty("mObj")->get(this);
163 ensure_not_equals(ref, null);
164 }
165
166 template<> template<>
167 void TestReflectionObject::test<8>()
168 {
169 // Check property count.
170 const LLMetaClass& meta_class = LLMetaClassT<TestReflectionData>::instance();
171 ensure_equals(meta_class.getPropertyCount(), TestReflectionData::getPropertyCount());
172 }
173
174 template<> template<>
175 void TestReflectionObject::test<9>()
176 {
177 // Check property iteration.
178 const LLMetaClass& meta_class = LLMetaClassT<TestReflectionData>::instance();
179 U32 count = 0;
180 LLMetaClass::PropertyIterator iter;
181 for(iter = meta_class.beginProperties(); iter != meta_class.endProperties(); ++iter)
182 {
183 ++count;
184 }
185 ensure_equals(count, TestReflectionData::getPropertyCount());
186 }
187
188 template<> template<>
189 void TestReflectionObject::test<10>()
190 {
191 // Check meta classes of different types do not compare equal.
192 const LLMetaClass* reflection_data_meta_class = &(LLMetaClassT<TestReflectionData>::instance());
193 const LLMetaClass* aggregated_data_meta_class = &(LLMetaClassT<TestAggregatedData>::instance());
194 ensure_not_equals(reflection_data_meta_class, aggregated_data_meta_class);
195 }
196
197 template<> template<>
198 void TestReflectionObject::test<11>()
199 {
200 // Check class cast checks.
201 const LLMetaClass& meta_class = LLMetaClassT<TestReflectionData>::instance();
202 TestAggregatedData* aggregated_data = new TestAggregatedData();
203 LLMetaClass::PropertyIterator iter;
204 U32 exception_count = 0;
205 for(iter = meta_class.beginProperties(); iter != meta_class.endProperties(); ++iter)
206 {
207 try
208 {
209 const LLMetaProperty* property = (*iter).second;
210 const LLReflective* reflective = property->get(aggregated_data); // Wrong reflective type, should throw exception.
211
212 // useless op to get rid of compiler warning.
213 reflective = NULL;
214 }
215 catch(...)
216 {
217 ++exception_count;
218 }
219 }
220 ensure_equals(exception_count, getPropertyCount());
221
222 }
223}