PageRenderTime 19ms CodeModel.GetById 2ms app.highlight 13ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/newview/tests/llworldmipmap_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 165 lines | 92 code | 9 blank | 64 comment | 9 complexity | 000dc87bd49151e07fd58224063a721f MD5 | raw file
  1/** 
  2 * @file llworldmipmap_test.cpp
  3 * @author Merov Linden
  4 * @date 2009-02-03
  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 "../llviewertexture.h"
 31#include "../llviewercontrol.h"
 32// Class to test
 33#include "../llworldmipmap.h"
 34// Tut header
 35#include "../test/lltut.h"
 36
 37// -------------------------------------------------------------------------------------------
 38// Stubbing: Declarations required to link and run the class being tested
 39// Notes: 
 40// * Add here stubbed implementation of the few classes and methods used in the class to be tested
 41// * Add as little as possible (let the link errors guide you)
 42// * Do not make any assumption as to how those classes or methods work (i.e. don't copy/paste code)
 43// * A simulator for a class can be implemented here. Please comment and document thoroughly.
 44
 45void LLViewerTexture::setBoostLevel(S32 ) { }
 46LLViewerFetchedTexture* LLViewerTextureManager::getFetchedTextureFromUrl(const std::string&, BOOL, LLViewerTexture::EBoostLevel, S8, 
 47																		 LLGLint, LLGLenum, const LLUUID& ) { return NULL; }
 48
 49LLControlGroup::LLControlGroup(const std::string& name) : LLInstanceTracker<LLControlGroup, std::string>(name) { }
 50LLControlGroup::~LLControlGroup() { }
 51std::string LLControlGroup::getString(const std::string& ) { return std::string("test_url"); }
 52LLControlGroup gSavedSettings("test_settings");
 53
 54// End Stubbing
 55// -------------------------------------------------------------------------------------------
 56
 57// -------------------------------------------------------------------------------------------
 58// TUT
 59// -------------------------------------------------------------------------------------------
 60namespace tut
 61{
 62	// Test wrapper declaration
 63	struct worldmipmap_test
 64	{
 65		// Derived test class
 66		class LLTestWorldMipmap : public LLWorldMipmap
 67		{
 68			// Put here stubbs of virtual methods we shouldn't call all the way down
 69		};
 70		// Instance to be tested
 71		LLTestWorldMipmap* mMap;
 72
 73		// Constructor and destructor of the test wrapper
 74		worldmipmap_test()
 75		{
 76			mMap = new LLTestWorldMipmap;
 77		}
 78		~worldmipmap_test()
 79		{
 80			delete mMap;
 81		}
 82	};
 83
 84	// Tut templating thingamagic: test group, object and test instance
 85	typedef test_group<worldmipmap_test> worldmipmap_t;
 86	typedef worldmipmap_t::object worldmipmap_object_t;
 87	tut::worldmipmap_t tut_worldmipmap("LLWorldMipmap");
 88
 89	// ---------------------------------------------------------------------------------------
 90	// Test functions
 91	// Notes:
 92	// * Test as many as you possibly can without requiring a full blown simulation of everything
 93	// * The tests are executed in sequence so the test instance state may change between calls
 94	// * Remember that you cannot test private methods with tut
 95	// ---------------------------------------------------------------------------------------
 96	// Test static methods
 97	// Test 1 : scaleToLevel()
 98	template<> template<>
 99	void worldmipmap_object_t::test<1>()
100	{
101		S32 level = mMap->scaleToLevel(0.0);
102		ensure("scaleToLevel() test 1 failed", level == LLWorldMipmap::MAP_LEVELS);
103		level = mMap->scaleToLevel(LLWorldMipmap::MAP_TILE_SIZE);
104		ensure("scaleToLevel() test 2 failed", level == 1);
105		level = mMap->scaleToLevel(10 * LLWorldMipmap::MAP_TILE_SIZE);
106		ensure("scaleToLevel() test 3 failed", level == 1);
107	}
108	// Test 2 : globalToMipmap()
109	template<> template<>
110	void worldmipmap_object_t::test<2>()
111	{
112		U32 grid_x, grid_y;
113		mMap->globalToMipmap(1000.f*REGION_WIDTH_METERS, 1000.f*REGION_WIDTH_METERS, 1, &grid_x, &grid_y);
114		ensure("globalToMipmap() test 1 failed", (grid_x == 1000) && (grid_y == 1000));
115		mMap->globalToMipmap(0.0, 0.0, LLWorldMipmap::MAP_LEVELS, &grid_x, &grid_y);
116		ensure("globalToMipmap() test 2 failed", (grid_x == 0) && (grid_y == 0));
117	}
118	// Test 3 : getObjectsTile()
119	template<> template<>
120	void worldmipmap_object_t::test<3>()
121	{
122		// Depends on some inline methods in LLViewerImage... Thinking about how to make this work
123		// LLPointer<LLViewerImage> img = mMap->getObjectsTile(0, 0, 1);
124		// ensure("getObjectsTile() test failed", img.isNull());
125	}
126	// Test 4 : equalizeBoostLevels()
127	template<> template<>
128	void worldmipmap_object_t::test<4>()
129	{
130		try
131		{
132			mMap->equalizeBoostLevels();
133		} 
134		catch (...)
135		{
136			fail("equalizeBoostLevels() test failed");
137		}
138	}
139	// Test 5 : dropBoostLevels()
140	template<> template<>
141	void worldmipmap_object_t::test<5>()
142	{
143		try
144		{
145			mMap->dropBoostLevels();
146		} 
147		catch (...)
148		{
149			fail("dropBoostLevels() test failed");
150		}
151	}
152	// Test 6 : reset()
153	template<> template<>
154	void worldmipmap_object_t::test<6>()
155	{
156		try
157		{
158			mMap->reset();
159		} 
160		catch (...)
161		{
162			fail("reset() test failed");
163		}
164	}
165}