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

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llwtextureinfo_test.cpp
  3.  * @author Si & Gabriel
  4.  * @date 2009-03-30
  5.  *
  6.  * $LicenseInfo:firstyear=2006&license=viewergpl$
  7.  * 
  8.  * Copyright (c) 2006-2010, Linden Research, Inc.
  9.  * 
  10.  * Second Life Viewer Source Code
  11.  * The source code in this file ("Source Code") is provided by Linden Lab
  12.  * to you under the terms of the GNU General Public License, version 2.0
  13.  * ("GPL"), unless you have obtained a separate licensing agreement
  14.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  15.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17.  * 
  18.  * There are special exceptions to the terms and conditions of the GPL as
  19.  * it is applied to this Source Code. View the full text of the exception
  20.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  21.  * online at
  22.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23.  * 
  24.  * By copying, modifying or distributing this software, you acknowledge
  25.  * that you have read and understood your obligations described above,
  26.  * and agree to abide by those obligations.
  27.  * 
  28.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30.  * COMPLETENESS OR PERFORMANCE.
  31.  * $/LicenseInfo$
  32.  */
  33. // Precompiled header: almost always required for newview cpp files
  34. #include "../llviewerprecompiledheaders.h"
  35. // Class to test
  36. #include "../lltextureinfo.h"
  37. // Dependencies
  38. #include "../lltextureinfodetails.cpp"
  39. // Tut header
  40. #include "../test/lltut.h"
  41. // -------------------------------------------------------------------------------------------
  42. // Stubbing: Declarations required to link and run the class being tested
  43. // Notes: 
  44. // * Add here stubbed implementation of the few classes and methods used in the class to be tested
  45. // * Add as little as possible (let the link errors guide you)
  46. // * Do not make any assumption as to how those classes or methods work (i.e. don't copy/paste code)
  47. // * A simulator for a class can be implemented here. Please comment and document thoroughly.
  48. // End Stubbing
  49. // -------------------------------------------------------------------------------------------
  50. // -------------------------------------------------------------------------------------------
  51. // TUT
  52. // -------------------------------------------------------------------------------------------
  53. namespace tut
  54. {
  55. // Test wrapper declarations
  56. struct textureinfo_test
  57. {
  58. // Constructor and destructor of the test wrapper
  59. textureinfo_test()
  60. {
  61. }
  62. ~textureinfo_test()
  63. {
  64. }
  65. };
  66. // Tut templating thingamagic: test group, object and test instance
  67. typedef test_group<textureinfo_test> textureinfo_t;
  68. typedef textureinfo_t::object textureinfo_object_t;
  69. tut::textureinfo_t tut_textureinfo("textureinfo");
  70. // ---------------------------------------------------------------------------------------
  71. // Test functions
  72. // Notes:
  73. // * Test as many as you possibly can without requiring a full blown simulation of everything
  74. // * The tests are executed in sequence so the test instance state may change between calls
  75. // * Remember that you cannot test private methods with tut
  76. // ---------------------------------------------------------------------------------------
  77. // ---------------------------------------------------------------------------------------
  78. // Test the LLTextureInfo
  79. // ---------------------------------------------------------------------------------------
  80. // Test instantiation
  81. template<> template<>
  82. void textureinfo_object_t::test<1>()
  83. {
  84. LLTextureInfo tex_info;
  85. tex_info.setUpLogging(true, true);
  86. ensure("have we crashed?", true);
  87. }
  88. // Check lltextureinfo does not contain UUIDs we haven't added
  89. template<> template<>
  90. void textureinfo_object_t::test<2>()
  91. {
  92. LLTextureInfo tex_info;
  93. tex_info.setUpLogging(true, true);
  94. LLUUID nonExistant("3a0efa3b-84dc-4e17-9b8c-79ea028850c1");
  95. ensure(!tex_info.has(nonExistant));
  96. }
  97. // Check we can add a request time for a texture
  98. template<> template<>
  99. void textureinfo_object_t::test<3>()
  100. {
  101. LLTextureInfo tex_info;
  102. tex_info.setUpLogging(true, true);
  103. LLUUID id("10e65d70-46fd-429f-841a-bf698e9424d3");
  104. tex_info.setRequestStartTime(id, 200);
  105. ensure_equals(tex_info.getRequestStartTime(id), 200);
  106. }
  107. // Check time for non-existant texture
  108. template<> template<>
  109. void textureinfo_object_t::test<4>()
  110. {
  111. LLTextureInfo tex_info;
  112. tex_info.setUpLogging(true, true);
  113. LLUUID nonExistant("3a0efa3b-84dc-4e17-9b8c-79ea028850c1");
  114. ensure_equals(tex_info.getRequestStartTime(nonExistant), 0);
  115. }
  116. // Check download complete time for non existant texture
  117. template<> template<>
  118. void textureinfo_object_t::test<5>()
  119. {
  120. LLTextureInfo tex_info;
  121. tex_info.setUpLogging(true, true);
  122. LLUUID nonExistant("3a0efa3b-84dc-4e17-9b8c-79ea028850c1");
  123. ensure_equals(tex_info.getRequestCompleteTime(nonExistant), 0);
  124. }
  125. // requested size is passed in correctly
  126. template<> template<>
  127. void textureinfo_object_t::test<6>()
  128. {
  129. LLTextureInfo tex_info;
  130. tex_info.setUpLogging(true, true);
  131. LLUUID id("10e65d70-46fd-429f-841a-bf698e9424d3");
  132. tex_info.setRequestSize(id, 600);
  133. ensure_equals(tex_info.getRequestSize(id), 600);
  134. }
  135. // transport type is recorded correctly (http)
  136. template<> template<>
  137. void textureinfo_object_t::test<7>()
  138. {
  139. LLTextureInfo tex_info;
  140. tex_info.setUpLogging(true, true);
  141. LLUUID id("10e65d70-46fd-429f-841a-bf698e9424d3");
  142. tex_info.setRequestType(id, LLTextureInfoDetails::REQUEST_TYPE_HTTP);
  143. ensure_equals(tex_info.getRequestType(id), LLTextureInfoDetails::REQUEST_TYPE_HTTP);
  144. }
  145. // transport type is recorded correctly (udp)
  146. template<> template<>
  147. void textureinfo_object_t::test<8>()
  148. {
  149. LLTextureInfo tex_info;
  150. tex_info.setUpLogging(true, true);
  151. LLUUID id("10e65d70-46fd-429f-841a-bf698e9424d3");
  152. tex_info.setRequestType(id, LLTextureInfoDetails::REQUEST_TYPE_UDP);
  153. ensure_equals(tex_info.getRequestType(id), LLTextureInfoDetails::REQUEST_TYPE_UDP);
  154. }
  155. // request offset is recorded correctly
  156. template<> template<>
  157. void textureinfo_object_t::test<9>()
  158. {
  159. LLTextureInfo tex_info;
  160. tex_info.setUpLogging(true, true);
  161. LLUUID id("10e65d70-46fd-429f-841a-bf698e9424d3");
  162. tex_info.setRequestOffset(id, 1234);
  163. ensure_equals(tex_info.getRequestOffset(id), 1234);
  164. }
  165. // ask for averages gives us correct figure
  166. template<> template<>
  167. void textureinfo_object_t::test<10>()
  168. {
  169. LLTextureInfo tex_info;
  170. tex_info.setUpLogging(true, true);
  171. S32 requestStartTimeOne = 200;
  172. S32 requestEndTimeOne = 400;
  173. S32 requestSizeOne = 1024;
  174. S32 requestSizeOneBits = requestSizeOne * 8;
  175. LLUUID id1("10e65d70-46fd-429f-841a-bf698e9424d3");
  176. tex_info.setRequestStartTime(id1, requestStartTimeOne);
  177. tex_info.setRequestSize(id1, requestSizeOne);
  178. tex_info.setRequestType(id1, LLTextureInfoDetails::REQUEST_TYPE_HTTP);
  179. tex_info.setRequestCompleteTimeAndLog(id1, requestEndTimeOne);
  180. U32 requestStartTimeTwo = 100;
  181. U32 requestEndTimeTwo = 500;
  182. U32 requestSizeTwo = 2048;
  183. S32 requestSizeTwoBits = requestSizeTwo * 8;
  184. LLUUID id2("10e65d70-46fd-429f-841a-bf698e9424d4");
  185. tex_info.setRequestStartTime(id2, requestStartTimeTwo);
  186. tex_info.setRequestSize(id2, requestSizeTwo);
  187. tex_info.setRequestType(id2, LLTextureInfoDetails::REQUEST_TYPE_HTTP);
  188. tex_info.setRequestCompleteTimeAndLog(id2, requestEndTimeTwo);
  189. S32 averageBitRate = ((requestSizeOneBits/(requestEndTimeOne - requestStartTimeOne)) +
  190. (requestSizeTwoBits/(requestEndTimeTwo - requestStartTimeTwo))) / 2;
  191. S32 totalBytes = requestSizeOne + requestSizeTwo;
  192. LLSD results = tex_info.getAverages();
  193. ensure_equals("is average bits per second correct", results["bits_per_second"].asInteger(), averageBitRate);
  194. ensure_equals("is total bytes is correct", results["bytes_downloaded"].asInteger(), totalBytes);
  195. ensure_equals("is transport correct", results["transport"].asString(), std::string("HTTP"));
  196. }
  197. // make sure averages cleared when reset is called
  198. template<> template<>
  199. void textureinfo_object_t::test<11>()
  200. {
  201. LLTextureInfo tex_info;
  202. tex_info.setUpLogging(true, true);
  203. S32 requestStartTimeOne = 200;
  204. S32 requestEndTimeOne = 400;
  205. S32 requestSizeOne = 1024;
  206. LLUUID id1("10e65d70-46fd-429f-841a-bf698e9424d3");
  207. tex_info.setRequestStartTime(id1, requestStartTimeOne);
  208. tex_info.setRequestSize(id1, requestSizeOne);
  209. tex_info.setRequestType(id1, LLTextureInfoDetails::REQUEST_TYPE_HTTP);
  210. tex_info.setRequestCompleteTimeAndLog(id1, requestEndTimeOne);
  211. tex_info.getAverages();
  212. tex_info.reset();
  213. LLSD results = tex_info.getAverages();
  214. ensure_equals("is average bits per second correct", results["bits_per_second"].asInteger(), 0);
  215. ensure_equals("is total bytes is correct", results["bytes_downloaded"].asInteger(), 0);
  216. ensure_equals("is transport correct", results["transport"].asString(), std::string("NONE"));
  217. }
  218. // make sure map item removed when expired
  219. template<> template<>
  220. void textureinfo_object_t::test<12>()
  221. {
  222. LLTextureInfo tex_info;
  223. tex_info.setUpLogging(true, true);
  224. S32 requestStartTimeOne = 200;
  225. S32 requestEndTimeOne = 400;
  226. S32 requestSizeOne = 1024;
  227. LLUUID id1("10e65d70-46fd-429f-841a-bf698e9424d3");
  228. tex_info.setRequestStartTime(id1, requestStartTimeOne);
  229. tex_info.setRequestSize(id1, requestSizeOne);
  230. tex_info.setRequestType(id1, LLTextureInfoDetails::REQUEST_TYPE_HTTP);
  231. ensure_equals("map item created", tex_info.getTextureInfoMapSize(), 1);
  232. tex_info.setRequestCompleteTimeAndLog(id1, requestEndTimeOne);
  233. ensure_equals("map item removed when consumed", tex_info.getTextureInfoMapSize(), 0);
  234. }
  235. }