PageRenderTime 25ms CodeModel.GetById 2ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llprimitive/tests/llprimitive_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 231 lines | 141 code | 43 blank | 47 comment | 23 complexity | 94a44f3cf9f23c8ff4020cf72e523c34 MD5 | raw file
  1/** 
  2 * @file llprimitive_test.cpp
  3 * @brief llprimitive tests
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "linden_common.h"
 28
 29#include "../test/lltut.h"
 30
 31#include "../llprimitive.h"
 32
 33#include "../../llmath/llvolumemgr.h"
 34
 35class DummyVolumeMgr : public LLVolumeMgr
 36{
 37public:
 38	DummyVolumeMgr() : LLVolumeMgr(), mVolumeTest(NULL), mCurrDetailTest(0) {}
 39	~DummyVolumeMgr() 
 40	{
 41	}
 42	
 43	
 44	virtual LLVolume *refVolume(const LLVolumeParams &volume_params, const S32 detail) 
 45	{
 46		if (mVolumeTest.isNull() || volume_params != mCurrParamsTest || detail != mCurrDetailTest)
 47		{
 48			F32 volume_detail = LLVolumeLODGroup::getVolumeScaleFromDetail(detail);
 49			mVolumeTest = new LLVolume(volume_params, volume_detail, FALSE, FALSE);
 50			mCurrParamsTest = volume_params;
 51			mCurrDetailTest = detail;
 52			return mVolumeTest;
 53		} 
 54		else 
 55		{
 56			return mVolumeTest;
 57		}
 58	}
 59	
 60	virtual void unrefVolume(LLVolume *volumep) 
 61	{
 62		if (mVolumeTest == volumep)
 63		{
 64			mVolumeTest = NULL;
 65		}
 66	}
 67	
 68private:
 69	LLPointer<LLVolume> mVolumeTest;
 70	LLVolumeParams mCurrParamsTest;
 71	S32 mCurrDetailTest;
 72};
 73
 74class PRIMITIVE_TEST_SETUP
 75{
 76public:
 77	PRIMITIVE_TEST_SETUP()
 78	{
 79		volume_manager_test = new DummyVolumeMgr();
 80		LLPrimitive::setVolumeManager(volume_manager_test);
 81	}
 82	
 83	~PRIMITIVE_TEST_SETUP()
 84	{
 85		LLPrimitive::cleanupVolumeManager();
 86	}
 87	DummyVolumeMgr * volume_manager_test;
 88}; 
 89
 90namespace tut
 91{
 92	struct llprimitive
 93	{
 94		PRIMITIVE_TEST_SETUP setup_class;
 95	};
 96    
 97	typedef test_group<llprimitive> llprimitive_t;
 98	typedef llprimitive_t::object llprimitive_object_t;
 99	tut::llprimitive_t tut_llprimitive("LLPrimitive");
100
101	template<> template<>
102	void llprimitive_object_t::test<1>()
103	{
104		set_test_name("Test LLPrimitive Instantiation");
105		LLPrimitive test;
106	}
107	
108	template<> template<>
109	void llprimitive_object_t::test<2>()
110	{
111		set_test_name("Test LLPrimitive PCode setter and getter.");
112		LLPrimitive test;
113		ensure_equals(test.getPCode(), 0);
114		LLPCode code = 1;
115		test.setPCode(code);
116		ensure_equals(test.getPCode(), code);
117	}
118	
119	template<> template<>
120	void llprimitive_object_t::test<3>()
121	{
122		set_test_name("Test llprimitive constructor and initer.");
123		LLPCode code = 1;
124		LLPrimitive primitive;
125		primitive.init_primitive(code);
126		ensure_equals(primitive.getPCode(), code);
127	}
128	
129	template<> template<>
130	void llprimitive_object_t::test<4>()
131	{
132		set_test_name("Test Static llprimitive constructor and initer.");
133		LLPCode code = 1;
134		LLPrimitive * primitive = LLPrimitive::createPrimitive(code);
135		ensure(primitive != NULL);
136		ensure_equals(primitive->getPCode(), code);
137	}
138
139	template<> template<>
140	void llprimitive_object_t::test<5>()
141	{
142		set_test_name("Test setVolume creation of new unique volume.");
143		LLPrimitive primitive;
144		LLVolumeParams params;
145		
146		// Make sure volume starts off null
147		ensure(primitive.getVolume() == NULL);
148		
149		// Make sure we have no texture entries before setting the volume
150		ensure_equals(primitive.getNumTEs(), 0);
151		
152		// Test that GEOMETRY has not been flagged as changed.
153		ensure(!primitive.isChanged(LLXform::GEOMETRY));
154		
155		// Make sure setVolume returns true
156		ensure(primitive.setVolume(params, 0, true) == TRUE);
157		LLVolume* new_volume = primitive.getVolume();
158		
159		// make sure new volume was actually created
160		ensure(new_volume != NULL);
161		
162		// Make sure that now that we've set the volume we have texture entries
163		ensure_not_equals(primitive.getNumTEs(), 0);
164		
165		// Make sure that the number of texture entries equals the number of faces in the volume (should be 6)
166		ensure_equals(new_volume->getNumFaces(), 6);
167		ensure_equals(primitive.getNumTEs(), new_volume->getNumFaces());
168		
169		// Test that GEOMETRY has been flagged as changed.
170		ensure(primitive.isChanged(LLXform::GEOMETRY));
171		
172		// Run it twice to make sure it doesn't create a different one if params are the same
173		ensure(primitive.setVolume(params, 0, true) == FALSE);
174		ensure(new_volume == primitive.getVolume());
175		
176		// Change the param definition and try setting it again.
177		params.setRevolutions(4);
178		ensure(primitive.setVolume(params, 0, true) == TRUE);
179		
180		// Ensure that we now have a different volume
181		ensure(new_volume != primitive.getVolume());
182	}
183	
184	template<> template<>
185	void llprimitive_object_t::test<6>()
186	{
187		set_test_name("Test setVolume creation of new NOT-unique volume.");
188		LLPrimitive primitive;
189		LLVolumeParams params;
190		
191		// Make sure volume starts off null
192		ensure(primitive.getVolume() == NULL);
193		
194		// Make sure we have no texture entries before setting the volume
195		ensure_equals(primitive.getNumTEs(), 0);
196		
197		// Test that GEOMETRY has not been flagged as changed.
198		ensure(!primitive.isChanged(LLXform::GEOMETRY));
199		
200		// Make sure setVolume returns true
201		ensure(primitive.setVolume(params, 0, false) == TRUE);
202		
203		LLVolume* new_volume = primitive.getVolume();
204		
205		// make sure new volume was actually created
206		ensure(new_volume != NULL);
207		
208		// Make sure that now that we've set the volume we have texture entries
209		ensure_not_equals(primitive.getNumTEs(), 0);
210		
211		// Make sure that the number of texture entries equals the number of faces in the volume (should be 6)
212		ensure_equals(new_volume->getNumFaces(), 6);
213		ensure_equals(primitive.getNumTEs(), new_volume->getNumFaces());
214		
215		// Test that GEOMETRY has been flagged as changed.
216		ensure(primitive.isChanged(LLXform::GEOMETRY));
217		
218		// Run it twice to make sure it doesn't create a different one if params are the same
219		ensure(primitive.setVolume(params, 0, false) == FALSE);
220		ensure(new_volume == primitive.getVolume());
221		
222		// Change the param definition and try setting it again.
223		params.setRevolutions(4);
224		ensure(primitive.setVolume(params, 0, false) == TRUE); 
225		
226		// Ensure that we now have a different volume
227		ensure(new_volume != primitive.getVolume());
228	}
229}
230
231#include "llmessagesystem_stub.cpp"