aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/test/llnamevalue_tut.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:02 -0500
committerJacek Antonelli2008-08-15 23:45:02 -0500
commitd644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd (patch)
tree7ed0c2c27d717801238a2e6b5749cd5bf88c3059 /linden/indra/test/llnamevalue_tut.cpp
parentSecond Life viewer sources 1.17.3.0 (diff)
downloadmeta-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/llnamevalue_tut.cpp')
-rw-r--r--linden/indra/test/llnamevalue_tut.cpp848
1 files changed, 848 insertions, 0 deletions
diff --git a/linden/indra/test/llnamevalue_tut.cpp b/linden/indra/test/llnamevalue_tut.cpp
new file mode 100644
index 0000000..77e5ff2
--- /dev/null
+++ b/linden/indra/test/llnamevalue_tut.cpp
@@ -0,0 +1,848 @@
1/**
2 * @file llnamevalue_tut.cpp
3 * @author Adroit
4 * @date 2007-02
5 * @brief LLNameValue unit test
6 *
7 * Copyright (c) 2007-2007, Linden Research, Inc.
8 *
9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlife.com/developers/opensource/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlife.com/developers/opensource/flossexception
21 *
22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above,
24 * and agree to abide by those obligations.
25 *
26 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28 * COMPLETENESS OR PERFORMANCE.
29 */
30
31#include "lltut.h"
32#include "linden_common.h"
33#include "llnamevalue.h"
34#include "llsdserialize.h"
35
36namespace tut
37{
38 struct namevalue_test
39 {
40 namevalue_test()
41 {
42 mExpectedNameValueReference.string = NULL;
43 mExpectedNameValueType = NVT_NULL;
44 mCallbackCount = 0;
45 }
46
47 ~namevalue_test()
48 {
49 reset();
50 };
51
52 void reset()
53 {
54 switch(mExpectedNameValueType)
55 {
56 case NVT_STRING:
57 case NVT_ASSET:
58 delete [] mExpectedNameValueReference.string;
59 mExpectedNameValueReference.string = NULL;
60 break;
61 case NVT_F32:
62 delete mExpectedNameValueReference.f32;
63 mExpectedNameValueReference.f32 = NULL;
64 break;
65 case NVT_S32:
66 delete mExpectedNameValueReference.s32;
67 mExpectedNameValueReference.s32 = NULL;
68 break;
69 case NVT_U32:
70 delete mExpectedNameValueReference.u32;
71 mExpectedNameValueReference.u32 = NULL;
72 break;
73 case NVT_VEC3:
74 delete mExpectedNameValueReference.vec3;
75 mExpectedNameValueReference.vec3 = NULL;
76 break;
77 case NVT_U64:
78 delete mExpectedNameValueReference.u64;
79 mExpectedNameValueReference.u64 = NULL;
80 default:
81 break;
82 }
83
84 mExpectedNameValueType = NVT_NULL;
85 mCallbackCount = 0;
86 }
87
88 void setExpectedResult(ENameValueType type, void* value)
89 {
90 reset();
91 mExpectedNameValueType = type;
92 switch(type)
93 {
94 case NVT_STRING:
95 case NVT_ASSET:
96 mExpectedNameValueReference.string = new char[strlen((const char*) value)+1];
97 strcpy(mExpectedNameValueReference.string, (const char*) value);
98 break;
99 case NVT_F32:
100 mExpectedNameValueReference.f32 = new F32(*((F32*) value));
101 break;
102 case NVT_S32:
103 mExpectedNameValueReference.s32 = new S32(*((S32*) value));
104 break;
105 case NVT_U32:
106 mExpectedNameValueReference.u32 = new U32(*((U32*) value));
107 break;
108 case NVT_VEC3:
109 mExpectedNameValueReference.vec3 = new LLVector3(*((LLVector3*) value));
110 break;
111 case NVT_U64:
112 mExpectedNameValueReference.u64 = new U64(*((U64*) value));
113 default:
114 break;
115 }
116 }
117
118 void verifyChange(LLNameValue* changed)
119 {
120 std::string str = "";
121 str += "Expected Value of type: ";
122 str += NameValueTypeStrings[mExpectedNameValueType];
123 str += "not equal";
124
125 switch(mExpectedNameValueType)
126 {
127 case NVT_STRING:
128 ensure_memory_matches(str.c_str(), changed->getString(), strlen(changed->getString()), mExpectedNameValueReference.string, strlen(mExpectedNameValueReference.string));
129 break;
130 case NVT_ASSET:
131 ensure_memory_matches(str.c_str(), changed->getAsset(), strlen(changed->getAsset()), mExpectedNameValueReference.string, strlen(mExpectedNameValueReference.string));
132 break;
133 case NVT_F32:
134 ensure(str, *(changed->getF32()) == *mExpectedNameValueReference.f32);
135 break;
136 case NVT_S32:
137 ensure(str, *(changed->getS32()) == *mExpectedNameValueReference.s32);
138 break;
139 case NVT_U32:
140 ensure(str, *(changed->getU32()) == *mExpectedNameValueReference.u32);
141 break;
142 case NVT_VEC3:
143 ensure(str, *(changed->getVec3()) == *mExpectedNameValueReference.vec3);
144 break;
145 case NVT_U64:
146 ensure(str, *(changed->getU64()) == *mExpectedNameValueReference.u64);
147 break;
148 default:
149 break;
150 }
151 }
152
153 void HandleCallback(LLNameValue* changed)
154 {
155 mCallbackCount++;
156 verifyChange(changed);
157 ensure("Callback called more than once", mCallbackCount == 1);
158 }
159
160 static void NameValueCallbackFunction(LLNameValue* changed, void** data)
161 {
162 namevalue_test* pNameValue = (namevalue_test*)data;
163 pNameValue->HandleCallback(changed);
164 }
165
166 ENameValueType mExpectedNameValueType;
167 UNameValueReference mExpectedNameValueReference;
168 int mCallbackCount;
169 };
170 typedef test_group<namevalue_test> namevalue_t;
171 typedef namevalue_t::object namevalue_object_t;
172 tut::namevalue_t tut_namevalue("namevalue_test");
173
174
175 template<> template<>
176 void namevalue_object_t::test<1>()
177 {
178 // LLNameValue()
179 LLNameValue nValue;
180 ensure("mName should have been NULL", nValue.mName == NULL);
181 ensure("getTypeEnum failed",nValue.getTypeEnum() == NVT_NULL);
182 ensure("getClassEnum failed",nValue.getClassEnum() == NVC_NULL);
183 ensure("getSendtoEnum failed",nValue.getSendtoEnum() == NVS_NULL);
184
185 LLNameValue nValue1(" SecondLife ASSET RW SIM 232324343");
186
187 }
188
189 // LLNameValue(const char* data);
190 // LLNameValue(const char* name, const char* data, const char* type, const char* nvclass, const char* nvsendto,
191 // TNameValueCallback nvcb = NULL, void** user_data = NULL);
192 template<> template<>
193 void namevalue_object_t::test<2>()
194 {
195 LLNameValue nValue(" SecondLife ASSET RW S 232324343");
196 ensure("mName not set correctly", (0 == strcmp(nValue.mName,"SecondLife")));
197 ensure("getTypeEnum failed", nValue.getTypeEnum() == NVT_ASSET);
198 ensure("getClassEnum failed", nValue.getClassEnum() == NVC_READ_WRITE);
199 ensure("getSendtoEnum failed", nValue.getSendtoEnum() == NVS_SIM);
200 ensure("getString failed", (0==strcmp(nValue.getAsset(),"232324343")));
201 ensure("sendToData or sendToViewer failed", !nValue.sendToData() && !nValue.sendToViewer());
202
203 LLNameValue nValue1("\n\r SecondLife_1 STRING READ_WRITE SIM 232324343");
204 ensure("1. mName not set correctly", (0 == strcmp(nValue1.mName,"SecondLife_1")));
205 ensure("1. getTypeEnum failed", nValue1.getTypeEnum() == NVT_STRING);
206 ensure("1. getClassEnum failed", nValue1.getClassEnum() == NVC_READ_WRITE);
207 ensure("1. getSendtoEnum failed", nValue1.getSendtoEnum() == NVS_SIM);
208 ensure("1. getString failed", (0==strcmp(nValue1.getString(),"232324343")));
209 ensure("1. sendToData or sendToViewer failed", !nValue1.sendToData() && !nValue1.sendToViewer());
210
211 LLNameValue nValue2("SecondLife", "23.5", "F32", "R", "DS");
212 ensure("2. getTypeEnum failed", nValue2.getTypeEnum() == NVT_F32);
213 ensure("2. getClassEnum failed", nValue2.getClassEnum() == NVC_READ_ONLY);
214 ensure("2. getSendtoEnum failed", nValue2.getSendtoEnum() == NVS_DATA_SIM);
215 ensure("2. getF32 failed", *nValue2.getF32() == 23.5f);
216 ensure("2. sendToData or sendToViewer failed", nValue2.sendToData() && !nValue2.sendToViewer());
217
218 LLNameValue nValue3("SecondLife", "-43456787", "S32", "READ_ONLY", "SIM_SPACE");
219 ensure("3. getTypeEnum failed", nValue3.getTypeEnum() == NVT_S32);
220 ensure("3. getClassEnum failed", nValue3.getClassEnum() == NVC_READ_ONLY);
221 ensure("3. getSendtoEnum failed", nValue3.getSendtoEnum() == NVS_DATA_SIM);
222 ensure("3. getS32 failed", *nValue3.getS32() == -43456787);
223 ensure("sendToData or sendToViewer failed", nValue3.sendToData() && !nValue3.sendToViewer());
224
225 LLNameValue nValue4("SecondLife", "<1.0, 2.0, 3.0>", "VEC3", "CB", "SV");
226 LLVector3 llvec4(1.0, 2.0, 3.0);
227 ensure("4. getTypeEnum failed", nValue4.getTypeEnum() == NVT_VEC3);
228 ensure("4. getClassEnum failed", nValue4.getClassEnum() == NVC_CALLBACK);
229 ensure("4. getSendtoEnum failed", nValue4.getSendtoEnum() == NVS_SIM_VIEWER);
230 ensure("4. getVec3 failed", *nValue4.getVec3() == llvec4);
231 ensure("4. sendToData or sendToViewer failed", !nValue4.sendToData() && nValue4.sendToViewer());
232
233 LLNameValue nValue5("SecondLife", "-1.0, 2.4, 3", "VEC3", "CALLBACK", "SIM_VIEWER");
234 LLVector3 llvec5(-1.0f, 2.4f, 3);
235 ensure("5. getTypeEnum failed", nValue5.getTypeEnum() == NVT_VEC3);
236 ensure("5. getClassEnum failed", nValue5.getClassEnum() == NVC_CALLBACK);
237 ensure("5. getSendtoEnum failed", nValue5.getSendtoEnum() == NVS_SIM_VIEWER);
238 ensure("5. getVec3 failed", *nValue5.getVec3() == llvec5);
239 ensure("5. sendToData or sendToViewer failed", !nValue5.sendToData() && nValue5.sendToViewer());
240
241 LLNameValue nValue6("SecondLife", "89764323", "U32", "CALLBACK", "DSV");
242 ensure("6. getTypeEnum failed", nValue6.getTypeEnum() == NVT_U32);
243 ensure("6. getClassEnum failed", nValue6.getClassEnum() == NVC_CALLBACK);
244 ensure("6. getSendtoEnum failed", nValue6.getSendtoEnum() == NVS_DATA_SIM_VIEWER);
245 ensure("6. getU32 failed", *nValue6.getU32() == 89764323);
246 ensure("6. sendToData or sendToViewer failed", nValue6.sendToData() && nValue6.sendToViewer());
247
248 LLNameValue nValue7("SecondLife", "89764323323232", "U64", "CALLBACK", "SIM_SPACE_VIEWER");
249 U64 u64_7 = U64L(89764323323232);
250 ensure("7. getTypeEnum failed", nValue7.getTypeEnum() == NVT_U64);
251 ensure("7. getClassEnum failed", nValue7.getClassEnum() == NVC_CALLBACK);
252 ensure("7. getSendtoEnum failed", nValue7.getSendtoEnum() == NVS_DATA_SIM_VIEWER);
253 ensure("7. getU32 failed", *nValue7.getU64() == u64_7);
254 ensure("7. sendToData or sendToViewer failed", nValue7.sendToData() && nValue7.sendToViewer());
255 }
256
257 // LLNameValue(const char* name, const char* data, const char* type, const char* nvclass,
258 // TNameValueCallback nvcb = NULL, void** user_data = NULL);
259 template<> template<>
260 void namevalue_object_t::test<3>()
261 {
262 LLNameValue nValue("SecondLife", "232324343", "ASSET", "READ_WRITE");
263 ensure("mName not set correctly", (0 == strcmp(nValue.mName,"SecondLife")));
264 ensure("getTypeEnum failed", nValue.getTypeEnum() == NVT_ASSET);
265 ensure("getClassEnum failed", nValue.getClassEnum() == NVC_READ_WRITE);
266 ensure("getSendtoEnum failed", nValue.getSendtoEnum() == NVS_SIM);
267 ensure("getString failed", (0==strcmp(nValue.getAsset(),"232324343")));
268
269 LLNameValue nValue1("SecondLife", "232324343", "STRING", "READ_WRITE");
270 ensure("1. mName not set correctly", (0 == strcmp(nValue1.mName,"SecondLife")));
271 ensure("1. getTypeEnum failed", nValue1.getTypeEnum() == NVT_STRING);
272 ensure("1. getClassEnum failed", nValue1.getClassEnum() == NVC_READ_WRITE);
273 ensure("1. getSendtoEnum failed", nValue1.getSendtoEnum() == NVS_SIM);
274 ensure("1. getString failed", (0==strcmp(nValue1.getString(),"232324343")));
275
276 LLNameValue nValue2("SecondLife", "23.5", "F32", "R");
277 ensure("2. getTypeEnum failed", nValue2.getTypeEnum() == NVT_F32);
278 ensure("2. getClassEnum failed", nValue2.getClassEnum() == NVC_READ_ONLY);
279 ensure("2. getSendtoEnum failed", nValue2.getSendtoEnum() == NVS_SIM);
280 ensure("2. getF32 failed", *nValue2.getF32() == 23.5f);
281
282 LLNameValue nValue3("SecondLife", "-43456787", "S32", "READ_ONLY");
283 ensure("3. getTypeEnum failed", nValue3.getTypeEnum() == NVT_S32);
284 ensure("3. getClassEnum failed", nValue3.getClassEnum() == NVC_READ_ONLY);
285 ensure("3. getSendtoEnum failed", nValue3.getSendtoEnum() == NVS_SIM);
286 ensure("3. getS32 failed", *nValue3.getS32() == -43456787);
287
288 LLNameValue nValue4("SecondLife", "<1.0, 2.0, 3.0>", "VEC3", "CB");
289 LLVector3 llvec4(1.0, 2.0, 3.0);
290 ensure("4. getTypeEnum failed", nValue4.getTypeEnum() == NVT_VEC3);
291 ensure("4. getClassEnum failed", nValue4.getClassEnum() == NVC_CALLBACK);
292 ensure("4. getSendtoEnum failed", nValue4.getSendtoEnum() == NVS_SIM);
293 ensure("4. getVec3 failed", *nValue4.getVec3() == llvec4);
294
295 LLNameValue nValue5("SecondLife", "-1.0, 2.4, 3", "VEC3", "CALLBACK");
296 LLVector3 llvec5(-1.0f, 2.4f, 3);
297 ensure("5. getTypeEnum failed", nValue5.getTypeEnum() == NVT_VEC3);
298 ensure("5. getClassEnum failed", nValue5.getClassEnum() == NVC_CALLBACK);
299 ensure("5. getSendtoEnum failed", nValue5.getSendtoEnum() == NVS_SIM);
300 ensure("5. getVec3 failed", *nValue5.getVec3() == llvec5);
301
302 LLNameValue nValue6("SecondLife", "89764323", "U32", "CALLBACK");
303 ensure("6. getTypeEnum failed", nValue6.getTypeEnum() == NVT_U32);
304 ensure("6. getClassEnum failed", nValue6.getClassEnum() == NVC_CALLBACK);
305 ensure("6. getSendtoEnum failed", nValue6.getSendtoEnum() == NVS_SIM);
306 ensure("6. getU32 failed", *nValue6.getU32() == 89764323);
307
308 LLNameValue nValue7("SecondLife", "89764323323232", "U64", "CALLBACK");
309 U64 u64_7 = U64L(89764323323232);
310 ensure("7. getTypeEnum failed", nValue7.getTypeEnum() == NVT_U64);
311 ensure("7. getClassEnum failed", nValue7.getClassEnum() == NVC_CALLBACK);
312 ensure("7. getSendtoEnum failed", nValue7.getSendtoEnum() == NVS_SIM);
313 ensure("7. getU32 failed", *nValue7.getU64() == u64_7);
314 }
315
316 // LLNameValue(const char* name, const char* type, const char* nvclass,
317 // TNameValueCallback nvcb = NULL, void** user_data = NULL);
318 template<> template<>
319 void namevalue_object_t::test<4>()
320 {
321 LLNameValue nValue("SecondLife", "STRING", "READ_WRITE");
322 ensure("mName not set correctly", (0 == strcmp(nValue.mName,"SecondLife")));
323 ensure("getTypeEnum failed", nValue.getTypeEnum() == NVT_STRING);
324 ensure("getClassEnum failed", nValue.getClassEnum() == NVC_READ_WRITE);
325 ensure("getSendtoEnum failed", nValue.getSendtoEnum() == NVS_SIM);
326
327 LLNameValue nValue1("SecondLife", "ASSET", "READ_WRITE");
328 ensure("1. mName not set correctly", (0 == strcmp(nValue1.mName,"SecondLife")));
329 ensure("1. getTypeEnum for RW failed", nValue1.getTypeEnum() == NVT_ASSET);
330 ensure("1. getClassEnum for RW failed", nValue1.getClassEnum() == NVC_READ_WRITE);
331 ensure("1. getSendtoEnum for RW failed", nValue1.getSendtoEnum() == NVS_SIM);
332
333 LLNameValue nValue2("SecondLife", "F32", "READ_ONLY");
334 ensure("2. getTypeEnum failed", nValue2.getTypeEnum() == NVT_F32);
335 ensure("2. getClassEnum failed", nValue2.getClassEnum() == NVC_READ_ONLY);
336 ensure("2. getSendtoEnum failed", nValue2.getSendtoEnum() == NVS_SIM);
337
338 LLNameValue nValue3("SecondLife", "S32", "READ_ONLY");
339 ensure("3. getTypeEnum failed", nValue3.getTypeEnum() == NVT_S32);
340 ensure("3. getClassEnum failed", nValue3.getClassEnum() == NVC_READ_ONLY);
341 ensure("3. getSendtoEnum failed", nValue3.getSendtoEnum() == NVS_SIM);
342
343 skip_fail("NVC_CALLBACK does not parse.");
344
345 LLNameValue nValue4("SecondLife", "VEC3", "CALLBACK");
346 ensure("4. getTypeEnum failed", nValue4.getTypeEnum() == NVT_VEC3);
347 ensure("4. getClassEnum failed", nValue4.getClassEnum() == NVC_CALLBACK);
348 ensure("4. getSendtoEnum failed", nValue4.getSendtoEnum() == NVS_SIM);
349
350 LLNameValue nValue6("SecondLife", "U32", "CALLBACK");
351 ensure("6. getTypeEnum failed", nValue6.getTypeEnum() == NVT_U32);
352 ensure("6. getClassEnum failed", nValue6.getClassEnum() == NVC_CALLBACK);
353 ensure("6. getSendtoEnum failed", nValue6.getSendtoEnum() == NVS_SIM);
354
355 LLNameValue nValue7("SecondLife", "U64", "CALLBACK");
356 ensure("7. getTypeEnum failed", nValue7.getTypeEnum() == NVT_U64);
357 ensure("7. getClassEnum failed", nValue7.getClassEnum() == NVC_CALLBACK);
358 ensure("7. getSendtoEnum failed", nValue7.getSendtoEnum() == NVS_SIM);
359 }
360
361 template<> template<>
362 void namevalue_object_t::test<5>()
363 {
364 skip_fail("callback will be called more than once.");
365 LLNameValue nValue("SecondLife", "This is a test", "STRING", "CB", "SIM", NameValueCallbackFunction, (void**) this);
366
367 ensure("getString failed", (0 == strcmp(nValue.getString(),"This is a test")));
368 reset();
369
370 setExpectedResult(NVT_STRING, (void*)"New Value");
371 nValue.setString("New Value");
372 ensure("String nonzero failed", nValue.nonzero() == TRUE);
373 reset();
374 setExpectedResult(NVT_STRING, (void*)"");
375 nValue.setString("");
376 ensure("String nonzero failed", nValue.nonzero() == FALSE);
377 reset();
378 }
379
380 template<> template<>
381 void namevalue_object_t::test<6>()
382 {
383 skip_fail("callback will be called more than once.");
384 LLNameValue nValue("SecondLife", "This is a test", "ASSET", "CALLBACK", "S", NameValueCallbackFunction, (void**) this);
385 ensure("getAsset failed", (0 == strcmp(nValue.getAsset(),"This is a test")));
386 reset();
387
388 setExpectedResult(NVT_ASSET, (void*)"New Value");
389 nValue.setAsset("New Value");
390 reset();
391 }
392
393 template<> template<>
394 void namevalue_object_t::test<7>()
395 {
396 skip_fail("callback will be called more than once.");
397 LLNameValue nValue("SecondLife", "555555", "F32", "CB", "SIM", NameValueCallbackFunction, (void**) this);
398
399 ensure("getF32 failed",*nValue.getF32() == 555555.f);
400 reset();
401
402 F32 fVal = 0.1f;
403 setExpectedResult(NVT_F32, &fVal);
404 nValue.setF32(fVal);
405
406 fVal = -11111.1f;
407 setExpectedResult(NVT_F32, &fVal);
408 nValue.setF32(fVal);
409 ensure("F32 nonzero failed", nValue.nonzero() == TRUE);
410 reset();
411
412 fVal = 0.;
413 setExpectedResult(NVT_F32, &fVal);
414 nValue.setF32(fVal);
415 ensure("F32 nonzero failed", nValue.nonzero() == FALSE);
416 reset();
417 }
418
419 template<> template<>
420 void namevalue_object_t::test<8>()
421 {
422 skip_fail("callback will be called more than once.");
423 LLNameValue nValue("SecondLife", "-5555", "S32", "CB", "SIM", NameValueCallbackFunction, (void**) this);
424
425 ensure("getS32 failed", *nValue.getS32() == -5555);
426 reset();
427
428 S32 sVal = 0x7FFFFFFF;
429 setExpectedResult(NVT_S32, &sVal);
430 nValue.setS32(sVal);
431
432 sVal = -0x7FFFFFFF;
433 setExpectedResult(NVT_S32, &sVal);
434 nValue.setS32(sVal);
435 ensure("S32 nonzero failed", nValue.nonzero() == TRUE);
436 reset();
437
438 sVal = 0;
439 setExpectedResult(NVT_S32, &sVal);
440 nValue.setS32(sVal);
441 ensure("S32 nonzero failed", nValue.nonzero() == FALSE);
442 reset();
443 }
444
445 template<> template<>
446 void namevalue_object_t::test<9>()
447 {
448 LLNameValue nValue("SecondLife", "<-3, 2, 1>", "VEC3", "CB", "SIM", NameValueCallbackFunction, (void**) this);
449 LLVector3 vecExpected(-3, 2, 1);
450 LLVector3 vec;
451 nValue.getVec3(vec);
452 ensure("getVec3 failed", vec == vecExpected);
453 reset();
454
455 vecExpected.setVec(2, -1, 0);
456 setExpectedResult(NVT_VEC3, &vecExpected);
457 nValue.setVec3(vecExpected);
458 ensure("VEC3 nonzero failed", nValue.nonzero() == TRUE);
459 reset();
460
461 vecExpected.setVec(0, 0, 0);
462 setExpectedResult(NVT_VEC3, &vecExpected);
463 nValue.setVec3(vecExpected);
464 ensure("VEC3 nonzero failed", nValue.nonzero() == FALSE);
465 reset();
466 }
467
468 template<> template<>
469 void namevalue_object_t::test<10>()
470 {
471 LLNameValue nValue("SecondLife", "12345678", "U32", "CB", "SIM", NameValueCallbackFunction, (void**) this);
472
473 ensure("getU32 failed",*nValue.getU32() == 12345678);
474
475 U32 val = 0xFFFFFFFF;
476 setExpectedResult(NVT_U32, &val);
477 nValue.setU32(val);
478 ensure("U32 nonzero failed", nValue.nonzero() == TRUE);
479 reset();
480
481 val = 0;
482 setExpectedResult(NVT_U32, &val);
483 nValue.setU32(val);
484 ensure("U32 nonzero failed", nValue.nonzero() == FALSE);
485 reset();
486 }
487
488 template<> template<>
489 void namevalue_object_t::test<11>()
490 {
491 skip_fail("incomplete support for U64.");
492 LLNameValue nValue("SecondLife", "44444444444", "U64", "CB", "SIM", NameValueCallbackFunction, (void**) this);
493
494 ensure("getU64 failed",*nValue.getU64() == U64L(44444444444));
495 ensure("U64 nonzero failed", nValue.nonzero() == TRUE);
496
497 // there is no LLNameValue::setU64()
498 }
499
500 template<> template<>
501 void namevalue_object_t::test<12>()
502 {
503 LLNameValue nValue("SecondLife F32 RW SIM -333.337600");
504 F32 val = nValue.magnitude();
505 ensure_equals("F32 magnitude failed", val, 333.337600f);
506
507 LLNameValue nValue1("SecondLife STRING RW SIM 3300");
508 val = nValue1.magnitude();
509 ensure_equals("STRING magnitude failed",val,4.0f);
510
511 LLNameValue nValue2("SecondLife S32 RW SIM -3300");
512 val = nValue2.magnitude();
513 ensure_equals("S32 magnitude failed", val, 3300.);
514
515 LLNameValue nValue3("SecondLife U32 RW SIM 3300");
516 val = nValue3.magnitude();
517 ensure_equals("U32 magnitude failed", val, 3300.);
518
519 LLNameValue nValue4("SecondLife VEC3 RW SIM <1,2,3>");
520 LLVector3 vec(1,2,3);
521 val = nValue4.magnitude();
522 ensure_equals("VEC3 magnitude failed", val, vec.magVec());
523
524 skip_fail("incomplete support for U64.");
525 LLNameValue nValue5("SecondLife U64 RW SIM 12345");
526 val = nValue5.magnitude();
527 ensure_equals("U62 magnitude failed", val, 12345);
528 }
529
530 template<> template<>
531 void namevalue_object_t::test<13>()
532 {
533 skip_fail("incomplete support for U64.");
534 LLNameValue nValue("SecondLife U64 RW DSV 44444444444");
535 std::string ret_str = nValue.printNameValue();
536
537 ensure_equals("1:printNameValue failed",ret_str,"SecondLife U64 RW DSV 44444444444");
538
539 LLNameValue nValue1(ret_str.c_str());
540 ensure_equals("Serialization of printNameValue failed", nValue, nValue1);
541 }
542
543 template<> template<>
544 void namevalue_object_t::test<14>()
545 {
546 LLNameValue nValue("SecondLife STRING RW DSV 44444444444");
547 std::string ret_str = nValue.printData();
548 ensure_equals("1:printData failed",ret_str,"44444444444");
549
550 LLNameValue nValue1("SecondLife S32 RW DSV 44444");
551 ret_str = nValue1.printData();
552 ensure_equals("2:printData failed",ret_str,"44444");
553 }
554
555 template<> template<>
556 void namevalue_object_t::test<15>()
557 {
558 LLNameValue nValue("SecodLife STRING RW SIM 22222");
559 std::ostringstream stream1,stream2,stream3, stream4, stream5;
560 stream1 << nValue;
561 ensure_equals("STRING << failed",stream1.str(),"22222");
562
563 LLNameValue nValue1("SecodLife F32 RW SIM 22222");
564 stream2 << nValue1;
565 ensure_equals("F32 << failed",stream2.str(),"22222");
566
567 LLNameValue nValue2("SecodLife S32 RW SIM 22222");
568 stream3<< nValue2;
569 ensure_equals("S32 << failed",stream3.str(),"22222");
570
571 LLNameValue nValue3("SecodLife U32 RW SIM 122222");
572 stream4<< nValue3;
573 ensure_equals("U32 << failed",stream4.str(),"122222");
574
575 skip_fail("incomplete support for U64.");
576 LLNameValue nValue4("SecodLife U64 RW SIM 22222");
577 stream5<< nValue4;
578 ensure("U64 << failed",0 == strcmp((stream5.str()).c_str(),"22222"));
579 }
580
581 template<> template<>
582 void namevalue_object_t::test<16>()
583 {
584 LLNameValue nValue1("SecondLife STRING RW DSV 44444");
585 LLNameValue nValue2("SecondLife STRING RW SIM 33333");
586 LLNameValue nValue3("SecondLife");
587 nValue3 = nValue1 + nValue2;
588 ensure("1:operator+ failed",(0==strcmp(nValue3.getString(),"4444433333")));
589
590 LLNameValue nValue4("SecondLife F32 R DSV 44444");
591 LLNameValue nValue5("SecondLife F32 RW SIM 33333");
592 LLNameValue nValue6("SecondLife");
593 nValue6 = nValue4 + nValue5;
594 ensure_equals("2:operator+ failed",*nValue6.getF32(),77777.0);
595
596 LLNameValue nValue7("SecondLife F32 R DSV 44444");
597 LLNameValue nValue8("SecondLife S32 RW SIM 33333");
598 LLNameValue nValue9("SecondLife F32");
599 nValue9 = nValue7 + nValue8;
600 ensure_equals("3:operator+ failed",*nValue9.getF32(),77777.0);
601
602 LLNameValue nValue10("SecondLife VEC3 RW SIM <4, 4, 4>");
603 LLNameValue nValue11("SecondLife VEC3 RW SV <3, 3, 3>");
604 LLNameValue nValue12("SecondLife VEC3");
605 nValue12 = nValue10 + nValue11;
606 LLVector3 vec(7,7,7);
607 ensure_equals("4:operator+ failed",*nValue12.getVec3(), vec);
608 }
609
610 template<> template<>
611 void namevalue_object_t::test<17>()
612 {
613 LLNameValue nValue7(" SecondLife S32 RW SIM 22222");
614 LLNameValue nValue8(" SecondLife F32 RW SIM 33333");
615 LLNameValue nValue9(" SecondLife F32");
616 nValue9 = nValue7 - nValue8;
617 ensure_equals("1:operator- failed",*nValue9.getF32(),-11111.f);
618
619 LLNameValue nValue10(" SecondLife VEC3 RW SIM <2, 2, 2>");
620 LLNameValue nValue11(" SecondLife VEC3 RW SIM <3, 3, 3>");
621 LLNameValue nValue12(" SecondLife VEC3");
622 LLVector3 vec(-1,-1,-1);
623 nValue12 = nValue10 - nValue11;
624 ensure_equals("2:operator- failed",*nValue12.getVec3(), vec);
625 }
626
627 template<> template<>
628 void namevalue_object_t::test<18>()
629 {
630
631 LLNameValue nValue1(" SecondLife F32 RW SIM 22222");
632 LLNameValue nValue2(" SecondLife F32 RW SIM 33333");
633 LLNameValue nValue3(" SecondLife F32");
634 nValue3 = nValue1 * nValue2;
635 ensure_equals("1:operator* failed",*nValue3.getF32(),740725926.f);
636
637 LLNameValue nValue4(" SecondLife S32 RW SIM 22222");
638 LLNameValue nValue5(" SecondLife F32 RW SIM 33333");
639 LLNameValue nValue6(" SecondLife F32");
640 nValue6 = nValue4 * nValue5;
641 ensure_equals("2:operator* failed",*nValue6.getF32(),740725926.f);
642
643 LLNameValue nValue10(" SecondLife VEC3 RW SIM <2, 2, 2>");
644 LLNameValue nValue11(" SecondLife VEC3 RW SIM <3, 3, 3>");
645 LLNameValue nValue12(" SecondLife F32");
646 LLVector3 vec1(2,2,2);
647 LLVector3 vec2(3,3,3);
648 nValue12 = nValue10 * nValue11;
649 ensure_equals("2:operator* failed",*nValue12.getF32(), (vec1 * vec2));
650 }
651
652 template<> template<>
653 void namevalue_object_t::test<19>()
654 {
655 LLNameValue nValue1(" SecondLife S32 RW SIM 22222");
656 LLNameValue nValue2(" Virtual F32 RW SIM 44444");
657 LLNameValue nValue3(" SecondLife F32");
658 nValue3 = nValue1 / nValue2;
659 ensure_equals("1:operator/ failed",*nValue3.getF32(),0.5);
660
661 LLNameValue nValue4(" SecondLife F32 RW SIM 33333");
662 LLNameValue nValue5(" SecondLife S32 RW SIM 22222");
663 LLNameValue nValue6(" SecondLife F32");
664 nValue6 = nValue4 / nValue5;
665 ensure_equals("2:operator/ failed",*nValue6.getF32(),1.5);
666 }
667
668 template<> template<>
669 void namevalue_object_t::test<20>()
670 {
671 LLNameValue nValue1(" SecondLife S32 RW SIM 22222");
672 LLNameValue nValue2(" Virtual S32 RW SIM 33333");
673 LLNameValue nValue3(" SecondLife S32");
674 nValue3 = nValue1 % nValue2;
675 ensure_equals("1:operator% failed",*nValue3.getS32(),22222);
676
677 LLNameValue nValue4(" SecondLife U32 RW SIM 3");
678 LLNameValue nValue5(" SecondLife S32 RW SIM 2");
679 LLNameValue nValue6(" SecondLife S32");
680 nValue6 = nValue4 % nValue5;
681 ensure_equals("2:operator% failed",*nValue6.getS32(),1);
682
683 LLNameValue nValue10(" SecondLife VEC3 RW SIM <4, 5, 6>");
684 LLNameValue nValue11(" SecondLife VEC3 RW SIM <1, 2, 3>");
685 LLNameValue nValue12(" SecondLife VEC3");
686 LLVector3 vec1(4,5,6);
687 LLVector3 vec2(1,2,3);
688 LLVector3 vec3(vec1 % vec2);
689 nValue12 = nValue10 % nValue11;
690 ensure_equals("5:operator% failed",*nValue12.getVec3(), vec3);
691 }
692
693 template<> template<>
694 void namevalue_object_t::test<21>()
695 {
696 LLNameValue nValue1(" SecondLife STRING RW SIM 22222");
697 LLNameValue nValue2(" Virtual STRING RW SIM 22222");
698 ensure("1:operator== failed", nValue1 == nValue2);
699
700 LLNameValue nValue3(" SecondLife F32 RW SIM 33333");
701 LLNameValue nValue4(" Virtual F32 RW SIM 22222");
702 ensure("2:operator== failed",!(nValue3 == nValue4));
703
704 LLNameValue nValue5(" SecondLife STRING RW SIM 22222");
705 LLNameValue nValue6(" Virtual STRING RW SIM 33333");
706 ensure("3:operator== failed",!(nValue5 == nValue6));
707
708 LLNameValue nValue7(" SecondLife VEC3 RW SIM <2, 2, 2>");
709 LLNameValue nValue8(" Virtual VEC3 RW SIM <2, 2, 2>");
710 ensure("4:operator== failed",(nValue7 == nValue8));
711 }
712
713 template<> template<>
714 void namevalue_object_t::test<22>()
715 {
716 LLNameValue nValue1(" SecondLife STRING RW SIM 22222");
717 LLNameValue nValue2(" Virtual STRING RW SIM 33333");
718 bool b_ret = (nValue1 <= nValue2) ? 1 : 0;
719 ensure("1:operator<= failed",(1==b_ret));
720
721 LLNameValue nValue3(" SecondLife F32 RW SIM 33333");
722 LLNameValue nValue4(" Virtual F32 RW SIM 22222");
723 b_ret = (nValue3 <= nValue4) ? 1 : 0;
724 ensure("2:operator<= failed",(0==b_ret));
725 }
726
727 template<> template<>
728 void namevalue_object_t::test<23>()
729 {
730 LLNameValue nValue1(" SecondLife STRING RW SIM 22222");
731 LLNameValue nValue2(" Virtual STRING RW SIM 33333");
732 bool b_ret = (nValue1 >= nValue2) ? 1 : 0;
733 ensure("operator>= failed",!b_ret);
734
735 LLNameValue nValue3(" SecondLife F32 RW SIM 33333");
736 LLNameValue nValue4(" Virtual F32 RW SIM 22222");
737 b_ret = (nValue3 >= nValue4) ? 1 : 0;
738 ensure("2:operator<= failed",b_ret);
739
740 }
741
742 template<> template<>
743 void namevalue_object_t::test<24>()
744 {
745 LLNameValue nValue1(" SecondLife STRING RW SIM 33333");
746 LLNameValue nValue2(" Virtual STRING RW SIM 33333");
747 bool b_ret = (nValue1 < nValue2) ? 1 : 0;
748 ensure("operator< failed",!b_ret);
749
750 LLNameValue nValue3(" SecondLife F32 RW SIM 11111");
751 LLNameValue nValue4(" Virtual F32 RW SIM 22222");
752 b_ret = (nValue3 < nValue4) ? 1 : 0;
753 ensure("2:operator< failed",b_ret);
754
755 }
756
757 template<> template<>
758 void namevalue_object_t::test<25>()
759 {
760 LLNameValue nValue1(" SecondLife STRING RW SIM 33333");
761 LLNameValue nValue2(" Virtual STRING RW SIM 33333");
762 bool b_ret = (nValue1 > nValue2) ? 1 : 0;
763 ensure("1:operator> failed",!b_ret);
764
765 LLNameValue nValue3(" SecondLife F32 RW SIM 11111");
766 LLNameValue nValue4(" Virtual F32 RW SIM 22222");
767 b_ret = (nValue3 > nValue4) ? 1 : 0;
768 ensure("2:operator> failed",!b_ret);
769
770 LLNameValue nValue5(" SecondLife S32 RW SIM 22222");
771 LLNameValue nValue6(" Virtual F32 RW SIM 11111");
772 b_ret = (nValue5 > nValue6) ? 1 : 0;
773 ensure("3:operator> failed",b_ret);
774 }
775
776 template<> template<>
777 void namevalue_object_t::test<26>()
778 {
779 LLNameValue nValue1(" SecondLife STRING RW SIM 33333");
780 LLNameValue nValue2(" Virtual STRING RW SIM 33333");
781 bool b_ret = (nValue1 != nValue2) ? 1 : 0;
782 ensure("1:operator!= failed",!b_ret);
783
784 LLNameValue nValue3(" SecondLife F32 RW SIM 11111");
785 LLNameValue nValue4(" Virtual F32 RW SIM 22222");
786 b_ret = (nValue3 != nValue4) ? 1 : 0;
787 ensure("2:operator!= failed",b_ret);
788
789 }
790
791
792 template<> template<>
793 void namevalue_object_t::test<27>()
794 {
795 LLNameValue nValue1(" SecondLife F32 RW SIM 33333");
796 LLNameValue nValue2("Virtual");
797 nValue2 = -nValue1;
798 ensure_equals("1:operator unary- failed",*nValue2.getF32(), -33333.f);
799
800 LLNameValue nValue3(" SecondLife U32 RW SIM 11111");
801 LLNameValue nValue4("Virtual S32");
802 nValue4 = -nValue3;
803 ensure_equals("2:operator unary- failed",*nValue4.getS32(), -11111);
804
805 LLNameValue nValue5(" SecondLife VEC3 RW SIM <1, 1, 1>");
806 LLNameValue nValue6("Virtual VEC3");
807 LLVector3 vec(-1, -1, -1);
808 nValue6 = -nValue5;
809 ensure_equals("3:operator unary- failed",*nValue6.getVec3(), vec);
810 }
811
812 template<> template<>
813 void namevalue_object_t::test<28>()
814 {
815 LLNameValue nValue("SecondLife", "This is a test", "ASSET", "R", "S", NameValueCallbackFunction, (void**) this);
816
817 ensure("getAsset failed", (0 == strcmp(nValue.getAsset(),"This is a test")));
818 // this should not have updated as it is read only.
819 nValue.setAsset("New Value should not be updated");
820 ensure("setAsset on ReadOnly failed", (0 == strcmp(nValue.getAsset(),"This is a test")));
821
822 LLNameValue nValue1("SecondLife", "1234", "U32", "R", "S", NameValueCallbackFunction, (void**) this);
823 // this should not have updated as it is read only.
824 nValue1.setU32(4567);
825 ensure("setU32 on ReadOnly failed", *nValue1.getU32() == 1234);
826
827 LLNameValue nValue2("SecondLife", "1234", "S32", "R", "S", NameValueCallbackFunction, (void**) this);
828 // this should not have updated as it is read only.
829 nValue2.setS32(4567);
830 ensure("setS32 on ReadOnly failed", *nValue2.getS32() == 1234);
831
832 LLNameValue nValue3("SecondLife", "1234", "F32", "R", "S", NameValueCallbackFunction, (void**) this);
833 // this should not have updated as it is read only.
834 nValue3.setF32(4567);
835 ensure("setF32 on ReadOnly failed", *nValue3.getF32() == 1234);
836 nValue3 = nValue3 * 2;
837 ensure("setF32 on ReadOnly failed", *nValue3.getF32() == 1234);
838
839 LLNameValue nValue4("SecondLife", "<1,2,3>", "VEC3", "R", "S", NameValueCallbackFunction, (void**) this);
840 // this should not have updated as it is read only.
841 LLVector3 vec(4,5,6);
842 nValue3.setVec3(vec);
843 LLVector3 vec1(1,2,3);
844 ensure("setVec3 on ReadOnly failed", *nValue4.getVec3() == vec1);
845
846 // cant test for U64 as no set64 exists nor any operators support U64 type
847 }
848}