lldatapacker_tut.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:22k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /**
  2.  * @file lldatapacker_tut.cpp
  3.  * @author Adroit
  4.  * @date 2007-02
  5.  * @brief LLDataPacker test cases.
  6.  *
  7.  * $LicenseInfo:firstyear=2007&license=viewergpl$
  8.  * 
  9.  * Copyright (c) 2007-2010, Linden Research, Inc.
  10.  * 
  11.  * Second Life Viewer Source Code
  12.  * The source code in this file ("Source Code") is provided by Linden Lab
  13.  * to you under the terms of the GNU General Public License, version 2.0
  14.  * ("GPL"), unless you have obtained a separate licensing agreement
  15.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  16.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  17.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  18.  * 
  19.  * There are special exceptions to the terms and conditions of the GPL as
  20.  * it is applied to this Source Code. View the full text of the exception
  21.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  22.  * online at
  23.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  24.  * 
  25.  * By copying, modifying or distributing this software, you acknowledge
  26.  * that you have read and understood your obligations described above,
  27.  * and agree to abide by those obligations.
  28.  * 
  29.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  30.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  31.  * COMPLETENESS OR PERFORMANCE.
  32.  * $/LicenseInfo$
  33.  */
  34. #include <tut/tut.hpp>
  35. #include "lltut.h"
  36. #include "linden_common.h"
  37. #include "lldatapacker.h"
  38. #include "v4color.h"
  39. #include "v4coloru.h"
  40. #include "v2math.h"
  41. #include "v3math.h"
  42. #include "v4math.h"
  43. #include "llsdserialize.h"
  44. #define TEST_FILE_NAME "datapacker_test.txt"
  45. namespace tut
  46. {
  47. struct datapacker_test
  48. {
  49. };
  50. typedef test_group<datapacker_test> datapacker_test_t;
  51. typedef datapacker_test_t::object datapacker_test_object_t;
  52. tut::datapacker_test_t tut_datapacker_test("datapacker_test");
  53. //*********LLDataPackerBinaryBuffer
  54. template<> template<>
  55. void datapacker_test_object_t::test<1>()
  56. {
  57. U8 packbuf[128];
  58. F32 f_val1 = 44.44f, f_unpkval1;
  59. F32 f_val2 = 12344.443232f, f_unpkval2;
  60. F32 f_val3 = 44.4456789f, f_unpkval3;
  61. LLDataPackerBinaryBuffer lldp(packbuf,128);
  62. lldp.packFixed( f_val1, "linden_lab", FALSE, 8, 8);
  63. lldp.packFixed( f_val2, "linden_lab", FALSE, 14, 16);
  64. lldp.packFixed( f_val3, "linden_lab", FALSE, 8, 23);
  65. LLDataPackerBinaryBuffer lldp1(packbuf, lldp.getCurrentSize());
  66. lldp1.unpackFixed(f_unpkval1, "linden_lab", FALSE, 8, 8);
  67. lldp1.unpackFixed(f_unpkval2, "linden_lab", FALSE, 14, 16);
  68. lldp1.unpackFixed(f_unpkval3, "linden_lab", FALSE, 8, 23);
  69. ensure_approximately_equals("LLDataPackerBinaryBuffer::packFixed 8 failed", f_val1, f_unpkval1, 8);
  70. ensure_approximately_equals("LLDataPackerBinaryBuffer::packFixed 16 failed", f_val2, f_unpkval2, 16);
  71. ensure_approximately_equals("LLDataPackerBinaryBuffer::packFixed 23 failed", f_val3, f_unpkval3, 31);
  72. }
  73. template<> template<>
  74. void datapacker_test_object_t::test<2>()
  75. {
  76. U8 packbuf[1024];
  77. char str[] = "SecondLife is virtual World";
  78. char strBinary[] = "SecondLife is virtual World";
  79. char strBinaryFixed[] = "Fixed Data";
  80. S32 sizeBinaryFixed = sizeof(strBinaryFixed);
  81. U8 valU8 = 'C';
  82. U16 valU16 = 0xFFFF;
  83. U32 valU32 = 0xFFFFFFFF;
  84. S32 valS32 = -94967295;
  85. F32 valF32 = 4354355.44f ;
  86. LLColor4 llcol4(3.3f, 0, 4.4f, 5.5f);
  87. LLColor4U llcol4u(3, 128, 24, 33);
  88. LLVector2 llvec2(333.33f, 444.44f);
  89. LLVector3 llvec3(333.33f, 444.44f, 555.55f);
  90. LLVector4 llvec4(333.33f, 444.44f, 555.55f, 666.66f);
  91. LLUUID uuid;
  92. std::string unpkstr;
  93. char unpkstrBinary[256];
  94. char unpkstrBinaryFixed[256];
  95. S32 unpksizeBinary;
  96. U8 unpkvalU8;
  97. U16 unpkvalU16;
  98. U32 unpkvalU32;
  99. S32 unpkvalS32;
  100. F32 unpkvalF32;
  101. LLColor4 unpkllcol4;
  102. LLColor4U unpkllcol4u;
  103. LLVector2 unpkllvec2;
  104. LLVector3 unpkllvec3;
  105. LLVector4 unpkllvec4;
  106. LLUUID unpkuuid;
  107. LLDataPackerBinaryBuffer lldp(packbuf,1024);
  108. lldp.packString(str , "linden_lab_str");
  109. lldp.packBinaryData((U8*)strBinary, sizeof(strBinary), "linden_lab_bd");
  110. lldp.packBinaryDataFixed((U8*)strBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
  111. lldp.packU8(valU8,"linden_lab_u8");
  112. lldp.packU16(valU16,"linden_lab_u16");
  113. lldp.packU32(valU32, "linden_lab_u32");
  114. lldp.packS32(valS32, "linden_lab_s32");
  115. lldp.packF32(valF32, "linden_lab_f32");
  116. lldp.packColor4(llcol4, "linden_lab_col4");
  117. lldp.packColor4U(llcol4u, "linden_lab_col4u");
  118. lldp.packVector2(llvec2, "linden_lab_vec2");
  119. lldp.packVector3(llvec3, "linden_lab_vec3");
  120. lldp.packVector4(llvec4, "linden_lab_vec4");
  121. uuid.generate();
  122. lldp.packUUID(uuid, "linden_lab_uuid");
  123. S32 cur_size = lldp.getCurrentSize();
  124. LLDataPackerBinaryBuffer lldp1(packbuf, cur_size);
  125. lldp1.unpackString(unpkstr , "linden_lab_str");
  126. lldp1.unpackBinaryData((U8*)unpkstrBinary, unpksizeBinary, "linden_lab_bd");
  127. lldp1.unpackBinaryDataFixed((U8*)unpkstrBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
  128. lldp1.unpackU8(unpkvalU8,"linden_lab_u8");
  129. lldp1.unpackU16(unpkvalU16,"linden_lab_u16");
  130. lldp1.unpackU32(unpkvalU32, "linden_lab_u32");
  131. lldp1.unpackS32(unpkvalS32, "linden_lab_s32");
  132. lldp1.unpackF32(unpkvalF32, "linden_lab_f32");
  133. lldp1.unpackColor4(unpkllcol4, "linden_lab_col4");
  134. lldp1.unpackColor4U(unpkllcol4u, "linden_lab_col4u");
  135. lldp1.unpackVector2(unpkllvec2, "linden_lab_vec2");
  136. lldp1.unpackVector3(unpkllvec3, "linden_lab_vec3");
  137. lldp1.unpackVector4(unpkllvec4, "linden_lab_vec4");
  138. lldp1.unpackUUID(unpkuuid, "linden_lab_uuid");
  139. ensure("LLDataPackerBinaryBuffer::packString failed", strcmp(str, unpkstr.c_str())  == 0);
  140. ensure("LLDataPackerBinaryBuffer::packBinaryData failed", strcmp(strBinary, unpkstrBinary)  == 0);
  141. ensure("LLDataPackerBinaryBuffer::packBinaryDataFixed failed", strcmp(strBinaryFixed, unpkstrBinaryFixed) == 0);
  142. ensure_equals("LLDataPackerBinaryBuffer::packU8 failed", valU8, unpkvalU8);
  143. ensure_equals("LLDataPackerBinaryBuffer::packU16 failed", valU16, unpkvalU16);
  144. ensure_equals("LLDataPackerBinaryBuffer::packU32 failed", valU32, unpkvalU32);
  145. ensure_equals("LLDataPackerBinaryBuffer::packS32 failed", valS32, unpkvalS32);
  146. ensure("LLDataPackerBinaryBuffer::packF32 failed", is_approx_equal(valF32, unpkvalF32));
  147. ensure_equals("LLDataPackerBinaryBuffer::packColor4 failed", llcol4, unpkllcol4);
  148. ensure_equals("LLDataPackerBinaryBuffer::packColor4U failed", llcol4u, unpkllcol4u);
  149. ensure_equals("LLDataPackerBinaryBuffer::packVector2 failed", llvec2, unpkllvec2);
  150. ensure_equals("LLDataPackerBinaryBuffer::packVector3 failed", llvec3, unpkllvec3);
  151. ensure_equals("LLDataPackerBinaryBuffer::packVector4 failed", llvec4, unpkllvec4);
  152. ensure_equals("LLDataPackerBinaryBuffer::packUUID failed", uuid, unpkuuid);
  153. }
  154. template<> template<>
  155. void datapacker_test_object_t::test<3>()
  156. {
  157. U8 packbuf[128];
  158. char str[] = "SecondLife is virtual World";
  159. S32 strSize = sizeof(str); // include ''
  160. LLDataPackerBinaryBuffer lldp(packbuf, 128);
  161. lldp.packString(str , "linden_lab");
  162. ensure("LLDataPackerBinaryBuffer: current size is wrong", strSize == lldp.getCurrentSize());
  163. ensure("LLDataPackerBinaryBuffer: buffer size is wrong", 128 == lldp.getBufferSize());
  164. lldp.reset();
  165. ensure("LLDataPackerBinaryBuffer::reset failed",0 == lldp.getCurrentSize());
  166. }
  167. template<> template<>
  168. void datapacker_test_object_t::test<4>()
  169. {
  170. U8* packbuf = new U8[128];
  171. char str[] = "SecondLife is virtual World";
  172. LLDataPackerBinaryBuffer lldp(packbuf, 128);
  173. lldp.packString(str , "linden_lab");
  174. lldp.freeBuffer();
  175. ensure("LLDataPackerBinaryBuffer.freeBuffer failed" , 0 == lldp.getBufferSize());
  176. }
  177. template<> template<>
  178. void datapacker_test_object_t::test<5>()
  179. {
  180. U8 buf[] = "SecondLife is virtual World";
  181. S32 size = sizeof(buf);
  182. LLDataPackerBinaryBuffer lldp(buf, size);
  183. U8 new_buf[] = "Its Amazing";
  184. size = sizeof(new_buf);
  185. lldp.assignBuffer(new_buf, size);
  186. ensure("LLDataPackerBinaryBuffer::assignBuffer failed" , ((lldp.getBufferSize() == size) && (0 == lldp.getCurrentSize()))) ;
  187. }
  188. template<> template<>
  189. void datapacker_test_object_t::test<6>()
  190. {
  191. U8 packbuf[128];
  192. char str[] = "SecondLife is virtual World";
  193. LLDataPackerBinaryBuffer lldp(packbuf, 128);
  194. lldp.packString(str , "linden_lab");
  195. U8 new_buffer[128];
  196. std::string unpkbuf;
  197. LLDataPackerBinaryBuffer lldp1(new_buffer,128);
  198. lldp1 = lldp;
  199. lldp1.unpackString(unpkbuf, "linden_lab");
  200. ensure("1. LLDataPackerBinaryBuffer::operator= failed" , lldp1.getBufferSize() == lldp.getBufferSize());
  201. ensure_equals("2.LLDataPackerBinaryBuffer::operator= failed", str,unpkbuf);
  202. }
  203. //*********LLDataPackerAsciiBuffer
  204. template<> template<>
  205. void datapacker_test_object_t::test<7>()
  206. {
  207. char packbuf[128];
  208. F32 f_val = 44.44f, f_unpkval;
  209. LLDataPackerAsciiBuffer lldp(packbuf,128);
  210. lldp.packFixed( f_val, "linden_lab", FALSE, 8, 8);
  211. LLDataPackerAsciiBuffer lldp1(packbuf, lldp.getCurrentSize());
  212. lldp1.unpackFixed(f_unpkval, "linden_lab", FALSE, 8, 8);
  213. ensure_approximately_equals("LLDataPackerAsciiBuffer::packFixed failed", f_val, f_unpkval, 8);
  214. }
  215. template<> template<>
  216. void datapacker_test_object_t::test<8>()
  217. {
  218. char packbuf[1024];
  219. char str[] = "SecondLife is virtual World";
  220. char strBinary[] = "SecondLife is virtual World";
  221. char strBinaryFixed[] = "Fixed Data";
  222. S32 sizeBinaryFixed = sizeof(strBinaryFixed);
  223. U8 valU8 = 'C';
  224. U16 valU16 = 0xFFFF;
  225. U32 valU32 = 0xFFFFFFFF;
  226. S32 valS32 = -94967295;
  227. F32 valF32 = 4354355.44f ;
  228. LLColor4 llcol4(3.3f, 0, 4.4f, 5.5f);
  229. LLColor4U llcol4u(3, 128, 24, 33);
  230. LLVector2 llvec2(333.33f, 444.44f);
  231. LLVector3 llvec3(333.33f, 444.44f, 555.55f);
  232. LLVector4 llvec4(4354355.44f, 444.44f, 555.55f, 666.66f);
  233. LLUUID uuid;
  234. std::string unpkstr;
  235. char unpkstrBinary[256];
  236. char unpkstrBinaryFixed[256];
  237. S32 unpksizeBinary;
  238. U8 unpkvalU8;
  239. U16 unpkvalU16;
  240. U32 unpkvalU32;
  241. S32 unpkvalS32;
  242. F32 unpkvalF32;
  243. LLColor4 unpkllcol4;
  244. LLColor4U unpkllcol4u;
  245. LLVector2 unpkllvec2;
  246. LLVector3 unpkllvec3;
  247. LLVector4 unpkllvec4;
  248. LLUUID unpkuuid;
  249. LLDataPackerAsciiBuffer lldp(packbuf,1024);
  250. lldp.packString(str , "linden_lab_str");
  251. lldp.packBinaryData((U8*)strBinary, sizeof(strBinary), "linden_lab_bd");
  252. lldp.packBinaryDataFixed((U8*)strBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
  253. lldp.packU8(valU8,"linden_lab_u8");
  254. lldp.packU16(valU16,"linden_lab_u16");
  255. lldp.packU32(valU32, "linden_lab_u32");
  256. lldp.packS32(valS32, "linden_lab_s32");
  257. lldp.packF32(valF32, "linden_lab_f32");
  258. lldp.packColor4(llcol4, "linden_lab_col4");
  259. lldp.packColor4U(llcol4u, "linden_lab_col4u");
  260. lldp.packVector2(llvec2, "linden_lab_vec2");
  261. lldp.packVector3(llvec3, "linden_lab_vec3");
  262. lldp.packVector4(llvec4, "linden_lab_vec4");
  263. uuid.generate();
  264. lldp.packUUID(uuid, "linden_lab_uuid");
  265. S32 cur_size = lldp.getCurrentSize();
  266. LLDataPackerAsciiBuffer lldp1(packbuf, cur_size);
  267. lldp1.unpackString(unpkstr , "linden_lab_str");
  268. lldp1.unpackBinaryData((U8*)unpkstrBinary, unpksizeBinary, "linden_lab_bd");
  269. lldp1.unpackBinaryDataFixed((U8*)unpkstrBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
  270. lldp1.unpackU8(unpkvalU8,"linden_lab_u8");
  271. lldp1.unpackU16(unpkvalU16,"linden_lab_u16");
  272. lldp1.unpackU32(unpkvalU32, "linden_lab_u32");
  273. lldp1.unpackS32(unpkvalS32, "linden_lab_s32");
  274. lldp1.unpackF32(unpkvalF32, "linden_lab_f32");
  275. lldp1.unpackColor4(unpkllcol4, "linden_lab_col4");
  276. lldp1.unpackColor4U(unpkllcol4u, "linden_lab_col4u");
  277. lldp1.unpackVector2(unpkllvec2, "linden_lab_vec2");
  278. lldp1.unpackVector3(unpkllvec3, "linden_lab_vec3");
  279. lldp1.unpackVector4(unpkllvec4, "linden_lab_vec4");
  280. lldp1.unpackUUID(unpkuuid, "linden_lab_uuid");
  281. ensure("LLDataPackerAsciiBuffer::packString failed", strcmp(str, unpkstr.c_str())  == 0);
  282. ensure("LLDataPackerAsciiBuffer::packBinaryData failed", strcmp(strBinary, unpkstrBinary)  == 0);
  283. ensure("LLDataPackerAsciiBuffer::packBinaryDataFixed failed", strcmp(strBinaryFixed, unpkstrBinaryFixed) == 0);
  284. ensure_equals("LLDataPackerAsciiBuffer::packU8 failed", valU8, unpkvalU8);
  285. ensure_equals("LLDataPackerAsciiBuffer::packU16 failed", valU16, unpkvalU16);
  286. ensure_equals("LLDataPackerAsciiBuffer::packU32 failed", valU32, unpkvalU32);
  287. ensure_equals("LLDataPackerAsciiBuffer::packS32 failed", valS32, unpkvalS32);
  288. ensure("LLDataPackerAsciiBuffer::packF32 failed", is_approx_equal(valF32, unpkvalF32));
  289. ensure_equals("LLDataPackerAsciiBuffer::packColor4 failed", llcol4, unpkllcol4);
  290. ensure_equals("LLDataPackerAsciiBuffer::packColor4U failed", llcol4u, unpkllcol4u);
  291. ensure_equals("LLDataPackerAsciiBuffer::packVector2 failed", llvec2, unpkllvec2);
  292. ensure_equals("LLDataPackerAsciiBuffer::packVector3 failed", llvec3, unpkllvec3);
  293. ensure_equals("LLDataPackerAsciiBuffer::packVector4 failed", llvec4, unpkllvec4);
  294. ensure_equals("LLDataPackerAsciiBuffer::packUUID failed", uuid, unpkuuid);
  295. }
  296. template<> template<>
  297. void datapacker_test_object_t::test<9>()
  298. {
  299. char* packbuf = new char[128];
  300. char str[] = "SecondLife is virtual World";
  301. LLDataPackerAsciiBuffer lldp(packbuf, 128);
  302. lldp.packString(str , "linden_lab");
  303. lldp.freeBuffer();
  304. ensure("LLDataPackerAsciiBuffer::freeBuffer failed" , 0 == lldp.getBufferSize());
  305. }
  306. template<> template<>
  307. void datapacker_test_object_t::test<10>()
  308. {
  309. char buf[] = "SecondLife is virtual World";
  310. S32 size = sizeof(buf);
  311. LLDataPackerAsciiBuffer lldp(buf, size);
  312. char new_buf[] = "Its Amazing";
  313. size = sizeof(new_buf);
  314. lldp.assignBuffer(new_buf, size);
  315. ensure("LLDataPackerAsciiBuffer::assignBuffer failed" , ((lldp.getBufferSize() == size) && (1 == lldp.getCurrentSize()))) ;
  316. }
  317. //*********LLDataPackerAsciiFile
  318. template<> template<>
  319. void datapacker_test_object_t::test<11>()
  320. {
  321. F32 f_val = 44.44f, f_unpkval;
  322. LLFILE* fp = LLFile::fopen(TEST_FILE_NAME, "w+");
  323. if(!fp)
  324. {
  325. llerrs << "File couldnt be open" <<llendl;
  326. return;
  327. }
  328. LLDataPackerAsciiFile lldp(fp,2);
  329. lldp.packFixed( f_val, "linden_lab", FALSE, 8, 8);
  330. fflush(fp);
  331. fseek(fp,0,SEEK_SET);
  332. LLDataPackerAsciiFile lldp1(fp,2);
  333. lldp1.unpackFixed(f_unpkval, "linden_lab", FALSE, 8, 8);
  334. fclose(fp);
  335. ensure_approximately_equals("LLDataPackerAsciiFile::packFixed failed", f_val, f_unpkval, 8);
  336. }
  337. template<> template<>
  338. void datapacker_test_object_t::test<12>()
  339. {
  340. char str[] = "SecondLife is virtual World";
  341. char strBinary[] = "SecondLife is virtual World";
  342. char strBinaryFixed[] = "Fixed Data";
  343. S32 sizeBinaryFixed = sizeof(strBinaryFixed);
  344. U8 valU8 = 'C';
  345. U16 valU16 = 0xFFFF;
  346. U32 valU32 = 0xFFFFFFFF;
  347. S32 valS32 = -94967295;
  348. F32 valF32 = 4354355.44f ;
  349. LLColor4 llcol4(3.3f, 0, 4.4f, 5.5f);
  350. LLColor4U llcol4u(3, 128, 24, 33);
  351. LLVector2 llvec2(333.33f, 444.44f);
  352. LLVector3 llvec3(333.33f, 444.44f, 555.55f);
  353. LLVector4 llvec4(333.33f, 444.44f, 555.55f, 666.66f);
  354. LLUUID uuid;
  355. std::string unpkstr;
  356. char unpkstrBinary[256];
  357. char unpkstrBinaryFixed[256];
  358. S32 unpksizeBinary;
  359. U8 unpkvalU8;
  360. U16 unpkvalU16;
  361. U32 unpkvalU32;
  362. S32 unpkvalS32;
  363. F32 unpkvalF32;
  364. LLColor4 unpkllcol4;
  365. LLColor4U unpkllcol4u;
  366. LLVector2 unpkllvec2;
  367. LLVector3 unpkllvec3;
  368. LLVector4 unpkllvec4;
  369. LLUUID unpkuuid;
  370. LLFILE* fp = LLFile::fopen(TEST_FILE_NAME,"w+");
  371. if(!fp)
  372. {
  373. llerrs << "File couldnt be open" <<llendl;
  374. return;
  375. }
  376. LLDataPackerAsciiFile lldp(fp,2);
  377. lldp.packString(str , "linden_lab_str");
  378. lldp.packBinaryData((U8*)strBinary, sizeof(strBinary), "linden_lab_bd");
  379. lldp.packBinaryDataFixed((U8*)strBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
  380. lldp.packU8(valU8,"linden_lab_u8");
  381. lldp.packU16(valU16,"linden_lab_u16");
  382. lldp.packU32(valU32, "linden_lab_u32");
  383. lldp.packS32(valS32, "linden_lab_s32");
  384. lldp.packF32(valF32, "linden_lab_f32");
  385. lldp.packColor4(llcol4, "linden_lab_col4");
  386. lldp.packColor4U(llcol4u, "linden_lab_col4u");
  387. lldp.packVector2(llvec2, "linden_lab_vec2");
  388. lldp.packVector3(llvec3, "linden_lab_vec3");
  389. lldp.packVector4(llvec4, "linden_lab_vec4");
  390. uuid.generate();
  391. lldp.packUUID(uuid, "linden_lab_uuid");
  392. fflush(fp);
  393. fseek(fp,0,SEEK_SET);
  394. LLDataPackerAsciiFile lldp1(fp,2);
  395. lldp1.unpackString(unpkstr , "linden_lab_str");
  396. lldp1.unpackBinaryData((U8*)unpkstrBinary, unpksizeBinary, "linden_lab_bd");
  397. lldp1.unpackBinaryDataFixed((U8*)unpkstrBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
  398. lldp1.unpackU8(unpkvalU8,"linden_lab_u8");
  399. lldp1.unpackU16(unpkvalU16,"linden_lab_u16");
  400. lldp1.unpackU32(unpkvalU32, "linden_lab_u32");
  401. lldp1.unpackS32(unpkvalS32, "linden_lab_s32");
  402. lldp1.unpackF32(unpkvalF32, "linden_lab_f32");
  403. lldp1.unpackColor4(unpkllcol4, "linden_lab_col4");
  404. lldp1.unpackColor4U(unpkllcol4u, "linden_lab_col4u");
  405. lldp1.unpackVector2(unpkllvec2, "linden_lab_vec2");
  406. lldp1.unpackVector3(unpkllvec3, "linden_lab_vec3");
  407. lldp1.unpackVector4(unpkllvec4, "linden_lab_vec4");
  408. lldp1.unpackUUID(unpkuuid, "linden_lab_uuid");
  409. fclose(fp);
  410. ensure("LLDataPackerAsciiFile::packString failed", strcmp(str, unpkstr.c_str())  == 0);
  411. ensure("LLDataPackerAsciiFile::packBinaryData failed", strcmp(strBinary, unpkstrBinary)  == 0);
  412. ensure("LLDataPackerAsciiFile::packBinaryDataFixed failed", strcmp(strBinaryFixed, unpkstrBinaryFixed) == 0);
  413. ensure_equals("LLDataPackerAsciiFile::packU8 failed", valU8, unpkvalU8);
  414. ensure_equals("LLDataPackerAsciiFile::packU16 failed", valU16, unpkvalU16);
  415. ensure_equals("LLDataPackerAsciiFile::packU32 failed", valU32, unpkvalU32);
  416. ensure_equals("LLDataPackerAsciiFile::packS32 failed", valS32, unpkvalS32);
  417. ensure("LLDataPackerAsciiFile::packF32 failed", is_approx_equal(valF32, unpkvalF32));
  418. ensure_equals("LLDataPackerAsciiFile::packColor4 failed", llcol4, unpkllcol4);
  419. ensure_equals("LLDataPackerAsciiFile::packColor4U failed", llcol4u, unpkllcol4u);
  420. ensure_equals("LLDataPackerAsciiFile::packVector2 failed", llvec2, unpkllvec2);
  421. ensure_equals("LLDataPackerAsciiFile::packVector3 failed", llvec3, unpkllvec3);
  422. ensure_equals("LLDataPackerAsciiFile::packVector4 failed", llvec4, unpkllvec4);
  423. ensure_equals("LLDataPackerAsciiFile::packUUID failed", uuid, unpkuuid);
  424. }
  425. template<> template<>
  426. void datapacker_test_object_t::test<13>()
  427. {
  428. F32 f_val = 44.44f, f_unpkval;
  429. std::ostringstream ostr;
  430. LLDataPackerAsciiFile lldp(ostr,2);
  431. lldp.packFixed( f_val, "linden_lab", FALSE, 8, 8);
  432. std::istringstream istr(ostr.str());
  433. LLDataPackerAsciiFile lldp1(istr,2);
  434. lldp1.unpackFixed(f_unpkval, "linden_lab", FALSE, 8, 8);
  435. ensure_approximately_equals("LLDataPackerAsciiFile::packFixed (iostring) failed", f_val, f_unpkval, 8);
  436. }
  437. template<> template<>
  438. void datapacker_test_object_t::test<14>()
  439. {
  440. char str[] = "SecondLife is virtual World";
  441. char strBinary[] = "SecondLife is virtual World";
  442. char strBinaryFixed[] = "Fixed Data";
  443. S32 sizeBinaryFixed = sizeof(strBinaryFixed);
  444. U8 valU8 = 'C';
  445. U16 valU16 = 0xFFFF;
  446. U32 valU32 = 0xFFFFFFFF;
  447. S32 valS32 = -94967295;
  448. F32 valF32 = 4354355.44f ;
  449. LLColor4 llcol4(3.3f, 0, 4.4f, 5.5f);
  450. LLColor4U llcol4u(3, 128, 24, 33);
  451. LLVector2 llvec2(3333333.33f, 444.333344f);
  452. LLVector3 llvec3(3323233.33f, 444.4324f, 555.553232f);
  453. LLVector4 llvec4(333.33233f, 444.4323234f, 55323225.55f, 6323236.66f);
  454. LLUUID uuid;
  455. std::string unpkstr;
  456. char unpkstrBinary[256];
  457. char unpkstrBinaryFixed[256];
  458. S32 unpksizeBinary;
  459. U8 unpkvalU8;
  460. U16 unpkvalU16;
  461. U32 unpkvalU32;
  462. S32 unpkvalS32;
  463. F32 unpkvalF32;
  464. LLColor4 unpkllcol4;
  465. LLColor4U unpkllcol4u;
  466. LLVector2 unpkllvec2;
  467. LLVector3 unpkllvec3;
  468. LLVector4 unpkllvec4;
  469. LLUUID unpkuuid;
  470. std::ostringstream ostr;
  471. LLDataPackerAsciiFile lldp(ostr,2);
  472. lldp.packString(str , "linden_lab_str");
  473. lldp.packBinaryData((U8*)strBinary, sizeof(strBinary), "linden_lab_bd");
  474. lldp.packBinaryDataFixed((U8*)strBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
  475. lldp.packU8(valU8,"linden_lab_u8");
  476. lldp.packU16(valU16,"linden_lab_u16");
  477. lldp.packU32(valU32, "linden_lab_u32");
  478. lldp.packS32(valS32, "linden_lab_s32");
  479. lldp.packF32(valF32, "linden_lab_f32");
  480. lldp.packColor4(llcol4, "linden_lab_col4");
  481. lldp.packColor4U(llcol4u, "linden_lab_col4u");
  482. lldp.packVector2(llvec2, "linden_lab_vec2");
  483. lldp.packVector3(llvec3, "linden_lab_vec3");
  484. lldp.packVector4(llvec4, "linden_lab_vec4");
  485. uuid.generate();
  486. lldp.packUUID(uuid, "linden_lab_uuid");
  487. std::istringstream istr(ostr.str());
  488. LLDataPackerAsciiFile lldp1(istr,2);
  489. lldp1.unpackString(unpkstr , "linden_lab_str");
  490. lldp1.unpackBinaryData((U8*)unpkstrBinary, unpksizeBinary, "linden_lab_bd");
  491. lldp1.unpackBinaryDataFixed((U8*)unpkstrBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
  492. lldp1.unpackU8(unpkvalU8,"linden_lab_u8");
  493. lldp1.unpackU16(unpkvalU16,"linden_lab_u16");
  494. lldp1.unpackU32(unpkvalU32, "linden_lab_u32");
  495. lldp1.unpackS32(unpkvalS32, "linden_lab_s32");
  496. lldp1.unpackF32(unpkvalF32, "linden_lab_f32");
  497. lldp1.unpackColor4(unpkllcol4, "linden_lab_col4");
  498. lldp1.unpackColor4U(unpkllcol4u, "linden_lab_col4u");
  499. lldp1.unpackVector2(unpkllvec2, "linden_lab_vec2");
  500. lldp1.unpackVector3(unpkllvec3, "linden_lab_vec3");
  501. lldp1.unpackVector4(unpkllvec4, "linden_lab_vec4");
  502. lldp1.unpackUUID(unpkuuid, "linden_lab_uuid");
  503. ensure("LLDataPackerAsciiFile::packString (iostring) failed", strcmp(str, unpkstr.c_str())  == 0);
  504. ensure("LLDataPackerAsciiFile::packBinaryData (iostring) failed", strcmp(strBinary, unpkstrBinary)  == 0);
  505. ensure("LLDataPackerAsciiFile::packBinaryDataFixed (iostring) failed", strcmp(strBinaryFixed, unpkstrBinaryFixed) == 0);
  506. ensure_equals("LLDataPackerAsciiFile::packU8 (iostring) failed", valU8, unpkvalU8);
  507. ensure_equals("LLDataPackerAsciiFile::packU16 (iostring) failed", valU16, unpkvalU16);
  508. ensure_equals("LLDataPackerAsciiFile::packU32 (iostring) failed", valU32, unpkvalU32);
  509. ensure_equals("LLDataPackerAsciiFile::packS32 (iostring) failed", valS32, unpkvalS32);
  510. ensure("LLDataPackerAsciiFile::packF32 (iostring) failed", is_approx_equal(valF32, unpkvalF32));
  511. ensure_equals("LLDataPackerAsciiFile::packColor4 (iostring) failed", llcol4, unpkllcol4);
  512. ensure_equals("LLDataPackerAsciiFile::packColor4U (iostring) failed", llcol4u, unpkllcol4u);
  513. ensure_equals("LLDataPackerAsciiFile::packVector2 (iostring) failed", llvec2, unpkllvec2);
  514. ensure_equals("LLDataPackerAsciiFile::packVector3 (iostring) failed", llvec3, unpkllvec3);
  515. ensure_equals("LLDataPackerAsciiFile::packVector4 (iostring) failed", llvec4, unpkllvec4);
  516. ensure_equals("LLDataPackerAsciiFile::packUUID (iostring) failed", uuid, unpkuuid);
  517. }
  518. }