aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiObjectTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiObjectTests.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiObjectTests.cs398
1 files changed, 398 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiObjectTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiObjectTests.cs
new file mode 100644
index 0000000..d957bf2
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiObjectTests.cs
@@ -0,0 +1,398 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Text;
32using log4net;
33using Nini.Config;
34using NUnit.Framework;
35using OpenMetaverse;
36using OpenMetaverse.Assets;
37using OpenMetaverse.StructuredData;
38using OpenSim.Framework;
39using OpenSim.Region.CoreModules.Avatar.AvatarFactory;
40using OpenSim.Region.OptionalModules.World.NPC;
41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.ScriptEngine.Shared;
43using OpenSim.Region.ScriptEngine.Shared.Api;
44using OpenSim.Region.ScriptEngine.Shared.Instance;
45using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
46using OpenSim.Services.Interfaces;
47using OpenSim.Tests.Common;
48using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
49using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
50
51namespace OpenSim.Region.ScriptEngine.Shared.Tests
52{
53 [TestFixture]
54 public class LSL_ApiObjectTests : OpenSimTestCase
55 {
56 private const double VECTOR_COMPONENT_ACCURACY = 0.0000005d;
57 private const float FLOAT_ACCURACY = 0.00005f;
58
59 protected Scene m_scene;
60 protected XEngine.XEngine m_engine;
61
62 [SetUp]
63 public override void SetUp()
64 {
65 base.SetUp();
66
67 IConfigSource initConfigSource = new IniConfigSource();
68 IConfig config = initConfigSource.AddConfig("XEngine");
69 config.Set("Enabled", "true");
70
71 m_scene = new SceneHelpers().SetupScene();
72 SceneHelpers.SetupSceneModules(m_scene, initConfigSource);
73
74 m_engine = new XEngine.XEngine();
75 m_engine.Initialise(initConfigSource);
76 m_engine.AddRegion(m_scene);
77 }
78
79 [Test]
80 public void TestllGetLinkPrimitiveParams()
81 {
82 TestHelpers.InMethod();
83 TestHelpers.EnableLogging();
84
85 UUID ownerId = TestHelpers.ParseTail(0x1);
86
87 SceneObjectGroup grp1 = SceneHelpers.CreateSceneObject(2, ownerId, "grp1-", 0x10);
88 grp1.AbsolutePosition = new Vector3(10, 11, 12);
89 m_scene.AddSceneObject(grp1);
90
91 LSL_Api apiGrp1 = new LSL_Api();
92 apiGrp1.Initialize(m_engine, grp1.RootPart, null);
93
94 // Check simple 1 prim case
95 {
96 LSL_List resList
97 = apiGrp1.llGetLinkPrimitiveParams(1, new LSL_List(new LSL_Integer(ScriptBaseClass.PRIM_ROTATION)));
98
99 Assert.That(resList.Length, Is.EqualTo(1));
100 }
101
102 // Check 2 prim case
103 {
104 LSL_List resList
105 = apiGrp1.llGetLinkPrimitiveParams(
106 1,
107 new LSL_List(
108 new LSL_Integer(ScriptBaseClass.PRIM_ROTATION),
109 new LSL_Integer(ScriptBaseClass.PRIM_LINK_TARGET),
110 new LSL_Integer(2),
111 new LSL_Integer(ScriptBaseClass.PRIM_ROTATION)));
112
113 Assert.That(resList.Length, Is.EqualTo(2));
114 }
115
116 // Check invalid parameters are ignored
117 {
118 LSL_List resList
119 = apiGrp1.llGetLinkPrimitiveParams(3, new LSL_List(new LSL_Integer(ScriptBaseClass.PRIM_ROTATION)));
120
121 Assert.That(resList.Length, Is.EqualTo(0));
122 }
123
124 // Check all parameters are ignored if an initial bad link is given
125 {
126 LSL_List resList
127 = apiGrp1.llGetLinkPrimitiveParams(
128 3,
129 new LSL_List(
130 new LSL_Integer(ScriptBaseClass.PRIM_ROTATION),
131 new LSL_Integer(ScriptBaseClass.PRIM_LINK_TARGET),
132 new LSL_Integer(1),
133 new LSL_Integer(ScriptBaseClass.PRIM_ROTATION)));
134
135 Assert.That(resList.Length, Is.EqualTo(0));
136 }
137
138 // Check only subsequent parameters are ignored when we hit the first bad link number
139 {
140 LSL_List resList
141 = apiGrp1.llGetLinkPrimitiveParams(
142 1,
143 new LSL_List(
144 new LSL_Integer(ScriptBaseClass.PRIM_ROTATION),
145 new LSL_Integer(ScriptBaseClass.PRIM_LINK_TARGET),
146 new LSL_Integer(3),
147 new LSL_Integer(ScriptBaseClass.PRIM_ROTATION)));
148
149 Assert.That(resList.Length, Is.EqualTo(1));
150 }
151 }
152
153 [Test]
154 // llSetPrimitiveParams and llGetPrimitiveParams test.
155 public void TestllSetPrimitiveParams()
156 {
157 TestHelpers.InMethod();
158
159 // Create Prim1.
160 Scene scene = new SceneHelpers().SetupScene();
161 string obj1Name = "Prim1";
162 UUID objUuid = new UUID("00000000-0000-0000-0000-000000000001");
163 SceneObjectPart part1 =
164 new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default,
165 Vector3.Zero, Quaternion.Identity,
166 Vector3.Zero) { Name = obj1Name, UUID = objUuid };
167 Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part1), false), Is.True);
168
169 LSL_Api apiGrp1 = new LSL_Api();
170 apiGrp1.Initialize(m_engine, part1, null);
171
172 // Note that prim hollow check is passed with the other prim params in order to allow the
173 // specification of a different check value from the prim param. A cylinder, prism, sphere,
174 // torus or ring, with a hole shape of square, is limited to a hollow of 70%. Test 5 below
175 // specifies a value of 95% and checks to see if 70% was properly returned.
176
177 // Test a sphere.
178 CheckllSetPrimitiveParams(
179 apiGrp1,
180 "test 1", // Prim test identification string
181 new LSL_Types.Vector3(6.0d, 9.9d, 9.9d), // Prim size
182 ScriptBaseClass.PRIM_TYPE_SPHERE, // Prim type
183 ScriptBaseClass.PRIM_HOLE_DEFAULT, // Prim hole type
184 new LSL_Types.Vector3(0.0d, 0.075d, 0.0d), // Prim cut
185 0.80f, // Prim hollow
186 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim twist
187 new LSL_Types.Vector3(0.32d, 0.76d, 0.0d), // Prim dimple
188 0.80f); // Prim hollow check
189
190 // Test a prism.
191 CheckllSetPrimitiveParams(
192 apiGrp1,
193 "test 2", // Prim test identification string
194 new LSL_Types.Vector3(3.5d, 3.5d, 3.5d), // Prim size
195 ScriptBaseClass.PRIM_TYPE_PRISM, // Prim type
196 ScriptBaseClass.PRIM_HOLE_CIRCLE, // Prim hole type
197 new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
198 0.90f, // Prim hollow
199 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim twist
200 new LSL_Types.Vector3(2.0d, 1.0d, 0.0d), // Prim taper
201 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear
202 0.90f); // Prim hollow check
203
204 // Test a box.
205 CheckllSetPrimitiveParams(
206 apiGrp1,
207 "test 3", // Prim test identification string
208 new LSL_Types.Vector3(3.5d, 3.5d, 3.5d), // Prim size
209 ScriptBaseClass.PRIM_TYPE_BOX, // Prim type
210 ScriptBaseClass.PRIM_HOLE_TRIANGLE, // Prim hole type
211 new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
212 0.99f, // Prim hollow
213 new LSL_Types.Vector3(1.0d, 0.0d, 0.0d), // Prim twist
214 new LSL_Types.Vector3(1.0d, 1.0d, 0.0d), // Prim taper
215 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear
216 0.99f); // Prim hollow check
217
218 // Test a tube.
219 CheckllSetPrimitiveParams(
220 apiGrp1,
221 "test 4", // Prim test identification string
222 new LSL_Types.Vector3(4.2d, 4.2d, 4.2d), // Prim size
223 ScriptBaseClass.PRIM_TYPE_TUBE, // Prim type
224 ScriptBaseClass.PRIM_HOLE_SQUARE, // Prim hole type
225 new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
226 0.00f, // Prim hollow
227 new LSL_Types.Vector3(1.0d, -1.0d, 0.0d), // Prim twist
228 new LSL_Types.Vector3(1.0d, 0.05d, 0.0d), // Prim hole size
229 // Expression for y selected to test precision problems during byte
230 // cast in SetPrimitiveShapeParams.
231 new LSL_Types.Vector3(0.0d, 0.35d + 0.1d, 0.0d), // Prim shear
232 new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim profile cut
233 // Expression for y selected to test precision problems during sbyte
234 // cast in SetPrimitiveShapeParams.
235 new LSL_Types.Vector3(-1.0d, 0.70d + 0.1d + 0.1d, 0.0d), // Prim taper
236 1.11f, // Prim revolutions
237 0.88f, // Prim radius
238 0.95f, // Prim skew
239 0.00f); // Prim hollow check
240
241 // Test a prism.
242 CheckllSetPrimitiveParams(
243 apiGrp1,
244 "test 5", // Prim test identification string
245 new LSL_Types.Vector3(3.5d, 3.5d, 3.5d), // Prim size
246 ScriptBaseClass.PRIM_TYPE_PRISM, // Prim type
247 ScriptBaseClass.PRIM_HOLE_SQUARE, // Prim hole type
248 new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
249 0.99f, // Prim hollow
250 // Expression for x selected to test precision problems during sbyte
251 // cast in SetPrimitiveShapeBlockParams.
252 new LSL_Types.Vector3(0.7d + 0.2d, 0.0d, 0.0d), // Prim twist
253 // Expression for y selected to test precision problems during sbyte
254 // cast in SetPrimitiveShapeParams.
255 new LSL_Types.Vector3(2.0d, (1.3d + 0.1d), 0.0d), // Prim taper
256 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear
257 0.70f); // Prim hollow check
258
259 // Test a sculpted prim.
260 CheckllSetPrimitiveParams(
261 apiGrp1,
262 "test 6", // Prim test identification string
263 new LSL_Types.Vector3(2.0d, 2.0d, 2.0d), // Prim size
264 ScriptBaseClass.PRIM_TYPE_SCULPT, // Prim type
265 "be293869-d0d9-0a69-5989-ad27f1946fd4", // Prim map
266 ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE); // Prim sculpt type
267 }
268
269 // Set prim params for a box, cylinder or prism and check results.
270 public void CheckllSetPrimitiveParams(LSL_Api api, string primTest,
271 LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
272 float primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primTaper, LSL_Types.Vector3 primShear,
273 float primHollowCheck)
274 {
275 // Set the prim params.
276 api.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
277 ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
278 primCut, primHollow, primTwist, primTaper, primShear));
279
280 // Get params for prim to validate settings.
281 LSL_Types.list primParams =
282 api.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
283
284 // Validate settings.
285 CheckllSetPrimitiveParamsVector(primSize, api.llList2Vector(primParams, 0), primTest + " prim size");
286 Assert.AreEqual(primType, api.llList2Integer(primParams, 1),
287 "TestllSetPrimitiveParams " + primTest + " prim type check fail");
288 Assert.AreEqual(primHoleType, api.llList2Integer(primParams, 2),
289 "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
290 CheckllSetPrimitiveParamsVector(primCut, api.llList2Vector(primParams, 3), primTest + " prim cut");
291 Assert.AreEqual(primHollowCheck, api.llList2Float(primParams, 4), FLOAT_ACCURACY,
292 "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
293 CheckllSetPrimitiveParamsVector(primTwist, api.llList2Vector(primParams, 5), primTest + " prim twist");
294 CheckllSetPrimitiveParamsVector(primTaper, api.llList2Vector(primParams, 6), primTest + " prim taper");
295 CheckllSetPrimitiveParamsVector(primShear, api.llList2Vector(primParams, 7), primTest + " prim shear");
296 }
297
298 // Set prim params for a sphere and check results.
299 public void CheckllSetPrimitiveParams(LSL_Api api, string primTest,
300 LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
301 float primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primDimple, float primHollowCheck)
302 {
303 // Set the prim params.
304 api.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
305 ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
306 primCut, primHollow, primTwist, primDimple));
307
308 // Get params for prim to validate settings.
309 LSL_Types.list primParams =
310 api.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
311
312 // Validate settings.
313 CheckllSetPrimitiveParamsVector(primSize, api.llList2Vector(primParams, 0), primTest + " prim size");
314 Assert.AreEqual(primType, api.llList2Integer(primParams, 1),
315 "TestllSetPrimitiveParams " + primTest + " prim type check fail");
316 Assert.AreEqual(primHoleType, api.llList2Integer(primParams, 2),
317 "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
318 CheckllSetPrimitiveParamsVector(primCut, api.llList2Vector(primParams, 3), primTest + " prim cut");
319 Assert.AreEqual(primHollowCheck, api.llList2Float(primParams, 4), FLOAT_ACCURACY,
320 "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
321 CheckllSetPrimitiveParamsVector(primTwist, api.llList2Vector(primParams, 5), primTest + " prim twist");
322 CheckllSetPrimitiveParamsVector(primDimple, api.llList2Vector(primParams, 6), primTest + " prim dimple");
323 }
324
325 // Set prim params for a torus, tube or ring and check results.
326 public void CheckllSetPrimitiveParams(LSL_Api api, string primTest,
327 LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
328 float primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primHoleSize,
329 LSL_Types.Vector3 primShear, LSL_Types.Vector3 primProfCut, LSL_Types.Vector3 primTaper,
330 float primRev, float primRadius, float primSkew, float primHollowCheck)
331 {
332 // Set the prim params.
333 api.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
334 ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
335 primCut, primHollow, primTwist, primHoleSize, primShear, primProfCut,
336 primTaper, primRev, primRadius, primSkew));
337
338 // Get params for prim to validate settings.
339 LSL_Types.list primParams =
340 api.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
341
342 // Valdate settings.
343 CheckllSetPrimitiveParamsVector(primSize, api.llList2Vector(primParams, 0), primTest + " prim size");
344 Assert.AreEqual(primType, api.llList2Integer(primParams, 1),
345 "TestllSetPrimitiveParams " + primTest + " prim type check fail");
346 Assert.AreEqual(primHoleType, api.llList2Integer(primParams, 2),
347 "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
348 CheckllSetPrimitiveParamsVector(primCut, api.llList2Vector(primParams, 3), primTest + " prim cut");
349 Assert.AreEqual(primHollowCheck, api.llList2Float(primParams, 4), FLOAT_ACCURACY,
350 "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
351 CheckllSetPrimitiveParamsVector(primTwist, api.llList2Vector(primParams, 5), primTest + " prim twist");
352 CheckllSetPrimitiveParamsVector(primHoleSize, api.llList2Vector(primParams, 6), primTest + " prim hole size");
353 CheckllSetPrimitiveParamsVector(primShear, api.llList2Vector(primParams, 7), primTest + " prim shear");
354 CheckllSetPrimitiveParamsVector(primProfCut, api.llList2Vector(primParams, 8), primTest + " prim profile cut");
355 CheckllSetPrimitiveParamsVector(primTaper, api.llList2Vector(primParams, 9), primTest + " prim taper");
356 Assert.AreEqual(primRev, api.llList2Float(primParams, 10), FLOAT_ACCURACY,
357 "TestllSetPrimitiveParams " + primTest + " prim revolutions fail");
358 Assert.AreEqual(primRadius, api.llList2Float(primParams, 11), FLOAT_ACCURACY,
359 "TestllSetPrimitiveParams " + primTest + " prim radius fail");
360 Assert.AreEqual(primSkew, api.llList2Float(primParams, 12), FLOAT_ACCURACY,
361 "TestllSetPrimitiveParams " + primTest + " prim skew fail");
362 }
363
364 // Set prim params for a sculpted prim and check results.
365 public void CheckllSetPrimitiveParams(LSL_Api api, string primTest,
366 LSL_Types.Vector3 primSize, int primType, string primMap, int primSculptType)
367 {
368 // Set the prim params.
369 api.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
370 ScriptBaseClass.PRIM_TYPE, primType, primMap, primSculptType));
371
372 // Get params for prim to validate settings.
373 LSL_Types.list primParams =
374 api.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
375
376 // Validate settings.
377 CheckllSetPrimitiveParamsVector(primSize, api.llList2Vector(primParams, 0), primTest + " prim size");
378 Assert.AreEqual(primType, api.llList2Integer(primParams, 1),
379 "TestllSetPrimitiveParams " + primTest + " prim type check fail");
380 Assert.AreEqual(primMap, (string)api.llList2String(primParams, 2),
381 "TestllSetPrimitiveParams " + primTest + " prim map check fail");
382 Assert.AreEqual(primSculptType, api.llList2Integer(primParams, 3),
383 "TestllSetPrimitiveParams " + primTest + " prim type scuplt check fail");
384 }
385
386 public void CheckllSetPrimitiveParamsVector(LSL_Types.Vector3 vecCheck, LSL_Types.Vector3 vecReturned, string msg)
387 {
388 // Check each vector component against expected result.
389 Assert.AreEqual(vecCheck.x, vecReturned.x, VECTOR_COMPONENT_ACCURACY,
390 "TestllSetPrimitiveParams " + msg + " vector check fail on x component");
391 Assert.AreEqual(vecCheck.y, vecReturned.y, VECTOR_COMPONENT_ACCURACY,
392 "TestllSetPrimitiveParams " + msg + " vector check fail on y component");
393 Assert.AreEqual(vecCheck.z, vecReturned.z, VECTOR_COMPONENT_ACCURACY,
394 "TestllSetPrimitiveParams " + msg + " vector check fail on z component");
395 }
396
397 }
398}