aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs13
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiObjectTests.cs385
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs238
3 files changed, 397 insertions, 239 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 924f4d9..bd451a5 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -8190,6 +8190,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8190 8190
8191 while (true) 8191 while (true)
8192 { 8192 {
8193// m_log.DebugFormat(
8194// "[LSL API]: GetEntityParams has {0} rules with scene entity named {1}",
8195// rules.Length, entity != null ? entity.Name : "NULL");
8196
8197 if (entity == null)
8198 return result;
8199
8193 if (entity is SceneObjectPart) 8200 if (entity is SceneObjectPart)
8194 remaining = GetPrimParams((SceneObjectPart)entity, rules, ref result); 8201 remaining = GetPrimParams((SceneObjectPart)entity, rules, ref result);
8195 else 8202 else
@@ -8400,7 +8407,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8400 while (idx < rules.Length) 8407 while (idx < rules.Length)
8401 { 8408 {
8402 int code = (int)rules.GetLSLIntegerItem(idx++); 8409 int code = (int)rules.GetLSLIntegerItem(idx++);
8403 int remain = rules.Length-idx; 8410 int remain = rules.Length - idx;
8404 8411
8405 switch (code) 8412 switch (code)
8406 { 8413 {
@@ -8777,7 +8784,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8777 )); 8784 ));
8778 break; 8785 break;
8779 case (int)ScriptBaseClass.PRIM_LINK_TARGET: 8786 case (int)ScriptBaseClass.PRIM_LINK_TARGET:
8780 if(remain < 3) 8787
8788 // TODO: Should be issuing a runtime script warning in this case.
8789 if (remain < 3)
8781 return null; 8790 return null;
8782 8791
8783 return rules.GetSublist(idx, -1); 8792 return rules.GetSublist(idx, -1);
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..ff87cc1
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiObjectTests.cs
@@ -0,0 +1,385 @@
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 OpenSim.Tests.Common.Mock;
49using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
50using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
51
52namespace OpenSim.Region.ScriptEngine.Shared.Tests
53{
54 [TestFixture]
55 public class LSL_ApiObjectTests : OpenSimTestCase
56 {
57 private const double VECTOR_COMPONENT_ACCURACY = 0.0000005d;
58 private const float FLOAT_ACCURACY = 0.00005f;
59
60 protected Scene m_scene;
61 protected XEngine.XEngine m_engine;
62
63 [SetUp]
64 public override void SetUp()
65 {
66 base.SetUp();
67
68 IConfigSource initConfigSource = new IniConfigSource();
69 IConfig config = initConfigSource.AddConfig("XEngine");
70 config.Set("Enabled", "true");
71
72 m_scene = new SceneHelpers().SetupScene();
73 SceneHelpers.SetupSceneModules(m_scene, initConfigSource);
74
75 m_engine = new XEngine.XEngine();
76 m_engine.Initialise(initConfigSource);
77 m_engine.AddRegion(m_scene);
78 }
79
80 [Test]
81 public void TestllGetLinkPrimitiveParams()
82 {
83 TestHelpers.InMethod();
84 TestHelpers.EnableLogging();
85
86 UUID ownerId = TestHelpers.ParseTail(0x1);
87
88 SceneObjectGroup grp1 = SceneHelpers.CreateSceneObject(2, ownerId, "grp1-", 0x10);
89 grp1.AbsolutePosition = new Vector3(10, 11, 12);
90 m_scene.AddSceneObject(grp1);
91
92 LSL_Api apiGrp1 = new LSL_Api();
93 apiGrp1.Initialize(m_engine, grp1.RootPart, null, null);
94
95 // Check simple 1 prim case
96 {
97 LSL_List resList
98 = apiGrp1.llGetLinkPrimitiveParams(1, new LSL_List(new LSL_Integer(ScriptBaseClass.PRIM_ROTATION)));
99
100 Assert.That(resList.Length, Is.EqualTo(1));
101 }
102
103 // Check invalid parameters are ignored
104 {
105 LSL_List resList
106 = apiGrp1.llGetLinkPrimitiveParams(3, new LSL_List(new LSL_Integer(ScriptBaseClass.PRIM_ROTATION)));
107
108 Assert.That(resList.Length, Is.EqualTo(0));
109 }
110
111 // Check all parameters are ignored if an initial bad link is given
112 {
113 LSL_List resList
114 = apiGrp1.llGetLinkPrimitiveParams(
115 3,
116 new LSL_List(
117 new LSL_Integer(ScriptBaseClass.PRIM_ROTATION),
118 new LSL_Integer(ScriptBaseClass.PRIM_LINK_TARGET),
119 new LSL_Integer(1),
120 new LSL_Integer(ScriptBaseClass.PRIM_ROTATION)));
121
122 Assert.That(resList.Length, Is.EqualTo(0));
123 }
124
125 // Check only subsequent parameters are ignored when we hit the first bad link number
126 {
127 LSL_List resList
128 = apiGrp1.llGetLinkPrimitiveParams(
129 1,
130 new LSL_List(
131 new LSL_Integer(ScriptBaseClass.PRIM_ROTATION),
132 new LSL_Integer(ScriptBaseClass.PRIM_LINK_TARGET),
133 new LSL_Integer(3),
134 new LSL_Integer(ScriptBaseClass.PRIM_ROTATION)));
135
136 Assert.That(resList.Length, Is.EqualTo(1));
137 }
138 }
139
140 [Test]
141 // llSetPrimitiveParams and llGetPrimitiveParams test.
142 public void TestllSetPrimitiveParams()
143 {
144 TestHelpers.InMethod();
145
146 // Create Prim1.
147 Scene scene = new SceneHelpers().SetupScene();
148 string obj1Name = "Prim1";
149 UUID objUuid = new UUID("00000000-0000-0000-0000-000000000001");
150 SceneObjectPart part1 =
151 new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default,
152 Vector3.Zero, Quaternion.Identity,
153 Vector3.Zero) { Name = obj1Name, UUID = objUuid };
154 Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part1), false), Is.True);
155
156 LSL_Api apiGrp1 = new LSL_Api();
157 apiGrp1.Initialize(m_engine, part1, null, null);
158
159 // Note that prim hollow check is passed with the other prim params in order to allow the
160 // specification of a different check value from the prim param. A cylinder, prism, sphere,
161 // torus or ring, with a hole shape of square, is limited to a hollow of 70%. Test 5 below
162 // specifies a value of 95% and checks to see if 70% was properly returned.
163
164 // Test a sphere.
165 CheckllSetPrimitiveParams(
166 apiGrp1,
167 "test 1", // Prim test identification string
168 new LSL_Types.Vector3(6.0d, 9.9d, 9.9d), // Prim size
169 ScriptBaseClass.PRIM_TYPE_SPHERE, // Prim type
170 ScriptBaseClass.PRIM_HOLE_DEFAULT, // Prim hole type
171 new LSL_Types.Vector3(0.0d, 0.075d, 0.0d), // Prim cut
172 0.80f, // Prim hollow
173 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim twist
174 new LSL_Types.Vector3(0.32d, 0.76d, 0.0d), // Prim dimple
175 0.80f); // Prim hollow check
176
177 // Test a prism.
178 CheckllSetPrimitiveParams(
179 apiGrp1,
180 "test 2", // Prim test identification string
181 new LSL_Types.Vector3(3.5d, 3.5d, 3.5d), // Prim size
182 ScriptBaseClass.PRIM_TYPE_PRISM, // Prim type
183 ScriptBaseClass.PRIM_HOLE_CIRCLE, // Prim hole type
184 new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
185 0.90f, // Prim hollow
186 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim twist
187 new LSL_Types.Vector3(2.0d, 1.0d, 0.0d), // Prim taper
188 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear
189 0.90f); // Prim hollow check
190
191 // Test a box.
192 CheckllSetPrimitiveParams(
193 apiGrp1,
194 "test 3", // Prim test identification string
195 new LSL_Types.Vector3(3.5d, 3.5d, 3.5d), // Prim size
196 ScriptBaseClass.PRIM_TYPE_BOX, // Prim type
197 ScriptBaseClass.PRIM_HOLE_TRIANGLE, // Prim hole type
198 new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
199 0.95f, // Prim hollow
200 new LSL_Types.Vector3(1.0d, 0.0d, 0.0d), // Prim twist
201 new LSL_Types.Vector3(1.0d, 1.0d, 0.0d), // Prim taper
202 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear
203 0.95f); // Prim hollow check
204
205 // Test a tube.
206 CheckllSetPrimitiveParams(
207 apiGrp1,
208 "test 4", // Prim test identification string
209 new LSL_Types.Vector3(4.2d, 4.2d, 4.2d), // Prim size
210 ScriptBaseClass.PRIM_TYPE_TUBE, // Prim type
211 ScriptBaseClass.PRIM_HOLE_SQUARE, // Prim hole type
212 new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
213 0.00f, // Prim hollow
214 new LSL_Types.Vector3(1.0d, -1.0d, 0.0d), // Prim twist
215 new LSL_Types.Vector3(1.0d, 0.05d, 0.0d), // Prim hole size
216 // Expression for y selected to test precision problems during byte
217 // cast in SetPrimitiveShapeParams.
218 new LSL_Types.Vector3(0.0d, 0.35d + 0.1d, 0.0d), // Prim shear
219 new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim profile cut
220 // Expression for y selected to test precision problems during sbyte
221 // cast in SetPrimitiveShapeParams.
222 new LSL_Types.Vector3(-1.0d, 0.70d + 0.1d + 0.1d, 0.0d), // Prim taper
223 1.11f, // Prim revolutions
224 0.88f, // Prim radius
225 0.95f, // Prim skew
226 0.00f); // Prim hollow check
227
228 // Test a prism.
229 CheckllSetPrimitiveParams(
230 apiGrp1,
231 "test 5", // Prim test identification string
232 new LSL_Types.Vector3(3.5d, 3.5d, 3.5d), // Prim size
233 ScriptBaseClass.PRIM_TYPE_PRISM, // Prim type
234 ScriptBaseClass.PRIM_HOLE_SQUARE, // Prim hole type
235 new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
236 0.95f, // Prim hollow
237 // Expression for x selected to test precision problems during sbyte
238 // cast in SetPrimitiveShapeBlockParams.
239 new LSL_Types.Vector3(0.7d + 0.2d, 0.0d, 0.0d), // Prim twist
240 // Expression for y selected to test precision problems during sbyte
241 // cast in SetPrimitiveShapeParams.
242 new LSL_Types.Vector3(2.0d, (1.3d + 0.1d), 0.0d), // Prim taper
243 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear
244 0.70f); // Prim hollow check
245
246 // Test a sculpted prim.
247 CheckllSetPrimitiveParams(
248 apiGrp1,
249 "test 6", // Prim test identification string
250 new LSL_Types.Vector3(2.0d, 2.0d, 2.0d), // Prim size
251 ScriptBaseClass.PRIM_TYPE_SCULPT, // Prim type
252 "be293869-d0d9-0a69-5989-ad27f1946fd4", // Prim map
253 ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE); // Prim sculpt type
254 }
255
256 // Set prim params for a box, cylinder or prism and check results.
257 public void CheckllSetPrimitiveParams(LSL_Api api, string primTest,
258 LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
259 float primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primTaper, LSL_Types.Vector3 primShear,
260 float primHollowCheck)
261 {
262 // Set the prim params.
263 api.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
264 ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
265 primCut, primHollow, primTwist, primTaper, primShear));
266
267 // Get params for prim to validate settings.
268 LSL_Types.list primParams =
269 api.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
270
271 // Validate settings.
272 CheckllSetPrimitiveParamsVector(primSize, api.llList2Vector(primParams, 0), primTest + " prim size");
273 Assert.AreEqual(primType, api.llList2Integer(primParams, 1),
274 "TestllSetPrimitiveParams " + primTest + " prim type check fail");
275 Assert.AreEqual(primHoleType, api.llList2Integer(primParams, 2),
276 "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
277 CheckllSetPrimitiveParamsVector(primCut, api.llList2Vector(primParams, 3), primTest + " prim cut");
278 Assert.AreEqual(primHollowCheck, api.llList2Float(primParams, 4), FLOAT_ACCURACY,
279 "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
280 CheckllSetPrimitiveParamsVector(primTwist, api.llList2Vector(primParams, 5), primTest + " prim twist");
281 CheckllSetPrimitiveParamsVector(primTaper, api.llList2Vector(primParams, 6), primTest + " prim taper");
282 CheckllSetPrimitiveParamsVector(primShear, api.llList2Vector(primParams, 7), primTest + " prim shear");
283 }
284
285 // Set prim params for a sphere and check results.
286 public void CheckllSetPrimitiveParams(LSL_Api api, string primTest,
287 LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
288 float primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primDimple, float primHollowCheck)
289 {
290 // Set the prim params.
291 api.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
292 ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
293 primCut, primHollow, primTwist, primDimple));
294
295 // Get params for prim to validate settings.
296 LSL_Types.list primParams =
297 api.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
298
299 // Validate settings.
300 CheckllSetPrimitiveParamsVector(primSize, api.llList2Vector(primParams, 0), primTest + " prim size");
301 Assert.AreEqual(primType, api.llList2Integer(primParams, 1),
302 "TestllSetPrimitiveParams " + primTest + " prim type check fail");
303 Assert.AreEqual(primHoleType, api.llList2Integer(primParams, 2),
304 "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
305 CheckllSetPrimitiveParamsVector(primCut, api.llList2Vector(primParams, 3), primTest + " prim cut");
306 Assert.AreEqual(primHollowCheck, api.llList2Float(primParams, 4), FLOAT_ACCURACY,
307 "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
308 CheckllSetPrimitiveParamsVector(primTwist, api.llList2Vector(primParams, 5), primTest + " prim twist");
309 CheckllSetPrimitiveParamsVector(primDimple, api.llList2Vector(primParams, 6), primTest + " prim dimple");
310 }
311
312 // Set prim params for a torus, tube or ring and check results.
313 public void CheckllSetPrimitiveParams(LSL_Api api, string primTest,
314 LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
315 float primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primHoleSize,
316 LSL_Types.Vector3 primShear, LSL_Types.Vector3 primProfCut, LSL_Types.Vector3 primTaper,
317 float primRev, float primRadius, float primSkew, float primHollowCheck)
318 {
319 // Set the prim params.
320 api.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
321 ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
322 primCut, primHollow, primTwist, primHoleSize, primShear, primProfCut,
323 primTaper, primRev, primRadius, primSkew));
324
325 // Get params for prim to validate settings.
326 LSL_Types.list primParams =
327 api.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
328
329 // Valdate settings.
330 CheckllSetPrimitiveParamsVector(primSize, api.llList2Vector(primParams, 0), primTest + " prim size");
331 Assert.AreEqual(primType, api.llList2Integer(primParams, 1),
332 "TestllSetPrimitiveParams " + primTest + " prim type check fail");
333 Assert.AreEqual(primHoleType, api.llList2Integer(primParams, 2),
334 "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
335 CheckllSetPrimitiveParamsVector(primCut, api.llList2Vector(primParams, 3), primTest + " prim cut");
336 Assert.AreEqual(primHollowCheck, api.llList2Float(primParams, 4), FLOAT_ACCURACY,
337 "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
338 CheckllSetPrimitiveParamsVector(primTwist, api.llList2Vector(primParams, 5), primTest + " prim twist");
339 CheckllSetPrimitiveParamsVector(primHoleSize, api.llList2Vector(primParams, 6), primTest + " prim hole size");
340 CheckllSetPrimitiveParamsVector(primShear, api.llList2Vector(primParams, 7), primTest + " prim shear");
341 CheckllSetPrimitiveParamsVector(primProfCut, api.llList2Vector(primParams, 8), primTest + " prim profile cut");
342 CheckllSetPrimitiveParamsVector(primTaper, api.llList2Vector(primParams, 9), primTest + " prim taper");
343 Assert.AreEqual(primRev, api.llList2Float(primParams, 10), FLOAT_ACCURACY,
344 "TestllSetPrimitiveParams " + primTest + " prim revolutions fail");
345 Assert.AreEqual(primRadius, api.llList2Float(primParams, 11), FLOAT_ACCURACY,
346 "TestllSetPrimitiveParams " + primTest + " prim radius fail");
347 Assert.AreEqual(primSkew, api.llList2Float(primParams, 12), FLOAT_ACCURACY,
348 "TestllSetPrimitiveParams " + primTest + " prim skew fail");
349 }
350
351 // Set prim params for a sculpted prim and check results.
352 public void CheckllSetPrimitiveParams(LSL_Api api, string primTest,
353 LSL_Types.Vector3 primSize, int primType, string primMap, int primSculptType)
354 {
355 // Set the prim params.
356 api.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
357 ScriptBaseClass.PRIM_TYPE, primType, primMap, primSculptType));
358
359 // Get params for prim to validate settings.
360 LSL_Types.list primParams =
361 api.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
362
363 // Validate settings.
364 CheckllSetPrimitiveParamsVector(primSize, api.llList2Vector(primParams, 0), primTest + " prim size");
365 Assert.AreEqual(primType, api.llList2Integer(primParams, 1),
366 "TestllSetPrimitiveParams " + primTest + " prim type check fail");
367 Assert.AreEqual(primMap, (string)api.llList2String(primParams, 2),
368 "TestllSetPrimitiveParams " + primTest + " prim map check fail");
369 Assert.AreEqual(primSculptType, api.llList2Integer(primParams, 3),
370 "TestllSetPrimitiveParams " + primTest + " prim type scuplt check fail");
371 }
372
373 public void CheckllSetPrimitiveParamsVector(LSL_Types.Vector3 vecCheck, LSL_Types.Vector3 vecReturned, string msg)
374 {
375 // Check each vector component against expected result.
376 Assert.AreEqual(vecCheck.x, vecReturned.x, VECTOR_COMPONENT_ACCURACY,
377 "TestllSetPrimitiveParams " + msg + " vector check fail on x component");
378 Assert.AreEqual(vecCheck.y, vecReturned.y, VECTOR_COMPONENT_ACCURACY,
379 "TestllSetPrimitiveParams " + msg + " vector check fail on y component");
380 Assert.AreEqual(vecCheck.z, vecReturned.z, VECTOR_COMPONENT_ACCURACY,
381 "TestllSetPrimitiveParams " + msg + " vector check fail on z component");
382 }
383
384 }
385} \ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
index e97ae06..7e3726a 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
@@ -47,9 +47,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
47 [TestFixture, LongRunning] 47 [TestFixture, LongRunning]
48 public class LSL_ApiTest 48 public class LSL_ApiTest
49 { 49 {
50 private const double ANGLE_ACCURACY_IN_RADIANS = 1E-6;
51 private const double VECTOR_COMPONENT_ACCURACY = 0.0000005d; 50 private const double VECTOR_COMPONENT_ACCURACY = 0.0000005d;
52 private const float FLOAT_ACCURACY = 0.00005f; 51 private const double ANGLE_ACCURACY_IN_RADIANS = 1E-6;
53 private LSL_Api m_lslApi; 52 private LSL_Api m_lslApi;
54 53
55 [SetUp] 54 [SetUp]
@@ -255,241 +254,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
255 } 254 }
256 255
257 [Test] 256 [Test]
258 // llSetPrimitiveParams and llGetPrimitiveParams test.
259 public void TestllSetPrimitiveParams()
260 {
261 TestHelpers.InMethod();
262
263 // Create Prim1.
264 Scene scene = new SceneHelpers().SetupScene();
265 string obj1Name = "Prim1";
266 UUID objUuid = new UUID("00000000-0000-0000-0000-000000000001");
267 SceneObjectPart part1 =
268 new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default,
269 Vector3.Zero, Quaternion.Identity,
270 Vector3.Zero) { Name = obj1Name, UUID = objUuid };
271 Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part1), false), Is.True);
272
273 // Note that prim hollow check is passed with the other prim params in order to allow the
274 // specification of a different check value from the prim param. A cylinder, prism, sphere,
275 // torus or ring, with a hole shape of square, is limited to a hollow of 70%. Test 5 below
276 // specifies a value of 95% and checks to see if 70% was properly returned.
277
278 // Test a sphere.
279 CheckllSetPrimitiveParams(
280 "test 1", // Prim test identification string
281 new LSL_Types.Vector3(6.0d, 9.9d, 9.9d), // Prim size
282 ScriptBaseClass.PRIM_TYPE_SPHERE, // Prim type
283 ScriptBaseClass.PRIM_HOLE_DEFAULT, // Prim hole type
284 new LSL_Types.Vector3(0.0d, 0.075d, 0.0d), // Prim cut
285 0.80f, // Prim hollow
286 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim twist
287 new LSL_Types.Vector3(0.32d, 0.76d, 0.0d), // Prim dimple
288 0.80f); // Prim hollow check
289
290 // Test a prism.
291 CheckllSetPrimitiveParams(
292 "test 2", // Prim test identification string
293 new LSL_Types.Vector3(3.5d, 3.5d, 3.5d), // Prim size
294 ScriptBaseClass.PRIM_TYPE_PRISM, // Prim type
295 ScriptBaseClass.PRIM_HOLE_CIRCLE, // Prim hole type
296 new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
297 0.90f, // Prim hollow
298 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim twist
299 new LSL_Types.Vector3(2.0d, 1.0d, 0.0d), // Prim taper
300 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear
301 0.90f); // Prim hollow check
302
303 // Test a box.
304 CheckllSetPrimitiveParams(
305 "test 3", // Prim test identification string
306 new LSL_Types.Vector3(3.5d, 3.5d, 3.5d), // Prim size
307 ScriptBaseClass.PRIM_TYPE_BOX, // Prim type
308 ScriptBaseClass.PRIM_HOLE_TRIANGLE, // Prim hole type
309 new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
310 0.95f, // Prim hollow
311 new LSL_Types.Vector3(1.0d, 0.0d, 0.0d), // Prim twist
312 new LSL_Types.Vector3(1.0d, 1.0d, 0.0d), // Prim taper
313 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear
314 0.95f); // Prim hollow check
315
316 // Test a tube.
317 CheckllSetPrimitiveParams(
318 "test 4", // Prim test identification string
319 new LSL_Types.Vector3(4.2d, 4.2d, 4.2d), // Prim size
320 ScriptBaseClass.PRIM_TYPE_TUBE, // Prim type
321 ScriptBaseClass.PRIM_HOLE_SQUARE, // Prim hole type
322 new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
323 0.00f, // Prim hollow
324 new LSL_Types.Vector3(1.0d, -1.0d, 0.0d), // Prim twist
325 new LSL_Types.Vector3(1.0d, 0.05d, 0.0d), // Prim hole size
326 // Expression for y selected to test precision problems during byte
327 // cast in SetPrimitiveShapeParams.
328 new LSL_Types.Vector3(0.0d, 0.35d + 0.1d, 0.0d), // Prim shear
329 new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim profile cut
330 // Expression for y selected to test precision problems during sbyte
331 // cast in SetPrimitiveShapeParams.
332 new LSL_Types.Vector3(-1.0d, 0.70d + 0.1d + 0.1d, 0.0d), // Prim taper
333 1.11f, // Prim revolutions
334 0.88f, // Prim radius
335 0.95f, // Prim skew
336 0.00f); // Prim hollow check
337
338 // Test a prism.
339 CheckllSetPrimitiveParams(
340 "test 5", // Prim test identification string
341 new LSL_Types.Vector3(3.5d, 3.5d, 3.5d), // Prim size
342 ScriptBaseClass.PRIM_TYPE_PRISM, // Prim type
343 ScriptBaseClass.PRIM_HOLE_SQUARE, // Prim hole type
344 new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
345 0.95f, // Prim hollow
346 // Expression for x selected to test precision problems during sbyte
347 // cast in SetPrimitiveShapeBlockParams.
348 new LSL_Types.Vector3(0.7d + 0.2d, 0.0d, 0.0d), // Prim twist
349 // Expression for y selected to test precision problems during sbyte
350 // cast in SetPrimitiveShapeParams.
351 new LSL_Types.Vector3(2.0d, (1.3d + 0.1d), 0.0d), // Prim taper
352 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear
353 0.70f); // Prim hollow check
354
355 // Test a sculpted prim.
356 CheckllSetPrimitiveParams(
357 "test 6", // Prim test identification string
358 new LSL_Types.Vector3(2.0d, 2.0d, 2.0d), // Prim size
359 ScriptBaseClass.PRIM_TYPE_SCULPT, // Prim type
360 "be293869-d0d9-0a69-5989-ad27f1946fd4", // Prim map
361 ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE); // Prim sculpt type
362 }
363
364 // Set prim params for a box, cylinder or prism and check results.
365 public void CheckllSetPrimitiveParams(string primTest,
366 LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
367 float primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primTaper, LSL_Types.Vector3 primShear,
368 float primHollowCheck)
369 {
370 // Set the prim params.
371 m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
372 ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
373 primCut, primHollow, primTwist, primTaper, primShear));
374
375 // Get params for prim to validate settings.
376 LSL_Types.list primParams =
377 m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
378
379 // Validate settings.
380 CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size");
381 Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1),
382 "TestllSetPrimitiveParams " + primTest + " prim type check fail");
383 Assert.AreEqual(primHoleType, m_lslApi.llList2Integer(primParams, 2),
384 "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
385 CheckllSetPrimitiveParamsVector(primCut, m_lslApi.llList2Vector(primParams, 3), primTest + " prim cut");
386 Assert.AreEqual(primHollowCheck, m_lslApi.llList2Float(primParams, 4), FLOAT_ACCURACY,
387 "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
388 CheckllSetPrimitiveParamsVector(primTwist, m_lslApi.llList2Vector(primParams, 5), primTest + " prim twist");
389 CheckllSetPrimitiveParamsVector(primTaper, m_lslApi.llList2Vector(primParams, 6), primTest + " prim taper");
390 CheckllSetPrimitiveParamsVector(primShear, m_lslApi.llList2Vector(primParams, 7), primTest + " prim shear");
391 }
392
393 // Set prim params for a sphere and check results.
394 public void CheckllSetPrimitiveParams(string primTest,
395 LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
396 float primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primDimple, float primHollowCheck)
397 {
398 // Set the prim params.
399 m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
400 ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
401 primCut, primHollow, primTwist, primDimple));
402
403 // Get params for prim to validate settings.
404 LSL_Types.list primParams =
405 m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
406
407 // Validate settings.
408 CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size");
409 Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1),
410 "TestllSetPrimitiveParams " + primTest + " prim type check fail");
411 Assert.AreEqual(primHoleType, m_lslApi.llList2Integer(primParams, 2),
412 "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
413 CheckllSetPrimitiveParamsVector(primCut, m_lslApi.llList2Vector(primParams, 3), primTest + " prim cut");
414 Assert.AreEqual(primHollowCheck, m_lslApi.llList2Float(primParams, 4), FLOAT_ACCURACY,
415 "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
416 CheckllSetPrimitiveParamsVector(primTwist, m_lslApi.llList2Vector(primParams, 5), primTest + " prim twist");
417 CheckllSetPrimitiveParamsVector(primDimple, m_lslApi.llList2Vector(primParams, 6), primTest + " prim dimple");
418 }
419
420 // Set prim params for a torus, tube or ring and check results.
421 public void CheckllSetPrimitiveParams(string primTest,
422 LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
423 float primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primHoleSize,
424 LSL_Types.Vector3 primShear, LSL_Types.Vector3 primProfCut, LSL_Types.Vector3 primTaper,
425 float primRev, float primRadius, float primSkew, float primHollowCheck)
426 {
427 // Set the prim params.
428 m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
429 ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
430 primCut, primHollow, primTwist, primHoleSize, primShear, primProfCut,
431 primTaper, primRev, primRadius, primSkew));
432
433 // Get params for prim to validate settings.
434 LSL_Types.list primParams =
435 m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
436
437 // Valdate settings.
438 CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size");
439 Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1),
440 "TestllSetPrimitiveParams " + primTest + " prim type check fail");
441 Assert.AreEqual(primHoleType, m_lslApi.llList2Integer(primParams, 2),
442 "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
443 CheckllSetPrimitiveParamsVector(primCut, m_lslApi.llList2Vector(primParams, 3), primTest + " prim cut");
444 Assert.AreEqual(primHollowCheck, m_lslApi.llList2Float(primParams, 4), FLOAT_ACCURACY,
445 "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
446 CheckllSetPrimitiveParamsVector(primTwist, m_lslApi.llList2Vector(primParams, 5), primTest + " prim twist");
447 CheckllSetPrimitiveParamsVector(primHoleSize, m_lslApi.llList2Vector(primParams, 6), primTest + " prim hole size");
448 CheckllSetPrimitiveParamsVector(primShear, m_lslApi.llList2Vector(primParams, 7), primTest + " prim shear");
449 CheckllSetPrimitiveParamsVector(primProfCut, m_lslApi.llList2Vector(primParams, 8), primTest + " prim profile cut");
450 CheckllSetPrimitiveParamsVector(primTaper, m_lslApi.llList2Vector(primParams, 9), primTest + " prim taper");
451 Assert.AreEqual(primRev, m_lslApi.llList2Float(primParams, 10), FLOAT_ACCURACY,
452 "TestllSetPrimitiveParams " + primTest + " prim revolutions fail");
453 Assert.AreEqual(primRadius, m_lslApi.llList2Float(primParams, 11), FLOAT_ACCURACY,
454 "TestllSetPrimitiveParams " + primTest + " prim radius fail");
455 Assert.AreEqual(primSkew, m_lslApi.llList2Float(primParams, 12), FLOAT_ACCURACY,
456 "TestllSetPrimitiveParams " + primTest + " prim skew fail");
457 }
458
459 // Set prim params for a sculpted prim and check results.
460 public void CheckllSetPrimitiveParams(string primTest,
461 LSL_Types.Vector3 primSize, int primType, string primMap, int primSculptType)
462 {
463 // Set the prim params.
464 m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
465 ScriptBaseClass.PRIM_TYPE, primType, primMap, primSculptType));
466
467 // Get params for prim to validate settings.
468 LSL_Types.list primParams =
469 m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
470
471 // Validate settings.
472 CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size");
473 Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1),
474 "TestllSetPrimitiveParams " + primTest + " prim type check fail");
475 Assert.AreEqual(primMap, (string)m_lslApi.llList2String(primParams, 2),
476 "TestllSetPrimitiveParams " + primTest + " prim map check fail");
477 Assert.AreEqual(primSculptType, m_lslApi.llList2Integer(primParams, 3),
478 "TestllSetPrimitiveParams " + primTest + " prim type scuplt check fail");
479 }
480
481 public void CheckllSetPrimitiveParamsVector(LSL_Types.Vector3 vecCheck, LSL_Types.Vector3 vecReturned, string msg)
482 {
483 // Check each vector component against expected result.
484 Assert.AreEqual(vecCheck.x, vecReturned.x, VECTOR_COMPONENT_ACCURACY,
485 "TestllSetPrimitiveParams " + msg + " vector check fail on x component");
486 Assert.AreEqual(vecCheck.y, vecReturned.y, VECTOR_COMPONENT_ACCURACY,
487 "TestllSetPrimitiveParams " + msg + " vector check fail on y component");
488 Assert.AreEqual(vecCheck.z, vecReturned.z, VECTOR_COMPONENT_ACCURACY,
489 "TestllSetPrimitiveParams " + msg + " vector check fail on z component");
490 }
491
492 [Test]
493 public void TestllVecNorm() 257 public void TestllVecNorm()
494 { 258 {
495 TestHelpers.InMethod(); 259 TestHelpers.InMethod();