PageRenderTime 73ms CodeModel.GetById 2ms app.highlight 66ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llmessage/tests/llnamevalue_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 406 lines | 287 code | 69 blank | 50 comment | 117 complexity | ecf8f4a5387bd19b546038304d370990 MD5 | raw file
  1/** 
  2 * @file llnamevalue_test.cpp
  3 * @author Adroit
  4 * @date 2007-02
  5 * @brief LLNameValue unit test
  6 *
  7 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  8 * Second Life Viewer Source Code
  9 * Copyright (C) 2010, Linden Research, Inc.
 10 * 
 11 * This library is free software; you can redistribute it and/or
 12 * modify it under the terms of the GNU Lesser General Public
 13 * License as published by the Free Software Foundation;
 14 * version 2.1 of the License only.
 15 * 
 16 * This library is distributed in the hope that it will be useful,
 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19 * Lesser General Public License for more details.
 20 * 
 21 * You should have received a copy of the GNU Lesser General Public
 22 * License along with this library; if not, write to the Free Software
 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 24 * 
 25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 26 * $/LicenseInfo$
 27 */
 28
 29#include "linden_common.h"
 30#include "llsdserialize.h"
 31
 32#include "../llnamevalue.h"
 33
 34#include "../test/lltut.h"
 35
 36
 37#if LL_WINDOWS
 38// disable unreachable code warnings
 39#pragma warning(disable: 4702)
 40#endif
 41
 42namespace tut
 43{
 44	struct namevalue_test
 45	{
 46		namevalue_test() 
 47		{			
 48		}
 49 	};
 50	typedef test_group<namevalue_test> namevalue_t;
 51	typedef namevalue_t::object namevalue_object_t;
 52	tut::namevalue_t tut_namevalue("LLNameValue");
 53
 54	
 55	template<> template<>
 56	void namevalue_object_t::test<1>()
 57	{
 58		// LLNameValue()
 59		LLNameValue nValue;
 60		ensure("mName should have been NULL", nValue.mName == NULL);
 61		ensure("getTypeEnum failed",nValue.getTypeEnum() == NVT_NULL);
 62		ensure("getClassEnum failed",nValue.getClassEnum() == NVC_NULL);
 63		ensure("getSendtoEnum failed",nValue.getSendtoEnum() == NVS_NULL);
 64
 65		LLNameValue nValue1(" SecondLife ASSET RW SIM 232324343");
 66
 67	}
 68
 69	// LLNameValue(const char* data);
 70	// 	LLNameValue(const char* name, const char* data, const char* type, const char* nvclass, const char* nvsendto, 
 71	//				TNameValueCallback nvcb = NULL, void** user_data = NULL);
 72	template<> template<>
 73	void namevalue_object_t::test<2>()
 74	{
 75		LLNameValue nValue(" SecondLife ASSET RW S 232324343");
 76		ensure("mName not set correctly", (0 == strcmp(nValue.mName,"SecondLife")));
 77		ensure("getTypeEnum failed", nValue.getTypeEnum() == NVT_ASSET);
 78		ensure("getClassEnum failed", nValue.getClassEnum() == NVC_READ_WRITE);
 79		ensure("getSendtoEnum failed", nValue.getSendtoEnum() == NVS_SIM);
 80		ensure("getString failed", (0==strcmp(nValue.getAsset(),"232324343")));
 81		ensure("sendToData or sendToViewer failed", !nValue.sendToData() && !nValue.sendToViewer());
 82		
 83		LLNameValue nValue1("\n\r SecondLife_1 STRING READ_WRITE SIM 232324343");
 84		ensure("1. mName not set correctly", (0 == strcmp(nValue1.mName,"SecondLife_1")));
 85		ensure("1. getTypeEnum failed", nValue1.getTypeEnum() == NVT_STRING);
 86		ensure("1. getClassEnum failed", nValue1.getClassEnum() == NVC_READ_WRITE);
 87		ensure("1. getSendtoEnum failed", nValue1.getSendtoEnum() == NVS_SIM);
 88		ensure("1. getString failed", (0==strcmp(nValue1.getString(),"232324343")));
 89		ensure("1. sendToData or sendToViewer failed", !nValue1.sendToData() && !nValue1.sendToViewer());
 90
 91		LLNameValue nValue2("SecondLife", "23.5", "F32", "R", "DS");
 92		ensure("2. getTypeEnum failed", nValue2.getTypeEnum() == NVT_F32);
 93		ensure("2. getClassEnum failed", nValue2.getClassEnum() == NVC_READ_ONLY);
 94		ensure("2. getSendtoEnum failed", nValue2.getSendtoEnum() == NVS_DATA_SIM);
 95		ensure("2. getF32 failed", *nValue2.getF32() == 23.5f);
 96		ensure("2. sendToData or sendToViewer failed", nValue2.sendToData() && !nValue2.sendToViewer());
 97
 98		LLNameValue nValue3("SecondLife", "-43456787", "S32", "READ_ONLY", "SIM_SPACE");
 99		ensure("3. getTypeEnum failed", nValue3.getTypeEnum() == NVT_S32);
100		ensure("3. getClassEnum failed", nValue3.getClassEnum() == NVC_READ_ONLY);
101		ensure("3. getSendtoEnum failed", nValue3.getSendtoEnum() == NVS_DATA_SIM);
102		ensure("3. getS32 failed", *nValue3.getS32() == -43456787);
103		ensure("sendToData or sendToViewer failed", nValue3.sendToData() && !nValue3.sendToViewer());
104
105		LLNameValue nValue4("SecondLife", "<1.0, 2.0, 3.0>", "VEC3", "RW", "SV");
106		LLVector3 llvec4(1.0, 2.0, 3.0);
107		ensure("4. getTypeEnum failed", nValue4.getTypeEnum() == NVT_VEC3);
108		ensure("4. getClassEnum failed", nValue4.getClassEnum() == NVC_READ_WRITE);
109		ensure("4. getSendtoEnum failed", nValue4.getSendtoEnum() == NVS_SIM_VIEWER);
110		ensure("4. getVec3 failed", *nValue4.getVec3() == llvec4);
111		ensure("4. sendToData or sendToViewer failed", !nValue4.sendToData() && nValue4.sendToViewer());
112
113		LLNameValue nValue5("SecondLife", "-1.0, 2.4, 3", "VEC3", "RW", "SIM_VIEWER");
114		LLVector3 llvec5(-1.0f, 2.4f, 3);
115		ensure("5. getTypeEnum failed", nValue5.getTypeEnum() == NVT_VEC3);
116		ensure("5. getClassEnum failed", nValue5.getClassEnum() == NVC_READ_WRITE);
117		ensure("5. getSendtoEnum failed", nValue5.getSendtoEnum() == NVS_SIM_VIEWER);
118		ensure("5. getVec3 failed", *nValue5.getVec3() == llvec5);
119		ensure("5. sendToData or sendToViewer failed", !nValue5.sendToData() && nValue5.sendToViewer());
120
121		LLNameValue nValue6("SecondLife", "89764323", "U32", "RW", "DSV");
122		ensure("6. getTypeEnum failed", nValue6.getTypeEnum() == NVT_U32);
123		ensure("6. getClassEnum failed", nValue6.getClassEnum() == NVC_READ_WRITE);
124		ensure("6. getSendtoEnum failed", nValue6.getSendtoEnum() == NVS_DATA_SIM_VIEWER);
125		ensure("6. getU32 failed", *nValue6.getU32() == 89764323);
126		ensure("6. sendToData or sendToViewer failed", nValue6.sendToData() && nValue6.sendToViewer());
127
128		LLNameValue nValue7("SecondLife", "89764323323232", "U64", "RW", "SIM_SPACE_VIEWER");
129		U64 u64_7 = U64L(89764323323232);
130		ensure("7. getTypeEnum failed", nValue7.getTypeEnum() == NVT_U64);
131		ensure("7. getClassEnum failed", nValue7.getClassEnum() == NVC_READ_WRITE);
132		ensure("7. getSendtoEnum failed", nValue7.getSendtoEnum() == NVS_DATA_SIM_VIEWER);
133		ensure("7. getU32 failed", *nValue7.getU64() == u64_7);
134		ensure("7. sendToData or sendToViewer failed", nValue7.sendToData() && nValue7.sendToViewer());
135	}
136
137	// LLNameValue(const char* name, const char* data, const char* type, const char* nvclass, 
138	//				TNameValueCallback nvcb = NULL, void** user_data = NULL);
139	template<> template<>
140	void namevalue_object_t::test<3>()
141	{
142		LLNameValue nValue("SecondLife", "232324343", "ASSET", "READ_WRITE");
143		ensure("mName not set correctly", (0 == strcmp(nValue.mName,"SecondLife")));
144		ensure("getTypeEnum failed", nValue.getTypeEnum() == NVT_ASSET);
145		ensure("getClassEnum failed", nValue.getClassEnum() == NVC_READ_WRITE);
146		ensure("getSendtoEnum failed", nValue.getSendtoEnum() == NVS_SIM);
147		ensure("getString failed", (0==strcmp(nValue.getAsset(),"232324343")));
148
149		LLNameValue nValue1("SecondLife", "232324343", "STRING", "READ_WRITE");
150		ensure("1. mName not set correctly", (0 == strcmp(nValue1.mName,"SecondLife")));
151		ensure("1. getTypeEnum failed", nValue1.getTypeEnum() == NVT_STRING);
152		ensure("1. getClassEnum failed", nValue1.getClassEnum() == NVC_READ_WRITE);
153		ensure("1. getSendtoEnum failed", nValue1.getSendtoEnum() == NVS_SIM);
154		ensure("1. getString failed", (0==strcmp(nValue1.getString(),"232324343")));
155
156		LLNameValue nValue2("SecondLife", "23.5", "F32", "R");
157		ensure("2. getTypeEnum failed", nValue2.getTypeEnum() == NVT_F32);
158		ensure("2. getClassEnum failed", nValue2.getClassEnum() == NVC_READ_ONLY);
159		ensure("2. getSendtoEnum failed", nValue2.getSendtoEnum() == NVS_SIM);
160		ensure("2. getF32 failed", *nValue2.getF32() == 23.5f);
161
162		LLNameValue nValue3("SecondLife", "-43456787", "S32", "READ_ONLY");
163		ensure("3. getTypeEnum failed", nValue3.getTypeEnum() == NVT_S32);
164		ensure("3. getClassEnum failed", nValue3.getClassEnum() == NVC_READ_ONLY);
165		ensure("3. getSendtoEnum failed", nValue3.getSendtoEnum() == NVS_SIM);
166		ensure("3. getS32 failed", *nValue3.getS32() == -43456787);
167
168		LLNameValue nValue4("SecondLife", "<1.0, 2.0, 3.0>", "VEC3", "RW");
169		LLVector3 llvec4(1.0, 2.0, 3.0);
170		ensure("4. getTypeEnum failed", nValue4.getTypeEnum() == NVT_VEC3);
171		ensure("4. getClassEnum failed", nValue4.getClassEnum() == NVC_READ_WRITE);
172		ensure("4. getSendtoEnum failed", nValue4.getSendtoEnum() == NVS_SIM);
173		ensure("4. getVec3 failed", *nValue4.getVec3() == llvec4);
174
175		LLNameValue nValue5("SecondLife", "-1.0, 2.4, 3", "VEC3", "RW");
176		LLVector3 llvec5(-1.0f, 2.4f, 3);
177		ensure("5. getTypeEnum failed", nValue5.getTypeEnum() == NVT_VEC3);
178		ensure("5. getClassEnum failed", nValue5.getClassEnum() == NVC_READ_WRITE);
179		ensure("5. getSendtoEnum failed", nValue5.getSendtoEnum() == NVS_SIM);
180		ensure("5. getVec3 failed", *nValue5.getVec3() == llvec5);
181
182		LLNameValue nValue6("SecondLife", "89764323", "U32", "RW");
183		ensure("6. getTypeEnum failed", nValue6.getTypeEnum() == NVT_U32);
184		ensure("6. getClassEnum failed", nValue6.getClassEnum() == NVC_READ_WRITE);
185		ensure("6. getSendtoEnum failed", nValue6.getSendtoEnum() == NVS_SIM);
186		ensure("6. getU32 failed", *nValue6.getU32() == 89764323);
187
188		LLNameValue nValue7("SecondLife", "89764323323232", "U64", "RW");
189		U64 u64_7 = U64L(89764323323232);
190		ensure("7. getTypeEnum failed", nValue7.getTypeEnum() == NVT_U64);
191		ensure("7. getClassEnum failed", nValue7.getClassEnum() == NVC_READ_WRITE);
192		ensure("7. getSendtoEnum failed", nValue7.getSendtoEnum() == NVS_SIM);
193		ensure("7. getU32 failed", *nValue7.getU64() == u64_7);
194	}
195
196	// LLNameValue(const char* name, const char* type, const char* nvclass, 
197	//				TNameValueCallback nvcb = NULL, void** user_data = NULL);
198	template<> template<>
199	void namevalue_object_t::test<4>()
200	{
201		LLNameValue nValue("SecondLife",  "STRING", "READ_WRITE");
202		ensure("mName not set correctly", (0 == strcmp(nValue.mName,"SecondLife")));
203		ensure("getTypeEnum failed", nValue.getTypeEnum() == NVT_STRING);
204		ensure("getClassEnum failed", nValue.getClassEnum() == NVC_READ_WRITE);
205		ensure("getSendtoEnum failed", nValue.getSendtoEnum() == NVS_SIM);
206
207		LLNameValue nValue1("SecondLife",  "ASSET", "READ_WRITE");
208		ensure("1. mName not set correctly", (0 == strcmp(nValue1.mName,"SecondLife")));
209		ensure("1. getTypeEnum for RW failed", nValue1.getTypeEnum() == NVT_ASSET);
210		ensure("1. getClassEnum for RW failed", nValue1.getClassEnum() == NVC_READ_WRITE);
211		ensure("1. getSendtoEnum for RW failed", nValue1.getSendtoEnum() == NVS_SIM);
212
213		LLNameValue nValue2("SecondLife", "F32", "READ_ONLY");
214		ensure("2. getTypeEnum failed", nValue2.getTypeEnum() == NVT_F32);
215		ensure("2. getClassEnum failed", nValue2.getClassEnum() == NVC_READ_ONLY);
216		ensure("2. getSendtoEnum failed", nValue2.getSendtoEnum() == NVS_SIM);
217
218		LLNameValue nValue3("SecondLife", "S32", "READ_ONLY");
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_SIM);
222
223		LLNameValue nValue4("SecondLife", "VEC3", "READ_WRITE");
224		ensure("4. getTypeEnum failed", nValue4.getTypeEnum() == NVT_VEC3);
225		ensure("4. getClassEnum failed", nValue4.getClassEnum() == NVC_READ_WRITE);
226		ensure("4. getSendtoEnum failed", nValue4.getSendtoEnum() == NVS_SIM);
227
228		LLNameValue nValue6("SecondLife", "U32", "READ_WRITE");
229		ensure("6. getTypeEnum failed", nValue6.getTypeEnum() == NVT_U32);
230		ensure("6. getClassEnum failed", nValue6.getClassEnum() == NVC_READ_WRITE);
231		ensure("6. getSendtoEnum failed", nValue6.getSendtoEnum() == NVS_SIM);
232
233		LLNameValue nValue7("SecondLife", "U64", "READ_WRITE");
234		ensure("7. getTypeEnum failed", nValue7.getTypeEnum() == NVT_U64);
235		ensure("7. getClassEnum failed", nValue7.getClassEnum() == NVC_READ_WRITE);
236		ensure("7. getSendtoEnum failed", nValue7.getSendtoEnum() == NVS_SIM);
237	}
238
239	template<> template<>
240	void namevalue_object_t::test<5>()
241	{
242		LLNameValue nValue("SecondLife", "This is a test", "STRING", "RW", "SIM");
243
244		ensure("getString failed", (0 == strcmp(nValue.getString(),"This is a test")));
245	}
246
247	template<> template<>
248	void namevalue_object_t::test<6>()
249	{
250		LLNameValue nValue("SecondLife", "This is a test", "ASSET", "RW", "S");
251		ensure("getAsset failed", (0 == strcmp(nValue.getAsset(),"This is a test")));
252	}
253         	
254	template<> template<>
255	void namevalue_object_t::test<7>()
256	{
257		LLNameValue nValue("SecondLife", "555555", "F32", "RW", "SIM");
258		
259		ensure("getF32 failed",*nValue.getF32() == 555555.f);
260	}
261
262	template<> template<>
263	void namevalue_object_t::test<8>()
264	{
265		LLNameValue nValue("SecondLife", "-5555", "S32", "RW", "SIM");
266
267		ensure("getS32 failed", *nValue.getS32() == -5555);
268
269		S32 sVal = 0x7FFFFFFF;
270		nValue.setS32(sVal);
271		ensure("getS32 failed", *nValue.getS32() == sVal);
272
273		sVal = -0x7FFFFFFF;
274		nValue.setS32(sVal);
275		ensure("getS32 failed", *nValue.getS32() == sVal);
276
277		sVal = 0;
278		nValue.setS32(sVal);
279		ensure("getS32 failed", *nValue.getS32() == sVal);
280	}
281	
282	template<> template<>
283	void namevalue_object_t::test<9>()
284	{
285		LLNameValue nValue("SecondLife", "<-3, 2, 1>", "VEC3", "RW", "SIM");
286		LLVector3 vecExpected(-3, 2, 1);
287		LLVector3 vec;
288		nValue.getVec3(vec);
289		ensure("getVec3 failed", vec == vecExpected);
290	}
291	
292	template<> template<>
293	void namevalue_object_t::test<10>()
294	{
295		LLNameValue nValue("SecondLife", "12345678", "U32", "RW", "SIM");
296
297		ensure("getU32 failed",*nValue.getU32() == 12345678);
298
299		U32 val = 0xFFFFFFFF;
300		nValue.setU32(val);
301		ensure("U32 max", *nValue.getU32() == val);
302
303		val = 0;
304		nValue.setU32(val);		
305		ensure("U32 min", *nValue.getU32() == val);
306	}
307	
308	template<> template<>
309	void namevalue_object_t::test<11>()
310	{
311		//skip_fail("incomplete support for U64.");
312		LLNameValue nValue("SecondLife", "44444444444", "U64", "RW", "SIM");
313
314		ensure("getU64 failed",*nValue.getU64() == U64L(44444444444));
315
316		// there is no LLNameValue::setU64()  
317	}
318	
319	
320	template<> template<>
321	void namevalue_object_t::test<12>()
322	{
323		//skip_fail("incomplete support for U64.");
324		LLNameValue nValue("SecondLife U64 RW DSV 44444444444");	
325		std::string ret_str = nValue.printNameValue();
326		
327		ensure_equals("1:printNameValue failed",ret_str,"SecondLife U64 RW DSV 44444444444");
328		
329		LLNameValue nValue1(ret_str.c_str());
330		ensure_equals("Serialization of printNameValue failed", *nValue.getU64(), *nValue1.getU64());		
331	}
332
333	template<> template<>
334	void namevalue_object_t::test<13>()
335	{
336		LLNameValue nValue("SecondLife STRING RW DSV 44444444444");	
337		std::string ret_str = nValue.printData();
338		ensure_equals("1:printData failed",ret_str,"44444444444");
339
340		LLNameValue nValue1("SecondLife S32 RW DSV 44444");	
341		ret_str = nValue1.printData();
342		ensure_equals("2:printData failed",ret_str,"44444");		
343	}
344	
345	template<> template<>
346	void namevalue_object_t::test<14>()
347	{
348		LLNameValue nValue("SecodLife STRING RW SIM 22222");
349		std::ostringstream stream1,stream2,stream3, stream4, stream5;
350		stream1 << nValue;
351		ensure_equals("STRING << failed",stream1.str(),"22222");
352
353		LLNameValue nValue1("SecodLife F32 RW SIM 22222");
354		stream2 << nValue1;
355		ensure_equals("F32 << failed",stream2.str(),"22222");
356
357		LLNameValue nValue2("SecodLife S32 RW SIM 22222");
358		stream3<< nValue2;
359		ensure_equals("S32 << failed",stream3.str(),"22222");
360
361		LLNameValue nValue3("SecodLife U32 RW SIM 122222");
362		stream4<< nValue3;
363		ensure_equals("U32 << failed",stream4.str(),"122222");
364
365		// I don't think we use U64 name value pairs.  JC
366		//skip_fail("incomplete support for U64.");
367		//LLNameValue nValue4("SecodLife U64 RW SIM 22222");
368		//stream5<< nValue4;
369		//ensure("U64 << failed",0 == strcmp((stream5.str()).c_str(),"22222"));
370	}
371
372	template<> template<>
373	void namevalue_object_t::test<15>()
374	{
375		LLNameValue nValue("SecondLife", "This is a test", "ASSET", "R", "S");
376
377		ensure("getAsset failed", (0 == strcmp(nValue.getAsset(),"This is a test")));
378		// this should not have updated as it is read only.
379		nValue.setAsset("New Value should not be updated");
380		ensure("setAsset on ReadOnly failed", (0 == strcmp(nValue.getAsset(),"This is a test")));
381
382		LLNameValue nValue1("SecondLife", "1234", "U32", "R", "S");
383		// this should not have updated as it is read only.
384		nValue1.setU32(4567);
385		ensure("setU32 on ReadOnly failed", *nValue1.getU32() == 1234);
386
387		LLNameValue nValue2("SecondLife", "1234", "S32", "R", "S");
388		// this should not have updated as it is read only.
389		nValue2.setS32(4567);
390		ensure("setS32 on ReadOnly failed", *nValue2.getS32() == 1234);
391
392		LLNameValue nValue3("SecondLife", "1234", "F32", "R", "S");
393		// this should not have updated as it is read only.
394		nValue3.setF32(4567);
395		ensure("setF32 on ReadOnly failed", *nValue3.getF32() == 1234);
396
397		LLNameValue nValue4("SecondLife", "<1,2,3>", "VEC3", "R", "S");
398		// this should not have updated as it is read only.
399		LLVector3 vec(4,5,6);
400		nValue3.setVec3(vec);
401		LLVector3 vec1(1,2,3);
402		ensure("setVec3 on ReadOnly failed", *nValue4.getVec3() == vec1);
403
404		// cant test for U64 as no set64 exists nor any operators support U64 type
405	}         
406}