summaryrefslogtreecommitdiff
path: root/indra/test/llsd_new_tut.cpp
blob: 529e0df20fcb509d16d556ff90f4bec352849a6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
/** 
 * @file llsd_new_tut.cpp
 * @date   February 2006
 * @brief LLSD unit tests
 *
 * $LicenseInfo:firstyear=2006&license=viewergpl$
 * 
 * Copyright (c) 2006-2007, Linden Research, Inc.
 * 
 * Second Life Viewer Source Code
 * The source code in this file ("Source Code") is provided by Linden Lab
 * to you under the terms of the GNU General Public License, version 2.0
 * ("GPL"), unless you have obtained a separate licensing agreement
 * ("Other License"), formally executed by you and Linden Lab.  Terms of
 * the GPL can be found in doc/GPL-license.txt in this distribution, or
 * online at http://secondlife.com/developers/opensource/gplv2
 * 
 * There are special exceptions to the terms and conditions of the GPL as
 * it is applied to this Source Code. View the full text of the exception
 * in the file doc/FLOSS-exception.txt in this software distribution, or
 * online at http://secondlife.com/developers/opensource/flossexception
 * 
 * By copying, modifying or distributing this software, you acknowledge
 * that you have read and understood your obligations described above,
 * and agree to abide by those obligations.
 * 
 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
 * COMPLETENESS OR PERFORMANCE.
 * $/LicenseInfo$
 */

#include <tut/tut.h>
#include "linden_common.h"
#include "lltut.h"

#include "llsdtraits.h"
#include "llstring.h"

namespace tut
{
	class SDCleanupCheck
	{
	private:
		U32	mOutstandingAtStart;
	public:
		SDCleanupCheck() : mOutstandingAtStart(LLSD::outstandingCount()) { }
		~SDCleanupCheck()
		{
			ensure_equals("SDCleanupCheck",
				LLSD::outstandingCount(), mOutstandingAtStart);
		}
	};

	class SDAllocationCheck : public SDCleanupCheck
	{
	private:
		std::string mMessage;
		U32 mExpectedAllocations;
		U32 mAllocationAtStart;
	public:
		SDAllocationCheck(const std::string& message, int expectedAllocations)
			: mMessage(message),
			mExpectedAllocations(expectedAllocations),
			mAllocationAtStart(LLSD::allocationCount())
			{ }
		~SDAllocationCheck()
		{
			ensure_equals(mMessage + " SDAllocationCheck",
				LLSD::allocationCount() - mAllocationAtStart,
				mExpectedAllocations);
		}
	};
	
	struct SDTestData {
		template<class T>
		static void ensureTypeAndValue(const char* msg, const LLSD& actual,
			T expectedValue)
		{
			LLSDTraits<T> traits;
			
			std::string s(msg);
			
			ensure(			s + " type",	traits.checkType(actual));
			ensure_equals(	s + " value",	traits.get(actual), expectedValue);
		}
	};
	
	typedef test_group<SDTestData>	SDTestGroup;
	typedef SDTestGroup::object		SDTestObject;

	SDTestGroup sdTestGroup("LLSD(new)");
	
	template<> template<>
	void SDTestObject::test<1>()
		// construction and test of undefined
	{
		SDCleanupCheck check;
		
		LLSD u;
		ensure("is undefined", u.isUndefined());
	}
	
	template<> template<>
	void SDTestObject::test<2>()
		// setting and fetching scalar types
	{
		SDCleanupCheck check;
		
		LLSD v;
		
		v = true;		ensureTypeAndValue("set true", v, true);
		v = false;		ensureTypeAndValue("set false", v, false);
		v = true;		ensureTypeAndValue("set true again", v, true);
		
		v = 42;			ensureTypeAndValue("set to 42", v, 42);
		v = 0;			ensureTypeAndValue("set to zero", v, 0);
		v = -12345;		ensureTypeAndValue("set to neg", v, -12345);
		v = 2000000000;	ensureTypeAndValue("set to big", v, 2000000000);
		
		v = 3.14159265359;
						ensureTypeAndValue("set to pi", v, 3.14159265359);
						ensure_not_equals("isn't float", v.asReal(),
							(float)3.14159265359);
		v = 6.7e256;	ensureTypeAndValue("set to big", v, 6.7e256);
		
		LLUUID nullUUID;
		LLUUID newUUID;
		newUUID.generate();
		
		v = nullUUID;	ensureTypeAndValue("set to null UUID", v, nullUUID);
		v = newUUID;	ensureTypeAndValue("set to new UUID", v, newUUID);
		v = nullUUID;	ensureTypeAndValue("set to null again", v, nullUUID);
		
		// strings must be tested with two types of string objects
		std::string s = "now is the time";
		const char* cs = "for all good zorks";

		v = s;			ensureTypeAndValue("set to std::string", v, s);		
		v = cs;			ensureTypeAndValue("set to const char*", v, cs);
	
		LLDate epoch;
		LLDate aDay("2001-10-22T10:11:12.00Z");
		
		v = epoch;		ensureTypeAndValue("set to epoch", v, epoch);
		v = aDay;		ensureTypeAndValue("set to a day", v, aDay);
		
		LLURI path("http://slurl.com/secondlife/Ambleside/57/104/26/");
		
		v = path;		ensureTypeAndValue("set to a uri", v, path);
		
		const char source[] = "once in a blue moon";
		std::vector<U8> data;
		copy(&source[0], &source[sizeof(source)], back_inserter(data));
		
		v = data;		ensureTypeAndValue("set to data", v, data);
		
		v.clear();
		ensure("reset to undefined", v.type() == LLSD::TypeUndefined);
	}
	
	template<> template<>
	void SDTestObject::test<3>()
		// construction via scalar values
		// tests both constructor and initialize forms
	{
		SDCleanupCheck check;
		
		LLSD b1(true);	ensureTypeAndValue("construct boolean", b1, true);
		LLSD b2 = true;	ensureTypeAndValue("initialize  boolean", b2, true);
		LLSD i1(42);	ensureTypeAndValue("construct int", i1, 42);
		LLSD i2 =42;	ensureTypeAndValue("initialize  int", i2, 42);
		LLSD d1(1.2);	ensureTypeAndValue("construct double", d1, 1.2);
		LLSD d2 = 1.2;	ensureTypeAndValue("initialize double", d2, 1.2);
		
		LLUUID newUUID;
		newUUID.generate();
		LLSD u1(newUUID);
						ensureTypeAndValue("construct UUID", u1, newUUID);
		LLSD u2 = newUUID;
						ensureTypeAndValue("initialize UUID", u2, newUUID);
		
		LLSD ss1(std::string("abc"));
						ensureTypeAndValue("construct std::string", ss1, "abc");
		LLSD ss2 = std::string("abc");
						ensureTypeAndValue("initialize std::string",ss2, "abc");
		LLSD sl1(std::string("def"));
						ensureTypeAndValue("construct std::string", sl1, "def");
		LLSD sl2 = std::string("def");
						ensureTypeAndValue("initialize std::string", sl2, "def");
		LLSD sc1("ghi");
						ensureTypeAndValue("construct const char*", sc1, "ghi");
		LLSD sc2 = "ghi";
						ensureTypeAndValue("initialize const char*",sc2, "ghi");

		LLDate aDay("2001-10-22T10:11:12.00Z");
		LLSD t1(aDay);	ensureTypeAndValue("construct LLDate", t1, aDay);
		LLSD t2 = aDay;	ensureTypeAndValue("initialize LLDate", t2, aDay);

		LLURI path("http://slurl.com/secondlife/Ambleside/57/104/26/");
		LLSD p1(path);	ensureTypeAndValue("construct LLURI", p1, path);
		LLSD p2 = path;	ensureTypeAndValue("initialize LLURI", p2, path);

		const char source[] = "once in a blue moon";
		std::vector<U8> data;
		copy(&source[0], &source[sizeof(source)], back_inserter(data));
		LLSD x1(data);	ensureTypeAndValue("construct vector<U8>", x1, data);
		LLSD x2 = data;	ensureTypeAndValue("initialize vector<U8>", x2, data);
	}
	
	void checkConversions(const char* msg, const LLSD& v,
		LLSD::Boolean eBoolean, LLSD::Integer eInteger,
		LLSD::Real eReal, const LLSD::String& eString)
	{
		std::string s(msg);
		
		ensure_equals(s+" to bool",	v.asBoolean(),	eBoolean);
		ensure_equals(s+" to int",	v.asInteger(),	eInteger);
		if (eReal == eReal)
		{
			ensure_equals(s+" to real",	v.asReal(),		eReal);
			ensure_equals(s+" to string",	v.asString(),	eString);
		}
		else
		{
// TODO: Fix on windows....
#ifndef LL_WINDOWS
# if !defined(fpclassify) && __GNUC__ >= 3
#   define FPCLASSIFY_NAMESPACE std::
# else
#   define FPCLASSIFY_NAMESPACE
# endif
			int left  = FPCLASSIFY_NAMESPACE fpclassify(v.asReal());
			int right = FPCLASSIFY_NAMESPACE fpclassify(eReal);

			ensure_equals(s+" to real", 	left, 			right);
			ensure_equals(s+" to string",	v.asString(),	eString);
#endif
		}
	}
	
	template<> template<>
	void SDTestObject::test<4>()
		// conversion between undefined and basic scalar types:
		//	boolean, integer, real and string
	{
		SDCleanupCheck check;
		
		LLSD v;			checkConversions("untitled", v, false, 0, 0.0, "");
		
		v = false;		checkConversions("false", v, false, 0, 0.0, "");
		v = true;		checkConversions("true", v, true, 1, 1.0, "true");
		
		v = 0;			checkConversions("zero", v, false, 0, 0.0, "0");
		v = 1;			checkConversions("one", v, true, 1, 1.0, "1");
		v = -33;		checkConversions("neg33", v, true, -33, -33.0, "-33");
		
		v = 0.0;		checkConversions("0.0", v, false, 0, 0.0, "0");
		v = 0.5;		checkConversions("point5", v, true, 0, 0.5, "0.5");
		v = 0.9;		checkConversions("point9", v, true, 0, 0.9, "0.9");
		v = -3.9;		checkConversions("neg3dot9", v, true, -3, -3.9, "-3.9");
		v = sqrt(-1.0);	checkConversions("NaN", v, false, 0, sqrt(-1.0), "nan");
		
		v = "";			checkConversions("empty", v, false, 0, 0.0, "");
		v = "0";		checkConversions("digit0", v, true, 0, 0.0, "0");
		v = "10";		checkConversions("digit10", v, true, 10, 10.0, "10");
		v = "-2.345";	checkConversions("decdigits", v,
							true, -2, -2.345, "-2.345");
		v = "apple";	checkConversions("apple", v, true, 0, 0.0, "apple");
		v = "33bob";	checkConversions("digialpha", v, true, 0, 0.0, "33bob");
		v = " ";		checkConversions("space", v, true, 0, 0.0, " ");
		v = "\n";		checkConversions("newline", v, true, 0, 0.0, "\n");
	}
	
	template<class T>
	void checkRoundTrip(const std::string& msg, const LLSD& actual,
		const char* sExpected, T vExpected)
	{
		std::string str = actual.asString();
		
		if (sExpected) {
			ensure_equals(msg + " string", str, sExpected);
		}
		
		LLSD u(str);
		LLSDTraits<T> traits;
		
		ensure_equals(msg + " value", traits.get(u), vExpected);
	}
	
	
	template<> template<>
	void SDTestObject::test<5>()
		// conversion of String to and from UUID, Date and URI.
	{
		SDCleanupCheck check;
		
		LLSD v;
		
		LLUUID nullUUID;
		LLUUID someUUID;
		someUUID.generate();
		
		v = nullUUID;	checkRoundTrip("null uuid", v,
							"00000000-0000-0000-0000-000000000000", nullUUID);
		v = someUUID;	checkRoundTrip("random uuid", v, 0, someUUID);
		
		LLDate epoch;
		LLDate beta("2003-04-30T04:00:00Z");
		LLDate oneOh("2003-06-23T04:00:00Z");
		
		v = epoch;		checkRoundTrip("epoch date", v, 0, epoch);
		v = beta;		checkRoundTrip("beta date", v,
							"2003-04-30T04:00:00Z", beta);
		v = oneOh;		checkRoundTrip("1.0 date", v,
							"2003-06-23T04:00:00Z", oneOh);
		
		LLURI empty;
		LLURI path("http://slurl.com/secondlife/Ambleside/57/104/26/");
		LLURI mail("mailto:zero.linden@secondlife.com");
		
		v = empty;		checkRoundTrip("empty URI", v, 0, empty);
		v = path;		checkRoundTrip("path URI", v,
							"http://slurl.com/secondlife/Ambleside/57/104/26/",
							path);
		v = mail;		checkRoundTrip("mail URI", v,
							"mailto:zero.linden@secondlife.com", mail);
	}
	
	template<> template<>
	void SDTestObject::test<6>()
		// copy construction and assignment
		// checking for shared values after constr. or assignment
		// checking in both the same type and change of type case
	{
		SDCleanupCheck check;
		
		{
			LLSD v = 42;
		
			LLSD w0(v);
			ensureTypeAndValue("int constr.", w0, 42);
			
			LLSD w1(v);
			w1 = 13;
			ensureTypeAndValue("int constr. change case 1", w1, 13);
			ensureTypeAndValue("int constr. change case 2", v, 42);
			
			LLSD w2(v);
			v = 7;
			ensureTypeAndValue("int constr. change case 3", w2, 42);
			ensureTypeAndValue("int constr. change case 4", v, 7);
		}

		{
			LLSD v = 42;
		
			LLSD w1(v);
			w1 = "bob";
			ensureTypeAndValue("string constr. change case 1", w1, "bob");
			ensureTypeAndValue("string constr. change case 2", v, 42);
			
			LLSD w2(v);
			v = "amy";
			ensureTypeAndValue("string constr. change case 3", w2, 42);
			ensureTypeAndValue("string constr. change case 4", v, "amy");
		}

		{
			LLSD v = 42;
		
			LLSD w0;
			w0 = v;
			ensureTypeAndValue("int assign", w0, 42);
			
			LLSD w1;
			w1 = v;
			w1 = 13;
			ensureTypeAndValue("int assign change case 1", w1, 13);
			ensureTypeAndValue("int assign change case 2", v, 42);
			
			LLSD w2;
			w2 = v;
			v = 7;
			ensureTypeAndValue("int assign change case 3", w2, 42);
			ensureTypeAndValue("int assign change case 4", v, 7);
		}

		{
			LLSD v = 42;
		
			LLSD w1;
			w1 = v;
			w1 = "bob";
			ensureTypeAndValue("string assign change case 1", w1, "bob");
			ensureTypeAndValue("string assign change case 2", v, 42);
			
			LLSD w2;
			w2 = v;
			v = "amy";
			ensureTypeAndValue("string assign change case 3", w2, 42);
			ensureTypeAndValue("string assign change case 4", v, "amy");
		}
	}
	
	
	template<> template<>
	void SDTestObject::test<7>()
		// Test assignment and casting to various scalar types.  These
		// assignments should invoke the right conversion without it being
		// mentioned explicitly.  The few exceptions are marked SAD.
	{
		SDCleanupCheck check;
		
		LLSD v("  42.375");
		
		bool b = false;
		b = v;				ensure_equals("assign to bool", b, true);
		b = (bool)v;		ensure_equals("cast to bool", b, true);
		
		int i = 99;
		i = v;				ensure_equals("assign to int", i, 42);
		i = (int)v;			ensure_equals("cast to int", i, 42);
		
		double d = 3.14159;
		d = v;				ensure_equals("assign to double", d, 42.375);
		d = (double)v;		ensure_equals("cast to double", d, 42.375);
		
		std::string s = "yo";
// SAD	s = v;				ensure_equals("assign to string", s, "  42.375");
		s = (std::string)v;	ensure_equals("cast to string", s, "  42.375");

		std::string uuidStr = "b1e50c2b-b627-4d23-8a86-a65d97b6319b";
		v = uuidStr;
		LLUUID u;
		u = v;
					ensure_equals("assign to LLUUID", u, LLUUID(uuidStr));
// SAD	u = (LLUUID)v;
//					ensure_equals("cast to LLUUID", u, LLUUID(uuidStr));
		
		std::string dateStr = "2005-10-24T15:00:00Z";
		v = dateStr;
		LLDate date;
		date = v;
					ensure_equals("assign to LLDate", date.asString(), dateStr);
// SAD	date = (LLDate)v;
//					ensure_equals("cast to LLDate", date.asString(), dateStr);
		
		std::string uriStr = "http://secondlife.com";
		v = uriStr;
		LLURI uri;
		uri = v;
					ensure_equals("assign to LLURI", uri.asString(), uriStr);
// SAD 	uri = (LLURI)v;
//					ensure_equals("cast to LLURI", uri.asString(), uriStr);
	}
	
	template<> template<>
	void SDTestObject::test<8>()
		// Test construction of various scalar types from LLSD.
		// Test both construction and initialization forms.
		// These should invoke the right conversion without it being
		// mentioned explicitly.  The few exceptions are marked SAD.
	{
		SDCleanupCheck check;
		
		LLSD v("  42.375");
		
		bool b1(v);		ensure_equals("contruct bool", b1, true);
		bool b2 = v;	ensure_equals("initialize bool", b2, true);
				
		int i1(v);		ensure_equals("contruct int", i1, 42);
		int i2 = v;		ensure_equals("initialize int", i2, 42);
		
		double d1(v);	ensure_equals("contruct double", d1, 42.375);
		double d2 = v;	ensure_equals("initialize double", d2, 42.375);
		
		std::string s1(v);
		std::string s2 = v;
						ensure_equals("contruct string", s1, "  42.375");
						ensure_equals("initialize string", s2, "  42.375");

		std::string t1(v);
		std::string t2 = v.asString();		// SAD
						ensure_equals("contruct std::string", t1, "  42.375");
						ensure_equals("initialize std::string", t2, "  42.375");

		std::string uuidStr = "b1e50c2b-b627-4d23-8a86-a65d97b6319b";
		v = uuidStr;
		LLUUID uuid1(v.asUUID());		// SAD
		LLUUID uuid2 = v;
				ensure_equals("contruct LLUUID", uuid1, LLUUID(uuidStr));
				ensure_equals("initialize LLUUID", uuid2, LLUUID(uuidStr));

		std::string dateStr = "2005-10-24T15:00:00Z";
		v = dateStr;
		LLDate date1(v.asDate());		// SAD
		LLDate date2 = v;
				ensure_equals("contruct LLDate", date1.asString(), dateStr);
				ensure_equals("initialize LLDate", date2.asString(), dateStr);
				
		std::string uriStr = "http://secondlife.com";
		v = uriStr;
		LLURI uri1(v.asURI());			// SAD
		LLURI uri2 = v;
				ensure_equals("contruct LLURI", uri1.asString(), uriStr);
				ensure_equals("initialize LLURI", uri2.asString(), uriStr);
	}
	
	
	template<> template<>
	void SDTestObject::test<9>()
		// test to make sure v is interpreted as a bool in a various
		// scenarios.
	{
		SDCleanupCheck check;
		
		LLSD v = "0";
		// magic value that is interpreted as boolean true, but integer false!
		
		ensure_equals("trinary operator bool", (v ? true : false), true);
		ensure_equals("convert to int, then bool",
											((int)v ? true : false), false);

		if(v)
		{
			ensure("if converted to bool", true);
		}
		else
		{
			fail("bool did not convert to a bool in if statement.");
		}

		if(!v)
		{
			fail("bool did not convert to a bool in negated if statement.");
		}
	}
	
	template<> template<>
	void SDTestObject::test<10>()
		// map operations
	{
		SDCleanupCheck check;
		
		LLSD v;
		ensure("undefined has no members", !v.has("amy"));
		ensure("undefined get() is undefined", v.get("bob").isUndefined());
		
		v = LLSD::emptyMap();
		ensure("empty map is a map", v.isMap());
		ensure("empty map has no members", !v.has("cam"));
		ensure("empty map get() is undefined", v.get("don").isUndefined());
		
		v.clear();
		v.insert("eli", 43);
		ensure("insert converts to map", v.isMap());
		ensure("inserted key is present", v.has("eli"));
		ensureTypeAndValue("inserted value", v.get("eli"), 43);
		
		v.insert("fra", false);
		ensure("first key still present", v.has("eli"));
		ensure("second key is present", v.has("fra"));
		ensureTypeAndValue("first value", v.get("eli"), 43);
		ensureTypeAndValue("second value", v.get("fra"), false);
		
		v.erase("eli");
		ensure("first key now gone", !v.has("eli"));
		ensure("second key still present", v.has("fra"));
		ensure("first value gone", v.get("eli").isUndefined());
		ensureTypeAndValue("second value sill there", v.get("fra"), false);
		
		v.erase("fra");
		ensure("second key now gone", !v.has("fra"));
		ensure("second value gone", v.get("fra").isUndefined());
		
		v["gil"] = (std::string)"good morning";
		ensure("third key present", v.has("gil"));
		ensureTypeAndValue("third key value", v.get("gil"), "good morning");
		
		const LLSD& cv = v;	// FIX ME IF POSSIBLE
		ensure("missing key", cv["ham"].isUndefined());
		ensure("key not present", !v.has("ham"));
	
		LLSD w = 43;
		const LLSD& cw = w;	// FIX ME IF POSSIBLE
		int i = cw["ian"];
		ensureTypeAndValue("other missing value", i, 0);
		ensure("other missing key", !w.has("ian"));
		ensure("no conversion", w.isInteger());
		
		LLSD x;
		x = v;
		ensure("copy map type", x.isMap());
		ensureTypeAndValue("copy map value gil", x.get("gil"), "good morning");
	}
	
	
	template<> template<>
	void SDTestObject::test<11>()
		// array operations
	{
		SDCleanupCheck check;
		
		LLSD v;
		ensure_equals("undefined has no size", v.size(), 0);
		ensure("undefined get() is undefined", v.get(0).isUndefined());
		
		v = LLSD::emptyArray();
		ensure("empty array is an array", v.isArray());
		ensure_equals("empty array has no size", v.size(), 0);
		ensure("empty map get() is undefined", v.get(0).isUndefined());
		
		v.clear();
		v.append(88);
		v.append("noodle");
		v.append(true);
		ensure_equals("appened array size", v.size(), 3);
		ensure("append array is an array", v.isArray());
		ensureTypeAndValue("append 0", v[0], 88);
		ensureTypeAndValue("append 1", v[1], "noodle");
		ensureTypeAndValue("append 2", v[2], true);
		
		v.insert(0, 77);
		v.insert(2, "soba");
		v.insert(4, false);
		ensure_equals("inserted array size", v.size(), 6);
		ensureTypeAndValue("post insert 0", v[0], 77);
		ensureTypeAndValue("post insert 1", v[1], 88);
		ensureTypeAndValue("post insert 2", v[2], "soba");
		ensureTypeAndValue("post insert 3", v[3], "noodle");
		ensureTypeAndValue("post insert 4", v[4], false);
		ensureTypeAndValue("post insert 5", v[5], true);
		
		ensureTypeAndValue("get 1", v.get(1), 88);
		v.set(1, "hot");
		ensureTypeAndValue("set 1", v.get(1), "hot");
		
		v.erase(3);
		ensure_equals("post erase array size", v.size(), 5);
		ensureTypeAndValue("post erase 0", v[0], 77);
		ensureTypeAndValue("post erase 1", v[1], "hot");
		ensureTypeAndValue("post erase 2", v[2], "soba");
		ensureTypeAndValue("post erase 3", v[3], false);
		ensureTypeAndValue("post erase 4", v[4], true);
		
		v.append(34);
		ensure_equals("size after append", v.size(), 6);
		ensureTypeAndValue("post append 5", v[5], 34);

		LLSD w;
		w = v;
		ensure("copy array type", w.isArray());
		ensure_equals("copy array size", w.size(), 6);
		ensureTypeAndValue("copy array 0", w[0], 77);
		ensureTypeAndValue("copy array 1", w[1], "hot");
		ensureTypeAndValue("copy array 2", w[2], "soba");
		ensureTypeAndValue("copy array 3", w[3], false);
		ensureTypeAndValue("copy array 4", w[4], true);
		ensureTypeAndValue("copy array 5", w[5], 34);
	}


	template<> template<>
	void SDTestObject::test<12>()
		// no sharing
	{
		SDCleanupCheck check;
		
		LLSD a = 99;
		LLSD b = a;
		a = 34;
		ensureTypeAndValue("top level original changed",	a, 34);
		ensureTypeAndValue("top level copy unaltered",		b, 99);
		b = a;
		b = 66;
		ensureTypeAndValue("top level original unaltered",	a, 34);
		ensureTypeAndValue("top level copy changed",		b, 66);

		a[0] = "uno";
		a[1] = 99;
		a[2] = 1.414;
		b = a;
		a[1] = 34;
		ensureTypeAndValue("array member original changed",	a[1], 34);
		ensureTypeAndValue("array member copy unaltered",	b[1], 99);
		b = a;
		b[1] = 66;
		ensureTypeAndValue("array member original unaltered", a[1], 34);
		ensureTypeAndValue("array member copy changed",		b[1], 66);
		
		a["alpha"] = "uno";
		a["beta"] = 99;
		a["gamma"] = 1.414;
		b = a;
		a["beta"] = 34;
		ensureTypeAndValue("map member original changed",	a["beta"], 34);
		ensureTypeAndValue("map member copy unaltered",		b["beta"], 99);
		b = a;
		b["beta"] = 66;
		ensureTypeAndValue("map member original unaltered",	a["beta"], 34);
		ensureTypeAndValue("map member copy changed",		b["beta"], 66);
	}
	
	template<> template<>
	void SDTestObject::test<13>()
		// sharing implementation
	{
		SDCleanupCheck check;
		
		{
			SDAllocationCheck check("copy construct undefinded", 0);
			LLSD v;
			LLSD w = v;
		}
		
		{
			SDAllocationCheck check("assign undefined", 0);
			LLSD v;
			LLSD w;
			w = v;
		}
		
		{
			SDAllocationCheck check("assign integer value", 1);
			LLSD v = 45;
			v = 33;
			v = 0;
		}

		{
			SDAllocationCheck check("copy construct integer", 1);
			LLSD v = 45;
			LLSD w = v;
		}

		{
			SDAllocationCheck check("assign integer", 1);
			LLSD v = 45;
			LLSD w;
			w = v;
		}
		
		{
			SDAllocationCheck check("avoids extra clone", 2);
			LLSD v = 45;
			LLSD w = v;
			w = "nice day";
		}
	}

	/* TO DO:
		conversion of undefined to UUID, Date, URI and Binary
		conversion of undefined to map and array
		test map operations
		test array operations
		test array extension
		
		test copying and assign maps and arrays (clone)
		test iteration over map
		test iteration over array
		test iteration over scalar

		test empty map and empty array are indeed shared
		test serializations
	*/
}