PageRenderTime 23ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/tests/lltextureinfo_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 278 lines | 162 code | 49 blank | 67 comment | 0 complexity | 91d86b11dd81677d5b1725a4009e7241 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llwtextureinfo_test.cpp
  3. * @author Si & Gabriel
  4. * @date 2009-03-30
  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. // Precompiled header: almost always required for newview cpp files
  28. #include "../llviewerprecompiledheaders.h"
  29. // Class to test
  30. #include "../lltextureinfo.h"
  31. // Dependencies
  32. #include "../lltextureinfodetails.cpp"
  33. // Tut header
  34. #include "../test/lltut.h"
  35. // -------------------------------------------------------------------------------------------
  36. // Stubbing: Declarations required to link and run the class being tested
  37. // Notes:
  38. // * Add here stubbed implementation of the few classes and methods used in the class to be tested
  39. // * Add as little as possible (let the link errors guide you)
  40. // * Do not make any assumption as to how those classes or methods work (i.e. don't copy/paste code)
  41. // * A simulator for a class can be implemented here. Please comment and document thoroughly.
  42. // End Stubbing
  43. // -------------------------------------------------------------------------------------------
  44. // -------------------------------------------------------------------------------------------
  45. // TUT
  46. // -------------------------------------------------------------------------------------------
  47. namespace tut
  48. {
  49. // Test wrapper declarations
  50. struct textureinfo_test
  51. {
  52. // Constructor and destructor of the test wrapper
  53. textureinfo_test()
  54. {
  55. }
  56. ~textureinfo_test()
  57. {
  58. }
  59. };
  60. // Tut templating thingamagic: test group, object and test instance
  61. typedef test_group<textureinfo_test> textureinfo_t;
  62. typedef textureinfo_t::object textureinfo_object_t;
  63. tut::textureinfo_t tut_textureinfo("LLTectureInfo");
  64. // ---------------------------------------------------------------------------------------
  65. // Test functions
  66. // Notes:
  67. // * Test as many as you possibly can without requiring a full blown simulation of everything
  68. // * The tests are executed in sequence so the test instance state may change between calls
  69. // * Remember that you cannot test private methods with tut
  70. // ---------------------------------------------------------------------------------------
  71. // ---------------------------------------------------------------------------------------
  72. // Test the LLTextureInfo
  73. // ---------------------------------------------------------------------------------------
  74. // Test instantiation
  75. template<> template<>
  76. void textureinfo_object_t::test<1>()
  77. {
  78. LLTextureInfo tex_info;
  79. tex_info.setUpLogging(true, true);
  80. ensure("have we crashed?", true);
  81. }
  82. // Check lltextureinfo does not contain UUIDs we haven't added
  83. template<> template<>
  84. void textureinfo_object_t::test<2>()
  85. {
  86. LLTextureInfo tex_info;
  87. tex_info.setUpLogging(true, true);
  88. LLUUID nonExistant("3a0efa3b-84dc-4e17-9b8c-79ea028850c1");
  89. ensure(!tex_info.has(nonExistant));
  90. }
  91. // Check we can add a request time for a texture
  92. template<> template<>
  93. void textureinfo_object_t::test<3>()
  94. {
  95. LLTextureInfo tex_info;
  96. tex_info.setUpLogging(true, true);
  97. LLUUID id("10e65d70-46fd-429f-841a-bf698e9424d3");
  98. tex_info.setRequestStartTime(id, 200);
  99. ensure_equals(tex_info.getRequestStartTime(id), 200);
  100. }
  101. // Check time for non-existant texture
  102. template<> template<>
  103. void textureinfo_object_t::test<4>()
  104. {
  105. LLTextureInfo tex_info;
  106. tex_info.setUpLogging(true, true);
  107. LLUUID nonExistant("3a0efa3b-84dc-4e17-9b8c-79ea028850c1");
  108. ensure_equals(tex_info.getRequestStartTime(nonExistant), 0);
  109. }
  110. // Check download complete time for non existant texture
  111. template<> template<>
  112. void textureinfo_object_t::test<5>()
  113. {
  114. LLTextureInfo tex_info;
  115. tex_info.setUpLogging(true, true);
  116. LLUUID nonExistant("3a0efa3b-84dc-4e17-9b8c-79ea028850c1");
  117. ensure_equals(tex_info.getRequestCompleteTime(nonExistant), 0);
  118. }
  119. // requested size is passed in correctly
  120. template<> template<>
  121. void textureinfo_object_t::test<6>()
  122. {
  123. LLTextureInfo tex_info;
  124. tex_info.setUpLogging(true, true);
  125. LLUUID id("10e65d70-46fd-429f-841a-bf698e9424d3");
  126. tex_info.setRequestSize(id, 600);
  127. ensure_equals(tex_info.getRequestSize(id), 600);
  128. }
  129. // transport type is recorded correctly (http)
  130. template<> template<>
  131. void textureinfo_object_t::test<7>()
  132. {
  133. LLTextureInfo tex_info;
  134. tex_info.setUpLogging(true, true);
  135. LLUUID id("10e65d70-46fd-429f-841a-bf698e9424d3");
  136. tex_info.setRequestType(id, LLTextureInfoDetails::REQUEST_TYPE_HTTP);
  137. ensure_equals(tex_info.getRequestType(id), LLTextureInfoDetails::REQUEST_TYPE_HTTP);
  138. }
  139. // transport type is recorded correctly (udp)
  140. template<> template<>
  141. void textureinfo_object_t::test<8>()
  142. {
  143. LLTextureInfo tex_info;
  144. tex_info.setUpLogging(true, true);
  145. LLUUID id("10e65d70-46fd-429f-841a-bf698e9424d3");
  146. tex_info.setRequestType(id, LLTextureInfoDetails::REQUEST_TYPE_UDP);
  147. ensure_equals(tex_info.getRequestType(id), LLTextureInfoDetails::REQUEST_TYPE_UDP);
  148. }
  149. // request offset is recorded correctly
  150. template<> template<>
  151. void textureinfo_object_t::test<9>()
  152. {
  153. LLTextureInfo tex_info;
  154. tex_info.setUpLogging(true, true);
  155. LLUUID id("10e65d70-46fd-429f-841a-bf698e9424d3");
  156. tex_info.setRequestOffset(id, 1234);
  157. ensure_equals(tex_info.getRequestOffset(id), 1234);
  158. }
  159. // ask for averages gives us correct figure
  160. template<> template<>
  161. void textureinfo_object_t::test<10>()
  162. {
  163. LLTextureInfo tex_info;
  164. tex_info.setUpLogging(true, true);
  165. S32 requestStartTimeOne = 200;
  166. S32 requestEndTimeOne = 400;
  167. S32 requestSizeOne = 1024;
  168. S32 requestSizeOneBits = requestSizeOne * 8;
  169. LLUUID id1("10e65d70-46fd-429f-841a-bf698e9424d3");
  170. tex_info.setRequestStartTime(id1, requestStartTimeOne);
  171. tex_info.setRequestSize(id1, requestSizeOne);
  172. tex_info.setRequestType(id1, LLTextureInfoDetails::REQUEST_TYPE_HTTP);
  173. tex_info.setRequestCompleteTimeAndLog(id1, requestEndTimeOne);
  174. U32 requestStartTimeTwo = 100;
  175. U32 requestEndTimeTwo = 500;
  176. U32 requestSizeTwo = 2048;
  177. S32 requestSizeTwoBits = requestSizeTwo * 8;
  178. LLUUID id2("10e65d70-46fd-429f-841a-bf698e9424d4");
  179. tex_info.setRequestStartTime(id2, requestStartTimeTwo);
  180. tex_info.setRequestSize(id2, requestSizeTwo);
  181. tex_info.setRequestType(id2, LLTextureInfoDetails::REQUEST_TYPE_HTTP);
  182. tex_info.setRequestCompleteTimeAndLog(id2, requestEndTimeTwo);
  183. S32 averageBitRate = ((requestSizeOneBits/(requestEndTimeOne - requestStartTimeOne)) +
  184. (requestSizeTwoBits/(requestEndTimeTwo - requestStartTimeTwo))) / 2;
  185. S32 totalBytes = requestSizeOne + requestSizeTwo;
  186. LLSD results = tex_info.getAverages();
  187. ensure_equals("is average bits per second correct", results["bits_per_second"].asInteger(), averageBitRate);
  188. ensure_equals("is total bytes is correct", results["bytes_downloaded"].asInteger(), totalBytes);
  189. ensure_equals("is transport correct", results["transport"].asString(), std::string("HTTP"));
  190. }
  191. // make sure averages cleared when reset is called
  192. template<> template<>
  193. void textureinfo_object_t::test<11>()
  194. {
  195. LLTextureInfo tex_info;
  196. tex_info.setUpLogging(true, true);
  197. S32 requestStartTimeOne = 200;
  198. S32 requestEndTimeOne = 400;
  199. S32 requestSizeOne = 1024;
  200. LLUUID id1("10e65d70-46fd-429f-841a-bf698e9424d3");
  201. tex_info.setRequestStartTime(id1, requestStartTimeOne);
  202. tex_info.setRequestSize(id1, requestSizeOne);
  203. tex_info.setRequestType(id1, LLTextureInfoDetails::REQUEST_TYPE_HTTP);
  204. tex_info.setRequestCompleteTimeAndLog(id1, requestEndTimeOne);
  205. tex_info.getAverages();
  206. tex_info.reset();
  207. LLSD results = tex_info.getAverages();
  208. ensure_equals("is average bits per second correct", results["bits_per_second"].asInteger(), 0);
  209. ensure_equals("is total bytes is correct", results["bytes_downloaded"].asInteger(), 0);
  210. ensure_equals("is transport correct", results["transport"].asString(), std::string("NONE"));
  211. }
  212. // make sure map item removed when expired
  213. template<> template<>
  214. void textureinfo_object_t::test<12>()
  215. {
  216. LLTextureInfo tex_info;
  217. tex_info.setUpLogging(true, true);
  218. S32 requestStartTimeOne = 200;
  219. S32 requestEndTimeOne = 400;
  220. S32 requestSizeOne = 1024;
  221. LLUUID id1("10e65d70-46fd-429f-841a-bf698e9424d3");
  222. tex_info.setRequestStartTime(id1, requestStartTimeOne);
  223. tex_info.setRequestSize(id1, requestSizeOne);
  224. tex_info.setRequestType(id1, LLTextureInfoDetails::REQUEST_TYPE_HTTP);
  225. ensure_equals("map item created", tex_info.getTextureInfoMapSize(), 1);
  226. tex_info.setRequestCompleteTimeAndLog(id1, requestEndTimeOne);
  227. ensure_equals("map item removed when consumed", tex_info.getTextureInfoMapSize(), 0);
  228. }
  229. }