aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llprimitive/tests/llprimitive_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llprimitive/tests/llprimitive_test.cpp')
-rwxr-xr-xlinden/indra/llprimitive/tests/llprimitive_test.cpp237
1 files changed, 237 insertions, 0 deletions
diff --git a/linden/indra/llprimitive/tests/llprimitive_test.cpp b/linden/indra/llprimitive/tests/llprimitive_test.cpp
new file mode 100755
index 0000000..c923442
--- /dev/null
+++ b/linden/indra/llprimitive/tests/llprimitive_test.cpp
@@ -0,0 +1,237 @@
1/**
2 * @file llprimitive_test.cpp
3 * @brief llprimitive tests
4 *
5 * $LicenseInfo:firstyear=2001&license=viewergpl$
6 *
7 * Copyright (c) 2001-2010, Linden Research, Inc.
8 *
9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at
21 * http://secondlifegrid.net/programs/open_source/licensing/flossexception
22 *
23 * By copying, modifying or distributing this software, you acknowledge
24 * that you have read and understood your obligations described above,
25 * and agree to abide by those obligations.
26 *
27 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
28 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
29 * COMPLETENESS OR PERFORMANCE.
30 * $/LicenseInfo$
31 */
32
33#include "linden_common.h"
34
35#include "../test/lltut.h"
36
37#include "../llprimitive.h"
38
39#include "../../llmath/llvolumemgr.h"
40
41class DummyVolumeMgr : public LLVolumeMgr
42{
43public:
44 DummyVolumeMgr() : LLVolumeMgr(), mVolumeTest(NULL), mCurrDetailTest(0) {}
45 ~DummyVolumeMgr()
46 {
47 }
48
49
50 virtual LLVolume *refVolume(const LLVolumeParams &volume_params, const S32 detail)
51 {
52 if (mVolumeTest.isNull() || volume_params != mCurrParamsTest || detail != mCurrDetailTest)
53 {
54 F32 volume_detail = LLVolumeLODGroup::getVolumeScaleFromDetail(detail);
55 mVolumeTest = new LLVolume(volume_params, volume_detail, FALSE, FALSE);
56 mCurrParamsTest = volume_params;
57 mCurrDetailTest = detail;
58 return mVolumeTest;
59 }
60 else
61 {
62 return mVolumeTest;
63 }
64 }
65
66 virtual void unrefVolume(LLVolume *volumep)
67 {
68 if (mVolumeTest == volumep)
69 {
70 mVolumeTest = NULL;
71 }
72 }
73
74private:
75 LLPointer<LLVolume> mVolumeTest;
76 LLVolumeParams mCurrParamsTest;
77 S32 mCurrDetailTest;
78};
79
80class PRIMITIVE_TEST_SETUP
81{
82public:
83 PRIMITIVE_TEST_SETUP()
84 {
85 volume_manager_test = new DummyVolumeMgr();
86 LLPrimitive::setVolumeManager(volume_manager_test);
87 }
88
89 ~PRIMITIVE_TEST_SETUP()
90 {
91 LLPrimitive::cleanupVolumeManager();
92 }
93 DummyVolumeMgr * volume_manager_test;
94};
95
96namespace tut
97{
98 struct llprimitive
99 {
100 PRIMITIVE_TEST_SETUP setup_class;
101 };
102
103 typedef test_group<llprimitive> llprimitive_t;
104 typedef llprimitive_t::object llprimitive_object_t;
105 tut::llprimitive_t tut_llprimitive("llprimitive");
106
107 template<> template<>
108 void llprimitive_object_t::test<1>()
109 {
110 set_test_name("Test LLPrimitive Instantiation");
111 LLPrimitive test;
112 }
113
114 template<> template<>
115 void llprimitive_object_t::test<2>()
116 {
117 set_test_name("Test LLPrimitive PCode setter and getter.");
118 LLPrimitive test;
119 ensure_equals(test.getPCode(), 0);
120 LLPCode code = 1;
121 test.setPCode(code);
122 ensure_equals(test.getPCode(), code);
123 }
124
125 template<> template<>
126 void llprimitive_object_t::test<3>()
127 {
128 set_test_name("Test llprimitive constructor and initer.");
129 LLPCode code = 1;
130 LLPrimitive primitive;
131 primitive.init_primitive(code);
132 ensure_equals(primitive.getPCode(), code);
133 }
134
135 template<> template<>
136 void llprimitive_object_t::test<4>()
137 {
138 set_test_name("Test Static llprimitive constructor and initer.");
139 LLPCode code = 1;
140 LLPrimitive * primitive = LLPrimitive::createPrimitive(code);
141 ensure(primitive != NULL);
142 ensure_equals(primitive->getPCode(), code);
143 }
144
145 template<> template<>
146 void llprimitive_object_t::test<5>()
147 {
148 set_test_name("Test setVolume creation of new unique volume.");
149 LLPrimitive primitive;
150 LLVolumeParams params;
151
152 // Make sure volume starts off null
153 ensure(primitive.getVolume() == NULL);
154
155 // Make sure we have no texture entries before setting the volume
156 ensure_equals(primitive.getNumTEs(), 0);
157
158 // Test that GEOMETRY has not been flagged as changed.
159 ensure(!primitive.isChanged(LLXform::GEOMETRY));
160
161 // Make sure setVolume returns true
162 ensure(primitive.setVolume(params, 0, true) == TRUE);
163 LLVolume* new_volume = primitive.getVolume();
164
165 // make sure new volume was actually created
166 ensure(new_volume != NULL);
167
168 // Make sure that now that we've set the volume we have texture entries
169 ensure_not_equals(primitive.getNumTEs(), 0);
170
171 // Make sure that the number of texture entries equals the number of faces in the volume (should be 6)
172 ensure_equals(new_volume->getNumFaces(), 6);
173 ensure_equals(primitive.getNumTEs(), new_volume->getNumFaces());
174
175 // Test that GEOMETRY has been flagged as changed.
176 ensure(primitive.isChanged(LLXform::GEOMETRY));
177
178 // Run it twice to make sure it doesn't create a different one if params are the same
179 ensure(primitive.setVolume(params, 0, true) == FALSE);
180 ensure(new_volume == primitive.getVolume());
181
182 // Change the param definition and try setting it again.
183 params.setRevolutions(4);
184 ensure(primitive.setVolume(params, 0, true) == TRUE);
185
186 // Ensure that we now have a different volume
187 ensure(new_volume != primitive.getVolume());
188 }
189
190 template<> template<>
191 void llprimitive_object_t::test<6>()
192 {
193 set_test_name("Test setVolume creation of new NOT-unique volume.");
194 LLPrimitive primitive;
195 LLVolumeParams params;
196
197 // Make sure volume starts off null
198 ensure(primitive.getVolume() == NULL);
199
200 // Make sure we have no texture entries before setting the volume
201 ensure_equals(primitive.getNumTEs(), 0);
202
203 // Test that GEOMETRY has not been flagged as changed.
204 ensure(!primitive.isChanged(LLXform::GEOMETRY));
205
206 // Make sure setVolume returns true
207 ensure(primitive.setVolume(params, 0, false) == TRUE);
208
209 LLVolume* new_volume = primitive.getVolume();
210
211 // make sure new volume was actually created
212 ensure(new_volume != NULL);
213
214 // Make sure that now that we've set the volume we have texture entries
215 ensure_not_equals(primitive.getNumTEs(), 0);
216
217 // Make sure that the number of texture entries equals the number of faces in the volume (should be 6)
218 ensure_equals(new_volume->getNumFaces(), 6);
219 ensure_equals(primitive.getNumTEs(), new_volume->getNumFaces());
220
221 // Test that GEOMETRY has been flagged as changed.
222 ensure(primitive.isChanged(LLXform::GEOMETRY));
223
224 // Run it twice to make sure it doesn't create a different one if params are the same
225 ensure(primitive.setVolume(params, 0, false) == FALSE);
226 ensure(new_volume == primitive.getVolume());
227
228 // Change the param definition and try setting it again.
229 params.setRevolutions(4);
230 ensure(primitive.setVolume(params, 0, false) == TRUE);
231
232 // Ensure that we now have a different volume
233 ensure(new_volume != primitive.getVolume());
234 }
235}
236
237#include "llmessagesystem_stub.cpp"