diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Tests')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs | 156 | ||||
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs | 170 |
2 files changed, 290 insertions, 36 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs index 0cbad41..3baa723 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs | |||
@@ -75,32 +75,49 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
75 | [Test] | 75 | [Test] |
76 | public void TestllAngleBetween() | 76 | public void TestllAngleBetween() |
77 | { | 77 | { |
78 | CheckllAngleBetween(new Vector3(1, 0, 0), 0); | 78 | CheckllAngleBetween(new Vector3(1, 0, 0), 0, 1, 1); |
79 | CheckllAngleBetween(new Vector3(1, 0, 0), 90); | 79 | CheckllAngleBetween(new Vector3(1, 0, 0), 90, 1, 1); |
80 | CheckllAngleBetween(new Vector3(1, 0, 0), 180); | 80 | CheckllAngleBetween(new Vector3(1, 0, 0), 180, 1, 1); |
81 | 81 | ||
82 | CheckllAngleBetween(new Vector3(0, 1, 0), 0); | 82 | CheckllAngleBetween(new Vector3(0, 1, 0), 0, 1, 1); |
83 | CheckllAngleBetween(new Vector3(0, 1, 0), 90); | 83 | CheckllAngleBetween(new Vector3(0, 1, 0), 90, 1, 1); |
84 | CheckllAngleBetween(new Vector3(0, 1, 0), 180); | 84 | CheckllAngleBetween(new Vector3(0, 1, 0), 180, 1, 1); |
85 | 85 | ||
86 | CheckllAngleBetween(new Vector3(0, 0, 1), 0); | 86 | CheckllAngleBetween(new Vector3(0, 0, 1), 0, 1, 1); |
87 | CheckllAngleBetween(new Vector3(0, 0, 1), 90); | 87 | CheckllAngleBetween(new Vector3(0, 0, 1), 90, 1, 1); |
88 | CheckllAngleBetween(new Vector3(0, 0, 1), 180); | 88 | CheckllAngleBetween(new Vector3(0, 0, 1), 180, 1, 1); |
89 | 89 | ||
90 | CheckllAngleBetween(new Vector3(1, 1, 1), 0); | 90 | CheckllAngleBetween(new Vector3(1, 1, 1), 0, 1, 1); |
91 | CheckllAngleBetween(new Vector3(1, 1, 1), 90); | 91 | CheckllAngleBetween(new Vector3(1, 1, 1), 90, 1, 1); |
92 | CheckllAngleBetween(new Vector3(1, 1, 1), 180); | 92 | CheckllAngleBetween(new Vector3(1, 1, 1), 180, 1, 1); |
93 | |||
94 | CheckllAngleBetween(new Vector3(1, 0, 0), 0, 1.6f, 1.8f); | ||
95 | CheckllAngleBetween(new Vector3(1, 0, 0), 90, 0.3f, 3.9f); | ||
96 | CheckllAngleBetween(new Vector3(1, 0, 0), 180, 8.8f, 7.4f); | ||
97 | |||
98 | CheckllAngleBetween(new Vector3(0, 1, 0), 0, 9.8f, -9.4f); | ||
99 | CheckllAngleBetween(new Vector3(0, 1, 0), 90, 8.4f, -8.2f); | ||
100 | CheckllAngleBetween(new Vector3(0, 1, 0), 180, 0.4f, -5.8f); | ||
101 | |||
102 | CheckllAngleBetween(new Vector3(0, 0, 1), 0, -6.8f, 3.4f); | ||
103 | CheckllAngleBetween(new Vector3(0, 0, 1), 90, -3.6f, 5.6f); | ||
104 | CheckllAngleBetween(new Vector3(0, 0, 1), 180, -3.8f, 1.1f); | ||
105 | |||
106 | CheckllAngleBetween(new Vector3(1, 1, 1), 0, -7.7f, -2.0f); | ||
107 | CheckllAngleBetween(new Vector3(1, 1, 1), 90, -3.0f, -9.1f); | ||
108 | CheckllAngleBetween(new Vector3(1, 1, 1), 180, -7.9f, -8.0f); | ||
93 | } | 109 | } |
94 | 110 | ||
95 | private void CheckllAngleBetween(Vector3 axis,float originalAngle) | 111 | private void CheckllAngleBetween(Vector3 axis,float originalAngle, float denorm1, float denorm2) |
96 | { | 112 | { |
97 | Quaternion rotation1 = Quaternion.CreateFromAxisAngle(axis, 0); | 113 | Quaternion rotation1 = Quaternion.CreateFromAxisAngle(axis, 0); |
98 | Quaternion rotation2 = Quaternion.CreateFromAxisAngle(axis, ToRadians(originalAngle)); | 114 | Quaternion rotation2 = Quaternion.CreateFromAxisAngle(axis, ToRadians(originalAngle)); |
115 | rotation1 *= denorm1; | ||
116 | rotation2 *= denorm2; | ||
99 | 117 | ||
100 | double deducedAngle = FromLslFloat(m_lslApi.llAngleBetween(ToLslQuaternion(rotation2), ToLslQuaternion(rotation1))); | 118 | double deducedAngle = FromLslFloat(m_lslApi.llAngleBetween(ToLslQuaternion(rotation2), ToLslQuaternion(rotation1))); |
101 | 119 | ||
102 | Assert.Greater(deducedAngle, ToRadians(originalAngle) - ANGLE_ACCURACY_IN_RADIANS); | 120 | Assert.That(deducedAngle, Is.EqualTo(ToRadians(originalAngle)).Within(ANGLE_ACCURACY_IN_RADIANS), "TestllAngleBetween check fail"); |
103 | Assert.Less(deducedAngle, ToRadians(originalAngle) + ANGLE_ACCURACY_IN_RADIANS); | ||
104 | } | 121 | } |
105 | 122 | ||
106 | #region Conversions to and from LSL_Types | 123 | #region Conversions to and from LSL_Types |
@@ -142,30 +159,97 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
142 | public void TestllRot2Euler() | 159 | public void TestllRot2Euler() |
143 | { | 160 | { |
144 | // 180, 90 and zero degree rotations. | 161 | // 180, 90 and zero degree rotations. |
145 | CheckllRot2Euler(new LSL_Types.Quaternion(1.0f, 0.0f, 0.0f, 0.0f), new LSL_Types.Vector3(Math.PI, 0.0f, 0.0f)); | 162 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, 0.0f, 0.0f, 1.0f)); |
146 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, 1.0f, 0.0f, 0.0f), new LSL_Types.Vector3(Math.PI, 0.0f, Math.PI)); | 163 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, 0.0f, 0.707107f, 0.707107f)); |
147 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, 0.0f, 1.0f, 0.0f), new LSL_Types.Vector3(0.0f, 0.0f, Math.PI)); | 164 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, 0.0f, 1.0f, 0.0f)); |
148 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, 0.0f, 0.0f, 1.0f), new LSL_Types.Vector3(0.0f, 0.0f, 0.0f)); | 165 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, 0.0f, 0.707107f, -0.707107f)); |
149 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.5f, -0.5f, 0.5f, 0.5f), new LSL_Types.Vector3(0, -Math.PI / 2.0f, Math.PI / 2.0f)); | 166 | CheckllRot2Euler(new LSL_Types.Quaternion(0.707107f, 0.0f, 0.0f, 0.707107f)); |
150 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.707107f, 0.0f, 0.0f, -0.707107f), new LSL_Types.Vector3(Math.PI / 2.0f, 0.0f, 0.0f)); | 167 | CheckllRot2Euler(new LSL_Types.Quaternion(0.5f, -0.5f, 0.5f, 0.5f)); |
168 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, -0.707107f, 0.707107f, 0.0f)); | ||
169 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.5f, -0.5f, 0.5f, -0.5f)); | ||
170 | CheckllRot2Euler(new LSL_Types.Quaternion(1.0f, 0.0f, 0.0f, 0.0f)); | ||
171 | CheckllRot2Euler(new LSL_Types.Quaternion(0.707107f, -0.707107f, 0.0f, 0.0f)); | ||
172 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, -1.0f, 0.0f, 0.0f)); | ||
173 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.707107f, -0.707107f, 0.0f, 0.0f)); | ||
174 | CheckllRot2Euler(new LSL_Types.Quaternion(0.707107f, 0.0f, 0.0f, -0.707107f)); | ||
175 | CheckllRot2Euler(new LSL_Types.Quaternion(0.5f, -0.5f, -0.5f, -0.5f)); | ||
176 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, -0.707107f, -0.707107f, 0.0f)); | ||
177 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.5f, -0.5f, -0.5f, 0.5f)); | ||
178 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, -0.707107f, 0.0f, 0.707107f)); | ||
179 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.5f, -0.5f, 0.5f, 0.5f)); | ||
180 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.707107f, 0.0f, 0.707107f, 0.0f)); | ||
181 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.5f, 0.5f, 0.5f, -0.5f)); | ||
182 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, -0.707107f, 0.0f, -0.707107f)); | ||
183 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.5f, -0.5f, -0.5f, -0.5f)); | ||
184 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.707107f, 0.0f, -0.707107f, 0.0f)); | ||
185 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.5f, 0.5f, -0.5f, 0.5f)); | ||
186 | |||
151 | // A couple of messy rotations. | 187 | // A couple of messy rotations. |
152 | CheckllRot2Euler(new LSL_Types.Quaternion(1.0f, 5.651f, -3.1f, 67.023f), new LSL_Types.Vector3(0.037818f, 0.166447f, -0.095595f)); | 188 | CheckllRot2Euler(new LSL_Types.Quaternion(1.0f, 5.651f, -3.1f, 67.023f)); |
153 | CheckllRot2Euler(new LSL_Types.Quaternion(0.719188f, -0.408934f, -0.363998f, -0.427841f), new LSL_Types.Vector3(-1.954769f, -0.174533f, 1.151917f)); | 189 | CheckllRot2Euler(new LSL_Types.Quaternion(0.719188f, -0.408934f, -0.363998f, -0.427841f)); |
190 | |||
191 | // Some deliberately malicious rotations (intended on provoking singularity errors) | ||
192 | // The "f" suffexes are deliberately omitted. | ||
193 | CheckllRot2Euler(new LSL_Types.Quaternion(0.50001f, 0.50001f, 0.50001f, 0.50001f)); | ||
194 | // More malice. The "f" suffixes are deliberately omitted. | ||
195 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.701055, 0.092296, 0.701055, -0.092296)); | ||
196 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.183005, -0.683010, 0.183005, 0.683010)); | ||
197 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.430460, -0.560982, 0.430460, 0.560982)); | ||
198 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.701066, 0.092301, -0.701066, 0.092301)); | ||
199 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.183013, -0.683010, 0.183013, 0.683010)); | ||
200 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.183005, -0.683014, -0.183005, -0.683014)); | ||
201 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.353556, 0.612375, 0.353556, -0.612375)); | ||
202 | CheckllRot2Euler(new LSL_Types.Quaternion(0.353554, -0.612385, -0.353554, 0.612385)); | ||
203 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.560989, 0.430450, 0.560989, -0.430450)); | ||
204 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.183013, 0.683009, -0.183013, 0.683009)); | ||
205 | CheckllRot2Euler(new LSL_Types.Quaternion(0.430457, -0.560985, -0.430457, 0.560985)); | ||
206 | CheckllRot2Euler(new LSL_Types.Quaternion(0.353552, 0.612360, -0.353552, -0.612360)); | ||
207 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.499991, 0.500003, 0.499991, -0.500003)); | ||
208 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.353555, -0.612385, -0.353555, -0.612385)); | ||
209 | CheckllRot2Euler(new LSL_Types.Quaternion(0.701066, -0.092301, -0.701066, 0.092301)); | ||
210 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.499991, 0.500007, 0.499991, -0.500007)); | ||
211 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.683002, 0.183016, -0.683002, 0.183016)); | ||
212 | CheckllRot2Euler(new LSL_Types.Quaternion(0.430458, 0.560982, 0.430458, 0.560982)); | ||
213 | CheckllRot2Euler(new LSL_Types.Quaternion(0.499991, -0.500003, -0.499991, 0.500003)); | ||
214 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.183009, 0.683011, -0.183009, 0.683011)); | ||
215 | CheckllRot2Euler(new LSL_Types.Quaternion(0.560975, -0.430457, 0.560975, -0.430457)); | ||
216 | CheckllRot2Euler(new LSL_Types.Quaternion(0.701055, 0.092300, 0.701055, 0.092300)); | ||
217 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.560990, 0.430459, -0.560990, 0.430459)); | ||
218 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.092302, -0.701059, -0.092302, -0.701059)); | ||
154 | } | 219 | } |
155 | 220 | ||
156 | private void CheckllRot2Euler(LSL_Types.Quaternion rot, LSL_Types.Vector3 eulerCheck) | 221 | /// <summary> |
222 | /// Check an llRot2Euler conversion. | ||
223 | /// </summary> | ||
224 | /// <remarks> | ||
225 | /// Testing Rot2Euler this way instead of comparing against expected angles because | ||
226 | /// 1. There are several ways to get to the original Quaternion. For example a rotation | ||
227 | /// of PI and -PI will give the same result. But PI and -PI aren't equal. | ||
228 | /// 2. This method checks to see if the calculated angles from a quaternion can be used | ||
229 | /// to create a new quaternion to produce the same rotation. | ||
230 | /// However, can't compare the newly calculated quaternion against the original because | ||
231 | /// once again, there are multiple quaternions that give the same result. For instance | ||
232 | /// <X, Y, Z, S> == <-X, -Y, -Z, -S>. Additionally, the magnitude of S can be changed | ||
233 | /// and will still result in the same rotation if the values for X, Y, Z are also changed | ||
234 | /// to compensate. | ||
235 | /// However, if two quaternions represent the same rotation, then multiplying the first | ||
236 | /// quaternion by the conjugate of the second, will give a third quaternion representing | ||
237 | /// a zero rotation. This can be tested for by looking at the X, Y, Z values which should | ||
238 | /// be zero. | ||
239 | /// </remarks> | ||
240 | /// <param name="rot"></param> | ||
241 | private void CheckllRot2Euler(LSL_Types.Quaternion rot) | ||
157 | { | 242 | { |
158 | // Call LSL function to convert quaternion rotaion to euler radians. | 243 | // Call LSL function to convert quaternion rotaion to euler radians. |
159 | LSL_Types.Vector3 eulerCalc = m_lslApi.llRot2Euler(rot); | 244 | LSL_Types.Vector3 eulerCalc = m_lslApi.llRot2Euler(rot); |
160 | // Check upper and lower bounds of x, y and z. | 245 | // Now use the euler radians to recalculate a new quaternion rotation |
161 | // This type of check is performed as opposed to comparing for equal numbers, in order to allow slight | 246 | LSL_Types.Quaternion newRot = m_lslApi.llEuler2Rot(eulerCalc); |
162 | // differences in accuracy. | 247 | // Multiple original quaternion by conjugate of quaternion calculated with angles. |
163 | Assert.Greater(eulerCalc.x, eulerCheck.x - ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler X lower bounds check fail"); | 248 | LSL_Types.Quaternion check = rot * new LSL_Types.Quaternion(-newRot.x, -newRot.y, -newRot.z, newRot.s); |
164 | Assert.Less(eulerCalc.x, eulerCheck.x + ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler X upper bounds check fail"); | 249 | |
165 | Assert.Greater(eulerCalc.y, eulerCheck.y - ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler Y lower bounds check fail"); | 250 | Assert.AreEqual(0.0, check.x, VECTOR_COMPONENT_ACCURACY, "TestllRot2Euler X bounds check fail"); |
166 | Assert.Less(eulerCalc.y, eulerCheck.y + ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler Y upper bounds check fail"); | 251 | Assert.AreEqual(0.0, check.y, VECTOR_COMPONENT_ACCURACY, "TestllRot2Euler Y bounds check fail"); |
167 | Assert.Greater(eulerCalc.z, eulerCheck.z - ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler Z lower bounds check fail"); | 252 | Assert.AreEqual(0.0, check.z, VECTOR_COMPONENT_ACCURACY, "TestllRot2Euler Z bounds check fail"); |
168 | Assert.Less(eulerCalc.z, eulerCheck.z + ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler Z upper bounds check fail"); | ||
169 | } | 253 | } |
170 | 254 | ||
171 | [Test] | 255 | [Test] |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs new file mode 100644 index 0000000..9d9fc51 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs | |||
@@ -0,0 +1,170 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using log4net; | ||
33 | using Nini.Config; | ||
34 | using NUnit.Framework; | ||
35 | using OpenMetaverse; | ||
36 | using OpenMetaverse.Assets; | ||
37 | using OpenMetaverse.StructuredData; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Region.CoreModules.Avatar.AvatarFactory; | ||
40 | using OpenSim.Region.OptionalModules.World.NPC; | ||
41 | using OpenSim.Region.Framework.Scenes; | ||
42 | using OpenSim.Region.ScriptEngine.Shared; | ||
43 | using OpenSim.Region.ScriptEngine.Shared.Api; | ||
44 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; | ||
45 | using OpenSim.Services.Interfaces; | ||
46 | using OpenSim.Tests.Common; | ||
47 | using OpenSim.Tests.Common.Mock; | ||
48 | |||
49 | namespace OpenSim.Region.ScriptEngine.Shared.Tests | ||
50 | { | ||
51 | /// <summary> | ||
52 | /// Tests for OSSL NPC API | ||
53 | /// </summary> | ||
54 | [TestFixture] | ||
55 | public class OSSL_NpcApiAppearanceTest | ||
56 | { | ||
57 | protected Scene m_scene; | ||
58 | protected XEngine.XEngine m_engine; | ||
59 | |||
60 | [SetUp] | ||
61 | public void SetUp() | ||
62 | { | ||
63 | IConfigSource initConfigSource = new IniConfigSource(); | ||
64 | IConfig config = initConfigSource.AddConfig("XEngine"); | ||
65 | config.Set("Enabled", "true"); | ||
66 | config.Set("AllowOSFunctions", "true"); | ||
67 | config.Set("OSFunctionThreatLevel", "Severe"); | ||
68 | config = initConfigSource.AddConfig("NPC"); | ||
69 | config.Set("Enabled", "true"); | ||
70 | |||
71 | m_scene = SceneHelpers.SetupScene(); | ||
72 | SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule()); | ||
73 | |||
74 | m_engine = new XEngine.XEngine(); | ||
75 | m_engine.Initialise(initConfigSource); | ||
76 | m_engine.AddRegion(m_scene); | ||
77 | } | ||
78 | |||
79 | /// <summary> | ||
80 | /// Test removal of an owned NPC. | ||
81 | /// </summary> | ||
82 | [Test] | ||
83 | public void TestOsNpcRemoveOwned() | ||
84 | { | ||
85 | TestHelpers.InMethod(); | ||
86 | // log4net.Config.XmlConfigurator.Configure(); | ||
87 | |||
88 | // Store an avatar with a different height from default in a notecard. | ||
89 | UUID userId = TestHelpers.ParseTail(0x1); | ||
90 | UUID otherUserId = TestHelpers.ParseTail(0x2); | ||
91 | float newHeight = 1.9f; | ||
92 | |||
93 | SceneHelpers.AddScenePresence(m_scene, otherUserId); | ||
94 | |||
95 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); | ||
96 | sp.Appearance.AvatarHeight = newHeight; | ||
97 | |||
98 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId); | ||
99 | SceneObjectPart part = so.RootPart; | ||
100 | m_scene.AddSceneObject(so); | ||
101 | |||
102 | SceneObjectGroup otherSo = SceneHelpers.CreateSceneObject(1, otherUserId); | ||
103 | SceneObjectPart otherPart = otherSo.RootPart; | ||
104 | m_scene.AddSceneObject(otherSo); | ||
105 | |||
106 | OSSL_Api osslApi = new OSSL_Api(); | ||
107 | osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); | ||
108 | |||
109 | OSSL_Api otherOsslApi = new OSSL_Api(); | ||
110 | otherOsslApi.Initialize(m_engine, otherPart, otherPart.LocalId, otherPart.UUID); | ||
111 | |||
112 | string notecardName = "appearanceNc"; | ||
113 | osslApi.osOwnerSaveAppearance(notecardName); | ||
114 | |||
115 | string npcRaw | ||
116 | = osslApi.osNpcCreate( | ||
117 | "Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName, ScriptBaseClass.OS_NPC_CREATOR_OWNED); | ||
118 | |||
119 | otherOsslApi.osNpcRemove(npcRaw); | ||
120 | |||
121 | // Should still be around | ||
122 | UUID npcId = new UUID(npcRaw); | ||
123 | ScenePresence npc = m_scene.GetScenePresence(npcId); | ||
124 | Assert.That(npc, Is.Not.Null); | ||
125 | |||
126 | osslApi.osNpcRemove(npcRaw); | ||
127 | |||
128 | npc = m_scene.GetScenePresence(npcId); | ||
129 | |||
130 | // Now the owner deleted it and it's gone | ||
131 | Assert.That(npc, Is.Null); | ||
132 | } | ||
133 | |||
134 | /// <summary> | ||
135 | /// Test removal of an unowned NPC. | ||
136 | /// </summary> | ||
137 | [Test] | ||
138 | public void TestOsNpcRemoveUnowned() | ||
139 | { | ||
140 | TestHelpers.InMethod(); | ||
141 | // log4net.Config.XmlConfigurator.Configure(); | ||
142 | |||
143 | // Store an avatar with a different height from default in a notecard. | ||
144 | UUID userId = TestHelpers.ParseTail(0x1); | ||
145 | float newHeight = 1.9f; | ||
146 | |||
147 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); | ||
148 | sp.Appearance.AvatarHeight = newHeight; | ||
149 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId); | ||
150 | SceneObjectPart part = so.RootPart; | ||
151 | m_scene.AddSceneObject(so); | ||
152 | |||
153 | OSSL_Api osslApi = new OSSL_Api(); | ||
154 | osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); | ||
155 | |||
156 | string notecardName = "appearanceNc"; | ||
157 | osslApi.osOwnerSaveAppearance(notecardName); | ||
158 | |||
159 | string npcRaw | ||
160 | = osslApi.osNpcCreate( | ||
161 | "Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName, ScriptBaseClass.OS_NPC_NOT_OWNED); | ||
162 | |||
163 | osslApi.osNpcRemove(npcRaw); | ||
164 | |||
165 | UUID npcId = new UUID(npcRaw); | ||
166 | ScenePresence npc = m_scene.GetScenePresence(npcId); | ||
167 | Assert.That(npc, Is.Null); | ||
168 | } | ||
169 | } | ||
170 | } \ No newline at end of file | ||