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