diff options
author | Jacek Antonelli | 2008-08-15 23:44:54 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:54 -0500 |
commit | b2afb8800bb033a04bb3ecdf0363068d56648ef1 (patch) | |
tree | 3568129b5bbddb47cd39d622b4137a8fbff4abaf /linden/indra/test/llsdmessagereader_tut.cpp | |
parent | Second Life viewer sources 1.14.0.1 (diff) | |
download | meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.zip meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.gz meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.bz2 meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.xz |
Second Life viewer sources 1.15.0.2
Diffstat (limited to 'linden/indra/test/llsdmessagereader_tut.cpp')
-rwxr-xr-x | linden/indra/test/llsdmessagereader_tut.cpp | 320 |
1 files changed, 320 insertions, 0 deletions
diff --git a/linden/indra/test/llsdmessagereader_tut.cpp b/linden/indra/test/llsdmessagereader_tut.cpp new file mode 100755 index 0000000..707cf31 --- /dev/null +++ b/linden/indra/test/llsdmessagereader_tut.cpp | |||
@@ -0,0 +1,320 @@ | |||
1 | /** | ||
2 | * @file llsdmessagereader_tut.cpp | ||
3 | * @date February 2006 | ||
4 | * @brief LLSDMessageReader unit tests | ||
5 | * | ||
6 | * Copyright (c) 2006-2007, Linden Research, Inc. | ||
7 | * | ||
8 | * Second Life Viewer Source Code | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
10 | * to you under the terms of the GNU General Public License, version 2.0 | ||
11 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
12 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
13 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
14 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
15 | * | ||
16 | * There are special exceptions to the terms and conditions of the GPL as | ||
17 | * it is applied to this Source Code. View the full text of the exception | ||
18 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
19 | * online at http://secondlife.com/developers/opensource/flossexception | ||
20 | * | ||
21 | * By copying, modifying or distributing this software, you acknowledge | ||
22 | * that you have read and understood your obligations described above, | ||
23 | * and agree to abide by those obligations. | ||
24 | * | ||
25 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
27 | * COMPLETENESS OR PERFORMANCE. | ||
28 | */ | ||
29 | |||
30 | #include <tut/tut.h> | ||
31 | #include "lltut.h" | ||
32 | |||
33 | #include "llsdmessagereader.h" | ||
34 | #include "llsdutil.h" | ||
35 | |||
36 | namespace tut | ||
37 | { | ||
38 | struct LLSDMessageReaderTestData { | ||
39 | static void ensureMessageName(const std::string& msg_name, | ||
40 | const LLSD& msg_data, | ||
41 | const std::string& expected_name) | ||
42 | { | ||
43 | LLSDMessageReader msg; | ||
44 | msg.setMessage(msg_name, msg_data); | ||
45 | ensure_equals("Ensure name", std::string(msg.getMessageName()), | ||
46 | expected_name); | ||
47 | } | ||
48 | |||
49 | static void ensureNumberOfBlocks(const LLSD& msg_data, | ||
50 | const std::string& block, | ||
51 | S32 expected_number) | ||
52 | { | ||
53 | LLSDMessageReader msg; | ||
54 | msg.setMessage("fakename", msg_data); | ||
55 | ensure_equals("Ensure number of blocks", msg.getNumberOfBlocks(block.c_str()), | ||
56 | expected_number); | ||
57 | } | ||
58 | |||
59 | static void ensureMessageSize(const LLSD& msg_data, | ||
60 | S32 expected_size) | ||
61 | { | ||
62 | LLSDMessageReader msg; | ||
63 | msg.setMessage("fakename", msg_data); | ||
64 | ensure_equals( "Ensure size", msg.getMessageSize(), expected_size); | ||
65 | } | ||
66 | |||
67 | static void ensureBool(const LLSD& msg_data, | ||
68 | const std::string& block, | ||
69 | const std::string& var, | ||
70 | S32 blocknum, | ||
71 | BOOL expected) | ||
72 | { | ||
73 | LLSDMessageReader msg; | ||
74 | msg.setMessage("fakename", msg_data); | ||
75 | BOOL test_data; | ||
76 | msg.getBOOL(block.c_str(), var.c_str(), test_data, blocknum); | ||
77 | ensure_equals( "Ensure bool field", test_data, expected); | ||
78 | } | ||
79 | }; | ||
80 | |||
81 | typedef test_group<LLSDMessageReaderTestData> LLSDMessageReaderTestGroup; | ||
82 | typedef LLSDMessageReaderTestGroup::object LLSDMessageReaderTestObject; | ||
83 | LLSDMessageReaderTestGroup llsdMessageReaderTestGroup("LLSDMessageReader"); | ||
84 | |||
85 | template<> template<> | ||
86 | void LLSDMessageReaderTestObject::test<1>() | ||
87 | // construction and test of empty LLSD | ||
88 | { | ||
89 | LLSD message = LLSD::emptyMap(); | ||
90 | |||
91 | ensureMessageName("", message, ""); | ||
92 | ensureNumberOfBlocks(message, "Fakeblock", 0); | ||
93 | ensureMessageSize(message, 0); | ||
94 | } | ||
95 | |||
96 | template<> template<> | ||
97 | void LLSDMessageReaderTestObject::test<2>() | ||
98 | // construction and test of simple message with one block | ||
99 | { | ||
100 | LLSD message = LLSD::emptyMap(); | ||
101 | message["block1"] = LLSD::emptyArray(); | ||
102 | message["block1"][0] = LLSD::emptyMap(); | ||
103 | message["block1"][0]["Field1"] = 0; | ||
104 | |||
105 | ensureMessageName("name2", message, "name2"); | ||
106 | ensureNumberOfBlocks(message, "block1", 1); | ||
107 | ensureMessageSize(message, 0); | ||
108 | } | ||
109 | |||
110 | template<> template<> | ||
111 | void LLSDMessageReaderTestObject::test<3>() | ||
112 | // multiple blocks | ||
113 | { | ||
114 | LLSD message = LLSD::emptyMap(); | ||
115 | message["block1"] = LLSD::emptyArray(); | ||
116 | BOOL bool_true = TRUE; | ||
117 | BOOL bool_false = FALSE; | ||
118 | message["block1"][0] = LLSD::emptyMap(); | ||
119 | message["block1"][0]["BoolField1"] = bool_true; | ||
120 | message["block1"][1] = LLSD::emptyMap(); | ||
121 | message["block1"][1]["BoolField1"] = bool_false; | ||
122 | message["block1"][1]["BoolField2"] = bool_true; | ||
123 | |||
124 | ensureMessageName("name3", message, "name3"); | ||
125 | ensureBool(message, "block1", "BoolField1", 0, TRUE); | ||
126 | ensureBool(message, "block1", "BoolField1", 1, FALSE); | ||
127 | ensureBool(message, "block1", "BoolField2", 1, TRUE); | ||
128 | ensureNumberOfBlocks(message, "block1", 2); | ||
129 | ensureMessageSize(message, 0); | ||
130 | } | ||
131 | |||
132 | template<typename T> | ||
133 | LLSDMessageReader testType(const T& value) | ||
134 | { | ||
135 | LLSD message = LLSD::emptyMap(); | ||
136 | message["block"][0]["var"] = value; | ||
137 | LLSDMessageReader msg; | ||
138 | msg.setMessage("fakename", message); | ||
139 | return msg; | ||
140 | } | ||
141 | |||
142 | template<> template<> | ||
143 | void LLSDMessageReaderTestObject::test<4>() | ||
144 | // S8 | ||
145 | { | ||
146 | S8 outValue, inValue = -3; | ||
147 | LLSDMessageReader msg = testType(inValue); | ||
148 | msg.getS8("block", "var", outValue); | ||
149 | ensure_equals("Ensure S8", outValue, inValue); | ||
150 | } | ||
151 | template<> template<> | ||
152 | void | ||
153 | LLSDMessageReaderTestObject::test<5>() | ||
154 | // U8 | ||
155 | { | ||
156 | U8 outValue, inValue = 2; | ||
157 | LLSDMessageReader msg = testType(inValue); | ||
158 | msg.getU8("block", "var", outValue); | ||
159 | ensure_equals("Ensure U8", outValue, inValue); | ||
160 | } | ||
161 | template<> template<> | ||
162 | void LLSDMessageReaderTestObject::test<6>() | ||
163 | // S16 | ||
164 | { | ||
165 | S16 outValue, inValue = 90; | ||
166 | LLSDMessageReader msg = testType(inValue); | ||
167 | msg.getS16("block", "var", outValue); | ||
168 | ensure_equals("Ensure S16", outValue, inValue); | ||
169 | } | ||
170 | template<> template<> | ||
171 | void LLSDMessageReaderTestObject::test<7>() | ||
172 | // U16 | ||
173 | { | ||
174 | U16 outValue, inValue = 3; | ||
175 | LLSDMessageReader msg = testType(inValue); | ||
176 | msg.getU16("block", "var", outValue); | ||
177 | ensure_equals("Ensure S16", outValue, inValue); | ||
178 | } | ||
179 | template<> template<> | ||
180 | void LLSDMessageReaderTestObject::test<8>() | ||
181 | // S32 | ||
182 | { | ||
183 | S32 outValue, inValue = 44; | ||
184 | LLSDMessageReader msg = testType(inValue); | ||
185 | msg.getS32("block", "var", outValue); | ||
186 | ensure_equals("Ensure S32", outValue, inValue); | ||
187 | } | ||
188 | template<> template<> | ||
189 | void LLSDMessageReaderTestObject::test<9>() | ||
190 | // F32 | ||
191 | { | ||
192 | F32 outValue, inValue = 121.44; | ||
193 | LLSDMessageReader msg = testType(inValue); | ||
194 | msg.getF32("block", "var", outValue); | ||
195 | ensure_equals("Ensure F32", outValue, inValue); | ||
196 | } | ||
197 | template<> template<> | ||
198 | void LLSDMessageReaderTestObject::test<10>() | ||
199 | // U32 | ||
200 | { | ||
201 | U32 outValue, inValue = 88; | ||
202 | LLSD sdValue = ll_sd_from_U32(inValue); | ||
203 | LLSDMessageReader msg = testType(sdValue); | ||
204 | msg.getU32("block", "var", outValue); | ||
205 | ensure_equals("Ensure U32", outValue, inValue); | ||
206 | } | ||
207 | template<> template<> | ||
208 | void LLSDMessageReaderTestObject::test<11>() | ||
209 | // U64 | ||
210 | { | ||
211 | U64 outValue, inValue = 121; | ||
212 | LLSD sdValue = ll_sd_from_U64(inValue); | ||
213 | LLSDMessageReader msg = testType(sdValue); | ||
214 | msg.getU64("block", "var", outValue); | ||
215 | ensure_equals("Ensure U64", outValue, inValue); | ||
216 | } | ||
217 | template<> template<> | ||
218 | void LLSDMessageReaderTestObject::test<12>() | ||
219 | // F64 | ||
220 | { | ||
221 | F64 outValue, inValue = 3232143.33; | ||
222 | LLSDMessageReader msg = testType(inValue); | ||
223 | msg.getF64("block", "var", outValue); | ||
224 | ensure_equals("Ensure F64", outValue, inValue); | ||
225 | } | ||
226 | template<> template<> | ||
227 | void LLSDMessageReaderTestObject::test<13>() | ||
228 | // String | ||
229 | { | ||
230 | std::string outValue, inValue = "testing"; | ||
231 | LLSDMessageReader msg = testType<std::string>(inValue.c_str()); | ||
232 | |||
233 | char buffer[MAX_STRING]; | ||
234 | msg.getString("block", "var", MAX_STRING, buffer); | ||
235 | outValue = buffer; | ||
236 | ensure_equals("Ensure String", outValue, inValue); | ||
237 | } | ||
238 | template<> template<> | ||
239 | void LLSDMessageReaderTestObject::test<14>() | ||
240 | // Vector3 | ||
241 | { | ||
242 | LLVector3 outValue, inValue = LLVector3(1,2,3); | ||
243 | LLSD sdValue = ll_sd_from_vector3(inValue); | ||
244 | LLSDMessageReader msg = testType(sdValue); | ||
245 | msg.getVector3("block", "var", outValue); | ||
246 | ensure_equals("Ensure Vector3", outValue, inValue); | ||
247 | } | ||
248 | template<> template<> | ||
249 | void LLSDMessageReaderTestObject::test<15>() | ||
250 | // Vector4 | ||
251 | { | ||
252 | LLVector4 outValue, inValue = LLVector4(1,2,3,4); | ||
253 | LLSD sdValue = ll_sd_from_vector4(inValue); | ||
254 | LLSDMessageReader msg = testType(sdValue); | ||
255 | msg.getVector4("block", "var", outValue); | ||
256 | ensure_equals("Ensure Vector4", outValue, inValue); | ||
257 | } | ||
258 | template<> template<> | ||
259 | void LLSDMessageReaderTestObject::test<16>() | ||
260 | // Vector3d | ||
261 | { | ||
262 | LLVector3d outValue, inValue = LLVector3d(1,2,3); | ||
263 | LLSD sdValue = ll_sd_from_vector3d(inValue); | ||
264 | LLSDMessageReader msg = testType(sdValue); | ||
265 | msg.getVector3d("block", "var", outValue); | ||
266 | ensure_equals("Ensure Vector3d", outValue, inValue); | ||
267 | } | ||
268 | template<> template<> | ||
269 | void LLSDMessageReaderTestObject::test<17>() | ||
270 | // Quaternion | ||
271 | { | ||
272 | LLQuaternion outValue, inValue = LLQuaternion(1,2,3,4); | ||
273 | LLSD sdValue = ll_sd_from_quaternion(inValue); | ||
274 | LLSDMessageReader msg = testType(sdValue); | ||
275 | msg.getQuat("block", "var", outValue); | ||
276 | ensure_equals("Ensure Quaternion", outValue, inValue); | ||
277 | } | ||
278 | template<> template<> | ||
279 | void LLSDMessageReaderTestObject::test<18>() | ||
280 | // UUID | ||
281 | { | ||
282 | LLUUID outValue, inValue; | ||
283 | inValue.generate(); | ||
284 | LLSDMessageReader msg = testType(inValue); | ||
285 | msg.getUUID("block", "var", outValue); | ||
286 | ensure_equals("Ensure UUID", outValue, inValue); | ||
287 | } | ||
288 | template<> template<> | ||
289 | void LLSDMessageReaderTestObject::test<19>() | ||
290 | // IPAddr | ||
291 | { | ||
292 | U32 outValue, inValue = 12344556; | ||
293 | LLSD sdValue = ll_sd_from_ipaddr(inValue); | ||
294 | LLSDMessageReader msg = testType(sdValue); | ||
295 | msg.getIPAddr("block", "var", outValue); | ||
296 | ensure_equals("Ensure IPAddr", outValue, inValue); | ||
297 | } | ||
298 | template<> template<> | ||
299 | void LLSDMessageReaderTestObject::test<20>() | ||
300 | // IPPort | ||
301 | { | ||
302 | U16 outValue, inValue = 80; | ||
303 | LLSDMessageReader msg = testType(inValue); | ||
304 | msg.getIPPort("block", "var", outValue); | ||
305 | ensure_equals("Ensure IPPort", outValue, inValue); | ||
306 | } | ||
307 | template<> template<> | ||
308 | void LLSDMessageReaderTestObject::test<21>() | ||
309 | // Binary | ||
310 | { | ||
311 | std::vector<U8> outValue(2), inValue(2); | ||
312 | inValue[0] = 0; | ||
313 | inValue[1] = 1; | ||
314 | |||
315 | LLSDMessageReader msg = testType(inValue); | ||
316 | msg.getBinaryData("block", "var", &(outValue[0]), inValue.size()); | ||
317 | ensure_equals("Ensure Binary", outValue, inValue); | ||
318 | } | ||
319 | } | ||
320 | |||