PageRenderTime 75ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/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
Possible License(s): LGPL-2.1
  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. #include "linden_common.h"
  29. #include "llsdserialize.h"
  30. #include "../llnamevalue.h"
  31. #include "../test/lltut.h"
  32. #if LL_WINDOWS
  33. // disable unreachable code warnings
  34. #pragma warning(disable: 4702)
  35. #endif
  36. namespace tut
  37. {
  38. struct namevalue_test
  39. {
  40. namevalue_test()
  41. {
  42. }
  43. };
  44. typedef test_group<namevalue_test> namevalue_t;
  45. typedef namevalue_t::object namevalue_object_t;
  46. tut::namevalue_t tut_namevalue("LLNameValue");
  47. template<> template<>
  48. void namevalue_object_t::test<1>()
  49. {
  50. // LLNameValue()
  51. LLNameValue nValue;
  52. ensure("mName should have been NULL", nValue.mName == NULL);
  53. ensure("getTypeEnum failed",nValue.getTypeEnum() == NVT_NULL);
  54. ensure("getClassEnum failed",nValue.getClassEnum() == NVC_NULL);
  55. ensure("getSendtoEnum failed",nValue.getSendtoEnum() == NVS_NULL);
  56. LLNameValue nValue1(" SecondLife ASSET RW SIM 232324343");
  57. }
  58. // LLNameValue(const char* data);
  59. // LLNameValue(const char* name, const char* data, const char* type, const char* nvclass, const char* nvsendto,
  60. // TNameValueCallback nvcb = NULL, void** user_data = NULL);
  61. template<> template<>
  62. void namevalue_object_t::test<2>()
  63. {
  64. LLNameValue nValue(" SecondLife ASSET RW S 232324343");
  65. ensure("mName not set correctly", (0 == strcmp(nValue.mName,"SecondLife")));
  66. ensure("getTypeEnum failed", nValue.getTypeEnum() == NVT_ASSET);
  67. ensure("getClassEnum failed", nValue.getClassEnum() == NVC_READ_WRITE);
  68. ensure("getSendtoEnum failed", nValue.getSendtoEnum() == NVS_SIM);
  69. ensure("getString failed", (0==strcmp(nValue.getAsset(),"232324343")));
  70. ensure("sendToData or sendToViewer failed", !nValue.sendToData() && !nValue.sendToViewer());
  71. LLNameValue nValue1("\n\r SecondLife_1 STRING READ_WRITE SIM 232324343");
  72. ensure("1. mName not set correctly", (0 == strcmp(nValue1.mName,"SecondLife_1")));
  73. ensure("1. getTypeEnum failed", nValue1.getTypeEnum() == NVT_STRING);
  74. ensure("1. getClassEnum failed", nValue1.getClassEnum() == NVC_READ_WRITE);
  75. ensure("1. getSendtoEnum failed", nValue1.getSendtoEnum() == NVS_SIM);
  76. ensure("1. getString failed", (0==strcmp(nValue1.getString(),"232324343")));
  77. ensure("1. sendToData or sendToViewer failed", !nValue1.sendToData() && !nValue1.sendToViewer());
  78. LLNameValue nValue2("SecondLife", "23.5", "F32", "R", "DS");
  79. ensure("2. getTypeEnum failed", nValue2.getTypeEnum() == NVT_F32);
  80. ensure("2. getClassEnum failed", nValue2.getClassEnum() == NVC_READ_ONLY);
  81. ensure("2. getSendtoEnum failed", nValue2.getSendtoEnum() == NVS_DATA_SIM);
  82. ensure("2. getF32 failed", *nValue2.getF32() == 23.5f);
  83. ensure("2. sendToData or sendToViewer failed", nValue2.sendToData() && !nValue2.sendToViewer());
  84. LLNameValue nValue3("SecondLife", "-43456787", "S32", "READ_ONLY", "SIM_SPACE");
  85. ensure("3. getTypeEnum failed", nValue3.getTypeEnum() == NVT_S32);
  86. ensure("3. getClassEnum failed", nValue3.getClassEnum() == NVC_READ_ONLY);
  87. ensure("3. getSendtoEnum failed", nValue3.getSendtoEnum() == NVS_DATA_SIM);
  88. ensure("3. getS32 failed", *nValue3.getS32() == -43456787);
  89. ensure("sendToData or sendToViewer failed", nValue3.sendToData() && !nValue3.sendToViewer());
  90. LLNameValue nValue4("SecondLife", "<1.0, 2.0, 3.0>", "VEC3", "RW", "SV");
  91. LLVector3 llvec4(1.0, 2.0, 3.0);
  92. ensure("4. getTypeEnum failed", nValue4.getTypeEnum() == NVT_VEC3);
  93. ensure("4. getClassEnum failed", nValue4.getClassEnum() == NVC_READ_WRITE);
  94. ensure("4. getSendtoEnum failed", nValue4.getSendtoEnum() == NVS_SIM_VIEWER);
  95. ensure("4. getVec3 failed", *nValue4.getVec3() == llvec4);
  96. ensure("4. sendToData or sendToViewer failed", !nValue4.sendToData() && nValue4.sendToViewer());
  97. LLNameValue nValue5("SecondLife", "-1.0, 2.4, 3", "VEC3", "RW", "SIM_VIEWER");
  98. LLVector3 llvec5(-1.0f, 2.4f, 3);
  99. ensure("5. getTypeEnum failed", nValue5.getTypeEnum() == NVT_VEC3);
  100. ensure("5. getClassEnum failed", nValue5.getClassEnum() == NVC_READ_WRITE);
  101. ensure("5. getSendtoEnum failed", nValue5.getSendtoEnum() == NVS_SIM_VIEWER);
  102. ensure("5. getVec3 failed", *nValue5.getVec3() == llvec5);
  103. ensure("5. sendToData or sendToViewer failed", !nValue5.sendToData() && nValue5.sendToViewer());
  104. LLNameValue nValue6("SecondLife", "89764323", "U32", "RW", "DSV");
  105. ensure("6. getTypeEnum failed", nValue6.getTypeEnum() == NVT_U32);
  106. ensure("6. getClassEnum failed", nValue6.getClassEnum() == NVC_READ_WRITE);
  107. ensure("6. getSendtoEnum failed", nValue6.getSendtoEnum() == NVS_DATA_SIM_VIEWER);
  108. ensure("6. getU32 failed", *nValue6.getU32() == 89764323);
  109. ensure("6. sendToData or sendToViewer failed", nValue6.sendToData() && nValue6.sendToViewer());
  110. LLNameValue nValue7("SecondLife", "89764323323232", "U64", "RW", "SIM_SPACE_VIEWER");
  111. U64 u64_7 = U64L(89764323323232);
  112. ensure("7. getTypeEnum failed", nValue7.getTypeEnum() == NVT_U64);
  113. ensure("7. getClassEnum failed", nValue7.getClassEnum() == NVC_READ_WRITE);
  114. ensure("7. getSendtoEnum failed", nValue7.getSendtoEnum() == NVS_DATA_SIM_VIEWER);
  115. ensure("7. getU32 failed", *nValue7.getU64() == u64_7);
  116. ensure("7. sendToData or sendToViewer failed", nValue7.sendToData() && nValue7.sendToViewer());
  117. }
  118. // LLNameValue(const char* name, const char* data, const char* type, const char* nvclass,
  119. // TNameValueCallback nvcb = NULL, void** user_data = NULL);
  120. template<> template<>
  121. void namevalue_object_t::test<3>()
  122. {
  123. LLNameValue nValue("SecondLife", "232324343", "ASSET", "READ_WRITE");
  124. ensure("mName not set correctly", (0 == strcmp(nValue.mName,"SecondLife")));
  125. ensure("getTypeEnum failed", nValue.getTypeEnum() == NVT_ASSET);
  126. ensure("getClassEnum failed", nValue.getClassEnum() == NVC_READ_WRITE);
  127. ensure("getSendtoEnum failed", nValue.getSendtoEnum() == NVS_SIM);
  128. ensure("getString failed", (0==strcmp(nValue.getAsset(),"232324343")));
  129. LLNameValue nValue1("SecondLife", "232324343", "STRING", "READ_WRITE");
  130. ensure("1. mName not set correctly", (0 == strcmp(nValue1.mName,"SecondLife")));
  131. ensure("1. getTypeEnum failed", nValue1.getTypeEnum() == NVT_STRING);
  132. ensure("1. getClassEnum failed", nValue1.getClassEnum() == NVC_READ_WRITE);
  133. ensure("1. getSendtoEnum failed", nValue1.getSendtoEnum() == NVS_SIM);
  134. ensure("1. getString failed", (0==strcmp(nValue1.getString(),"232324343")));
  135. LLNameValue nValue2("SecondLife", "23.5", "F32", "R");
  136. ensure("2. getTypeEnum failed", nValue2.getTypeEnum() == NVT_F32);
  137. ensure("2. getClassEnum failed", nValue2.getClassEnum() == NVC_READ_ONLY);
  138. ensure("2. getSendtoEnum failed", nValue2.getSendtoEnum() == NVS_SIM);
  139. ensure("2. getF32 failed", *nValue2.getF32() == 23.5f);
  140. LLNameValue nValue3("SecondLife", "-43456787", "S32", "READ_ONLY");
  141. ensure("3. getTypeEnum failed", nValue3.getTypeEnum() == NVT_S32);
  142. ensure("3. getClassEnum failed", nValue3.getClassEnum() == NVC_READ_ONLY);
  143. ensure("3. getSendtoEnum failed", nValue3.getSendtoEnum() == NVS_SIM);
  144. ensure("3. getS32 failed", *nValue3.getS32() == -43456787);
  145. LLNameValue nValue4("SecondLife", "<1.0, 2.0, 3.0>", "VEC3", "RW");
  146. LLVector3 llvec4(1.0, 2.0, 3.0);
  147. ensure("4. getTypeEnum failed", nValue4.getTypeEnum() == NVT_VEC3);
  148. ensure("4. getClassEnum failed", nValue4.getClassEnum() == NVC_READ_WRITE);
  149. ensure("4. getSendtoEnum failed", nValue4.getSendtoEnum() == NVS_SIM);
  150. ensure("4. getVec3 failed", *nValue4.getVec3() == llvec4);
  151. LLNameValue nValue5("SecondLife", "-1.0, 2.4, 3", "VEC3", "RW");
  152. LLVector3 llvec5(-1.0f, 2.4f, 3);
  153. ensure("5. getTypeEnum failed", nValue5.getTypeEnum() == NVT_VEC3);
  154. ensure("5. getClassEnum failed", nValue5.getClassEnum() == NVC_READ_WRITE);
  155. ensure("5. getSendtoEnum failed", nValue5.getSendtoEnum() == NVS_SIM);
  156. ensure("5. getVec3 failed", *nValue5.getVec3() == llvec5);
  157. LLNameValue nValue6("SecondLife", "89764323", "U32", "RW");
  158. ensure("6. getTypeEnum failed", nValue6.getTypeEnum() == NVT_U32);
  159. ensure("6. getClassEnum failed", nValue6.getClassEnum() == NVC_READ_WRITE);
  160. ensure("6. getSendtoEnum failed", nValue6.getSendtoEnum() == NVS_SIM);
  161. ensure("6. getU32 failed", *nValue6.getU32() == 89764323);
  162. LLNameValue nValue7("SecondLife", "89764323323232", "U64", "RW");
  163. U64 u64_7 = U64L(89764323323232);
  164. ensure("7. getTypeEnum failed", nValue7.getTypeEnum() == NVT_U64);
  165. ensure("7. getClassEnum failed", nValue7.getClassEnum() == NVC_READ_WRITE);
  166. ensure("7. getSendtoEnum failed", nValue7.getSendtoEnum() == NVS_SIM);
  167. ensure("7. getU32 failed", *nValue7.getU64() == u64_7);
  168. }
  169. // LLNameValue(const char* name, const char* type, const char* nvclass,
  170. // TNameValueCallback nvcb = NULL, void** user_data = NULL);
  171. template<> template<>
  172. void namevalue_object_t::test<4>()
  173. {
  174. LLNameValue nValue("SecondLife", "STRING", "READ_WRITE");
  175. ensure("mName not set correctly", (0 == strcmp(nValue.mName,"SecondLife")));
  176. ensure("getTypeEnum failed", nValue.getTypeEnum() == NVT_STRING);
  177. ensure("getClassEnum failed", nValue.getClassEnum() == NVC_READ_WRITE);
  178. ensure("getSendtoEnum failed", nValue.getSendtoEnum() == NVS_SIM);
  179. LLNameValue nValue1("SecondLife", "ASSET", "READ_WRITE");
  180. ensure("1. mName not set correctly", (0 == strcmp(nValue1.mName,"SecondLife")));
  181. ensure("1. getTypeEnum for RW failed", nValue1.getTypeEnum() == NVT_ASSET);
  182. ensure("1. getClassEnum for RW failed", nValue1.getClassEnum() == NVC_READ_WRITE);
  183. ensure("1. getSendtoEnum for RW failed", nValue1.getSendtoEnum() == NVS_SIM);
  184. LLNameValue nValue2("SecondLife", "F32", "READ_ONLY");
  185. ensure("2. getTypeEnum failed", nValue2.getTypeEnum() == NVT_F32);
  186. ensure("2. getClassEnum failed", nValue2.getClassEnum() == NVC_READ_ONLY);
  187. ensure("2. getSendtoEnum failed", nValue2.getSendtoEnum() == NVS_SIM);
  188. LLNameValue nValue3("SecondLife", "S32", "READ_ONLY");
  189. ensure("3. getTypeEnum failed", nValue3.getTypeEnum() == NVT_S32);
  190. ensure("3. getClassEnum failed", nValue3.getClassEnum() == NVC_READ_ONLY);
  191. ensure("3. getSendtoEnum failed", nValue3.getSendtoEnum() == NVS_SIM);
  192. LLNameValue nValue4("SecondLife", "VEC3", "READ_WRITE");
  193. ensure("4. getTypeEnum failed", nValue4.getTypeEnum() == NVT_VEC3);
  194. ensure("4. getClassEnum failed", nValue4.getClassEnum() == NVC_READ_WRITE);
  195. ensure("4. getSendtoEnum failed", nValue4.getSendtoEnum() == NVS_SIM);
  196. LLNameValue nValue6("SecondLife", "U32", "READ_WRITE");
  197. ensure("6. getTypeEnum failed", nValue6.getTypeEnum() == NVT_U32);
  198. ensure("6. getClassEnum failed", nValue6.getClassEnum() == NVC_READ_WRITE);
  199. ensure("6. getSendtoEnum failed", nValue6.getSendtoEnum() == NVS_SIM);
  200. LLNameValue nValue7("SecondLife", "U64", "READ_WRITE");
  201. ensure("7. getTypeEnum failed", nValue7.getTypeEnum() == NVT_U64);
  202. ensure("7. getClassEnum failed", nValue7.getClassEnum() == NVC_READ_WRITE);
  203. ensure("7. getSendtoEnum failed", nValue7.getSendtoEnum() == NVS_SIM);
  204. }
  205. template<> template<>
  206. void namevalue_object_t::test<5>()
  207. {
  208. LLNameValue nValue("SecondLife", "This is a test", "STRING", "RW", "SIM");
  209. ensure("getString failed", (0 == strcmp(nValue.getString(),"This is a test")));
  210. }
  211. template<> template<>
  212. void namevalue_object_t::test<6>()
  213. {
  214. LLNameValue nValue("SecondLife", "This is a test", "ASSET", "RW", "S");
  215. ensure("getAsset failed", (0 == strcmp(nValue.getAsset(),"This is a test")));
  216. }
  217. template<> template<>
  218. void namevalue_object_t::test<7>()
  219. {
  220. LLNameValue nValue("SecondLife", "555555", "F32", "RW", "SIM");
  221. ensure("getF32 failed",*nValue.getF32() == 555555.f);
  222. }
  223. template<> template<>
  224. void namevalue_object_t::test<8>()
  225. {
  226. LLNameValue nValue("SecondLife", "-5555", "S32", "RW", "SIM");
  227. ensure("getS32 failed", *nValue.getS32() == -5555);
  228. S32 sVal = 0x7FFFFFFF;
  229. nValue.setS32(sVal);
  230. ensure("getS32 failed", *nValue.getS32() == sVal);
  231. sVal = -0x7FFFFFFF;
  232. nValue.setS32(sVal);
  233. ensure("getS32 failed", *nValue.getS32() == sVal);
  234. sVal = 0;
  235. nValue.setS32(sVal);
  236. ensure("getS32 failed", *nValue.getS32() == sVal);
  237. }
  238. template<> template<>
  239. void namevalue_object_t::test<9>()
  240. {
  241. LLNameValue nValue("SecondLife", "<-3, 2, 1>", "VEC3", "RW", "SIM");
  242. LLVector3 vecExpected(-3, 2, 1);
  243. LLVector3 vec;
  244. nValue.getVec3(vec);
  245. ensure("getVec3 failed", vec == vecExpected);
  246. }
  247. template<> template<>
  248. void namevalue_object_t::test<10>()
  249. {
  250. LLNameValue nValue("SecondLife", "12345678", "U32", "RW", "SIM");
  251. ensure("getU32 failed",*nValue.getU32() == 12345678);
  252. U32 val = 0xFFFFFFFF;
  253. nValue.setU32(val);
  254. ensure("U32 max", *nValue.getU32() == val);
  255. val = 0;
  256. nValue.setU32(val);
  257. ensure("U32 min", *nValue.getU32() == val);
  258. }
  259. template<> template<>
  260. void namevalue_object_t::test<11>()
  261. {
  262. //skip_fail("incomplete support for U64.");
  263. LLNameValue nValue("SecondLife", "44444444444", "U64", "RW", "SIM");
  264. ensure("getU64 failed",*nValue.getU64() == U64L(44444444444));
  265. // there is no LLNameValue::setU64()
  266. }
  267. template<> template<>
  268. void namevalue_object_t::test<12>()
  269. {
  270. //skip_fail("incomplete support for U64.");
  271. LLNameValue nValue("SecondLife U64 RW DSV 44444444444");
  272. std::string ret_str = nValue.printNameValue();
  273. ensure_equals("1:printNameValue failed",ret_str,"SecondLife U64 RW DSV 44444444444");
  274. LLNameValue nValue1(ret_str.c_str());
  275. ensure_equals("Serialization of printNameValue failed", *nValue.getU64(), *nValue1.getU64());
  276. }
  277. template<> template<>
  278. void namevalue_object_t::test<13>()
  279. {
  280. LLNameValue nValue("SecondLife STRING RW DSV 44444444444");
  281. std::string ret_str = nValue.printData();
  282. ensure_equals("1:printData failed",ret_str,"44444444444");
  283. LLNameValue nValue1("SecondLife S32 RW DSV 44444");
  284. ret_str = nValue1.printData();
  285. ensure_equals("2:printData failed",ret_str,"44444");
  286. }
  287. template<> template<>
  288. void namevalue_object_t::test<14>()
  289. {
  290. LLNameValue nValue("SecodLife STRING RW SIM 22222");
  291. std::ostringstream stream1,stream2,stream3, stream4, stream5;
  292. stream1 << nValue;
  293. ensure_equals("STRING << failed",stream1.str(),"22222");
  294. LLNameValue nValue1("SecodLife F32 RW SIM 22222");
  295. stream2 << nValue1;
  296. ensure_equals("F32 << failed",stream2.str(),"22222");
  297. LLNameValue nValue2("SecodLife S32 RW SIM 22222");
  298. stream3<< nValue2;
  299. ensure_equals("S32 << failed",stream3.str(),"22222");
  300. LLNameValue nValue3("SecodLife U32 RW SIM 122222");
  301. stream4<< nValue3;
  302. ensure_equals("U32 << failed",stream4.str(),"122222");
  303. // I don't think we use U64 name value pairs. JC
  304. //skip_fail("incomplete support for U64.");
  305. //LLNameValue nValue4("SecodLife U64 RW SIM 22222");
  306. //stream5<< nValue4;
  307. //ensure("U64 << failed",0 == strcmp((stream5.str()).c_str(),"22222"));
  308. }
  309. template<> template<>
  310. void namevalue_object_t::test<15>()
  311. {
  312. LLNameValue nValue("SecondLife", "This is a test", "ASSET", "R", "S");
  313. ensure("getAsset failed", (0 == strcmp(nValue.getAsset(),"This is a test")));
  314. // this should not have updated as it is read only.
  315. nValue.setAsset("New Value should not be updated");
  316. ensure("setAsset on ReadOnly failed", (0 == strcmp(nValue.getAsset(),"This is a test")));
  317. LLNameValue nValue1("SecondLife", "1234", "U32", "R", "S");
  318. // this should not have updated as it is read only.
  319. nValue1.setU32(4567);
  320. ensure("setU32 on ReadOnly failed", *nValue1.getU32() == 1234);
  321. LLNameValue nValue2("SecondLife", "1234", "S32", "R", "S");
  322. // this should not have updated as it is read only.
  323. nValue2.setS32(4567);
  324. ensure("setS32 on ReadOnly failed", *nValue2.getS32() == 1234);
  325. LLNameValue nValue3("SecondLife", "1234", "F32", "R", "S");
  326. // this should not have updated as it is read only.
  327. nValue3.setF32(4567);
  328. ensure("setF32 on ReadOnly failed", *nValue3.getF32() == 1234);
  329. LLNameValue nValue4("SecondLife", "<1,2,3>", "VEC3", "R", "S");
  330. // this should not have updated as it is read only.
  331. LLVector3 vec(4,5,6);
  332. nValue3.setVec3(vec);
  333. LLVector3 vec1(1,2,3);
  334. ensure("setVec3 on ReadOnly failed", *nValue4.getVec3() == vec1);
  335. // cant test for U64 as no set64 exists nor any operators support U64 type
  336. }
  337. }