PageRenderTime 90ms CodeModel.GetById 26ms app.highlight 57ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/test/llsdmessagebuilder_tut.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 837 lines | 604 code | 149 blank | 84 comment | 3 complexity | 14818e7efa4cc1424649b23f7e9994dd MD5 | raw file
  1/** 
  2 * @file llsdmessagebuilder_tut.cpp
  3 * @date   February 2006
  4 * @brief LLSDMessageBuilder unit tests
  5 *
  6 * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#include <tut/tut.hpp>
 29
 30#include "linden_common.h"
 31#include "lltut.h"
 32#include "llmessagetemplate.h"
 33#include "llsdmessagebuilder.h"
 34#include "llsdmessagereader.h"
 35#include "llsdtraits.h"
 36#include "llmath.h"
 37#include "llquaternion.h"
 38#include "u64.h"
 39#include "v3dmath.h"
 40#include "v3math.h"
 41#include "v4math.h"
 42#include "llsdutil.h"
 43//#include "llsdutil.cpp"
 44#include "llsdutil_math.cpp"
 45#include "lltemplatemessagebuilder.h"
 46
 47namespace tut
 48{	
 49	static LLTemplateMessageBuilder::message_template_name_map_t templateNameMap;
 50
 51    LLMsgData* messageData = NULL;
 52    LLMsgBlkData* messageBlockData = NULL;
 53
 54	struct LLSDMessageBuilderTestData {
 55
 56		LLSDMessageBuilderTestData()
 57		{
 58			messageData = new LLMsgData("testMessage");
 59			messageBlockData = new LLMsgBlkData("testBlock", 0);
 60		}
 61
 62		static LLSDMessageBuilder defaultBuilder()
 63		{
 64			LLSDMessageBuilder builder;
 65			builder.newMessage("name");
 66			builder.nextBlock("block");
 67			return builder;
 68		}
 69
 70		static LLSDMessageReader setReader(const LLSDMessageBuilder& builder)
 71		{
 72			LLSDMessageReader reader;
 73			reader.setMessage("name", builder.getMessage());
 74			return reader;
 75		}
 76
 77		static void addValue(LLMsgBlkData* mbd, char* name, void* v, EMsgVariableType type, int size, int data_size = -1)
 78		{
 79			LLMsgVarData tmp(name, type);
 80			tmp.addData(v, size, type, data_size);
 81			mbd->mMemberVarData[name] = tmp;
 82		}
 83
 84
 85		static LLMessageBlock* defaultTemplateBlock(const EMsgVariableType type = MVT_NULL, const S32 size = 0, EMsgBlockType block = MBT_VARIABLE)
 86		{
 87			return createTemplateBlock(_PREHASH_Test0, type, size, block);
 88		}
 89
 90		static LLMessageBlock* createTemplateBlock(const char* name, const EMsgVariableType type = MVT_NULL, const S32 size = 0, EMsgBlockType block = MBT_VARIABLE)
 91		{
 92			LLMessageBlock* result = new LLMessageBlock(name, block);
 93			if(type != MVT_NULL)
 94			{
 95				result->addVariable(const_cast<char*>(_PREHASH_Test0), type, size);
 96			}
 97			return result;
 98		}
 99
100		static LLTemplateMessageBuilder* defaultTemplateBuilder(LLMessageTemplate& messageTemplate, char* name = const_cast<char*>(_PREHASH_Test0))
101		{
102			templateNameMap[_PREHASH_TestMessage] = &messageTemplate;
103			LLTemplateMessageBuilder* builder = new LLTemplateMessageBuilder(templateNameMap);
104			builder->newMessage(_PREHASH_TestMessage);
105			builder->nextBlock(name);
106			return builder;
107		}
108
109		static LLMessageTemplate defaultTemplate()
110		{
111			return LLMessageTemplate(_PREHASH_TestMessage, 1, MFT_HIGH);
112		}
113	};
114	
115	typedef test_group<LLSDMessageBuilderTestData>	LLSDMessageBuilderTestGroup;
116	typedef LLSDMessageBuilderTestGroup::object		LLSDMessageBuilderTestObject;
117	LLSDMessageBuilderTestGroup llsdMessageBuilderTestGroup("LLSDMessageBuilder");
118	
119	template<> template<>
120	void LLSDMessageBuilderTestObject::test<1>()
121		// construction and test of undefined
122	{
123	  LLSDMessageBuilder builder = defaultBuilder();
124	  LLSDMessageReader reader = setReader(builder);
125	}
126	
127	template<> template<>
128	void LLSDMessageBuilderTestObject::test<2>()
129		 // BOOL
130	{
131	  BOOL outValue, inValue = TRUE;
132	  LLSDMessageBuilder builder = defaultBuilder();
133	  builder.addBOOL("var", inValue);
134	  LLSDMessageReader reader = setReader(builder);
135	  reader.getBOOL("block", "var", outValue);
136	  ensure_equals("Ensure BOOL", inValue, outValue);
137	}
138
139	template<> template<>
140	void LLSDMessageBuilderTestObject::test<3>()
141		 // U8
142	{
143	  U8 outValue, inValue = 2;
144	  LLSDMessageBuilder builder = defaultBuilder();
145	  builder.addU8("var", inValue);
146	  LLSDMessageReader reader = setReader(builder);
147	  reader.getU8("block", "var", outValue);
148	  ensure_equals("Ensure U8", inValue, outValue);
149	}
150
151	template<> template<>
152	void LLSDMessageBuilderTestObject::test<4>()
153		 // S16
154	{
155	  S16 outValue, inValue = 90;
156	  LLSDMessageBuilder builder = defaultBuilder();
157	  builder.addS16("var", inValue);
158	  LLSDMessageReader reader = setReader(builder);
159	  reader.getS16("block", "var", outValue);
160	  ensure_equals("Ensure S16", inValue, outValue);
161	}
162
163	template<> template<>
164	void LLSDMessageBuilderTestObject::test<5>()
165		 // U16
166	{
167	  U16 outValue, inValue = 3;
168	  LLSDMessageBuilder builder = defaultBuilder();
169	  builder.addU16("var", inValue);
170	  LLSDMessageReader reader = setReader(builder);
171	  reader.getU16("block", "var", outValue);
172	  ensure_equals("Ensure U16", inValue, outValue);
173	}
174
175	template<> template<>
176	void LLSDMessageBuilderTestObject::test<6>()
177		 // S32
178	{
179	  S32 outValue, inValue = 44;
180	  LLSDMessageBuilder builder = defaultBuilder();
181	  builder.addS32("var", inValue);
182	  LLSDMessageReader reader = setReader(builder);
183	  reader.getS32("block", "var", outValue);
184	  ensure_equals("Ensure S32", inValue, outValue);
185	}
186
187	template<> template<>
188	void LLSDMessageBuilderTestObject::test<7>()
189		 // F32
190	{
191	  F32 outValue, inValue = 121.44f;
192	  LLSDMessageBuilder builder = defaultBuilder();
193	  builder.addF32("var", inValue);
194	  LLSDMessageReader reader = setReader(builder);
195	  reader.getF32("block", "var", outValue);
196	  ensure_equals("Ensure F32", inValue, outValue);
197	}
198
199	template<> template<>
200	void LLSDMessageBuilderTestObject::test<8>()
201		 // U32
202	{
203	  U32 outValue, inValue = 88;
204	  LLSDMessageBuilder builder = defaultBuilder();
205	  builder.addU32("var", inValue);
206	  LLSDMessageReader reader = setReader(builder);
207	  reader.getU32("block", "var", outValue);
208	  ensure_equals("Ensure U32", inValue, outValue);
209	}
210
211	template<> template<>
212	void LLSDMessageBuilderTestObject::test<9>()
213		 // U64
214	{
215	  U64 outValue, inValue = 121;
216	  LLSDMessageBuilder builder = defaultBuilder();
217	  builder.addU64("var", inValue);
218	  LLSDMessageReader reader = setReader(builder);
219	  reader.getU64("block", "var", outValue);
220	  ensure_equals("Ensure U64", inValue, outValue);
221	}
222
223	template<> template<>
224	void LLSDMessageBuilderTestObject::test<10>()
225		 // F64
226	{
227	  F64 outValue, inValue = 3232143.33;
228	  LLSDMessageBuilder builder = defaultBuilder();
229	  builder.addF64("var", inValue);
230	  LLSDMessageReader reader = setReader(builder);
231	  reader.getF64("block", "var", outValue);
232	  ensure_equals("Ensure F64", inValue, outValue);
233	}
234
235	template<> template<>
236	void LLSDMessageBuilderTestObject::test<11>()
237		 // Vector3
238	{
239	  LLVector3 outValue, inValue = LLVector3(1,2,3);
240	  LLSDMessageBuilder builder = defaultBuilder();
241	  builder.addVector3("var", inValue);
242	  LLSDMessageReader reader = setReader(builder);
243	  reader.getVector3("block", "var", outValue);
244	  ensure_equals("Ensure Vector3", inValue, outValue);
245	}
246
247	template<> template<>
248	void LLSDMessageBuilderTestObject::test<12>()
249		 // Vector4
250	{
251	  LLVector4 outValue, inValue = LLVector4(1,2,3,4);
252	  LLSDMessageBuilder builder = defaultBuilder();
253	  builder.addVector4("var", inValue);
254	  LLSDMessageReader reader = setReader(builder);
255	  reader.getVector4("block", "var", outValue);
256	  ensure_equals("Ensure Vector4", inValue, outValue);
257	}
258
259	template<> template<>
260	void LLSDMessageBuilderTestObject::test<13>()
261		 // Vector3d
262	{
263	  LLVector3d outValue, inValue = LLVector3d(1,2,3);
264	  LLSDMessageBuilder builder = defaultBuilder();
265	  builder.addVector3d("var", inValue);
266	  LLSDMessageReader reader = setReader(builder);
267	  reader.getVector3d("block", "var", outValue);
268	  ensure_equals("Ensure Vector3d", inValue, outValue);
269	}
270
271	template<> template<>
272	void LLSDMessageBuilderTestObject::test<14>()
273		 // Quaternion
274	{
275	  LLQuaternion outValue, inValue = LLQuaternion(1,2,3,4);
276	  LLSDMessageBuilder builder = defaultBuilder();
277	  builder.addQuat("var", inValue);
278	  LLSDMessageReader reader = setReader(builder);
279	  reader.getQuat("block", "var", outValue);
280	  ensure_equals("Ensure Quaternion", inValue, outValue);
281	}
282
283	template<> template<>
284	void LLSDMessageBuilderTestObject::test<15>()
285		 // UUID
286	{
287	  LLUUID outValue, inValue;
288	  inValue.generate();
289	  LLSDMessageBuilder builder = defaultBuilder();
290	  builder.addUUID("var", inValue);
291	  LLSDMessageReader reader = setReader(builder);
292	  reader.getUUID("block", "var", outValue);
293	  ensure_equals("Ensure UUID", inValue, outValue);
294	}
295
296	template<> template<>
297	void LLSDMessageBuilderTestObject::test<16>()
298		 // IPAddr
299	{
300	  U32 outValue, inValue = 12344556;
301	  LLSDMessageBuilder builder = defaultBuilder();
302	  builder.addIPAddr("var", inValue);
303	  LLSDMessageReader reader = setReader(builder);
304	  reader.getIPAddr("block", "var", outValue);
305	  ensure_equals("Ensure IPAddr", inValue, outValue);
306	}
307
308	 template<> template<>
309	void LLSDMessageBuilderTestObject::test<17>()
310		 // IPPort
311	{
312		 U16 outValue, inValue = 80;
313	  LLSDMessageBuilder builder = defaultBuilder();
314	  builder.addIPPort("var", inValue);
315	  LLSDMessageReader reader = setReader(builder);
316	  reader.getIPPort("block", "var", outValue);
317	  ensure_equals("Ensure IPPort", inValue, outValue);
318	}
319
320	template<> template<>
321	void LLSDMessageBuilderTestObject::test<18>()
322	{
323		 std::string outValue, inValue = "testing";
324	  LLSDMessageBuilder builder = defaultBuilder();
325	  builder.addString("var", inValue.c_str());
326	  LLSDMessageReader reader = setReader(builder);
327	  char buffer[MAX_STRING];
328	  reader.getString("block", "var", MAX_STRING, buffer);
329	  outValue = buffer;
330	  ensure_equals("Ensure String", inValue, outValue);
331	}
332
333	template<> template<>
334	void LLSDMessageBuilderTestObject::test<19>()
335	{
336	  LLMsgBlkData* mbd = new LLMsgBlkData("testBlock", 0);
337	  LLMsgData* md = new LLMsgData("testMessage");
338	  md->addBlock(mbd);
339	  LLSDMessageBuilder builder = defaultBuilder();
340	  
341	  builder.copyFromMessageData(*md);
342	  LLSD output = builder.getMessage();
343
344	  ensure("Ensure message block created when copied from legacy message to llsd", output["testBlock"].isDefined());
345	}
346
347	// MVT_FIXED
348	template<> template<>
349	void LLSDMessageBuilderTestObject::test<20>()
350	{
351	  char binData[] = "abcdefghijklmnop";
352
353	  addValue(messageBlockData, (char *)"testBinData", &binData, MVT_FIXED, sizeof(binData));
354	  messageData->addBlock(messageBlockData);
355	  LLSDMessageBuilder builder = defaultBuilder();
356	  
357	  builder.copyFromMessageData(*messageData);
358	  LLSD output = builder.getMessage();
359
360	  std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary();
361	  ensure("Ensure MVT_S16Array data copied from legacy to llsd give a valid vector", v.size() > 0);
362
363	  ensure_memory_matches("Ensure fixed binary data works in a message copied from legacy to llsd",
364		  &v[0], sizeof(binData), binData, sizeof(binData));
365	}
366
367	// MVT_VARIABLE data_size 1 (U8's)
368	template<> template<>
369	void LLSDMessageBuilderTestObject::test<21>()
370	{
371	 /* U8 binData[] = "abcdefghijklmnop";
372
373	  addValue(messageBlockData, "testBinData", &binData, MVT_VARIABLE, sizeof(binData), 1);
374	  messageData->addBlock(messageBlockData);
375	  LLSDMessageBuilder builder = defaultBuilder();
376	  
377	  builder.copyFromMessageData(*messageData);
378	  LLSD output = builder.getMessage();
379
380	  std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary();
381	  ensure("Ensure MVT_S16Array data copied from legacy to llsd give a valid vector", v.size() > 0);
382
383	  ensure_memory_matches("Ensure MVT_VARIABLE U8 binary data works in a message copied from legacy to llsd",
384		  &v[0], sizeof(binData), binData, sizeof(binData));*/
385	}
386
387	// MVT_VARIABLE data_size 2 (U16's)
388	template<> template<>
389	void LLSDMessageBuilderTestObject::test<22>()
390	{
391	  U16 binData[] = {1,2,3,4,5,6,7,8,9}; //9 shorts
392
393	  addValue(messageBlockData, (char *)"testBinData", &binData, MVT_VARIABLE, sizeof(binData) >> 1, 2);
394	  messageData->addBlock(messageBlockData);
395	  LLSDMessageBuilder builder = defaultBuilder();
396	  
397	  builder.copyFromMessageData(*messageData);
398	  LLSD output = builder.getMessage();
399
400	  std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary();
401	  ensure("Ensure MVT_S16Array data copied from legacy to llsd give a valid vector", v.size() > 0);
402
403	  ensure_memory_matches("Ensure MVT_VARIABLE U16 binary data works in a message copied from legacy to llsd",
404		  &v[0], sizeof(binData) >> 1, binData, sizeof(binData) >> 1);
405	}
406
407	// MVT_VARIABLE data_size 4 (S32's)
408	template<> template<>
409	void LLSDMessageBuilderTestObject::test<23>()
410	{
411	  U32 binData[] = {9,8,7,6,5,4,3,2,1};
412
413	  addValue(messageBlockData, (char *)"testBinData", &binData, MVT_VARIABLE, sizeof(binData) >> 2, 4);
414	  messageData->addBlock(messageBlockData);
415	  LLSDMessageBuilder builder = defaultBuilder();
416	  
417	  builder.copyFromMessageData(*messageData);
418	  LLSD output = builder.getMessage();
419
420	  std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary();
421	  ensure("Ensure MVT_S16Array data copied from legacy to llsd give a valid vector", v.size() > 0);
422
423	  ensure_memory_matches("Ensure MVT_VARIABLE S32 binary data works in a message copied from legacy to llsd",
424		  &v[0], sizeof(binData) >> 2, binData, sizeof(binData) >> 2);
425	}
426
427	// MVT_U8
428	template<> template<>
429	void LLSDMessageBuilderTestObject::test<24>()
430	{
431	  U8 data = 0xa5;
432
433	  addValue(messageBlockData, (char *)"testBinData", &data, MVT_U8, sizeof(data));
434	  messageData->addBlock(messageBlockData);
435	  LLSDMessageBuilder builder = defaultBuilder();
436	  
437	  builder.copyFromMessageData(*messageData);
438	  LLSD output = builder.getMessage();
439
440	  ensure_equals("Ensure MVT_U8 data works in a message copied from legacy to llsd",
441		  output["testBlock"][0]["testBinData"].asInteger(), data);
442	}
443
444	// MVT_U16
445	template<> template<>
446	void LLSDMessageBuilderTestObject::test<25>()
447	{
448	  U16 data = 0xa55a;
449
450	  addValue(messageBlockData, (char *)"testBinData", &data, MVT_U16, sizeof(data));
451	  messageData->addBlock(messageBlockData);
452	  LLSDMessageBuilder builder = defaultBuilder();
453	  
454	  builder.copyFromMessageData(*messageData);
455	  LLSD output = builder.getMessage();
456
457	  ensure_equals("Ensure MVT_U16 data works in a message copied from legacy to llsd",
458		  output["testBlock"][0]["testBinData"].asInteger(), data);
459	}
460
461	// MVT_U32
462	template<> template<>
463	void LLSDMessageBuilderTestObject::test<26>()
464	{
465	  U32 data = 0xa55a7117;
466
467	  addValue(messageBlockData, (char *)"testBinData", &data, MVT_U32, sizeof(data));
468	  messageData->addBlock(messageBlockData);
469	  LLSDMessageBuilder builder = defaultBuilder();
470	  
471	  builder.copyFromMessageData(*messageData);
472	  LLSD output = builder.getMessage();
473
474	  ensure_equals("Ensure MVT_U32 data works in a message copied from legacy to llsd",
475		  ll_U32_from_sd(output["testBlock"][0]["testBinData"]), data);
476	}
477
478	// MVT_U64 - crush into an s32: LLSD does not support 64 bit values
479	template<> template<>
480	void LLSDMessageBuilderTestObject::test<27>()
481	{
482	  U64 data = U64L(0xa55a711711223344);
483	  addValue(messageBlockData, (char *)"testBinData", &data, MVT_U64, sizeof(data));
484	  messageData->addBlock(messageBlockData);
485	  LLSDMessageBuilder builder = defaultBuilder();
486	  
487	  builder.copyFromMessageData(*messageData);
488	  LLSD output = builder.getMessage();
489
490	  ensure_equals("Ensure MVT_U64 data works in a message copied from legacy to llsd",
491		  ll_U64_from_sd(output["testBlock"][0]["testBinData"]), data);
492	}
493
494	// MVT_S8
495	template<> template<>
496	void LLSDMessageBuilderTestObject::test<28>()
497	{
498	  S8 data = -31;
499
500	  addValue(messageBlockData, (char *)"testBinData", &data, MVT_S8, sizeof(data));
501	  messageData->addBlock(messageBlockData);
502	  LLSDMessageBuilder builder = defaultBuilder();
503	  
504	  builder.copyFromMessageData(*messageData);
505	  LLSD output = builder.getMessage();
506
507	  ensure_equals("Ensure MVT_S8 data works in a message copied from legacy to llsd",
508		  output["testBlock"][0]["testBinData"].asInteger(), data);
509	}
510
511	// MVT_S16
512	template<> template<>
513	void LLSDMessageBuilderTestObject::test<29>()
514	{
515	  S16 data = -31;
516
517	  addValue(messageBlockData, (char *)"testBinData", &data, MVT_S16, sizeof(data));
518	  messageData->addBlock(messageBlockData);
519	  LLSDMessageBuilder builder = defaultBuilder();
520	  
521	  builder.copyFromMessageData(*messageData);
522	  LLSD output = builder.getMessage();
523
524	  ensure_equals("Ensure MVT_S16 data works in a message copied from legacy to llsd",
525		  output["testBlock"][0]["testBinData"].asInteger(), data);
526	}
527
528	// MVT_S32
529	template<> template<>
530	void LLSDMessageBuilderTestObject::test<30>()
531	{
532	  S32 data = -3100;
533
534	  addValue(messageBlockData, (char *)"testBinData", &data, MVT_S32, sizeof(data));
535	  messageData->addBlock(messageBlockData);
536	  LLSDMessageBuilder builder = defaultBuilder();
537	  
538	  builder.copyFromMessageData(*messageData);
539	  LLSD output = builder.getMessage();
540
541	  ensure_equals("Ensure MVT_S32 data works in a message copied from legacy to llsd",
542		  output["testBlock"][0]["testBinData"].asInteger(), data);
543	}
544
545	// MVT_S64 - crush into an s32: LLSD does not support 64 bit values
546	template<> template<>
547	void LLSDMessageBuilderTestObject::test<31>()
548	{
549	  S64 data = -31003100;
550
551	  addValue(messageBlockData, (char *)"testBinData", &data, MVT_S64, sizeof(data));
552	  messageData->addBlock(messageBlockData);
553	  LLSDMessageBuilder builder = defaultBuilder();
554	  
555	  builder.copyFromMessageData(*messageData);
556	  LLSD output = builder.getMessage();
557
558	  ensure_equals("Ensure MVT_S64 data works in a message copied from legacy to llsd",
559		  output["testBlock"][0]["testBinData"].asInteger(), (S32)data);
560	}
561
562	// MVT_F32
563	template<> template<>
564	void LLSDMessageBuilderTestObject::test<32>()
565	{
566	  F32 data = 1234.1234f;
567
568	  addValue(messageBlockData, (char *)"testBinData", &data, MVT_F32, sizeof(data));
569	  messageData->addBlock(messageBlockData);
570	  LLSDMessageBuilder builder = defaultBuilder();
571	  
572	  builder.copyFromMessageData(*messageData);
573	  LLSD output = builder.getMessage();
574
575	  ensure_equals("Ensure MVT_F32 data works in a message copied from legacy to llsd",
576		  output["testBlock"][0]["testBinData"].asReal(), data);
577	}
578
579	// MVT_F64
580	template<> template<>
581	void LLSDMessageBuilderTestObject::test<33>()
582	{
583	  F64 data = 1234.1234;
584
585	  addValue(messageBlockData, (char *)"testBinData", &data, MVT_F64, sizeof(data));
586	  messageData->addBlock(messageBlockData);
587	  LLSDMessageBuilder builder = defaultBuilder();
588	  
589	  builder.copyFromMessageData(*messageData);
590	  LLSD output = builder.getMessage();
591
592	  ensure_equals("Ensure MVT_F64 data works in a message copied from legacy to llsd",
593		  output["testBlock"][0]["testBinData"].asReal(), data);
594	}
595
596	// MVT_LLVector3
597	template<> template<>
598	void LLSDMessageBuilderTestObject::test<34>()
599	{
600	  LLVector3 data(1,2,3);
601
602	  addValue(messageBlockData, (char *)"testBinData", &data, MVT_LLVector3, sizeof(data));
603	  messageData->addBlock(messageBlockData);
604	  LLSDMessageBuilder builder = defaultBuilder();
605	  
606	  builder.copyFromMessageData(*messageData);
607	  LLSD output = builder.getMessage();
608
609	  ensure_equals("Ensure MVT_LLVector3 data works in a message copied from legacy to llsd",
610		  ll_vector3_from_sd(output["testBlock"][0]["testBinData"]), data);
611	}
612
613	// MVT_LLVector3d
614	template<> template<>
615	void LLSDMessageBuilderTestObject::test<35>()
616	{
617	  LLVector3d data(1,2,3);
618
619	  addValue(messageBlockData, (char *)"testBinData", &data, MVT_LLVector3d, sizeof(data));
620	  messageData->addBlock(messageBlockData);
621	  LLSDMessageBuilder builder = defaultBuilder();
622	  
623	  builder.copyFromMessageData(*messageData);
624	  LLSD output = builder.getMessage();
625
626	  ensure_equals("Ensure MVT_LLVector3 data works in a message copied from legacy to llsd",
627		  ll_vector3d_from_sd(output["testBlock"][0]["testBinData"]), data);
628	}
629
630	// MVT_LLVector4
631	template<> template<>
632	void LLSDMessageBuilderTestObject::test<36>()
633	{
634	  LLVector4 data(1,2,3,4);
635	  LLSD v = ll_sd_from_vector4(data);
636
637	  addValue(messageBlockData, (char *)"testBinData", &data, MVT_LLVector4, sizeof(data));
638	  messageData->addBlock(messageBlockData);
639	  LLSDMessageBuilder builder = defaultBuilder();
640	  
641	  builder.copyFromMessageData(*messageData);
642	  LLSD output = builder.getMessage();
643
644	  ensure_equals("Ensure MVT_LLVector4 data works in a message copied from legacy to llsd",
645		  output["testBlock"][0]["testBinData"], v);
646	}
647
648	// MVT_LLQuaternion
649	template<> template<>
650	void LLSDMessageBuilderTestObject::test<37>()
651	{
652	  LLQuaternion data(1,2,3,0);
653
654	  //we send a quaternion packed into a vec3 (w is infered) - so sizeof(vec) == 12 bytes not 16.
655	  LLVector3 vec = data.packToVector3();
656
657	  addValue(messageBlockData, (char *)"testBinData", &vec, MVT_LLQuaternion, sizeof(vec));
658	  messageData->addBlock(messageBlockData);
659	  LLSDMessageBuilder builder = defaultBuilder();
660	  
661	  builder.copyFromMessageData(*messageData);
662	  LLSD output = builder.getMessage();
663
664	  ensure_equals("Ensure MVT_LLQuaternion data works in a message copied from legacy to llsd",
665		  ll_quaternion_from_sd(output["testBlock"][0]["testBinData"]), data);
666	}
667
668	// MVT_LLUUID
669	template<> template<>
670	void LLSDMessageBuilderTestObject::test<38>()
671	{
672	  LLUUID data("01234567-0123-0123-0123-234567abcdef");
673
674	  addValue(messageBlockData, (char *)"testBinData", &data, MVT_LLUUID, sizeof(data));
675	  messageData->addBlock(messageBlockData);
676	  LLSDMessageBuilder builder = defaultBuilder();
677	  
678	  builder.copyFromMessageData(*messageData);
679	  LLSD output = builder.getMessage();
680	 
681	  std::string v = output["testBlock"][0]["testBinData"].asUUID().asString();
682
683	  ensure_equals("Ensure MVT_LLUUID data works in a message copied from legacy to llsd",
684		  output["testBlock"][0]["testBinData"].asUUID(), data);
685	}
686
687	// MVT_BOOL
688	template<> template<>
689	void LLSDMessageBuilderTestObject::test<39>()
690	{
691	  BOOL valueTrue = true;
692	  BOOL valueFalse = false;
693
694	  LLMsgData* md = new LLMsgData("testMessage");
695	  LLMsgBlkData* mbd = new LLMsgBlkData("testBlock", 0);
696	  addValue(mbd, (char *)"testBoolFalse", &valueFalse, MVT_BOOL, sizeof(BOOL));
697	  addValue(mbd, (char *)"testBoolTrue", &valueTrue, MVT_BOOL, sizeof(BOOL));
698	  md->addBlock(mbd);
699	  LLSDMessageBuilder builder = defaultBuilder();
700	  
701	  builder.copyFromMessageData(*md);
702	  LLSD output = builder.getMessage();
703
704	  ensure("Ensure bools work in a message copied from legacy to llsd",
705		  output["testBlock"][0]["testBoolTrue"].asBoolean() && !output["testBlock"][0]["testBoolFalse"].asBoolean());
706	}
707
708	// MVT_IP_ADDR
709	template<> template<>
710	void LLSDMessageBuilderTestObject::test<40>()
711	{
712	  U32 data(0xff887766);
713	  LLSD v = ll_sd_from_ipaddr(data);
714
715	  addValue(messageBlockData, (char *)"testBinData", &data, MVT_IP_ADDR, sizeof(data));
716	  messageData->addBlock(messageBlockData);
717	  LLSDMessageBuilder builder = defaultBuilder();
718	  
719	  builder.copyFromMessageData(*messageData);
720	  LLSD output = builder.getMessage();
721
722	  ensure_equals("Ensure MVT_IP_ADDR data works in a message copied from legacy to llsd",
723		  output["testBlock"][0]["testBinData"], v);
724	}
725
726	// MVT_IP_PORT
727	template<> template<>
728	void LLSDMessageBuilderTestObject::test<41>()
729	{
730	  U16 data = 0xff88;
731
732	  addValue(messageBlockData, (char *)"testBinData", &data, MVT_IP_PORT, sizeof(data));
733	  messageData->addBlock(messageBlockData);
734	  LLSDMessageBuilder builder = defaultBuilder();
735	  
736	  builder.copyFromMessageData(*messageData);
737	  LLSD output = builder.getMessage();
738
739	  ensure_equals("Ensure MVT_IP_PORT data works in a message copied from legacy to llsd",
740		  output["testBlock"][0]["testBinData"].asInteger(), data);
741	}
742
743	// MVT_U16Vec3
744	template<> template<>
745	void LLSDMessageBuilderTestObject::test<42>()
746	{
747	  U16 data[3] = {0,1,2};
748
749	  addValue(messageBlockData, (char *)"testBinData", &data, MVT_U16Vec3, sizeof(data));
750	  messageData->addBlock(messageBlockData);
751	  LLSDMessageBuilder builder = defaultBuilder();
752	  
753	  builder.copyFromMessageData(*messageData);
754	  LLSD output = builder.getMessage();
755
756	  std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary();
757	  ensure("Ensure MVT_U16Vec3 data copied from legacy to llsd give a valid vector", v.size() > 0);
758
759	  ensure_memory_matches("Ensure MVT_U16Vec3 data works in a message copied from legacy to llsd",
760		  (U16*)&v[0], 6, data, 6);
761	}
762
763	// MVT_U16Quat
764	template<> template<>
765	void LLSDMessageBuilderTestObject::test<43>()
766	{
767	  U16 data[4] = {0,1,2,4};
768
769	  addValue(messageBlockData, (char *)"testBinData", &data, MVT_U16Quat, sizeof(data));
770	  messageData->addBlock(messageBlockData);
771	  LLSDMessageBuilder builder = defaultBuilder();
772	  
773	  builder.copyFromMessageData(*messageData);
774	  LLSD output = builder.getMessage();
775
776	  std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary();
777	  ensure("Ensure MVT_U16Quat data copied from legacy to llsd give a valid vector", v.size() > 0);
778
779	  ensure_memory_matches("Ensure MVT_U16Quat data works in a message copied from legacy to llsd",
780		  (U16*)&v[0], 8, data, 8);
781	}
782
783	// MVT_S16Array
784	template<> template<>
785	void LLSDMessageBuilderTestObject::test<44>()
786	{
787	  S16 data[19] = {0,-1,2,-4,5,-6,7,-8,9,-10,11,-12,13,-14,15,16,17,18};
788
789	  addValue(messageBlockData, (char *)"testBinData", &data, MVT_S16Array, sizeof(data));
790	  messageData->addBlock(messageBlockData);
791	  LLSDMessageBuilder builder = defaultBuilder();
792	  
793	  builder.copyFromMessageData(*messageData);
794	  LLSD output = builder.getMessage();
795
796	  std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary();
797	  ensure("Ensure MVT_S16Array data copied from legacy to llsd give a valid vector", v.size() > 0);
798
799	  ensure_memory_matches("Ensure MVT_S16Array data works in a message copied from legacy to llsd",
800		  (U16*)&v[0], 19, data, 19);
801	}
802
803	template<> template<>
804	void LLSDMessageBuilderTestObject::test<45>()
805	{
806		LLMessageTemplate messageTemplate = defaultTemplate();
807		messageTemplate.addBlock(defaultTemplateBlock(MVT_U8, 1));
808		U8 inValue = 2;
809		LLTemplateMessageBuilder* template_builder = defaultTemplateBuilder(messageTemplate);
810		template_builder->addU8(_PREHASH_Test0, inValue);
811
812		LLSDMessageBuilder builder;
813		builder.copyFromMessageData(*template_builder->getCurrentMessage());
814		LLSD output = builder.getMessage();
815		
816		ensure_equals(output["Test0"][0]["Test0"].asInteger(), 2);
817
818	}
819
820	template<> template<>
821	void LLSDMessageBuilderTestObject::test<46>()
822	{
823		LLMessageTemplate messageTemplate = defaultTemplate();
824		messageTemplate.addBlock(defaultTemplateBlock(MVT_VARIABLE, 1));
825		std::string inValue = "testing";
826		LLTemplateMessageBuilder* builder = defaultTemplateBuilder(messageTemplate);
827		builder->addString(_PREHASH_Test0, inValue.c_str());
828
829		LLSDMessageBuilder sd_builder;
830		sd_builder.copyFromMessageData(*builder->getCurrentMessage());
831		LLSD output = sd_builder.getMessage();
832		
833		ensure_equals(output["Test0"][0]["Test0"].asString(), std::string("testing"));
834	}
835
836}
837