aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/test/lldatapacker_tut.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/test/lldatapacker_tut.cpp')
-rw-r--r--linden/indra/test/lldatapacker_tut.cpp571
1 files changed, 571 insertions, 0 deletions
diff --git a/linden/indra/test/lldatapacker_tut.cpp b/linden/indra/test/lldatapacker_tut.cpp
new file mode 100644
index 0000000..71def35
--- /dev/null
+++ b/linden/indra/test/lldatapacker_tut.cpp
@@ -0,0 +1,571 @@
1/**
2 * @file lldatapacker_tut.cpp
3 * @author Adroit
4 * @date February 2007
5 * @brief LLDataPacker test cases.
6 *
7 * Copyright (c) 2007-2007, Linden Research, Inc.
8 *
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#include "linden_common.h"
33#include "lldatapacker.h"
34#include "v4color.h"
35#include "v4coloru.h"
36#include "v2math.h"
37#include "v3math.h"
38#include "v4math.h"
39#include "llsdserialize.h"
40
41#define TEST_FILE_NAME "datapacker_test.txt"
42namespace tut
43{
44 struct datapacker_test
45 {
46 };
47 typedef test_group<datapacker_test> datapacker_test_t;
48 typedef datapacker_test_t::object datapacker_test_object_t;
49 tut::datapacker_test_t tut_datapacker_test("datapacker_test");
50
51 //*********LLDataPackerBinaryBuffer
52 template<> template<>
53 void datapacker_test_object_t::test<1>()
54 {
55 U8 packbuf[128];
56 F32 f_val1 = 44.44f, f_unpkval1;
57 F32 f_val2 = 12344.443232f, f_unpkval2;
58 F32 f_val3 = 44.4456789f, f_unpkval3;
59 LLDataPackerBinaryBuffer lldp(packbuf,128);
60 lldp.packFixed( f_val1, "linden_lab", FALSE, 8, 8);
61 lldp.packFixed( f_val2, "linden_lab", FALSE, 14, 16);
62 lldp.packFixed( f_val3, "linden_lab", FALSE, 8, 23);
63
64 LLDataPackerBinaryBuffer lldp1(packbuf, lldp.getCurrentSize());
65 lldp1.unpackFixed(f_unpkval1, "linden_lab", FALSE, 8, 8);
66 lldp1.unpackFixed(f_unpkval2, "linden_lab", FALSE, 14, 16);
67 lldp1.unpackFixed(f_unpkval3, "linden_lab", FALSE, 8, 23);
68 ensure_approximately_equals("LLDataPackerBinaryBuffer::packFixed 8 failed", f_val1, f_unpkval1, 8);
69 ensure_approximately_equals("LLDataPackerBinaryBuffer::packFixed 16 failed", f_val2, f_unpkval2, 16);
70 ensure_approximately_equals("LLDataPackerBinaryBuffer::packFixed 23 failed", f_val3, f_unpkval3, 31);
71 }
72
73 template<> template<>
74 void datapacker_test_object_t::test<2>()
75 {
76 U8 packbuf[1024];
77
78 char str[] = "SecondLife is virtual World\0";
79 char strBinary[] = "SecondLife is virtual World";
80 char strBinaryFixed[] = "Fixed Data";
81 S32 sizeBinaryFixed = sizeof(strBinaryFixed);
82 U8 valU8 = 'C';
83 U16 valU16 = 0xFFFF;
84 U32 valU32 = 0xFFFFFFFF;
85 S32 valS32 = -94967295;
86 F32 valF32 = 4354355.44f ;
87 LLColor4 llcol4(3.3f, 0, 4.4f, 5.5f);
88 LLColor4U llcol4u(3, 128, 24, 33);
89 LLVector2 llvec2(333.33f, 444.44f);
90 LLVector3 llvec3(333.33f, 444.44f, 555.55f);
91 LLVector4 llvec4(333.33f, 444.44f, 555.55f, 666.66f);
92 LLUUID uuid;
93
94 std::string unpkstr;
95 char unpkstrBinary[256];
96 char unpkstrBinaryFixed[256];
97 S32 unpksizeBinary;
98 U8 unpkvalU8;
99 U16 unpkvalU16;
100 U32 unpkvalU32;
101 S32 unpkvalS32;
102 F32 unpkvalF32;
103 LLColor4 unpkllcol4;
104 LLColor4U unpkllcol4u;
105 LLVector2 unpkllvec2;
106 LLVector3 unpkllvec3;
107 LLVector4 unpkllvec4;
108 LLUUID unpkuuid;
109
110 LLDataPackerBinaryBuffer lldp(packbuf,1024);
111 lldp.packString(str , "linden_lab_str");
112 lldp.packBinaryData((U8*)strBinary, sizeof(strBinary), "linden_lab_bd");
113 lldp.packBinaryDataFixed((U8*)strBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
114 lldp.packU8(valU8,"linden_lab_u8");
115 lldp.packU16(valU16,"linden_lab_u16");
116 lldp.packU32(valU32, "linden_lab_u32");
117 lldp.packS32(valS32, "linden_lab_s32");
118 lldp.packF32(valF32, "linden_lab_f32");
119 lldp.packColor4(llcol4, "linden_lab_col4");
120 lldp.packColor4U(llcol4u, "linden_lab_col4u");
121 lldp.packVector2(llvec2, "linden_lab_vec2");
122 lldp.packVector3(llvec3, "linden_lab_vec3");
123 lldp.packVector4(llvec4, "linden_lab_vec4");
124 uuid.generate();
125 lldp.packUUID(uuid, "linden_lab_uuid");
126
127 S32 cur_size = lldp.getCurrentSize();
128
129 LLDataPackerBinaryBuffer lldp1(packbuf, cur_size);
130 lldp1.unpackString(unpkstr , "linden_lab_str");
131 lldp1.unpackBinaryData((U8*)unpkstrBinary, unpksizeBinary, "linden_lab_bd");
132 lldp1.unpackBinaryDataFixed((U8*)unpkstrBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
133 lldp1.unpackU8(unpkvalU8,"linden_lab_u8");
134 lldp1.unpackU16(unpkvalU16,"linden_lab_u16");
135 lldp1.unpackU32(unpkvalU32, "linden_lab_u32");
136 lldp1.unpackS32(unpkvalS32, "linden_lab_s32");
137 lldp1.unpackF32(unpkvalF32, "linden_lab_f32");
138 lldp1.unpackColor4(unpkllcol4, "linden_lab_col4");
139 lldp1.unpackColor4U(unpkllcol4u, "linden_lab_col4u");
140 lldp1.unpackVector2(unpkllvec2, "linden_lab_vec2");
141 lldp1.unpackVector3(unpkllvec3, "linden_lab_vec3");
142 lldp1.unpackVector4(unpkllvec4, "linden_lab_vec4");
143 lldp1.unpackUUID(unpkuuid, "linden_lab_uuid");
144
145 ensure("LLDataPackerBinaryBuffer::packString failed", strcmp(str, unpkstr.c_str()) == 0);
146 ensure("LLDataPackerBinaryBuffer::packBinaryData failed", strcmp(strBinary, unpkstrBinary) == 0);
147 ensure("LLDataPackerBinaryBuffer::packBinaryDataFixed failed", strcmp(strBinaryFixed, unpkstrBinaryFixed) == 0);
148 ensure_equals("LLDataPackerBinaryBuffer::packU8 failed", valU8, unpkvalU8);
149 ensure_equals("LLDataPackerBinaryBuffer::packU16 failed", valU16, unpkvalU16);
150 ensure_equals("LLDataPackerBinaryBuffer::packU32 failed", valU32, unpkvalU32);
151 ensure_equals("LLDataPackerBinaryBuffer::packS32 failed", valS32, unpkvalS32);
152 ensure("LLDataPackerBinaryBuffer::packF32 failed", is_approx_equal(valF32, unpkvalF32));
153 ensure_equals("LLDataPackerBinaryBuffer::packColor4 failed", llcol4, unpkllcol4);
154 ensure_equals("LLDataPackerBinaryBuffer::packColor4U failed", llcol4u, unpkllcol4u);
155 ensure_equals("LLDataPackerBinaryBuffer::packVector2 failed", llvec2, unpkllvec2);
156 ensure_equals("LLDataPackerBinaryBuffer::packVector3 failed", llvec3, unpkllvec3);
157 ensure_equals("LLDataPackerBinaryBuffer::packVector4 failed", llvec4, unpkllvec4);
158 ensure_equals("LLDataPackerBinaryBuffer::packUUID failed", uuid, unpkuuid);
159 }
160
161 template<> template<>
162 void datapacker_test_object_t::test<3>()
163 {
164 U8 packbuf[128];
165 char str[] = "SecondLife is virtual World";
166 S32 strSize = sizeof(str); // include '\0'
167 LLDataPackerBinaryBuffer lldp(packbuf, 128);
168 lldp.packString(str , "linden_lab");
169
170 ensure("LLDataPackerBinaryBuffer: current size is wrong", strSize == lldp.getCurrentSize());
171 ensure("LLDataPackerBinaryBuffer: buffer size is wrong", 128 == lldp.getBufferSize());
172
173 lldp.reset();
174 ensure("LLDataPackerBinaryBuffer::reset failed",0 == lldp.getCurrentSize());
175 }
176
177 template<> template<>
178 void datapacker_test_object_t::test<4>()
179 {
180 U8* packbuf = new U8[128];
181 char str[] = "SecondLife is virtual World";
182 LLDataPackerBinaryBuffer lldp(packbuf, 128);
183 lldp.packString(str , "linden_lab");
184 lldp.freeBuffer();
185 ensure("LLDataPackerBinaryBuffer.freeBuffer failed" , 0 == lldp.getBufferSize());
186
187 }
188
189 template<> template<>
190 void datapacker_test_object_t::test<5>()
191 {
192 U8 buf[] = "SecondLife is virtual World";
193 S32 size = sizeof(buf);
194 LLDataPackerBinaryBuffer lldp(buf, size);
195 U8 new_buf[] = "Its Amazing";
196 size = sizeof(new_buf);
197 lldp.assignBuffer(new_buf, size);
198 ensure("LLDataPackerBinaryBuffer::assignBuffer failed" , ((lldp.getBufferSize() == size) && (0 == lldp.getCurrentSize()))) ;
199 }
200
201 template<> template<>
202 void datapacker_test_object_t::test<6>()
203 {
204 U8 packbuf[128];
205 char str[] = "SecondLife is virtual World";
206 LLDataPackerBinaryBuffer lldp(packbuf, 128);
207 lldp.packString(str , "linden_lab");
208 U8 new_buffer[128];
209 std::string unpkbuf;
210 LLDataPackerBinaryBuffer lldp1(new_buffer,128);
211 lldp1 = lldp;
212 lldp1.unpackString(unpkbuf, "linden_lab");
213 ensure("1. LLDataPackerBinaryBuffer::operator= failed" , lldp1.getBufferSize() == lldp.getBufferSize());
214 ensure_equals("2.LLDataPackerBinaryBuffer::operator= failed", str,unpkbuf);
215 }
216
217 //*********LLDataPackerAsciiBuffer
218
219 template<> template<>
220 void datapacker_test_object_t::test<7>()
221 {
222 char packbuf[128];
223 F32 f_val = 44.44f, f_unpkval;
224 LLDataPackerAsciiBuffer lldp(packbuf,128);
225 lldp.packFixed( f_val, "linden_lab", FALSE, 8, 8);
226
227 LLDataPackerAsciiBuffer lldp1(packbuf, lldp.getCurrentSize());
228 lldp1.unpackFixed(f_unpkval, "linden_lab", FALSE, 8, 8);
229 ensure_approximately_equals("LLDataPackerAsciiBuffer::packFixed failed", f_val, f_unpkval, 8);
230 }
231
232 template<> template<>
233 void datapacker_test_object_t::test<8>()
234 {
235 char packbuf[1024];
236
237 char str[] = "SecondLife is virtual World\0";
238 char strBinary[] = "SecondLife is virtual World";
239 char strBinaryFixed[] = "Fixed Data";
240 S32 sizeBinaryFixed = sizeof(strBinaryFixed);
241 U8 valU8 = 'C';
242 U16 valU16 = 0xFFFF;
243 U32 valU32 = 0xFFFFFFFF;
244 S32 valS32 = -94967295;
245 F32 valF32 = 4354355.44f ;
246 LLColor4 llcol4(3.3f, 0, 4.4f, 5.5f);
247 LLColor4U llcol4u(3, 128, 24, 33);
248 LLVector2 llvec2(333.33f, 444.44f);
249 LLVector3 llvec3(333.33f, 444.44f, 555.55f);
250 LLVector4 llvec4(4354355.44f, 444.44f, 555.55f, 666.66f);
251 LLUUID uuid;
252
253 std::string unpkstr;
254 char unpkstrBinary[256];
255 char unpkstrBinaryFixed[256];
256 S32 unpksizeBinary;
257 U8 unpkvalU8;
258 U16 unpkvalU16;
259 U32 unpkvalU32;
260 S32 unpkvalS32;
261 F32 unpkvalF32;
262 LLColor4 unpkllcol4;
263 LLColor4U unpkllcol4u;
264 LLVector2 unpkllvec2;
265 LLVector3 unpkllvec3;
266 LLVector4 unpkllvec4;
267 LLUUID unpkuuid;
268
269 LLDataPackerAsciiBuffer lldp(packbuf,1024);
270 lldp.packString(str , "linden_lab_str");
271 lldp.packBinaryData((U8*)strBinary, sizeof(strBinary), "linden_lab_bd");
272 lldp.packBinaryDataFixed((U8*)strBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
273 lldp.packU8(valU8,"linden_lab_u8");
274 lldp.packU16(valU16,"linden_lab_u16");
275 lldp.packU32(valU32, "linden_lab_u32");
276 lldp.packS32(valS32, "linden_lab_s32");
277 lldp.packF32(valF32, "linden_lab_f32");
278 lldp.packColor4(llcol4, "linden_lab_col4");
279 lldp.packColor4U(llcol4u, "linden_lab_col4u");
280 lldp.packVector2(llvec2, "linden_lab_vec2");
281 lldp.packVector3(llvec3, "linden_lab_vec3");
282 lldp.packVector4(llvec4, "linden_lab_vec4");
283 uuid.generate();
284 lldp.packUUID(uuid, "linden_lab_uuid");
285
286 S32 cur_size = lldp.getCurrentSize();
287
288 LLDataPackerAsciiBuffer lldp1(packbuf, cur_size);
289 lldp1.unpackString(unpkstr , "linden_lab_str");
290 lldp1.unpackBinaryData((U8*)unpkstrBinary, unpksizeBinary, "linden_lab_bd");
291 lldp1.unpackBinaryDataFixed((U8*)unpkstrBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
292 lldp1.unpackU8(unpkvalU8,"linden_lab_u8");
293 lldp1.unpackU16(unpkvalU16,"linden_lab_u16");
294 lldp1.unpackU32(unpkvalU32, "linden_lab_u32");
295 lldp1.unpackS32(unpkvalS32, "linden_lab_s32");
296 lldp1.unpackF32(unpkvalF32, "linden_lab_f32");
297 lldp1.unpackColor4(unpkllcol4, "linden_lab_col4");
298 lldp1.unpackColor4U(unpkllcol4u, "linden_lab_col4u");
299 lldp1.unpackVector2(unpkllvec2, "linden_lab_vec2");
300 lldp1.unpackVector3(unpkllvec3, "linden_lab_vec3");
301 lldp1.unpackVector4(unpkllvec4, "linden_lab_vec4");
302 lldp1.unpackUUID(unpkuuid, "linden_lab_uuid");
303
304 ensure("LLDataPackerAsciiBuffer::packString failed", strcmp(str, unpkstr.c_str()) == 0);
305 ensure("LLDataPackerAsciiBuffer::packBinaryData failed", strcmp(strBinary, unpkstrBinary) == 0);
306 ensure("LLDataPackerAsciiBuffer::packBinaryDataFixed failed", strcmp(strBinaryFixed, unpkstrBinaryFixed) == 0);
307 ensure_equals("LLDataPackerAsciiBuffer::packU8 failed", valU8, unpkvalU8);
308 ensure_equals("LLDataPackerAsciiBuffer::packU16 failed", valU16, unpkvalU16);
309 ensure_equals("LLDataPackerAsciiBuffer::packU32 failed", valU32, unpkvalU32);
310 ensure_equals("LLDataPackerAsciiBuffer::packS32 failed", valS32, unpkvalS32);
311 ensure("LLDataPackerAsciiBuffer::packF32 failed", is_approx_equal(valF32, unpkvalF32));
312 ensure_equals("LLDataPackerAsciiBuffer::packColor4 failed", llcol4, unpkllcol4);
313 ensure_equals("LLDataPackerAsciiBuffer::packColor4U failed", llcol4u, unpkllcol4u);
314 ensure_equals("LLDataPackerAsciiBuffer::packVector2 failed", llvec2, unpkllvec2);
315 ensure_equals("LLDataPackerAsciiBuffer::packVector3 failed", llvec3, unpkllvec3);
316 ensure_equals("LLDataPackerAsciiBuffer::packVector4 failed", llvec4, unpkllvec4);
317 ensure_equals("LLDataPackerAsciiBuffer::packUUID failed", uuid, unpkuuid);
318 }
319
320 template<> template<>
321 void datapacker_test_object_t::test<9>()
322 {
323 char* packbuf = new char[128];
324 char str[] = "SecondLife is virtual World";
325 LLDataPackerAsciiBuffer lldp(packbuf, 128);
326 lldp.packString(str , "linden_lab");
327 lldp.freeBuffer();
328 ensure("LLDataPackerAsciiBuffer::freeBuffer failed" , 0 == lldp.getBufferSize());
329 }
330
331 template<> template<>
332 void datapacker_test_object_t::test<10>()
333 {
334 char buf[] = "SecondLife is virtual World";
335 S32 size = sizeof(buf);
336 LLDataPackerAsciiBuffer lldp(buf, size);
337 char new_buf[] = "Its Amazing";
338 size = sizeof(new_buf);
339 lldp.assignBuffer(new_buf, size);
340 ensure("LLDataPackerAsciiBuffer::assignBuffer failed" , ((lldp.getBufferSize() == size) && (1 == lldp.getCurrentSize()))) ;
341 }
342
343 //*********LLDataPackerAsciiFile
344
345 template<> template<>
346 void datapacker_test_object_t::test<11>()
347 {
348 F32 f_val = 44.44f, f_unpkval;
349
350 FILE* fp = fopen(TEST_FILE_NAME, "w+");
351 if(!fp)
352 {
353 llerrs << "File couldnt be open" <<llendl;
354 return;
355 }
356
357 LLDataPackerAsciiFile lldp(fp,2);
358 lldp.packFixed( f_val, "linden_lab", FALSE, 8, 8);
359
360 fflush(fp);
361 fseek(fp,0,SEEK_SET);
362 LLDataPackerAsciiFile lldp1(fp,2);
363
364 lldp1.unpackFixed(f_unpkval, "linden_lab", FALSE, 8, 8);
365 fclose(fp);
366
367 ensure_approximately_equals("LLDataPackerAsciiFile::packFixed failed", f_val, f_unpkval, 8);
368 }
369
370 template<> template<>
371 void datapacker_test_object_t::test<12>()
372 {
373 char str[] = "SecondLife is virtual World\0";
374 char strBinary[] = "SecondLife is virtual World";
375 char strBinaryFixed[] = "Fixed Data";
376 S32 sizeBinaryFixed = sizeof(strBinaryFixed);
377 U8 valU8 = 'C';
378 U16 valU16 = 0xFFFF;
379 U32 valU32 = 0xFFFFFFFF;
380 S32 valS32 = -94967295;
381 F32 valF32 = 4354355.44f ;
382 LLColor4 llcol4(3.3f, 0, 4.4f, 5.5f);
383 LLColor4U llcol4u(3, 128, 24, 33);
384 LLVector2 llvec2(333.33f, 444.44f);
385 LLVector3 llvec3(333.33f, 444.44f, 555.55f);
386 LLVector4 llvec4(333.33f, 444.44f, 555.55f, 666.66f);
387 LLUUID uuid;
388
389 std::string unpkstr;
390 char unpkstrBinary[256];
391 char unpkstrBinaryFixed[256];
392 S32 unpksizeBinary;
393 U8 unpkvalU8;
394 U16 unpkvalU16;
395 U32 unpkvalU32;
396 S32 unpkvalS32;
397 F32 unpkvalF32;
398 LLColor4 unpkllcol4;
399 LLColor4U unpkllcol4u;
400 LLVector2 unpkllvec2;
401 LLVector3 unpkllvec3;
402 LLVector4 unpkllvec4;
403 LLUUID unpkuuid;
404
405 FILE* fp = fopen(TEST_FILE_NAME,"w+");
406 if(!fp)
407 {
408 llerrs << "File couldnt be open" <<llendl;
409 return;
410 }
411
412 LLDataPackerAsciiFile lldp(fp,2);
413
414 lldp.packString(str , "linden_lab_str");
415 lldp.packBinaryData((U8*)strBinary, sizeof(strBinary), "linden_lab_bd");
416 lldp.packBinaryDataFixed((U8*)strBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
417 lldp.packU8(valU8,"linden_lab_u8");
418 lldp.packU16(valU16,"linden_lab_u16");
419 lldp.packU32(valU32, "linden_lab_u32");
420 lldp.packS32(valS32, "linden_lab_s32");
421 lldp.packF32(valF32, "linden_lab_f32");
422 lldp.packColor4(llcol4, "linden_lab_col4");
423 lldp.packColor4U(llcol4u, "linden_lab_col4u");
424 lldp.packVector2(llvec2, "linden_lab_vec2");
425 lldp.packVector3(llvec3, "linden_lab_vec3");
426 lldp.packVector4(llvec4, "linden_lab_vec4");
427 uuid.generate();
428 lldp.packUUID(uuid, "linden_lab_uuid");
429
430 fflush(fp);
431 fseek(fp,0,SEEK_SET);
432 LLDataPackerAsciiFile lldp1(fp,2);
433
434 lldp1.unpackString(unpkstr , "linden_lab_str");
435 lldp1.unpackBinaryData((U8*)unpkstrBinary, unpksizeBinary, "linden_lab_bd");
436 lldp1.unpackBinaryDataFixed((U8*)unpkstrBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
437 lldp1.unpackU8(unpkvalU8,"linden_lab_u8");
438 lldp1.unpackU16(unpkvalU16,"linden_lab_u16");
439 lldp1.unpackU32(unpkvalU32, "linden_lab_u32");
440 lldp1.unpackS32(unpkvalS32, "linden_lab_s32");
441 lldp1.unpackF32(unpkvalF32, "linden_lab_f32");
442 lldp1.unpackColor4(unpkllcol4, "linden_lab_col4");
443 lldp1.unpackColor4U(unpkllcol4u, "linden_lab_col4u");
444 lldp1.unpackVector2(unpkllvec2, "linden_lab_vec2");
445 lldp1.unpackVector3(unpkllvec3, "linden_lab_vec3");
446 lldp1.unpackVector4(unpkllvec4, "linden_lab_vec4");
447 lldp1.unpackUUID(unpkuuid, "linden_lab_uuid");
448
449 fclose(fp);
450
451 ensure("LLDataPackerAsciiFile::packString failed", strcmp(str, unpkstr.c_str()) == 0);
452 ensure("LLDataPackerAsciiFile::packBinaryData failed", strcmp(strBinary, unpkstrBinary) == 0);
453 ensure("LLDataPackerAsciiFile::packBinaryDataFixed failed", strcmp(strBinaryFixed, unpkstrBinaryFixed) == 0);
454 ensure_equals("LLDataPackerAsciiFile::packU8 failed", valU8, unpkvalU8);
455 ensure_equals("LLDataPackerAsciiFile::packU16 failed", valU16, unpkvalU16);
456 ensure_equals("LLDataPackerAsciiFile::packU32 failed", valU32, unpkvalU32);
457 ensure_equals("LLDataPackerAsciiFile::packS32 failed", valS32, unpkvalS32);
458 ensure("LLDataPackerAsciiFile::packF32 failed", is_approx_equal(valF32, unpkvalF32));
459 ensure_equals("LLDataPackerAsciiFile::packColor4 failed", llcol4, unpkllcol4);
460 ensure_equals("LLDataPackerAsciiFile::packColor4U failed", llcol4u, unpkllcol4u);
461 ensure_equals("LLDataPackerAsciiFile::packVector2 failed", llvec2, unpkllvec2);
462 ensure_equals("LLDataPackerAsciiFile::packVector3 failed", llvec3, unpkllvec3);
463 ensure_equals("LLDataPackerAsciiFile::packVector4 failed", llvec4, unpkllvec4);
464 ensure_equals("LLDataPackerAsciiFile::packUUID failed", uuid, unpkuuid);
465 }
466
467 template<> template<>
468 void datapacker_test_object_t::test<13>()
469 {
470 F32 f_val = 44.44f, f_unpkval;
471
472 std::ostringstream ostr;
473 LLDataPackerAsciiFile lldp(ostr,2);
474 lldp.packFixed( f_val, "linden_lab", FALSE, 8, 8);
475
476 std::istringstream istr(ostr.str());
477 LLDataPackerAsciiFile lldp1(istr,2);
478
479 lldp1.unpackFixed(f_unpkval, "linden_lab", FALSE, 8, 8);
480
481 ensure_approximately_equals("LLDataPackerAsciiFile::packFixed (iostring) failed", f_val, f_unpkval, 8);
482 }
483
484 template<> template<>
485 void datapacker_test_object_t::test<14>()
486 {
487 char str[] = "SecondLife is virtual World\0";
488 char strBinary[] = "SecondLife is virtual World";
489 char strBinaryFixed[] = "Fixed Data";
490 S32 sizeBinaryFixed = sizeof(strBinaryFixed);
491 U8 valU8 = 'C';
492 U16 valU16 = 0xFFFF;
493 U32 valU32 = 0xFFFFFFFF;
494 S32 valS32 = -94967295;
495 F32 valF32 = 4354355.44f ;
496 LLColor4 llcol4(3.3f, 0, 4.4f, 5.5f);
497 LLColor4U llcol4u(3, 128, 24, 33);
498 LLVector2 llvec2(3333333.33f, 444.333344f);
499 LLVector3 llvec3(3323233.33f, 444.4324f, 555.553232f);
500 LLVector4 llvec4(333.33233f, 444.4323234f, 55323225.55f, 6323236.66f);
501 LLUUID uuid;
502
503 std::string unpkstr;
504 char unpkstrBinary[256];
505 char unpkstrBinaryFixed[256];
506 S32 unpksizeBinary;
507 U8 unpkvalU8;
508 U16 unpkvalU16;
509 U32 unpkvalU32;
510 S32 unpkvalS32;
511 F32 unpkvalF32;
512 LLColor4 unpkllcol4;
513 LLColor4U unpkllcol4u;
514 LLVector2 unpkllvec2;
515 LLVector3 unpkllvec3;
516 LLVector4 unpkllvec4;
517 LLUUID unpkuuid;
518
519 std::ostringstream ostr;
520 LLDataPackerAsciiFile lldp(ostr,2);
521
522 lldp.packString(str , "linden_lab_str");
523 lldp.packBinaryData((U8*)strBinary, sizeof(strBinary), "linden_lab_bd");
524 lldp.packBinaryDataFixed((U8*)strBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
525 lldp.packU8(valU8,"linden_lab_u8");
526 lldp.packU16(valU16,"linden_lab_u16");
527 lldp.packU32(valU32, "linden_lab_u32");
528 lldp.packS32(valS32, "linden_lab_s32");
529 lldp.packF32(valF32, "linden_lab_f32");
530 lldp.packColor4(llcol4, "linden_lab_col4");
531 lldp.packColor4U(llcol4u, "linden_lab_col4u");
532 lldp.packVector2(llvec2, "linden_lab_vec2");
533 lldp.packVector3(llvec3, "linden_lab_vec3");
534 lldp.packVector4(llvec4, "linden_lab_vec4");
535 uuid.generate();
536 lldp.packUUID(uuid, "linden_lab_uuid");
537
538 std::istringstream istr(ostr.str());
539 LLDataPackerAsciiFile lldp1(istr,2);
540
541 lldp1.unpackString(unpkstr , "linden_lab_str");
542 lldp1.unpackBinaryData((U8*)unpkstrBinary, unpksizeBinary, "linden_lab_bd");
543 lldp1.unpackBinaryDataFixed((U8*)unpkstrBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
544 lldp1.unpackU8(unpkvalU8,"linden_lab_u8");
545 lldp1.unpackU16(unpkvalU16,"linden_lab_u16");
546 lldp1.unpackU32(unpkvalU32, "linden_lab_u32");
547 lldp1.unpackS32(unpkvalS32, "linden_lab_s32");
548 lldp1.unpackF32(unpkvalF32, "linden_lab_f32");
549 lldp1.unpackColor4(unpkllcol4, "linden_lab_col4");
550 lldp1.unpackColor4U(unpkllcol4u, "linden_lab_col4u");
551 lldp1.unpackVector2(unpkllvec2, "linden_lab_vec2");
552 lldp1.unpackVector3(unpkllvec3, "linden_lab_vec3");
553 lldp1.unpackVector4(unpkllvec4, "linden_lab_vec4");
554 lldp1.unpackUUID(unpkuuid, "linden_lab_uuid");
555
556 ensure("LLDataPackerAsciiFile::packString (iostring) failed", strcmp(str, unpkstr.c_str()) == 0);
557 ensure("LLDataPackerAsciiFile::packBinaryData (iostring) failed", strcmp(strBinary, unpkstrBinary) == 0);
558 ensure("LLDataPackerAsciiFile::packBinaryDataFixed (iostring) failed", strcmp(strBinaryFixed, unpkstrBinaryFixed) == 0);
559 ensure_equals("LLDataPackerAsciiFile::packU8 (iostring) failed", valU8, unpkvalU8);
560 ensure_equals("LLDataPackerAsciiFile::packU16 (iostring) failed", valU16, unpkvalU16);
561 ensure_equals("LLDataPackerAsciiFile::packU32 (iostring) failed", valU32, unpkvalU32);
562 ensure_equals("LLDataPackerAsciiFile::packS32 (iostring) failed", valS32, unpkvalS32);
563 ensure("LLDataPackerAsciiFile::packF32 (iostring) failed", is_approx_equal(valF32, unpkvalF32));
564 ensure_equals("LLDataPackerAsciiFile::packColor4 (iostring) failed", llcol4, unpkllcol4);
565 ensure_equals("LLDataPackerAsciiFile::packColor4U (iostring) failed", llcol4u, unpkllcol4u);
566 ensure_equals("LLDataPackerAsciiFile::packVector2 (iostring) failed", llvec2, unpkllvec2);
567 ensure_equals("LLDataPackerAsciiFile::packVector3 (iostring) failed", llvec3, unpkllvec3);
568 ensure_equals("LLDataPackerAsciiFile::packVector4 (iostring) failed", llvec4, unpkllvec4);
569 ensure_equals("LLDataPackerAsciiFile::packUUID (iostring) failed", uuid, unpkuuid);
570 }
571}