summaryrefslogtreecommitdiff
path: root/indra/llprimitive/tests/llprimitive_test.cpp
blob: 590b97645fe38c159b6384e51a8c9b8d785e0ab2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/** 
 * @file llprimitive_test.cpp
 * @brief llprimitive tests
 *
 * $LicenseInfo:firstyear=2001&license=viewergpl$
 * Copyright (c) 2001-2009, Linden Research, Inc.
 * $/LicenseInfo$
 */

#include "linden_common.h"

#include "../test/lltut.h"

#include "../llprimitive.h"

#include "../../llmath/llvolumemgr.h"

class DummyVolumeMgr : public LLVolumeMgr
{
public:
	DummyVolumeMgr() : LLVolumeMgr(), mVolumeTest(NULL), mCurrDetailTest(0) {}
	~DummyVolumeMgr() 
	{
	}
	
	
	virtual LLVolume *refVolume(const LLVolumeParams &volume_params, const S32 detail) 
	{
		if (mVolumeTest.isNull() || volume_params != mCurrParamsTest || detail != mCurrDetailTest)
		{
			F32 volume_detail = LLVolumeLODGroup::getVolumeScaleFromDetail(detail);
			mVolumeTest = new LLVolume(volume_params, volume_detail, FALSE, FALSE);
			mCurrParamsTest = volume_params;
			mCurrDetailTest = detail;
			return mVolumeTest;
		} 
		else 
		{
			return mVolumeTest;
		}
	}
	
	virtual void unrefVolume(LLVolume *volumep) 
	{
		if (mVolumeTest == volumep)
		{
			mVolumeTest = NULL;
		}
	}
	
private:
	LLPointer<LLVolume> mVolumeTest;
	LLVolumeParams mCurrParamsTest;
	S32 mCurrDetailTest;
};

class PRIMITIVE_TEST_SETUP
{
public:
	PRIMITIVE_TEST_SETUP()
	{
		volume_manager_test = new DummyVolumeMgr();
		LLPrimitive::setVolumeManager(volume_manager_test);
	}
	
	~PRIMITIVE_TEST_SETUP()
	{
		LLPrimitive::cleanupVolumeManager();
	}
	DummyVolumeMgr * volume_manager_test;
}; 

namespace tut
{
	struct llprimitive
	{
		PRIMITIVE_TEST_SETUP setup_class;
	};
    
	typedef test_group<llprimitive> llprimitive_t;
	typedef llprimitive_t::object llprimitive_object_t;
	tut::llprimitive_t tut_llprimitive("LLPrimitive");

	template<> template<>
	void llprimitive_object_t::test<1>()
	{
		set_test_name("Test LLPrimitive Instantiation");
		LLPrimitive test;
	}
	
	template<> template<>
	void llprimitive_object_t::test<2>()
	{
		set_test_name("Test LLPrimitive PCode setter and getter.");
		LLPrimitive test;
		ensure_equals(test.getPCode(), 0);
		LLPCode code = 1;
		test.setPCode(code);
		ensure_equals(test.getPCode(), code);
	}
	
	template<> template<>
	void llprimitive_object_t::test<3>()
	{
		set_test_name("Test llprimitive constructor and initer.");
		LLPCode code = 1;
		LLPrimitive primitive;
		primitive.init_primitive(code);
		ensure_equals(primitive.getPCode(), code);
	}
	
	template<> template<>
	void llprimitive_object_t::test<4>()
	{
		set_test_name("Test Static llprimitive constructor and initer.");
		LLPCode code = 1;
		LLPrimitive * primitive = LLPrimitive::createPrimitive(code);
		ensure(primitive != NULL);
		ensure_equals(primitive->getPCode(), code);
	}

	template<> template<>
	void llprimitive_object_t::test<5>()
	{
		set_test_name("Test setVolume creation of new unique volume.");
		LLPrimitive primitive;
		LLVolumeParams params;
		
		// Make sure volume starts off null
		ensure(primitive.getVolume() == NULL);
		
		// Make sure we have no texture entries before setting the volume
		ensure_equals(primitive.getNumTEs(), 0);
		
		// Test that GEOMETRY has not been flagged as changed.
		ensure(!primitive.isChanged(LLXform::GEOMETRY));
		
		// Make sure setVolume returns true
		ensure(primitive.setVolume(params, 0, true) == TRUE);
		LLVolume* new_volume = primitive.getVolume();
		
		// make sure new volume was actually created
		ensure(new_volume != NULL);
		
		// Make sure that now that we've set the volume we have texture entries
		ensure_not_equals(primitive.getNumTEs(), 0);
		
		// Make sure that the number of texture entries equals the number of faces in the volume (should be 6)
		ensure_equals(new_volume->getNumFaces(), 6);
		ensure_equals(primitive.getNumTEs(), new_volume->getNumFaces());
		
		// Test that GEOMETRY has been flagged as changed.
		ensure(primitive.isChanged(LLXform::GEOMETRY));
		
		// Run it twice to make sure it doesn't create a different one if params are the same
		ensure(primitive.setVolume(params, 0, true) == FALSE);
		ensure(new_volume == primitive.getVolume());
		
		// Change the param definition and try setting it again.
		params.setRevolutions(4);
		ensure(primitive.setVolume(params, 0, true) == TRUE);
		
		// Ensure that we now have a different volume
		ensure(new_volume != primitive.getVolume());
	}
	
	template<> template<>
	void llprimitive_object_t::test<6>()
	{
		set_test_name("Test setVolume creation of new NOT-unique volume.");
		LLPrimitive primitive;
		LLVolumeParams params;
		
		// Make sure volume starts off null
		ensure(primitive.getVolume() == NULL);
		
		// Make sure we have no texture entries before setting the volume
		ensure_equals(primitive.getNumTEs(), 0);
		
		// Test that GEOMETRY has not been flagged as changed.
		ensure(!primitive.isChanged(LLXform::GEOMETRY));
		
		// Make sure setVolume returns true
		ensure(primitive.setVolume(params, 0, false) == TRUE);
		
		LLVolume* new_volume = primitive.getVolume();
		
		// make sure new volume was actually created
		ensure(new_volume != NULL);
		
		// Make sure that now that we've set the volume we have texture entries
		ensure_not_equals(primitive.getNumTEs(), 0);
		
		// Make sure that the number of texture entries equals the number of faces in the volume (should be 6)
		ensure_equals(new_volume->getNumFaces(), 6);
		ensure_equals(primitive.getNumTEs(), new_volume->getNumFaces());
		
		// Test that GEOMETRY has been flagged as changed.
		ensure(primitive.isChanged(LLXform::GEOMETRY));
		
		// Run it twice to make sure it doesn't create a different one if params are the same
		ensure(primitive.setVolume(params, 0, false) == FALSE);
		ensure(new_volume == primitive.getVolume());
		
		// Change the param definition and try setting it again.
		params.setRevolutions(4);
		ensure(primitive.setVolume(params, 0, false) == TRUE); 
		
		// Ensure that we now have a different volume
		ensure(new_volume != primitive.getVolume());
	}
}

#include "llmessagesystem_stub.cpp"