OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
OSSL_ApiNpcTests.cs
Go to the documentation of this file.
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 
50 namespace OpenSim.Region.ScriptEngine.Shared.Tests
51 {
55  [TestFixture]
57  {
58  protected Scene m_scene;
60 
61  [SetUp]
62  public override void SetUp()
63  {
64  base.SetUp();
65 
66  IConfigSource initConfigSource = new IniConfigSource();
67  IConfig config = initConfigSource.AddConfig("XEngine");
68  config.Set("Enabled", "true");
69  config.Set("AllowOSFunctions", "true");
70  config.Set("OSFunctionThreatLevel", "Severe");
71  config = initConfigSource.AddConfig("NPC");
72  config.Set("Enabled", "true");
73 
74  m_scene = new SceneHelpers().SetupScene();
75  SceneHelpers.SetupSceneModules(
76  m_scene, initConfigSource, new AvatarFactoryModule(), new AttachmentsModule(), new NPCModule());
77 
78  m_engine = new XEngine.XEngine();
79  m_engine.Initialise(initConfigSource);
80  m_engine.AddRegion(m_scene);
81  }
82 
86  [Test]
88  {
89  TestHelpers.InMethod();
90 
91  // Store an avatar with a different height from default in a notecard.
92  UUID userId = TestHelpers.ParseTail(0x1);
93  float newHeight = 1.9f;
94 
95  ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
96  sp.Appearance.AvatarHeight = newHeight;
97  SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
98  SceneObjectPart part = so.RootPart;
99  m_scene.AddSceneObject(so);
100 
101  OSSL_Api osslApi = new OSSL_Api();
102  osslApi.Initialize(m_engine, part, null);
103 
104  string notecardName = "appearanceNc";
105  osslApi.osOwnerSaveAppearance(notecardName);
106 
107  // Try creating a bot using the appearance in the notecard.
108  string npcRaw = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName);
109  Assert.That(npcRaw, Is.Not.Null);
110 
111  UUID npcId = new UUID(npcRaw);
112  ScenePresence npc = m_scene.GetScenePresence(npcId);
113  Assert.That(npc, Is.Not.Null);
114  Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(newHeight));
115  }
116 
117  [Test]
119  {
120  TestHelpers.InMethod();
121 
122  UUID userId = TestHelpers.ParseTail(0x1);
123 
124  SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
125  m_scene.AddSceneObject(so);
126 
127  OSSL_Api osslApi = new OSSL_Api();
128  osslApi.Initialize(m_engine, so.RootPart, null);
129 
130  bool gotExpectedException = false;
131  try
132  {
133  osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), "not existing notecard name");
134  }
135  catch (ScriptException)
136  {
137  gotExpectedException = true;
138  }
139 
140  Assert.That(gotExpectedException, Is.True);
141  }
142 
146  [Test]
148  {
149  TestHelpers.InMethod();
150 // TestHelpers.EnableLogging();
151 
152  // Store an avatar with a different height from default in a notecard.
153  UUID userId = TestHelpers.ParseTail(0x1);
154  float newHeight = 1.9f;
155 
156  ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
157  sp.Appearance.AvatarHeight = newHeight;
158  SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
159  SceneObjectPart part = so.RootPart;
160  m_scene.AddSceneObject(so);
161 
162  OSSL_Api osslApi = new OSSL_Api();
163  osslApi.Initialize(m_engine, part, null);
164 
165  string notecardName = "appearanceNc";
166  osslApi.osOwnerSaveAppearance(notecardName);
167 
168  // Try creating a bot using the existing avatar's appearance
169  string npcRaw = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), sp.UUID.ToString());
170  Assert.That(npcRaw, Is.Not.Null);
171 
172  UUID npcId = new UUID(npcRaw);
173  ScenePresence npc = m_scene.GetScenePresence(npcId);
174  Assert.That(npc, Is.Not.Null);
175  Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(newHeight));
176  }
177 
178  [Test]
180  {
181  TestHelpers.InMethod();
182  //TestHelpers.EnableLogging();
183 
184  // Store an avatar with a different height from default in a notecard.
185  UUID userId = TestHelpers.ParseTail(0x1);
186  float firstHeight = 1.9f;
187  float secondHeight = 2.1f;
188  string firstAppearanceNcName = "appearanceNc1";
189  string secondAppearanceNcName = "appearanceNc2";
190 
191  ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
192  sp.Appearance.AvatarHeight = firstHeight;
193  SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
194  SceneObjectPart part = so.RootPart;
195  m_scene.AddSceneObject(so);
196 
197  OSSL_Api osslApi = new OSSL_Api();
198  osslApi.Initialize(m_engine, part, null);
199 
200  osslApi.osOwnerSaveAppearance(firstAppearanceNcName);
201 
202  string npcRaw
203  = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), firstAppearanceNcName);
204 
205  // Create a second appearance notecard with a different height
206  sp.Appearance.AvatarHeight = secondHeight;
207  osslApi.osOwnerSaveAppearance(secondAppearanceNcName);
208 
209  osslApi.osNpcLoadAppearance(npcRaw, secondAppearanceNcName);
210 
211  UUID npcId = new UUID(npcRaw);
212  ScenePresence npc = m_scene.GetScenePresence(npcId);
213  Assert.That(npc, Is.Not.Null);
214  Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(secondHeight));
215  }
216 
217  [Test]
219  {
220  TestHelpers.InMethod();
221 
222  // Store an avatar with a different height from default in a notecard.
223  UUID userId = TestHelpers.ParseTail(0x1);
224  float firstHeight = 1.9f;
225 // float secondHeight = 2.1f;
226  string firstAppearanceNcName = "appearanceNc1";
227  string secondAppearanceNcName = "appearanceNc2";
228 
229  ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
230  sp.Appearance.AvatarHeight = firstHeight;
231  SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
232  SceneObjectPart part = so.RootPart;
233  m_scene.AddSceneObject(so);
234 
235  OSSL_Api osslApi = new OSSL_Api();
236  osslApi.Initialize(m_engine, part, null);
237 
238  osslApi.osOwnerSaveAppearance(firstAppearanceNcName);
239 
240  string npcRaw
241  = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), firstAppearanceNcName);
242 
243  bool gotExpectedException = false;
244  try
245  {
246  osslApi.osNpcLoadAppearance(npcRaw, secondAppearanceNcName);
247  }
248  catch (ScriptException)
249  {
250  gotExpectedException = true;
251  }
252 
253  Assert.That(gotExpectedException, Is.True);
254 
255  UUID npcId = new UUID(npcRaw);
256  ScenePresence npc = m_scene.GetScenePresence(npcId);
257  Assert.That(npc, Is.Not.Null);
258  Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(firstHeight));
259  }
260 
264  [Test]
265  public void TestOsNpcRemoveOwned()
266  {
267  TestHelpers.InMethod();
268 
269  // Store an avatar with a different height from default in a notecard.
270  UUID userId = TestHelpers.ParseTail(0x1);
271  UUID otherUserId = TestHelpers.ParseTail(0x2);
272  float newHeight = 1.9f;
273 
274  SceneHelpers.AddScenePresence(m_scene, otherUserId);
275 
276  ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
277  sp.Appearance.AvatarHeight = newHeight;
278 
279  SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
280  SceneObjectPart part = so.RootPart;
281  m_scene.AddSceneObject(so);
282 
283  SceneObjectGroup otherSo = SceneHelpers.CreateSceneObject(1, otherUserId, 0x20);
284  SceneObjectPart otherPart = otherSo.RootPart;
285  m_scene.AddSceneObject(otherSo);
286 
287  OSSL_Api osslApi = new OSSL_Api();
288  osslApi.Initialize(m_engine, part, null);
289 
290  OSSL_Api otherOsslApi = new OSSL_Api();
291  otherOsslApi.Initialize(m_engine, otherPart, null);
292 
293  string notecardName = "appearanceNc";
294  osslApi.osOwnerSaveAppearance(notecardName);
295 
296  string npcRaw
297  = osslApi.osNpcCreate(
298  "Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName, ScriptBaseClass.OS_NPC_CREATOR_OWNED);
299 
300  otherOsslApi.osNpcRemove(npcRaw);
301 
302  // Should still be around
303  UUID npcId = new UUID(npcRaw);
304  ScenePresence npc = m_scene.GetScenePresence(npcId);
305  Assert.That(npc, Is.Not.Null);
306 
307  osslApi.osNpcRemove(npcRaw);
308 
309  npc = m_scene.GetScenePresence(npcId);
310 
311  // Now the owner deleted it and it's gone
312  Assert.That(npc, Is.Null);
313  }
314 
318  [Test]
320  {
321  TestHelpers.InMethod();
322 // log4net.Config.XmlConfigurator.Configure();
323 
324  // Store an avatar with a different height from default in a notecard.
325  UUID userId = TestHelpers.ParseTail(0x1);
326  float newHeight = 1.9f;
327 
328  ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
329  sp.Appearance.AvatarHeight = newHeight;
330  SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
331  SceneObjectPart part = so.RootPart;
332  m_scene.AddSceneObject(so);
333 
334  OSSL_Api osslApi = new OSSL_Api();
335  osslApi.Initialize(m_engine, part, null);
336 
337  string notecardName = "appearanceNc";
338  osslApi.osOwnerSaveAppearance(notecardName);
339 
340  string npcRaw
341  = osslApi.osNpcCreate(
342  "Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName, ScriptBaseClass.OS_NPC_NOT_OWNED);
343 
344  osslApi.osNpcRemove(npcRaw);
345 
346  UUID npcId = new UUID(npcRaw);
347  ScenePresence npc = m_scene.GetScenePresence(npcId);
348  Assert.That(npc, Is.Null);
349  }
350  }
351 }
void TestOsNpcCreateUsingAppearanceFromAvatar()
Test creation of an NPC where the appearance data comes from an avatar already in the region...
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60
void TestOsNpcCreateUsingAppearanceFromNotecard()
Test creation of an NPC where the appearance data comes from a notecard