diff options
author | Jacek Antonelli | 2008-08-15 23:45:02 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:02 -0500 |
commit | d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd (patch) | |
tree | 7ed0c2c27d717801238a2e6b5749cd5bf88c3059 /linden/indra/test/lltemplatemessagebuilder_tut.cpp | |
parent | Second Life viewer sources 1.17.3.0 (diff) | |
download | meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.zip meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.tar.gz meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.tar.bz2 meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.tar.xz |
Second Life viewer sources 1.18.0.6
Diffstat (limited to 'linden/indra/test/lltemplatemessagebuilder_tut.cpp')
-rw-r--r-- | linden/indra/test/lltemplatemessagebuilder_tut.cpp | 964 |
1 files changed, 964 insertions, 0 deletions
diff --git a/linden/indra/test/lltemplatemessagebuilder_tut.cpp b/linden/indra/test/lltemplatemessagebuilder_tut.cpp new file mode 100644 index 0000000..d25e57e --- /dev/null +++ b/linden/indra/test/lltemplatemessagebuilder_tut.cpp | |||
@@ -0,0 +1,964 @@ | |||
1 | /** | ||
2 | * @file lltemplatemessagebuilder_tut.cpp | ||
3 | * @date 2007-04 | ||
4 | * @brief Tests for building messages. | ||
5 | * | ||
6 | * Copyright (c) 2007-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 "llapr.h" | ||
34 | #include "llmessagetemplate.h" | ||
35 | #include "llquaternion.h" | ||
36 | #include "lltemplatemessagebuilder.h" | ||
37 | #include "lltemplatemessagereader.h" | ||
38 | #include "llversion.h" | ||
39 | #include "message_prehash.h" | ||
40 | #include "u64.h" | ||
41 | #include "v3dmath.h" | ||
42 | #include "v3math.h" | ||
43 | #include "v4math.h" | ||
44 | |||
45 | namespace tut | ||
46 | { | ||
47 | static LLTemplateMessageBuilder::message_template_name_map_t nameMap; | ||
48 | static LLTemplateMessageReader::message_template_number_map_t numberMap; | ||
49 | |||
50 | struct LLTemplateMessageBuilderTestData | ||
51 | { | ||
52 | static LLMessageTemplate defaultTemplate() | ||
53 | { | ||
54 | static bool init = false; | ||
55 | if(! init) | ||
56 | { | ||
57 | ll_init_apr(); | ||
58 | start_messaging_system("notafile", 13035, | ||
59 | LL_VERSION_MAJOR, | ||
60 | LL_VERSION_MINOR, | ||
61 | LL_VERSION_PATCH, | ||
62 | FALSE, | ||
63 | "notasharedsecret"); | ||
64 | init_prehash_data(); | ||
65 | init = true; | ||
66 | } | ||
67 | return LLMessageTemplate(_PREHASH_TestMessage, 1, MFT_HIGH); | ||
68 | } | ||
69 | |||
70 | static LLMessageBlock* defaultBlock(const EMsgVariableType type = MVT_NULL, const S32 size = 0, EMsgBlockType block = MBT_VARIABLE) | ||
71 | { | ||
72 | return createBlock(_PREHASH_Test0, type, size, block); | ||
73 | } | ||
74 | |||
75 | static LLMessageBlock* createBlock(char* name, const EMsgVariableType type = MVT_NULL, const S32 size = 0, EMsgBlockType block = MBT_VARIABLE) | ||
76 | { | ||
77 | LLMessageBlock* result = new LLMessageBlock(name, block); | ||
78 | if(type != MVT_NULL) | ||
79 | { | ||
80 | result->addVariable(_PREHASH_Test0, type, size); | ||
81 | } | ||
82 | return result; | ||
83 | } | ||
84 | |||
85 | static LLTemplateMessageBuilder* defaultBuilder(LLMessageTemplate& messageTemplate, char* name = _PREHASH_Test0) | ||
86 | { | ||
87 | nameMap[_PREHASH_TestMessage] = &messageTemplate; | ||
88 | LLTemplateMessageBuilder* builder = new LLTemplateMessageBuilder(nameMap); | ||
89 | builder->newMessage(_PREHASH_TestMessage); | ||
90 | builder->nextBlock(name); | ||
91 | return builder; | ||
92 | } | ||
93 | |||
94 | /** Takes ownership of builder */ | ||
95 | static LLTemplateMessageReader* setReader( | ||
96 | LLMessageTemplate& messageTemplate, | ||
97 | LLTemplateMessageBuilder* builder, | ||
98 | U8 offset = 0) | ||
99 | { | ||
100 | numberMap[1] = &messageTemplate; | ||
101 | const U32 bufferSize = 1024; | ||
102 | U8 buffer[bufferSize]; | ||
103 | // zero out the packet ID field | ||
104 | memset(buffer, 0, LL_PACKET_ID_SIZE); | ||
105 | U32 builtSize = builder->buildMessage(buffer, bufferSize, offset); | ||
106 | delete builder; | ||
107 | LLTemplateMessageReader* reader = new LLTemplateMessageReader(numberMap); | ||
108 | reader->validateMessage(buffer, builtSize, LLHost()); | ||
109 | reader->readMessage(buffer, LLHost()); | ||
110 | return reader; | ||
111 | } | ||
112 | |||
113 | }; | ||
114 | |||
115 | typedef test_group<LLTemplateMessageBuilderTestData> LLTemplateMessageBuilderTestGroup; | ||
116 | typedef LLTemplateMessageBuilderTestGroup::object LLTemplateMessageBuilderTestObject; | ||
117 | LLTemplateMessageBuilderTestGroup templateMessageBuilderTestGroup("LLTemplateMessageBuilder"); | ||
118 | |||
119 | template<> template<> | ||
120 | void LLTemplateMessageBuilderTestObject::test<1>() | ||
121 | // construction and test of undefined | ||
122 | { | ||
123 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
124 | messageTemplate.addBlock(defaultBlock()); | ||
125 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
126 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
127 | delete reader; | ||
128 | } | ||
129 | |||
130 | template<> template<> | ||
131 | void LLTemplateMessageBuilderTestObject::test<2>() | ||
132 | // BOOL | ||
133 | { | ||
134 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
135 | messageTemplate.addBlock(defaultBlock(MVT_BOOL, 1)); | ||
136 | BOOL outValue, inValue = TRUE; | ||
137 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
138 | builder->addBOOL(_PREHASH_Test0, inValue); | ||
139 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
140 | reader->getBOOL(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
141 | ensure_equals("Ensure BOOL", inValue, outValue); | ||
142 | delete reader; | ||
143 | } | ||
144 | |||
145 | template<> template<> | ||
146 | void LLTemplateMessageBuilderTestObject::test<3>() | ||
147 | // U8 | ||
148 | { | ||
149 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
150 | messageTemplate.addBlock(defaultBlock(MVT_U8, 1)); | ||
151 | U8 outValue, inValue = 2; | ||
152 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
153 | builder->addU8(_PREHASH_Test0, inValue); | ||
154 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
155 | reader->getU8(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
156 | ensure_equals("Ensure U8", inValue, outValue); | ||
157 | delete reader; | ||
158 | } | ||
159 | |||
160 | template<> template<> | ||
161 | void LLTemplateMessageBuilderTestObject::test<4>() | ||
162 | // S16 | ||
163 | { | ||
164 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
165 | messageTemplate.addBlock(defaultBlock(MVT_S16, 2)); | ||
166 | S16 outValue, inValue = 90; | ||
167 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
168 | builder->addS16(_PREHASH_Test0, inValue); | ||
169 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
170 | reader->getS16(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
171 | ensure_equals("Ensure S16", inValue, outValue); | ||
172 | delete reader; | ||
173 | } | ||
174 | |||
175 | template<> template<> | ||
176 | void LLTemplateMessageBuilderTestObject::test<5>() | ||
177 | // U16 | ||
178 | { | ||
179 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
180 | messageTemplate.addBlock(defaultBlock(MVT_U16, 2)); | ||
181 | U16 outValue, inValue = 3; | ||
182 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
183 | builder->addU16(_PREHASH_Test0, inValue); | ||
184 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
185 | reader->getU16(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
186 | ensure_equals("Ensure U16", inValue, outValue); | ||
187 | delete reader; | ||
188 | } | ||
189 | |||
190 | template<> template<> | ||
191 | void LLTemplateMessageBuilderTestObject::test<6>() | ||
192 | // S32 | ||
193 | { | ||
194 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
195 | messageTemplate.addBlock(defaultBlock(MVT_S32, 4)); | ||
196 | S32 outValue, inValue = 44; | ||
197 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
198 | builder->addS32(_PREHASH_Test0, inValue); | ||
199 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
200 | reader->getS32(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
201 | ensure_equals("Ensure S32", inValue, outValue); | ||
202 | delete reader; | ||
203 | } | ||
204 | |||
205 | template<> template<> | ||
206 | void LLTemplateMessageBuilderTestObject::test<7>() | ||
207 | // F32 | ||
208 | { | ||
209 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
210 | messageTemplate.addBlock(defaultBlock(MVT_F32, 4)); | ||
211 | F32 outValue, inValue = 121.44f; | ||
212 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
213 | builder->addF32(_PREHASH_Test0, inValue); | ||
214 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
215 | reader->getF32(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
216 | ensure_equals("Ensure F32", inValue, outValue); | ||
217 | delete reader; | ||
218 | } | ||
219 | |||
220 | template<> template<> | ||
221 | void LLTemplateMessageBuilderTestObject::test<8>() | ||
222 | // U32 | ||
223 | { | ||
224 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
225 | messageTemplate.addBlock(defaultBlock(MVT_U32, 4)); | ||
226 | U32 outValue, inValue = 88; | ||
227 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
228 | builder->addU32(_PREHASH_Test0, inValue); | ||
229 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
230 | reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
231 | ensure_equals("Ensure U32", inValue, outValue); | ||
232 | delete reader; | ||
233 | } | ||
234 | |||
235 | template<> template<> | ||
236 | void LLTemplateMessageBuilderTestObject::test<9>() | ||
237 | // U64 | ||
238 | { | ||
239 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
240 | messageTemplate.addBlock(defaultBlock(MVT_U64, 8)); | ||
241 | U64 outValue, inValue = 121; | ||
242 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
243 | builder->addU64(_PREHASH_Test0, inValue); | ||
244 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
245 | reader->getU64(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
246 | ensure_equals("Ensure U64", inValue, outValue); | ||
247 | delete reader; | ||
248 | } | ||
249 | |||
250 | template<> template<> | ||
251 | void LLTemplateMessageBuilderTestObject::test<10>() | ||
252 | // F64 | ||
253 | { | ||
254 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
255 | messageTemplate.addBlock(defaultBlock(MVT_F64, 8)); | ||
256 | F64 outValue, inValue = 3232143.33; | ||
257 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
258 | builder->addF64(_PREHASH_Test0, inValue); | ||
259 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
260 | reader->getF64(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
261 | ensure_equals("Ensure F64", inValue, outValue); | ||
262 | delete reader; | ||
263 | } | ||
264 | |||
265 | template<> template<> | ||
266 | void LLTemplateMessageBuilderTestObject::test<11>() | ||
267 | // Vector3 | ||
268 | { | ||
269 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
270 | messageTemplate.addBlock(defaultBlock(MVT_LLVector3, 12)); | ||
271 | LLVector3 outValue, inValue = LLVector3(1,2,3); | ||
272 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
273 | builder->addVector3(_PREHASH_Test0, inValue); | ||
274 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
275 | reader->getVector3(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
276 | ensure_equals("Ensure LLVector3", inValue, outValue); | ||
277 | delete reader; | ||
278 | } | ||
279 | |||
280 | template<> template<> | ||
281 | void LLTemplateMessageBuilderTestObject::test<12>() | ||
282 | // Vector4 | ||
283 | { | ||
284 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
285 | messageTemplate.addBlock(defaultBlock(MVT_LLVector4, 16)); | ||
286 | LLVector4 outValue, inValue = LLVector4(1,2,3,4); | ||
287 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
288 | builder->addVector4(_PREHASH_Test0, inValue); | ||
289 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
290 | reader->getVector4(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
291 | ensure_equals("Ensure LLVector4", inValue, outValue); | ||
292 | delete reader; | ||
293 | } | ||
294 | |||
295 | template<> template<> | ||
296 | void LLTemplateMessageBuilderTestObject::test<13>() | ||
297 | // Vector3d | ||
298 | { | ||
299 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
300 | messageTemplate.addBlock(defaultBlock(MVT_LLVector3d, 24)); | ||
301 | LLVector3d outValue, inValue = LLVector3d(1,2,3); | ||
302 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
303 | builder->addVector3d(_PREHASH_Test0, inValue); | ||
304 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
305 | reader->getVector3d(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
306 | ensure_equals("Ensure LLVector3d", inValue, outValue); | ||
307 | delete reader; | ||
308 | } | ||
309 | |||
310 | template<> template<> | ||
311 | void LLTemplateMessageBuilderTestObject::test<14>() | ||
312 | // Quaternion | ||
313 | { | ||
314 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
315 | messageTemplate.addBlock(defaultBlock(MVT_LLQuaternion, 12)); | ||
316 | LLQuaternion outValue, inValue = LLQuaternion(1,2,3,0); | ||
317 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
318 | builder->addQuat(_PREHASH_Test0, inValue); | ||
319 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
320 | reader->getQuat(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
321 | ensure_equals("Ensure LLQuaternion", inValue, outValue); | ||
322 | delete reader; | ||
323 | } | ||
324 | |||
325 | template<> template<> | ||
326 | void LLTemplateMessageBuilderTestObject::test<15>() | ||
327 | // UUID | ||
328 | { | ||
329 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
330 | messageTemplate.addBlock(defaultBlock(MVT_LLUUID, 16)); | ||
331 | LLUUID outValue, inValue; | ||
332 | inValue.generate(); | ||
333 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
334 | builder->addUUID(_PREHASH_Test0, inValue); | ||
335 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
336 | reader->getUUID(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
337 | ensure_equals("Ensure UUID", inValue, outValue); | ||
338 | delete reader; | ||
339 | } | ||
340 | |||
341 | template<> template<> | ||
342 | void LLTemplateMessageBuilderTestObject::test<16>() | ||
343 | // IPAddr | ||
344 | { | ||
345 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
346 | messageTemplate.addBlock(defaultBlock(MVT_IP_ADDR, 4)); | ||
347 | U32 outValue, inValue = 12344556; | ||
348 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
349 | builder->addIPAddr(_PREHASH_Test0, inValue); | ||
350 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
351 | reader->getIPAddr(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
352 | ensure_equals("Ensure IPAddr", inValue, outValue); | ||
353 | delete reader; | ||
354 | } | ||
355 | |||
356 | template<> template<> | ||
357 | void LLTemplateMessageBuilderTestObject::test<17>() | ||
358 | // IPPort | ||
359 | { | ||
360 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
361 | messageTemplate.addBlock(defaultBlock(MVT_IP_PORT, 2)); | ||
362 | U16 outValue, inValue = 80; | ||
363 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
364 | builder->addIPPort(_PREHASH_Test0, inValue); | ||
365 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
366 | reader->getIPPort(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
367 | ensure_equals("Ensure IPPort", inValue, outValue); | ||
368 | delete reader; | ||
369 | } | ||
370 | |||
371 | template<> template<> | ||
372 | void LLTemplateMessageBuilderTestObject::test<18>() | ||
373 | // String | ||
374 | { | ||
375 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
376 | messageTemplate.addBlock(defaultBlock(MVT_VARIABLE, 1)); | ||
377 | std::string outValue, inValue = "testing"; | ||
378 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
379 | builder->addString(_PREHASH_Test0, inValue.c_str()); | ||
380 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
381 | char buffer[MAX_STRING]; | ||
382 | reader->getString(_PREHASH_Test0, _PREHASH_Test0, MAX_STRING, buffer); | ||
383 | outValue = buffer; | ||
384 | ensure_equals("Ensure String", inValue, outValue); | ||
385 | delete reader; | ||
386 | } | ||
387 | |||
388 | template<> template<> | ||
389 | void LLTemplateMessageBuilderTestObject::test<19>() | ||
390 | // block name !-> binary order | ||
391 | { | ||
392 | U8 buffer1[MAX_BUFFER_SIZE]; | ||
393 | memset(buffer1, 0, MAX_BUFFER_SIZE); | ||
394 | U8 buffer2[MAX_BUFFER_SIZE]; | ||
395 | memset(buffer2, 0, MAX_BUFFER_SIZE); | ||
396 | U32 bufferSize1, bufferSize2; | ||
397 | |||
398 | // build template: Test0 before Test1 | ||
399 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
400 | messageTemplate.addBlock(createBlock(_PREHASH_Test0, MVT_U32, 4, MBT_SINGLE)); | ||
401 | messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4, MBT_SINGLE)); | ||
402 | |||
403 | // build message: 1st declared block var == 0xaaaa, 2nd declared block var == 0xbbbb | ||
404 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate, _PREHASH_Test0); | ||
405 | builder->addU32(_PREHASH_Test0, 0xaaaa); | ||
406 | builder->nextBlock(_PREHASH_Test1); | ||
407 | builder->addU32(_PREHASH_Test0, 0xbbbb); | ||
408 | bufferSize1 = builder->buildMessage(buffer1, MAX_BUFFER_SIZE, 0); | ||
409 | delete builder; | ||
410 | |||
411 | // build template: Test1 before Test0 | ||
412 | messageTemplate = defaultTemplate(); | ||
413 | messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4, MBT_SINGLE)); | ||
414 | messageTemplate.addBlock(createBlock(_PREHASH_Test0, MVT_U32, 4, MBT_SINGLE)); | ||
415 | |||
416 | // build message: 1st declared block var == 0xaaaa, 2nd declared block var == 0xbbbb | ||
417 | builder = defaultBuilder(messageTemplate, _PREHASH_Test1); | ||
418 | builder->addU32(_PREHASH_Test0, 0xaaaa); | ||
419 | builder->nextBlock(_PREHASH_Test0); | ||
420 | builder->addU32(_PREHASH_Test0, 0xbbbb); | ||
421 | bufferSize2 = builder->buildMessage(buffer2, MAX_BUFFER_SIZE, 0); | ||
422 | delete builder; | ||
423 | |||
424 | ensure_equals("Ensure Buffer Sizes Equal", bufferSize1, bufferSize2); | ||
425 | ensure_equals("Ensure Buffer Contents Equal", memcmp(buffer1, buffer2, bufferSize1), 0); | ||
426 | } | ||
427 | |||
428 | template<> template<> | ||
429 | void LLTemplateMessageBuilderTestObject::test<20>() | ||
430 | // block build order !-> binary order | ||
431 | { | ||
432 | U8 buffer1[MAX_BUFFER_SIZE]; | ||
433 | memset(buffer1, 0, MAX_BUFFER_SIZE); | ||
434 | U8 buffer2[MAX_BUFFER_SIZE]; | ||
435 | memset(buffer2, 0, MAX_BUFFER_SIZE); | ||
436 | U32 bufferSize1, bufferSize2; | ||
437 | |||
438 | // build template: Test0 before Test1 | ||
439 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
440 | messageTemplate.addBlock(createBlock(_PREHASH_Test0, MVT_U32, 4, MBT_SINGLE)); | ||
441 | messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4, MBT_SINGLE)); | ||
442 | |||
443 | // build message: 1st declared block var == 0xaaaa, 2nd declared block var == 0xbbbb | ||
444 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate, _PREHASH_Test0); | ||
445 | builder->addU32(_PREHASH_Test0, 0xaaaa); | ||
446 | builder->nextBlock(_PREHASH_Test1); | ||
447 | builder->addU32(_PREHASH_Test0, 0xbbbb); | ||
448 | bufferSize1 = builder->buildMessage(buffer1, MAX_BUFFER_SIZE, 0); | ||
449 | delete builder; | ||
450 | |||
451 | // build message: 1st declared block var == 0xaaaa, 2nd declared block var == 0xbbbb | ||
452 | builder = defaultBuilder(messageTemplate, _PREHASH_Test1); | ||
453 | builder->addU32(_PREHASH_Test0, 0xbbbb); | ||
454 | builder->nextBlock(_PREHASH_Test0); | ||
455 | builder->addU32(_PREHASH_Test0, 0xaaaa); | ||
456 | bufferSize2 = builder->buildMessage(buffer2, MAX_BUFFER_SIZE, 0); | ||
457 | delete builder; | ||
458 | |||
459 | ensure_equals("Ensure Buffer Sizes Equal", bufferSize1, bufferSize2); | ||
460 | ensure_equals("Ensure Buffer Contents Equal", memcmp(buffer1, buffer2, bufferSize1), 0); | ||
461 | } | ||
462 | |||
463 | template<> template<> | ||
464 | void LLTemplateMessageBuilderTestObject::test<21>() | ||
465 | // block appended in declaration -> data appended in binary | ||
466 | { | ||
467 | U8 buffer1[MAX_BUFFER_SIZE]; | ||
468 | memset(buffer1, 0, MAX_BUFFER_SIZE); | ||
469 | U8 buffer2[MAX_BUFFER_SIZE]; | ||
470 | memset(buffer2, 0, MAX_BUFFER_SIZE); | ||
471 | U32 bufferSize1, bufferSize2; | ||
472 | |||
473 | // Build template: Test0 only | ||
474 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
475 | messageTemplate.addBlock(createBlock(_PREHASH_Test0, MVT_U32, 4, MBT_SINGLE)); | ||
476 | |||
477 | // Build message | ||
478 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate, _PREHASH_Test0); | ||
479 | builder->addU32(_PREHASH_Test0, 0xaaaa); | ||
480 | bufferSize1 = builder->buildMessage(buffer1, MAX_BUFFER_SIZE, 0); | ||
481 | delete builder; | ||
482 | |||
483 | // Build template: Test0 before Test1 | ||
484 | messageTemplate = defaultTemplate(); | ||
485 | messageTemplate.addBlock(createBlock(_PREHASH_Test0, MVT_U32, 4, MBT_SINGLE)); | ||
486 | messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4, MBT_SINGLE)); | ||
487 | |||
488 | // Build message | ||
489 | builder = defaultBuilder(messageTemplate, _PREHASH_Test0); | ||
490 | builder->addU32(_PREHASH_Test0, 0xaaaa); | ||
491 | builder->nextBlock(_PREHASH_Test1); | ||
492 | builder->addU32(_PREHASH_Test0, 0xbbbb); | ||
493 | bufferSize2 = builder->buildMessage(buffer2, MAX_BUFFER_SIZE, 0); | ||
494 | delete builder; | ||
495 | |||
496 | ensure_not_equals("Ensure Buffer Sizes Not Equal", bufferSize1, bufferSize2); | ||
497 | ensure_equals("Ensure Buffer Prefix Equal", memcmp(buffer1, buffer2, bufferSize1), 0); | ||
498 | ensure_not_equals("Ensure Buffer Contents Not Equal", memcmp(buffer1, buffer2, bufferSize2), 0); | ||
499 | } | ||
500 | |||
501 | template<> template<> | ||
502 | void LLTemplateMessageBuilderTestObject::test<22>() | ||
503 | // repeated penultimate block (crashes when data in LLDynamicArrayIndexed) | ||
504 | { | ||
505 | U32 inTest00 = 0, inTest01 = 1, inTest1 = 2; | ||
506 | U32 outTest00, outTest01, outTest1; | ||
507 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
508 | messageTemplate.addBlock(createBlock(_PREHASH_Test0, MVT_U32, 4)); | ||
509 | messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4)); | ||
510 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
511 | builder->addU32(_PREHASH_Test0, inTest00); | ||
512 | builder->nextBlock(_PREHASH_Test0); | ||
513 | builder->addU32(_PREHASH_Test0, inTest01); | ||
514 | builder->nextBlock(_PREHASH_Test1); | ||
515 | builder->addU32(_PREHASH_Test0, inTest1); | ||
516 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
517 | reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outTest00, 0); | ||
518 | reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outTest01, 1); | ||
519 | reader->getU32(_PREHASH_Test1, _PREHASH_Test0, outTest1); | ||
520 | ensure_equals("Ensure Test0[0]", inTest00, outTest00); | ||
521 | ensure_equals("Ensure Test0[1]", inTest01, outTest01); | ||
522 | ensure_equals("Ensure Test1", inTest1, outTest1); | ||
523 | delete reader; | ||
524 | } | ||
525 | |||
526 | template<> template<> | ||
527 | void LLTemplateMessageBuilderTestObject::test<23>() | ||
528 | // variable repeated block name never accessed | ||
529 | { | ||
530 | U32 inTest = 1, outTest; | ||
531 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
532 | messageTemplate.addBlock( | ||
533 | createBlock(_PREHASH_Test0, MVT_U32, 4, MBT_SINGLE)); | ||
534 | messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4)); | ||
535 | |||
536 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
537 | builder->addU32(_PREHASH_Test0, inTest); | ||
538 | |||
539 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
540 | reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outTest); | ||
541 | S32 blockCount = reader->getNumberOfBlocks(_PREHASH_Test1); | ||
542 | ensure_equals("Ensure block count", blockCount, 0); | ||
543 | ensure_equals("Ensure Test0", inTest, outTest); | ||
544 | delete reader; | ||
545 | } | ||
546 | |||
547 | template<> template<> | ||
548 | void LLTemplateMessageBuilderTestObject::test<24>() | ||
549 | // forwarding message | ||
550 | { | ||
551 | // build template | ||
552 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
553 | messageTemplate.addBlock(createBlock(_PREHASH_Test0, MVT_U32, 4)); | ||
554 | |||
555 | // build message | ||
556 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
557 | builder->addU32(_PREHASH_Test0, 42); | ||
558 | |||
559 | // read message | ||
560 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
561 | |||
562 | // forward message | ||
563 | builder = defaultBuilder(messageTemplate); | ||
564 | builder->newMessage(_PREHASH_TestMessage); | ||
565 | reader->copyToBuilder(*builder); | ||
566 | U8 buffer[MAX_BUFFER_SIZE]; | ||
567 | builder->buildMessage(buffer, MAX_BUFFER_SIZE, 0); | ||
568 | |||
569 | delete builder; | ||
570 | delete reader; | ||
571 | } | ||
572 | |||
573 | template<> template<> | ||
574 | void LLTemplateMessageBuilderTestObject::test<25>() | ||
575 | // non-zero offset with undefined | ||
576 | { | ||
577 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
578 | messageTemplate.addBlock(defaultBlock()); | ||
579 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
580 | LLTemplateMessageReader* reader = setReader( | ||
581 | messageTemplate, builder, 10); | ||
582 | delete reader; | ||
583 | } | ||
584 | |||
585 | template<> template<> | ||
586 | void LLTemplateMessageBuilderTestObject::test<26>() | ||
587 | // non-zero offset with BOOL | ||
588 | { | ||
589 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
590 | messageTemplate.addBlock(defaultBlock(MVT_BOOL, 1)); | ||
591 | BOOL outValue, inValue = TRUE; | ||
592 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
593 | builder->addBOOL(_PREHASH_Test0, inValue); | ||
594 | LLTemplateMessageReader* reader = setReader( | ||
595 | messageTemplate, builder, 1); | ||
596 | reader->getBOOL(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
597 | ensure_equals("Ensure BOOL", inValue, outValue); | ||
598 | delete reader; | ||
599 | } | ||
600 | |||
601 | template<> template<> | ||
602 | void LLTemplateMessageBuilderTestObject::test<27>() | ||
603 | // non-zero offset with U8 | ||
604 | { | ||
605 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
606 | messageTemplate.addBlock(defaultBlock(MVT_U8, 1)); | ||
607 | U8 outValue, inValue = 2; | ||
608 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
609 | builder->addU8(_PREHASH_Test0, inValue); | ||
610 | LLTemplateMessageReader* reader = setReader( | ||
611 | messageTemplate, builder, 255); | ||
612 | reader->getU8(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
613 | ensure_equals("Ensure U8", inValue, outValue); | ||
614 | delete reader; | ||
615 | } | ||
616 | |||
617 | template<> template<> | ||
618 | void LLTemplateMessageBuilderTestObject::test<28>() | ||
619 | // non-zero offset with S16 | ||
620 | { | ||
621 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
622 | messageTemplate.addBlock(defaultBlock(MVT_S16, 2)); | ||
623 | S16 outValue, inValue = 90; | ||
624 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
625 | builder->addS16(_PREHASH_Test0, inValue); | ||
626 | LLTemplateMessageReader* reader = setReader( | ||
627 | messageTemplate, builder, 2); | ||
628 | reader->getS16(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
629 | ensure_equals("Ensure S16", inValue, outValue); | ||
630 | delete reader; | ||
631 | } | ||
632 | |||
633 | template<> template<> | ||
634 | void LLTemplateMessageBuilderTestObject::test<29>() | ||
635 | // non-zero offset with U16 | ||
636 | { | ||
637 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
638 | messageTemplate.addBlock(defaultBlock(MVT_U16, 2)); | ||
639 | U16 outValue, inValue = 3; | ||
640 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
641 | builder->addU16(_PREHASH_Test0, inValue); | ||
642 | LLTemplateMessageReader* reader = setReader( | ||
643 | messageTemplate, builder, 4); | ||
644 | reader->getU16(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
645 | ensure_equals("Ensure U16", inValue, outValue); | ||
646 | delete reader; | ||
647 | } | ||
648 | |||
649 | template<> template<> | ||
650 | void LLTemplateMessageBuilderTestObject::test<30>() | ||
651 | // non-zero offset with S32 | ||
652 | { | ||
653 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
654 | messageTemplate.addBlock(defaultBlock(MVT_S32, 4)); | ||
655 | S32 outValue, inValue = 44; | ||
656 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
657 | builder->addS32(_PREHASH_Test0, inValue); | ||
658 | LLTemplateMessageReader* reader = setReader( | ||
659 | messageTemplate, builder, 4); | ||
660 | reader->getS32(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
661 | ensure_equals("Ensure S32", inValue, outValue); | ||
662 | delete reader; | ||
663 | } | ||
664 | |||
665 | template<> template<> | ||
666 | void LLTemplateMessageBuilderTestObject::test<31>() | ||
667 | // non-zero offset with F32 | ||
668 | { | ||
669 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
670 | messageTemplate.addBlock(defaultBlock(MVT_F32, 4)); | ||
671 | F32 outValue, inValue = 121.44f; | ||
672 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
673 | builder->addF32(_PREHASH_Test0, inValue); | ||
674 | LLTemplateMessageReader* reader = setReader( | ||
675 | messageTemplate, builder, 16); | ||
676 | reader->getF32(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
677 | ensure_equals("Ensure F32", inValue, outValue); | ||
678 | delete reader; | ||
679 | } | ||
680 | |||
681 | template<> template<> | ||
682 | void LLTemplateMessageBuilderTestObject::test<32>() | ||
683 | // non-zero offset with U32 | ||
684 | { | ||
685 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
686 | messageTemplate.addBlock(defaultBlock(MVT_U32, 4)); | ||
687 | U32 outValue, inValue = 88; | ||
688 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
689 | builder->addU32(_PREHASH_Test0, inValue); | ||
690 | LLTemplateMessageReader* reader = setReader( | ||
691 | messageTemplate, builder, 127); | ||
692 | reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
693 | ensure_equals("Ensure U32", inValue, outValue); | ||
694 | delete reader; | ||
695 | } | ||
696 | |||
697 | template<> template<> | ||
698 | void LLTemplateMessageBuilderTestObject::test<33>() | ||
699 | // non-zero offset with U64 | ||
700 | { | ||
701 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
702 | messageTemplate.addBlock(defaultBlock(MVT_U64, 8)); | ||
703 | U64 outValue, inValue = 121; | ||
704 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
705 | builder->addU64(_PREHASH_Test0, inValue); | ||
706 | LLTemplateMessageReader* reader = setReader( | ||
707 | messageTemplate, builder, 32); | ||
708 | reader->getU64(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
709 | ensure_equals("Ensure U64", inValue, outValue); | ||
710 | delete reader; | ||
711 | } | ||
712 | |||
713 | template<> template<> | ||
714 | void LLTemplateMessageBuilderTestObject::test<34>() | ||
715 | // non-zero offset with F64 | ||
716 | { | ||
717 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
718 | messageTemplate.addBlock(defaultBlock(MVT_F64, 8)); | ||
719 | F64 outValue, inValue = 3232143.33; | ||
720 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
721 | builder->addF64(_PREHASH_Test0, inValue); | ||
722 | LLTemplateMessageReader* reader = setReader( | ||
723 | messageTemplate, builder, 128); | ||
724 | reader->getF64(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
725 | ensure_equals("Ensure F64", inValue, outValue); | ||
726 | delete reader; | ||
727 | } | ||
728 | |||
729 | template<> template<> | ||
730 | void LLTemplateMessageBuilderTestObject::test<35>() | ||
731 | // non-zero offset with Vector3 | ||
732 | { | ||
733 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
734 | messageTemplate.addBlock(defaultBlock(MVT_LLVector3, 12)); | ||
735 | LLVector3 outValue, inValue = LLVector3(1,2,3); | ||
736 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
737 | builder->addVector3(_PREHASH_Test0, inValue); | ||
738 | LLTemplateMessageReader* reader = setReader( | ||
739 | messageTemplate, builder, 63); | ||
740 | reader->getVector3(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
741 | ensure_equals("Ensure LLVector3", inValue, outValue); | ||
742 | delete reader; | ||
743 | } | ||
744 | |||
745 | template<> template<> | ||
746 | void LLTemplateMessageBuilderTestObject::test<36>() | ||
747 | // non-zero offset with Vector4 | ||
748 | { | ||
749 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
750 | messageTemplate.addBlock(defaultBlock(MVT_LLVector4, 16)); | ||
751 | LLVector4 outValue, inValue = LLVector4(1,2,3,4); | ||
752 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
753 | builder->addVector4(_PREHASH_Test0, inValue); | ||
754 | LLTemplateMessageReader* reader = setReader( | ||
755 | messageTemplate, builder, 64); | ||
756 | reader->getVector4(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
757 | ensure_equals("Ensure LLVector4", inValue, outValue); | ||
758 | delete reader; | ||
759 | } | ||
760 | |||
761 | template<> template<> | ||
762 | void LLTemplateMessageBuilderTestObject::test<37>() | ||
763 | // non-zero offset with Vector3d | ||
764 | { | ||
765 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
766 | messageTemplate.addBlock(defaultBlock(MVT_LLVector3d, 24)); | ||
767 | LLVector3d outValue, inValue = LLVector3d(1,2,3); | ||
768 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
769 | builder->addVector3d(_PREHASH_Test0, inValue); | ||
770 | LLTemplateMessageReader* reader = setReader( | ||
771 | messageTemplate, builder, 64); | ||
772 | reader->getVector3d(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
773 | ensure_equals("Ensure LLVector3d", inValue, outValue); | ||
774 | delete reader; | ||
775 | } | ||
776 | |||
777 | template<> template<> | ||
778 | void LLTemplateMessageBuilderTestObject::test<38>() | ||
779 | // non-zero offset with Quaternion | ||
780 | { | ||
781 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
782 | messageTemplate.addBlock(defaultBlock(MVT_LLQuaternion, 12)); | ||
783 | LLQuaternion outValue, inValue = LLQuaternion(1,2,3,0); | ||
784 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
785 | builder->addQuat(_PREHASH_Test0, inValue); | ||
786 | LLTemplateMessageReader* reader = setReader( | ||
787 | messageTemplate, builder, 12); | ||
788 | reader->getQuat(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
789 | ensure_equals("Ensure LLQuaternion", inValue, outValue); | ||
790 | delete reader; | ||
791 | } | ||
792 | |||
793 | template<> template<> | ||
794 | void LLTemplateMessageBuilderTestObject::test<39>() | ||
795 | // non-zero offset with UUID | ||
796 | { | ||
797 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
798 | messageTemplate.addBlock(defaultBlock(MVT_LLUUID, 16)); | ||
799 | LLUUID outValue, inValue; | ||
800 | inValue.generate(); | ||
801 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
802 | builder->addUUID(_PREHASH_Test0, inValue); | ||
803 | LLTemplateMessageReader* reader = setReader( | ||
804 | messageTemplate, builder, 31); | ||
805 | reader->getUUID(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
806 | ensure_equals("Ensure UUID", inValue, outValue); | ||
807 | delete reader; | ||
808 | } | ||
809 | |||
810 | template<> template<> | ||
811 | void LLTemplateMessageBuilderTestObject::test<40>() | ||
812 | // non-zero offset with IPAddr | ||
813 | { | ||
814 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
815 | messageTemplate.addBlock(defaultBlock(MVT_IP_ADDR, 4)); | ||
816 | U32 outValue, inValue = 12344556; | ||
817 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
818 | builder->addIPAddr(_PREHASH_Test0, inValue); | ||
819 | LLTemplateMessageReader* reader = setReader( | ||
820 | messageTemplate, builder, 32); | ||
821 | reader->getIPAddr(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
822 | ensure_equals("Ensure IPAddr", inValue, outValue); | ||
823 | delete reader; | ||
824 | } | ||
825 | |||
826 | template<> template<> | ||
827 | void LLTemplateMessageBuilderTestObject::test<41>() | ||
828 | // non-zero offset with IPPort | ||
829 | { | ||
830 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
831 | messageTemplate.addBlock(defaultBlock(MVT_IP_PORT, 2)); | ||
832 | U16 outValue, inValue = 80; | ||
833 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
834 | builder->addIPPort(_PREHASH_Test0, inValue); | ||
835 | LLTemplateMessageReader* reader = setReader( | ||
836 | messageTemplate, builder, 6); | ||
837 | reader->getIPPort(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
838 | ensure_equals("Ensure IPPort", inValue, outValue); | ||
839 | delete reader; | ||
840 | } | ||
841 | |||
842 | template<> template<> | ||
843 | void LLTemplateMessageBuilderTestObject::test<42>() | ||
844 | // non-zero offset with String | ||
845 | { | ||
846 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
847 | messageTemplate.addBlock(defaultBlock(MVT_VARIABLE, 1)); | ||
848 | std::string outValue, inValue = "testing"; | ||
849 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
850 | builder->addString(_PREHASH_Test0, inValue.c_str()); | ||
851 | LLTemplateMessageReader* reader = setReader( | ||
852 | messageTemplate, builder, 255); | ||
853 | char buffer[MAX_STRING]; | ||
854 | reader->getString(_PREHASH_Test0, _PREHASH_Test0, MAX_STRING, buffer); | ||
855 | outValue = buffer; | ||
856 | ensure_equals("Ensure String", inValue, outValue); | ||
857 | delete reader; | ||
858 | } | ||
859 | |||
860 | template<> template<> | ||
861 | void LLTemplateMessageBuilderTestObject::test<43>() | ||
862 | // read past end of message -> default values (forward compatibility) | ||
863 | { | ||
864 | // build message with single block | ||
865 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
866 | messageTemplate.addBlock(defaultBlock(MVT_U32, 4, MBT_SINGLE)); | ||
867 | U32 outValue, outValue2, inValue = 0xbbbbbbbb; | ||
868 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
869 | builder->addU32(_PREHASH_Test0, inValue); | ||
870 | const U32 bufferSize = 1024; | ||
871 | U8 buffer[bufferSize]; | ||
872 | memset(buffer, 0xaa, bufferSize); | ||
873 | memset(buffer, 0, LL_PACKET_ID_SIZE); | ||
874 | U32 builtSize = builder->buildMessage(buffer, bufferSize, 0); | ||
875 | delete builder; | ||
876 | |||
877 | // add block to reader template | ||
878 | messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4, MBT_SINGLE)); | ||
879 | |||
880 | // read message value and default value | ||
881 | numberMap[1] = &messageTemplate; | ||
882 | LLTemplateMessageReader* reader = | ||
883 | new LLTemplateMessageReader(numberMap); | ||
884 | reader->validateMessage(buffer, builtSize, LLHost()); | ||
885 | reader->readMessage(buffer, LLHost()); | ||
886 | reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
887 | reader->getU32(_PREHASH_Test1, _PREHASH_Test0, outValue2); | ||
888 | ensure_equals("Ensure present value ", outValue, inValue); | ||
889 | ensure_equals("Ensure default value ", outValue2, 0); | ||
890 | delete reader; | ||
891 | } | ||
892 | |||
893 | template<> template<> | ||
894 | void LLTemplateMessageBuilderTestObject::test<44>() | ||
895 | // read variable block past end of message -> 0 repeats | ||
896 | { | ||
897 | // build message with single block | ||
898 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
899 | messageTemplate.addBlock(defaultBlock(MVT_U32, 4, MBT_SINGLE)); | ||
900 | U32 outValue, outValue2, inValue = 0xbbbbbbbb; | ||
901 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
902 | builder->addU32(_PREHASH_Test0, inValue); | ||
903 | const U32 bufferSize = 1024; | ||
904 | U8 buffer[bufferSize]; | ||
905 | memset(buffer, 0xaa, bufferSize); | ||
906 | memset(buffer, 0, LL_PACKET_ID_SIZE); | ||
907 | U32 builtSize = builder->buildMessage(buffer, bufferSize, 0); | ||
908 | delete builder; | ||
909 | |||
910 | // add variable block to reader template | ||
911 | messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4)); | ||
912 | |||
913 | // read message value and check block repeat count | ||
914 | numberMap[1] = &messageTemplate; | ||
915 | LLTemplateMessageReader* reader = | ||
916 | new LLTemplateMessageReader(numberMap); | ||
917 | reader->validateMessage(buffer, builtSize, LLHost()); | ||
918 | reader->readMessage(buffer, LLHost()); | ||
919 | reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
920 | outValue2 = reader->getNumberOfBlocks(_PREHASH_Test1); | ||
921 | ensure_equals("Ensure present value ", outValue, inValue); | ||
922 | ensure_equals("Ensure 0 repeats ", outValue2, 0); | ||
923 | delete reader; | ||
924 | } | ||
925 | |||
926 | template<> template<> | ||
927 | void LLTemplateMessageBuilderTestObject::test<45>() | ||
928 | // read variable length data past end of message -> 0 length | ||
929 | { | ||
930 | // build message with single block | ||
931 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
932 | messageTemplate.addBlock(defaultBlock(MVT_U32, 4, MBT_SINGLE)); | ||
933 | U32 outValue, outValue2, inValue = 0xbbbbbbbb; | ||
934 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
935 | builder->addU32(_PREHASH_Test0, inValue); | ||
936 | const U32 bufferSize = 1024; | ||
937 | U8 buffer[bufferSize]; | ||
938 | memset(buffer, 0xaa, bufferSize); | ||
939 | memset(buffer, 0, LL_PACKET_ID_SIZE); | ||
940 | U32 builtSize = builder->buildMessage(buffer, bufferSize, 0); | ||
941 | delete builder; | ||
942 | |||
943 | // add variable block to reader template | ||
944 | messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_VARIABLE, 4, | ||
945 | MBT_SINGLE)); | ||
946 | |||
947 | // read message value and default string | ||
948 | numberMap[1] = &messageTemplate; | ||
949 | LLTemplateMessageReader* reader = | ||
950 | new LLTemplateMessageReader(numberMap); | ||
951 | reader->validateMessage(buffer, builtSize, LLHost()); | ||
952 | reader->readMessage(buffer, LLHost()); | ||
953 | reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
954 | char outBuffer[bufferSize]; | ||
955 | memset(buffer, 0xcc, bufferSize); | ||
956 | reader->getString(_PREHASH_Test1, _PREHASH_Test0, bufferSize, | ||
957 | outBuffer); | ||
958 | outValue2 = reader->getNumberOfBlocks(_PREHASH_Test1); | ||
959 | ensure_equals("Ensure present value ", outValue, inValue); | ||
960 | ensure_equals("Ensure unchanged buffer ", strlen(outBuffer), 0); | ||
961 | delete reader; | ||
962 | } | ||
963 | } | ||
964 | |||