aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared
diff options
context:
space:
mode:
authorCharles Krinke2009-02-07 18:11:04 +0000
committerCharles Krinke2009-02-07 18:11:04 +0000
commit63fd4c0fb2adb46e5181305164cbeecede199cc8 (patch)
tree5218407731fd788d99040beefd1360f1abbaeb4d /OpenSim/Region/ScriptEngine/Shared
parentAdd TLaukkan (Tommil) to CONTRIBUTORS.txt for OpenSim (diff)
downloadopensim-SC-63fd4c0fb2adb46e5181305164cbeecede199cc8.zip
opensim-SC-63fd4c0fb2adb46e5181305164cbeecede199cc8.tar.gz
opensim-SC-63fd4c0fb2adb46e5181305164cbeecede199cc8.tar.bz2
opensim-SC-63fd4c0fb2adb46e5181305164cbeecede199cc8.tar.xz
Thank you kindly, TLaukkan (Tommil) for a patch that:
Created nunit test for LSL API and example test for llAngleBetween which was marked untested in wiki. Run new test succesfully with NUnitGUI and nant build.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs140
1 files changed, 140 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
new file mode 100644
index 0000000..e2718cc
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
@@ -0,0 +1,140 @@
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 OpenSim 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.Collections.Generic;
29using NUnit.Framework;
30using OpenSim.Tests.Common;
31using OpenSim.Region.ScriptEngine.Shared;
32using OpenSim.Tests.Common.Setup;
33using OpenSim.Region.Framework.Scenes;
34using Nini.Config;
35using OpenSim.Region.ScriptEngine.Shared.Api;
36using OpenMetaverse;
37using System;
38
39namespace OpenSim.Region.ScriptEngine.Shared.Tests
40{
41 /// <summary>
42 /// Tests for LSL_Api
43 /// </summary>
44 [TestFixture]
45 public class LSL_ApiTest
46 {
47
48 private const double ANGLE_ACCURACY_IN_RADIANS = 1E-7;
49 private LSL_Api lslApi;
50
51 [SetUp]
52 public void SetUp()
53 {
54
55 IniConfigSource initConfigSource = new IniConfigSource();
56 IConfig config = initConfigSource.AddConfig("XEngine");
57 config.Set("Enabled", "true");
58
59 Scene scene = SceneSetupHelpers.SetupScene();
60 SceneObjectPart part = SceneSetupHelpers.AddSceneObject(scene);
61
62 XEngine.XEngine engine = new XEngine.XEngine();
63 engine.Initialise(scene, initConfigSource);
64
65 lslApi = new LSL_Api();
66 lslApi.Initialize(engine, part, part.LocalId, part.UUID);
67
68 }
69
70 [Test]
71 public void TestllAngleBetween()
72 {
73 TestllAngleBetween(new Vector3(1, 0, 0), 0);
74 TestllAngleBetween(new Vector3(1, 0, 0), 90);
75 TestllAngleBetween(new Vector3(1, 0, 0), 180);
76 TestllAngleBetween(new Vector3(1, 0, 0), 270);
77
78 TestllAngleBetween(new Vector3(0, 1, 0), 0);
79 TestllAngleBetween(new Vector3(0, 1, 0), 90);
80 TestllAngleBetween(new Vector3(0, 1, 0), 180);
81 TestllAngleBetween(new Vector3(0, 1, 0), 270);
82
83 TestllAngleBetween(new Vector3(0, 0, 1), 0);
84 TestllAngleBetween(new Vector3(0, 0, 1), 90);
85 TestllAngleBetween(new Vector3(0, 0, 1), 180);
86 TestllAngleBetween(new Vector3(0, 0, 1), 270);
87
88 TestllAngleBetween(new Vector3(1, 1, 1), 0);
89 TestllAngleBetween(new Vector3(1, 1, 1), 90);
90 TestllAngleBetween(new Vector3(1, 1, 1), 180);
91 TestllAngleBetween(new Vector3(1, 1, 1), 270);
92 }
93
94 private void TestllAngleBetween(Vector3 axis,float originalAngle)
95 {
96 Quaternion rotation1 = Quaternion.CreateFromAxisAngle(axis, 0);
97 Quaternion rotation2 = Quaternion.CreateFromAxisAngle(axis, ToRadians(originalAngle));
98
99 double deducedAngle = FromLslFloat(lslApi.llAngleBetween(ToLslQuaternion(rotation2), ToLslQuaternion(rotation1)));
100
101 Assert.Greater(deducedAngle, ToRadians(originalAngle) - ANGLE_ACCURACY_IN_RADIANS);
102 Assert.Less(deducedAngle, ToRadians(originalAngle) + ANGLE_ACCURACY_IN_RADIANS);
103 }
104
105 #region Conversions to and from LSL_Types
106
107 private float ToRadians(double degrees)
108 {
109 return (float)(Math.PI * degrees / 180);
110 }
111
112 private double FromRadians(float radians)
113 {
114 return radians * 180 / Math.PI;
115 }
116
117 private double FromLslFloat(LSL_Types.LSLFloat lslFloat)
118 {
119 return lslFloat.value;
120 }
121
122 private LSL_Types.LSLFloat ToLslFloat(double value)
123 {
124 return new LSL_Types.LSLFloat(value);
125 }
126
127 private Quaternion FromLslQuaternion(LSL_Types.Quaternion lslQuaternion)
128 {
129 return new Quaternion((float)lslQuaternion.x, (float)lslQuaternion.y, (float)lslQuaternion.z, (float)lslQuaternion.s);
130 }
131
132 private LSL_Types.Quaternion ToLslQuaternion(Quaternion quaternion)
133 {
134 return new LSL_Types.Quaternion(quaternion.X, quaternion.Y, quaternion.Z, quaternion.W);
135 }
136
137 #endregion
138
139 }
140}