clockwerk-opensim-stable – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 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.Attachments; |
||
40 | using OpenSim.Region.CoreModules.Avatar.AvatarFactory; |
||
41 | using OpenSim.Region.OptionalModules.World.NPC; |
||
42 | using OpenSim.Region.Framework.Scenes; |
||
43 | using OpenSim.Region.ScriptEngine.Shared; |
||
44 | using OpenSim.Region.ScriptEngine.Shared.Api; |
||
45 | using OpenSim.Region.ScriptEngine.Shared.Instance; |
||
46 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; |
||
47 | using OpenSim.Services.Interfaces; |
||
48 | using OpenSim.Tests.Common; |
||
49 | using OpenSim.Tests.Common.Mock; |
||
50 | |||
51 | namespace OpenSim.Region.ScriptEngine.Shared.Tests |
||
52 | { |
||
53 | /// <summary> |
||
54 | /// Tests for OSSL NPC API |
||
55 | /// </summary> |
||
56 | [TestFixture] |
||
57 | public class OSSL_NpcApiAppearanceTest : OpenSimTestCase |
||
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 | config.Set("AllowOSFunctions", "true"); |
||
71 | config.Set("OSFunctionThreatLevel", "Severe"); |
||
72 | config = initConfigSource.AddConfig("NPC"); |
||
73 | config.Set("Enabled", "true"); |
||
74 | |||
75 | m_scene = new SceneHelpers().SetupScene(); |
||
76 | SceneHelpers.SetupSceneModules( |
||
77 | m_scene, initConfigSource, new AvatarFactoryModule(), new AttachmentsModule(), new NPCModule()); |
||
78 | |||
79 | m_engine = new XEngine.XEngine(); |
||
80 | m_engine.Initialise(initConfigSource); |
||
81 | m_engine.AddRegion(m_scene); |
||
82 | } |
||
83 | |||
84 | /// <summary> |
||
85 | /// Test creation of an NPC where the appearance data comes from a notecard |
||
86 | /// </summary> |
||
87 | [Test] |
||
88 | public void TestOsNpcCreateUsingAppearanceFromNotecard() |
||
89 | { |
||
90 | TestHelpers.InMethod(); |
||
91 | |||
92 | // Store an avatar with a different height from default in a notecard. |
||
93 | UUID userId = TestHelpers.ParseTail(0x1); |
||
94 | float newHeight = 1.9f; |
||
95 | |||
96 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); |
||
97 | sp.Appearance.AvatarHeight = newHeight; |
||
98 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10); |
||
99 | SceneObjectPart part = so.RootPart; |
||
100 | m_scene.AddSceneObject(so); |
||
101 | |||
102 | OSSL_Api osslApi = new OSSL_Api(); |
||
103 | osslApi.Initialize(m_engine, part, null, null); |
||
104 | |||
105 | string notecardName = "appearanceNc"; |
||
106 | osslApi.osOwnerSaveAppearance(notecardName); |
||
107 | |||
108 | // Try creating a bot using the appearance in the notecard. |
||
109 | string npcRaw = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName); |
||
110 | Assert.That(npcRaw, Is.Not.Null); |
||
111 | |||
112 | UUID npcId = new UUID(npcRaw); |
||
113 | ScenePresence npc = m_scene.GetScenePresence(npcId); |
||
114 | Assert.That(npc, Is.Not.Null); |
||
115 | Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(newHeight)); |
||
116 | } |
||
117 | |||
118 | [Test] |
||
119 | public void TestOsNpcCreateNotExistingNotecard() |
||
120 | { |
||
121 | TestHelpers.InMethod(); |
||
122 | |||
123 | UUID userId = TestHelpers.ParseTail(0x1); |
||
124 | |||
125 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10); |
||
126 | m_scene.AddSceneObject(so); |
||
127 | |||
128 | OSSL_Api osslApi = new OSSL_Api(); |
||
129 | osslApi.Initialize(m_engine, so.RootPart, null, null); |
||
130 | |||
131 | bool gotExpectedException = false; |
||
132 | try |
||
133 | { |
||
134 | osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), "not existing notecard name"); |
||
135 | } |
||
136 | catch (ScriptException) |
||
137 | { |
||
138 | gotExpectedException = true; |
||
139 | } |
||
140 | |||
141 | Assert.That(gotExpectedException, Is.True); |
||
142 | } |
||
143 | |||
144 | /// <summary> |
||
145 | /// Test creation of an NPC where the appearance data comes from an avatar already in the region. |
||
146 | /// </summary> |
||
147 | [Test] |
||
148 | public void TestOsNpcCreateUsingAppearanceFromAvatar() |
||
149 | { |
||
150 | TestHelpers.InMethod(); |
||
151 | // TestHelpers.EnableLogging(); |
||
152 | |||
153 | // Store an avatar with a different height from default in a notecard. |
||
154 | UUID userId = TestHelpers.ParseTail(0x1); |
||
155 | float newHeight = 1.9f; |
||
156 | |||
157 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); |
||
158 | sp.Appearance.AvatarHeight = newHeight; |
||
159 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10); |
||
160 | SceneObjectPart part = so.RootPart; |
||
161 | m_scene.AddSceneObject(so); |
||
162 | |||
163 | OSSL_Api osslApi = new OSSL_Api(); |
||
164 | osslApi.Initialize(m_engine, part, null, null); |
||
165 | |||
166 | string notecardName = "appearanceNc"; |
||
167 | osslApi.osOwnerSaveAppearance(notecardName); |
||
168 | |||
169 | // Try creating a bot using the existing avatar's appearance |
||
170 | string npcRaw = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), sp.UUID.ToString()); |
||
171 | Assert.That(npcRaw, Is.Not.Null); |
||
172 | |||
173 | UUID npcId = new UUID(npcRaw); |
||
174 | ScenePresence npc = m_scene.GetScenePresence(npcId); |
||
175 | Assert.That(npc, Is.Not.Null); |
||
176 | Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(newHeight)); |
||
177 | } |
||
178 | |||
179 | [Test] |
||
180 | public void TestOsNpcLoadAppearance() |
||
181 | { |
||
182 | TestHelpers.InMethod(); |
||
183 | //TestHelpers.EnableLogging(); |
||
184 | |||
185 | // Store an avatar with a different height from default in a notecard. |
||
186 | UUID userId = TestHelpers.ParseTail(0x1); |
||
187 | float firstHeight = 1.9f; |
||
188 | float secondHeight = 2.1f; |
||
189 | string firstAppearanceNcName = "appearanceNc1"; |
||
190 | string secondAppearanceNcName = "appearanceNc2"; |
||
191 | |||
192 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); |
||
193 | sp.Appearance.AvatarHeight = firstHeight; |
||
194 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10); |
||
195 | SceneObjectPart part = so.RootPart; |
||
196 | m_scene.AddSceneObject(so); |
||
197 | |||
198 | OSSL_Api osslApi = new OSSL_Api(); |
||
199 | osslApi.Initialize(m_engine, part, null, null); |
||
200 | |||
201 | osslApi.osOwnerSaveAppearance(firstAppearanceNcName); |
||
202 | |||
203 | string npcRaw |
||
204 | = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), firstAppearanceNcName); |
||
205 | |||
206 | // Create a second appearance notecard with a different height |
||
207 | sp.Appearance.AvatarHeight = secondHeight; |
||
208 | osslApi.osOwnerSaveAppearance(secondAppearanceNcName); |
||
209 | |||
210 | osslApi.osNpcLoadAppearance(npcRaw, secondAppearanceNcName); |
||
211 | |||
212 | UUID npcId = new UUID(npcRaw); |
||
213 | ScenePresence npc = m_scene.GetScenePresence(npcId); |
||
214 | Assert.That(npc, Is.Not.Null); |
||
215 | Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(secondHeight)); |
||
216 | } |
||
217 | |||
218 | [Test] |
||
219 | public void TestOsNpcLoadAppearanceNotExistingNotecard() |
||
220 | { |
||
221 | TestHelpers.InMethod(); |
||
222 | |||
223 | // Store an avatar with a different height from default in a notecard. |
||
224 | UUID userId = TestHelpers.ParseTail(0x1); |
||
225 | float firstHeight = 1.9f; |
||
226 | // float secondHeight = 2.1f; |
||
227 | string firstAppearanceNcName = "appearanceNc1"; |
||
228 | string secondAppearanceNcName = "appearanceNc2"; |
||
229 | |||
230 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); |
||
231 | sp.Appearance.AvatarHeight = firstHeight; |
||
232 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10); |
||
233 | SceneObjectPart part = so.RootPart; |
||
234 | m_scene.AddSceneObject(so); |
||
235 | |||
236 | OSSL_Api osslApi = new OSSL_Api(); |
||
237 | osslApi.Initialize(m_engine, part, null, null); |
||
238 | |||
239 | osslApi.osOwnerSaveAppearance(firstAppearanceNcName); |
||
240 | |||
241 | string npcRaw |
||
242 | = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), firstAppearanceNcName); |
||
243 | |||
244 | bool gotExpectedException = false; |
||
245 | try |
||
246 | { |
||
247 | osslApi.osNpcLoadAppearance(npcRaw, secondAppearanceNcName); |
||
248 | } |
||
249 | catch (ScriptException) |
||
250 | { |
||
251 | gotExpectedException = true; |
||
252 | } |
||
253 | |||
254 | Assert.That(gotExpectedException, Is.True); |
||
255 | |||
256 | UUID npcId = new UUID(npcRaw); |
||
257 | ScenePresence npc = m_scene.GetScenePresence(npcId); |
||
258 | Assert.That(npc, Is.Not.Null); |
||
259 | Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(firstHeight)); |
||
260 | } |
||
261 | |||
262 | /// <summary> |
||
263 | /// Test removal of an owned NPC. |
||
264 | /// </summary> |
||
265 | [Test] |
||
266 | public void TestOsNpcRemoveOwned() |
||
267 | { |
||
268 | TestHelpers.InMethod(); |
||
269 | |||
270 | // Store an avatar with a different height from default in a notecard. |
||
271 | UUID userId = TestHelpers.ParseTail(0x1); |
||
272 | UUID otherUserId = TestHelpers.ParseTail(0x2); |
||
273 | float newHeight = 1.9f; |
||
274 | |||
275 | SceneHelpers.AddScenePresence(m_scene, otherUserId); |
||
276 | |||
277 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); |
||
278 | sp.Appearance.AvatarHeight = newHeight; |
||
279 | |||
280 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10); |
||
281 | SceneObjectPart part = so.RootPart; |
||
282 | m_scene.AddSceneObject(so); |
||
283 | |||
284 | SceneObjectGroup otherSo = SceneHelpers.CreateSceneObject(1, otherUserId, 0x20); |
||
285 | SceneObjectPart otherPart = otherSo.RootPart; |
||
286 | m_scene.AddSceneObject(otherSo); |
||
287 | |||
288 | OSSL_Api osslApi = new OSSL_Api(); |
||
289 | osslApi.Initialize(m_engine, part, null, null); |
||
290 | |||
291 | OSSL_Api otherOsslApi = new OSSL_Api(); |
||
292 | otherOsslApi.Initialize(m_engine, otherPart, null, null); |
||
293 | |||
294 | string notecardName = "appearanceNc"; |
||
295 | osslApi.osOwnerSaveAppearance(notecardName); |
||
296 | |||
297 | string npcRaw |
||
298 | = osslApi.osNpcCreate( |
||
299 | "Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName, ScriptBaseClass.OS_NPC_CREATOR_OWNED); |
||
300 | |||
301 | otherOsslApi.osNpcRemove(npcRaw); |
||
302 | |||
303 | // Should still be around |
||
304 | UUID npcId = new UUID(npcRaw); |
||
305 | ScenePresence npc = m_scene.GetScenePresence(npcId); |
||
306 | Assert.That(npc, Is.Not.Null); |
||
307 | |||
308 | osslApi.osNpcRemove(npcRaw); |
||
309 | |||
310 | npc = m_scene.GetScenePresence(npcId); |
||
311 | |||
312 | // Now the owner deleted it and it's gone |
||
313 | Assert.That(npc, Is.Null); |
||
314 | } |
||
315 | |||
316 | /// <summary> |
||
317 | /// Test removal of an unowned NPC. |
||
318 | /// </summary> |
||
319 | [Test] |
||
320 | public void TestOsNpcRemoveUnowned() |
||
321 | { |
||
322 | TestHelpers.InMethod(); |
||
323 | // log4net.Config.XmlConfigurator.Configure(); |
||
324 | |||
325 | // Store an avatar with a different height from default in a notecard. |
||
326 | UUID userId = TestHelpers.ParseTail(0x1); |
||
327 | float newHeight = 1.9f; |
||
328 | |||
329 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); |
||
330 | sp.Appearance.AvatarHeight = newHeight; |
||
331 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10); |
||
332 | SceneObjectPart part = so.RootPart; |
||
333 | m_scene.AddSceneObject(so); |
||
334 | |||
335 | OSSL_Api osslApi = new OSSL_Api(); |
||
336 | osslApi.Initialize(m_engine, part, null, null); |
||
337 | |||
338 | string notecardName = "appearanceNc"; |
||
339 | osslApi.osOwnerSaveAppearance(notecardName); |
||
340 | |||
341 | string npcRaw |
||
342 | = osslApi.osNpcCreate( |
||
343 | "Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName, ScriptBaseClass.OS_NPC_NOT_OWNED); |
||
344 | |||
345 | osslApi.osNpcRemove(npcRaw); |
||
346 | |||
347 | UUID npcId = new UUID(npcRaw); |
||
348 | ScenePresence npc = m_scene.GetScenePresence(npcId); |
||
349 | Assert.That(npc, Is.Null); |
||
350 | } |
||
351 | } |
||
352 | } |