PageRenderTime 762ms CodeModel.GetById 202ms app.highlight 293ms RepoModel.GetById 260ms app.codeStats 1ms

/indra/newview/tests/llworldmap_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 515 lines | 339 code | 46 blank | 130 comment | 35 complexity | 2bf98cebfef3d7ef7444f45ce34e43f3 MD5 | raw file
  1/** 
  2 * @file llworldmap_test.cpp
  3 * @author Merov Linden
  4 * @date 2009-03-09
  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// Dependencies
 29#include "linden_common.h"
 30#include "llapr.h"
 31#include "llsingleton.h"
 32#include "lltrans.h"
 33#include "lluistring.h"
 34#include "../llviewertexture.h"
 35#include "../llworldmapmessage.h"
 36// Class to test
 37#include "../llworldmap.h"
 38// Tut header
 39#include "../test/lltut.h"
 40
 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
 49// Stub image calls
 50void LLViewerTexture::setBoostLevel(S32 ) { }
 51void LLViewerTexture::setAddressMode(LLTexUnit::eTextureAddressMode ) { }
 52LLViewerFetchedTexture* LLViewerTextureManager::getFetchedTexture(const LLUUID&, BOOL, LLViewerTexture::EBoostLevel, S8,
 53																  LLGLint, LLGLenum, LLHost ) { return NULL; }
 54
 55// Stub related map calls
 56LLWorldMapMessage::LLWorldMapMessage() { }
 57LLWorldMapMessage::~LLWorldMapMessage() { }
 58void LLWorldMapMessage::sendItemRequest(U32 type, U64 handle) { }
 59void LLWorldMapMessage::sendMapBlockRequest(U16 min_x, U16 min_y, U16 max_x, U16 max_y, bool return_nonexistent) { }
 60
 61LLWorldMipmap::LLWorldMipmap() { }
 62LLWorldMipmap::~LLWorldMipmap() { }
 63void LLWorldMipmap::reset() { }
 64void LLWorldMipmap::dropBoostLevels() { }
 65void LLWorldMipmap::equalizeBoostLevels() { }
 66LLPointer<LLViewerFetchedTexture> LLWorldMipmap::getObjectsTile(U32 grid_x, U32 grid_y, S32 level, bool load) { return NULL; }
 67
 68// Stub other stuff
 69std::string LLTrans::getString(const std::string &, const LLStringUtil::format_map_t& ) { return std::string("test_trans"); }
 70void LLUIString::updateResult() const { }
 71void LLUIString::setArg(const std::string& , const std::string& ) { }
 72void LLUIString::assign(const std::string& ) { }
 73
 74// End Stubbing
 75// -------------------------------------------------------------------------------------------
 76
 77// -------------------------------------------------------------------------------------------
 78// TUT
 79// -------------------------------------------------------------------------------------------
 80
 81const F32 X_WORLD_TEST = 1000.0f * REGION_WIDTH_METERS;
 82const F32 Y_WORLD_TEST = 2000.0f * REGION_WIDTH_METERS;
 83const F32 Z_WORLD_TEST = 240.0f;
 84const std::string ITEM_NAME_TEST = "Item Foo";
 85const std::string TOOLTIP_TEST = "Tooltip Foo";
 86
 87const std::string SIM_NAME_TEST = "Sim Foo";
 88
 89namespace tut
 90{
 91	// Test wrapper declarations
 92	struct iteminfo_test
 93	{
 94		// Instance to be tested
 95		LLItemInfo* mItem;
 96
 97		// Constructor and destructor of the test wrapper
 98		iteminfo_test()
 99		{
100			LLUUID id;
101			mItem = new LLItemInfo(X_WORLD_TEST, Y_WORLD_TEST, ITEM_NAME_TEST, id);
102		}
103		~iteminfo_test()
104		{
105			delete mItem;
106		}
107	};
108
109	struct siminfo_test
110	{
111		// Instance to be tested
112		LLSimInfo* mSim;
113
114		// Constructor and destructor of the test wrapper
115		siminfo_test()
116		{
117			U64 handle = to_region_handle_global(X_WORLD_TEST, Y_WORLD_TEST);
118			mSim = new LLSimInfo(handle);
119		}
120		~siminfo_test()
121		{
122			delete mSim;
123		}
124	};
125
126	struct worldmap_test
127	{
128		// Instance to be tested
129		LLWorldMap* mWorld;
130
131		// Constructor and destructor of the test wrapper
132		worldmap_test()
133		{
134			mWorld = LLWorldMap::getInstance();
135		}
136		~worldmap_test()
137		{
138			mWorld = NULL;
139		}
140	};
141
142	// Tut templating thingamagic: test group, object and test instance
143	typedef test_group<iteminfo_test> iteminfo_t;
144	typedef iteminfo_t::object iteminfo_object_t;
145	tut::iteminfo_t tut_iteminfo("LLItemInfo");
146
147	typedef test_group<siminfo_test> siminfo_t;
148	typedef siminfo_t::object siminfo_object_t;
149	tut::siminfo_t tut_siminfo("LLSimInfo");
150
151	typedef test_group<worldmap_test> worldmap_t;
152	typedef worldmap_t::object worldmap_object_t;
153	tut::worldmap_t tut_worldmap("LLWorldMap");
154
155	// ---------------------------------------------------------------------------------------
156	// Test functions
157	// Notes:
158	// * Test as many as you possibly can without requiring a full blown simulation of everything
159	// * The tests are executed in sequence so the test instance state may change between calls
160	// * Remember that you cannot test private methods with tut
161	// ---------------------------------------------------------------------------------------
162
163	// ---------------------------------------------------------------------------------------
164	// Test the LLItemInfo interface
165	// ---------------------------------------------------------------------------------------
166	template<> template<>
167	void iteminfo_object_t::test<1>()
168	{
169		// Test 1 : setCount() / getCount()
170		mItem->setCount(10);
171		ensure("LLItemInfo::setCount() test failed", mItem->getCount() == 10);
172		// Test 2 : setTooltip() / getToolTip()
173		std::string tooltip = TOOLTIP_TEST;
174		mItem->setTooltip(tooltip);
175		ensure("LLItemInfo::setTooltip() test failed", mItem->getToolTip() == TOOLTIP_TEST);
176		// Test 3 : setElevation() / getGlobalPosition()
177		mItem->setElevation(Z_WORLD_TEST);
178		LLVector3d pos = mItem->getGlobalPosition();
179		LLVector3d ref(X_WORLD_TEST, Y_WORLD_TEST, Z_WORLD_TEST);
180		ensure("LLItemInfo::getGlobalPosition() test failed", pos == ref);
181		// Test 4 : getName()
182		std::string name = mItem->getName();
183		ensure("LLItemInfo::getName() test failed", name == ITEM_NAME_TEST);
184		// Test 5 : isName()
185		ensure("LLItemInfo::isName() test failed", mItem->isName(name));
186		// Test 6 : getUUID()
187		LLUUID id;
188		ensure("LLItemInfo::getUUID() test failed", mItem->getUUID() == id);
189		// Test 7 : getRegionHandle()
190		U64 handle = to_region_handle_global(X_WORLD_TEST, Y_WORLD_TEST);
191		ensure("LLItemInfo::getRegionHandle() test failed", mItem->getRegionHandle() == handle);
192	}
193	// ---------------------------------------------------------------------------------------
194	// Test the LLSimInfo interface
195	// ---------------------------------------------------------------------------------------
196	// Test Setters and Accessors methods
197	template<> template<>
198	void siminfo_object_t::test<1>()
199	{
200		// Test 1 : setName() / getName()
201		std::string name = SIM_NAME_TEST;
202		mSim->setName(name);
203		ensure("LLSimInfo::setName() test failed", mSim->getName() == SIM_NAME_TEST);
204		// Test 2 : isName()
205		ensure("LLSimInfo::isName() test failed", mSim->isName(name));
206		// Test 3 : getGlobalPos()
207		LLVector3 local;
208		LLVector3d ref(X_WORLD_TEST, Y_WORLD_TEST, 0.0f);
209		LLVector3d pos = mSim->getGlobalPos(local);
210		ensure("LLSimInfo::getGlobalPos() test failed", pos == ref);
211		// Test 4 : getGlobalOrigin()
212		pos = mSim->getGlobalOrigin();
213		ensure("LLSimInfo::getGlobalOrigin() test failed", pos == ref);
214		// Test 5 : clearImage()
215		try {
216			mSim->clearImage();
217		} catch (...) {
218			fail("LLSimInfo::clearImage() test failed");
219		}
220		// Test 6 : dropImagePriority()
221		try {
222			mSim->dropImagePriority();
223		} catch (...) {
224			fail("LLSimInfo::dropImagePriority() test failed");
225		}
226		// Test 7 : updateAgentCount()
227		try {
228			mSim->updateAgentCount(0.0f);
229		} catch (...) {
230			fail("LLSimInfo::updateAgentCount() test failed");
231		}
232		// Test 8 : getAgentCount()
233		S32 agents = mSim->getAgentCount();
234		ensure("LLSimInfo::getAgentCount() test failed", agents == 0);
235		// Test 9 : setLandForSaleImage() / getLandForSaleImage()
236		LLUUID id;
237		mSim->setLandForSaleImage(id);
238		LLPointer<LLViewerFetchedTexture> image = mSim->getLandForSaleImage();
239		ensure("LLSimInfo::getLandForSaleImage() test failed", image.isNull());
240		// Test 10 : isPG()
241		mSim->setAccess(SIM_ACCESS_PG);
242		ensure("LLSimInfo::isPG() test failed", mSim->isPG());
243		// Test 11 : isDown()
244		mSim->setAccess(SIM_ACCESS_DOWN);
245		ensure("LLSimInfo::isDown() test failed", mSim->isDown());
246		// Test 12 : Access strings can't be accessed from unit test...
247		//ensure("LLSimInfo::getAccessString() test failed", mSim->getAccessString() == "Offline");
248		// Test 13 : Region strings can't be accessed from unit test...
249		//mSim->setRegionFlags(REGION_FLAGS_SANDBOX);
250		//ensure("LLSimInfo::setRegionFlags() test failed", mSim->getFlagsString() == "Sandbox");
251	}
252	// Test management of LLInfoItem lists
253	template<> template<>
254	void siminfo_object_t::test<2>()
255	{
256		// Test 14 : clearItems()
257		try {
258			mSim->clearItems();
259		} catch (...) {
260			fail("LLSimInfo::clearItems() at init test failed");
261		}
262
263		// Test 15 : Verify that all the lists are empty
264		LLSimInfo::item_info_list_t list;
265		list = mSim->getTeleHub();
266		ensure("LLSimInfo::getTeleHub() empty at init test failed", list.empty());
267		list = mSim->getInfoHub();
268		ensure("LLSimInfo::getInfoHub() empty at init test failed", list.empty());
269		list = mSim->getPGEvent();
270		ensure("LLSimInfo::getPGEvent() empty at init test failed", list.empty());
271		list = mSim->getMatureEvent();
272		ensure("LLSimInfo::getMatureEvent() empty at init test failed", list.empty());
273		list = mSim->getLandForSale();
274		ensure("LLSimInfo::getLandForSale() empty at init test failed", list.empty());
275		list = mSim->getAgentLocation();
276		ensure("LLSimInfo::getAgentLocation() empty at init test failed", list.empty());
277
278		// Create an item to be inserted
279		LLUUID id;
280		LLItemInfo item(X_WORLD_TEST, Y_WORLD_TEST, ITEM_NAME_TEST, id);
281
282		// Insert the item in each list
283		mSim->insertTeleHub(item);
284		mSim->insertInfoHub(item);
285		mSim->insertPGEvent(item);
286		mSim->insertMatureEvent(item);
287		mSim->insertLandForSale(item);
288		mSim->insertAgentLocation(item);
289
290		// Test 16 : Verify that the lists contain 1 item each
291		list = mSim->getTeleHub();
292		ensure("LLSimInfo::insertTeleHub() test failed", list.size() == 1);
293		list = mSim->getInfoHub();
294		ensure("LLSimInfo::insertInfoHub() test failed", list.size() == 1);
295		list = mSim->getPGEvent();
296		ensure("LLSimInfo::insertPGEvent() test failed", list.size() == 1);
297		list = mSim->getMatureEvent();
298		ensure("LLSimInfo::insertMatureEvent() test failed", list.size() == 1);
299		list = mSim->getLandForSale();
300		ensure("LLSimInfo::insertLandForSale() test failed", list.size() == 1);
301		list = mSim->getAgentLocation();
302		ensure("LLSimInfo::insertAgentLocation() test failed", list.size() == 1);
303
304		// Test 17 : clearItems()
305		try {
306			mSim->clearItems();
307		} catch (...) {
308			fail("LLSimInfo::clearItems() at end test failed");
309		}
310
311		// Test 18 : Verify that all the lists are empty again... *except* agent which is persisted!! (on purpose)
312		list = mSim->getTeleHub();
313		ensure("LLSimInfo::getTeleHub() empty after clear test failed", list.empty());
314		list = mSim->getInfoHub();
315		ensure("LLSimInfo::getInfoHub() empty after clear test failed", list.empty());
316		list = mSim->getPGEvent();
317		ensure("LLSimInfo::getPGEvent() empty after clear test failed", list.empty());
318		list = mSim->getMatureEvent();
319		ensure("LLSimInfo::getMatureEvent() empty after clear test failed", list.empty());
320		list = mSim->getLandForSale();
321		ensure("LLSimInfo::getLandForSale() empty after clear test failed", list.empty());
322		list = mSim->getAgentLocation();
323		ensure("LLSimInfo::getAgentLocation() empty after clear test failed", list.size() == 1);
324	}
325
326	// ---------------------------------------------------------------------------------------
327	// Test the LLWorldMap interface
328	// ---------------------------------------------------------------------------------------
329	// Test Setters and Accessors methods
330	template<> template<>
331	void worldmap_object_t::test<1>()
332	{
333		// Test 1 : reset()
334		try {
335			mWorld->reset();
336		} catch (...) {
337			fail("LLWorldMap::reset() at init test failed");
338		}
339		// Test 2 : clearImageRefs()
340		try {
341			mWorld->clearImageRefs();
342		} catch (...) {
343			fail("LLWorldMap::clearImageRefs() test failed");
344		}
345		// Test 3 : dropImagePriorities()
346		try {
347			mWorld->dropImagePriorities();
348		} catch (...) {
349			fail("LLWorldMap::dropImagePriorities() test failed");
350		}
351		// Test 4 : reloadItems()
352		try {
353			mWorld->reloadItems(true);
354		} catch (...) {
355			fail("LLWorldMap::reloadItems() test failed");
356		}
357		// Test 5 : updateRegions()
358		try {
359			mWorld->updateRegions(1000, 1000, 1004, 1004);
360		} catch (...) {
361			fail("LLWorldMap::updateRegions() test failed");
362		}
363		// Test 6 : equalizeBoostLevels()
364 		try {
365 			mWorld->equalizeBoostLevels();
366 		} catch (...) {
367 			fail("LLWorldMap::equalizeBoostLevels() test failed");
368 		}
369		// Test 7 : getObjectsTile()
370		try {
371			LLPointer<LLViewerFetchedTexture> image = mWorld->getObjectsTile((U32)(X_WORLD_TEST/REGION_WIDTH_METERS), (U32)(Y_WORLD_TEST/REGION_WIDTH_METERS), 1);
372			ensure("LLWorldMap::getObjectsTile() failed", image.isNull());
373		} catch (...) {
374			fail("LLWorldMap::getObjectsTile() test failed with exception");
375		}
376	}
377	// Test management of LLSimInfo lists
378	template<> template<>
379	void worldmap_object_t::test<2>()
380	{
381		// Test 8 : reset()
382		try {
383			mWorld->reset();
384		} catch (...) {
385			fail("LLWorldMap::reset() at init test failed");
386		}
387
388		// Test 9 : Verify that all the region list is empty
389		LLWorldMap::sim_info_map_t list;
390		list = mWorld->getRegionMap();
391		ensure("LLWorldMap::getRegionMap() empty at init test failed", list.empty());
392
393		// Test 10 : Insert a region
394		bool success;
395		LLUUID id;
396		std::string name_sim = SIM_NAME_TEST;
397		success = mWorld->insertRegion(	U32(X_WORLD_TEST), 
398						U32(Y_WORLD_TEST), 
399										name_sim,
400										id,
401										SIM_ACCESS_PG,
402										REGION_FLAGS_SANDBOX);
403		list = mWorld->getRegionMap();
404		ensure("LLWorldMap::insertRegion() failed", success && (list.size() == 1));
405
406		// Test 11 : Insert an item in the same region -> number of regions doesn't increase
407		std::string name_item = ITEM_NAME_TEST;
408		success = mWorld->insertItem(	U32(X_WORLD_TEST + REGION_WIDTH_METERS/2),
409						U32(Y_WORLD_TEST + REGION_WIDTH_METERS/2), 
410										name_item,
411										id,
412										MAP_ITEM_LAND_FOR_SALE,
413										0, 0);
414		list = mWorld->getRegionMap();
415		ensure("LLWorldMap::insertItem() in existing region failed", success && (list.size() == 1));
416
417		// Test 12 : Insert an item in another region -> number of regions increases
418		success = mWorld->insertItem(	U32(X_WORLD_TEST + REGION_WIDTH_METERS*2), 
419						U32(Y_WORLD_TEST + REGION_WIDTH_METERS*2), 
420										name_item,
421										id,
422										MAP_ITEM_LAND_FOR_SALE,
423										0, 0);
424		list = mWorld->getRegionMap();
425		ensure("LLWorldMap::insertItem() in unexisting region failed", success && (list.size() == 2));
426
427		// Test 13 : simInfoFromPosGlobal() in region
428		LLVector3d pos1(	X_WORLD_TEST + REGION_WIDTH_METERS*2 + REGION_WIDTH_METERS/2, 
429							Y_WORLD_TEST + REGION_WIDTH_METERS*2 + REGION_WIDTH_METERS/2, 
430							0.0f);
431		LLSimInfo* sim;
432		sim = mWorld->simInfoFromPosGlobal(pos1);
433		ensure("LLWorldMap::simInfoFromPosGlobal() test on existing region failed", sim != NULL);
434
435		// Test 14 : simInfoFromPosGlobal() outside region
436		LLVector3d pos2(	X_WORLD_TEST + REGION_WIDTH_METERS*4 + REGION_WIDTH_METERS/2, 
437							Y_WORLD_TEST + REGION_WIDTH_METERS*4 + REGION_WIDTH_METERS/2, 
438							0.0f);
439		sim = mWorld->simInfoFromPosGlobal(pos2);
440		ensure("LLWorldMap::simInfoFromPosGlobal() test outside region failed", sim == NULL);
441
442		// Test 15 : simInfoFromName()
443		sim = mWorld->simInfoFromName(name_sim);
444		ensure("LLWorldMap::simInfoFromName() test on existing region failed", sim != NULL);
445
446		// Test 16 : simInfoFromHandle()
447		U64 handle = to_region_handle_global(X_WORLD_TEST, Y_WORLD_TEST);
448		sim = mWorld->simInfoFromHandle(handle);
449		ensure("LLWorldMap::simInfoFromHandle() test on existing region failed", sim != NULL);
450
451		// Test 17 : simNameFromPosGlobal()
452		LLVector3d pos3(	X_WORLD_TEST + REGION_WIDTH_METERS/2, 
453							Y_WORLD_TEST + REGION_WIDTH_METERS/2, 
454							0.0f);
455		success = mWorld->simNameFromPosGlobal(pos3, name_sim);
456		ensure("LLWorldMap::simNameFromPosGlobal() test on existing region failed", success && (name_sim == SIM_NAME_TEST));
457		
458		// Test 18 : reset()
459		try {
460			mWorld->reset();
461		} catch (...) {
462			fail("LLWorldMap::reset() at end test failed");
463		}
464
465		// Test 19 : Verify that all the region list is empty
466		list = mWorld->getRegionMap();
467		ensure("LLWorldMap::getRegionMap() empty at end test failed", list.empty());
468	}
469	// Test tracking
470	template<> template<>
471	void worldmap_object_t::test<3>()
472	{
473		// Point to track
474		LLVector3d pos( X_WORLD_TEST + REGION_WIDTH_METERS/2, Y_WORLD_TEST + REGION_WIDTH_METERS/2, Z_WORLD_TEST);
475
476		// Test 20 : no tracking
477		mWorld->cancelTracking();
478		ensure("LLWorldMap::cancelTracking() at begin test failed", mWorld->isTracking() == false);
479
480		// Test 21 : set tracking
481		mWorld->setTracking(pos);
482		ensure("LLWorldMap::setTracking() failed", mWorld->isTracking() && !mWorld->isTrackingValidLocation());
483
484		// Test 22 : set click and commit flags
485		mWorld->setTrackingDoubleClick();
486		ensure("LLWorldMap::setTrackingDoubleClick() failed", mWorld->isTrackingDoubleClick());
487		mWorld->setTrackingCommit();
488		ensure("LLWorldMap::setTrackingCommit() failed", mWorld->isTrackingCommit());
489
490		// Test 23 : in rectangle test
491		bool inRect = mWorld->isTrackingInRectangle(	X_WORLD_TEST, Y_WORLD_TEST,  
492														X_WORLD_TEST + REGION_WIDTH_METERS, 
493														Y_WORLD_TEST + REGION_WIDTH_METERS);
494		ensure("LLWorldMap::isTrackingInRectangle() in rectangle failed", inRect);
495		inRect = mWorld->isTrackingInRectangle(			X_WORLD_TEST + REGION_WIDTH_METERS, 
496														Y_WORLD_TEST + REGION_WIDTH_METERS,  
497														X_WORLD_TEST + 2 * REGION_WIDTH_METERS, 
498														Y_WORLD_TEST + 2 * REGION_WIDTH_METERS);
499		ensure("LLWorldMap::isTrackingInRectangle() outside rectangle failed", !inRect);
500
501		// Test 24 : set tracking to valid and invalid
502		mWorld->setTrackingValid();
503		ensure("LLWorldMap::setTrackingValid() failed", mWorld->isTrackingValidLocation() && !mWorld->isTrackingInvalidLocation());
504		mWorld->setTrackingInvalid();
505		ensure("LLWorldMap::setTrackingInvalid() failed", !mWorld->isTrackingValidLocation() && mWorld->isTrackingInvalidLocation());
506
507		// Test 25 : getTrackedPositionGlobal()
508		LLVector3d res = mWorld->getTrackedPositionGlobal();
509		ensure("LLWorldMap::getTrackedPositionGlobal() failed", res == pos);
510
511		// Test 26 : reset tracking
512		mWorld->cancelTracking();
513		ensure("LLWorldMap::cancelTracking() at end test failed", mWorld->isTracking() == false);
514	}
515}