OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
LSL_ApiLinkingTests.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.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.Instance;
45 using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
46 using OpenSim.Services.Interfaces;
47 using OpenSim.Tests.Common;
48 
49 namespace OpenSim.Region.ScriptEngine.Shared.Tests
50 {
58  [TestFixture]
60  {
61  protected Scene m_scene;
63 
64  [SetUp]
65  public override void SetUp()
66  {
67  base.SetUp();
68 
69  IConfigSource initConfigSource = new IniConfigSource();
70  IConfig config = initConfigSource.AddConfig("XEngine");
71  config.Set("Enabled", "true");
72 
73  m_scene = new SceneHelpers().SetupScene();
74  SceneHelpers.SetupSceneModules(m_scene, initConfigSource);
75 
76  m_engine = new XEngine.XEngine();
77  m_engine.Initialise(initConfigSource);
78  m_engine.AddRegion(m_scene);
79  }
80 
81  [Test]
82  public void TestllCreateLink()
83  {
84  TestHelpers.InMethod();
85 
86  UUID ownerId = TestHelpers.ParseTail(0x1);
87 
88  SceneObjectGroup grp1 = SceneHelpers.CreateSceneObject(2, ownerId, "grp1-", 0x10);
89  grp1.AbsolutePosition = new Vector3(10, 10, 10);
90  m_scene.AddSceneObject(grp1);
91 
92  // FIXME: This should really be a script item (with accompanying script)
93  TaskInventoryItem grp1Item
94  = TaskInventoryHelpers.AddNotecard(
95  m_scene.AssetService, grp1.RootPart, "ncItem", TestHelpers.ParseTail(0x800), TestHelpers.ParseTail(0x900), "Hello World!");
96  grp1Item.PermsMask |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
97 
98  SceneObjectGroup grp2 = SceneHelpers.CreateSceneObject(2, ownerId, "grp2-", 0x20);
99  grp2.AbsolutePosition = new Vector3(20, 20, 20);
100 
101  // <180,0,0>
102  grp2.UpdateGroupRotationR(Quaternion.CreateFromEulers(180 * Utils.DEG_TO_RAD, 0, 0));
103 
104  m_scene.AddSceneObject(grp2);
105 
106  LSL_Api apiGrp1 = new LSL_Api();
107  apiGrp1.Initialize(m_engine, grp1.RootPart, grp1Item);
108 
109  apiGrp1.llCreateLink(grp2.UUID.ToString(), ScriptBaseClass.TRUE);
110 
111  Assert.That(grp1.Parts.Length, Is.EqualTo(4));
112  Assert.That(grp2.IsDeleted, Is.True);
113  }
114 
115  [Test]
116  public void TestllBreakLink()
117  {
118  TestHelpers.InMethod();
119 
120  UUID ownerId = TestHelpers.ParseTail(0x1);
121 
122  SceneObjectGroup grp1 = SceneHelpers.CreateSceneObject(2, ownerId, "grp1-", 0x10);
123  grp1.AbsolutePosition = new Vector3(10, 10, 10);
124  m_scene.AddSceneObject(grp1);
125 
126  // FIXME: This should really be a script item (with accompanying script)
127  TaskInventoryItem grp1Item
128  = TaskInventoryHelpers.AddNotecard(
129  m_scene.AssetService, grp1.RootPart, "ncItem", TestHelpers.ParseTail(0x800), TestHelpers.ParseTail(0x900), "Hello World!");
130 
131  grp1Item.PermsMask |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
132 
133  LSL_Api apiGrp1 = new LSL_Api();
134  apiGrp1.Initialize(m_engine, grp1.RootPart, grp1Item);
135 
136  apiGrp1.llBreakLink(2);
137 
138  Assert.That(grp1.Parts.Length, Is.EqualTo(1));
139 
140  SceneObjectGroup grp2 = m_scene.GetSceneObjectGroup("grp1-Part1");
141  Assert.That(grp2, Is.Not.Null);
142  }
143 
144  [Test]
145  public void TestllBreakAllLinks()
146  {
147  TestHelpers.InMethod();
148 
149  UUID ownerId = TestHelpers.ParseTail(0x1);
150 
151  SceneObjectGroup grp1 = SceneHelpers.CreateSceneObject(3, ownerId, "grp1-", 0x10);
152  grp1.AbsolutePosition = new Vector3(10, 10, 10);
153  m_scene.AddSceneObject(grp1);
154 
155  // FIXME: This should really be a script item (with accompanying script)
156  TaskInventoryItem grp1Item
157  = TaskInventoryHelpers.AddNotecard(
158  m_scene.AssetService, grp1.RootPart, "ncItem", TestHelpers.ParseTail(0x800), TestHelpers.ParseTail(0x900), "Hello World!");
159 
160  grp1Item.PermsMask |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
161 
162  LSL_Api apiGrp1 = new LSL_Api();
163  apiGrp1.Initialize(m_engine, grp1.RootPart, grp1Item);
164 
165  apiGrp1.llBreakAllLinks();
166 
167  {
168  SceneObjectGroup nowGrp = m_scene.GetSceneObjectGroup("grp1-Part1");
169  Assert.That(nowGrp, Is.Not.Null);
170  Assert.That(nowGrp.Parts.Length, Is.EqualTo(1));
171  }
172 
173  {
174  SceneObjectGroup nowGrp = m_scene.GetSceneObjectGroup("grp1-Part2");
175  Assert.That(nowGrp, Is.Not.Null);
176  Assert.That(nowGrp.Parts.Length, Is.EqualTo(1));
177  }
178 
179  {
180  SceneObjectGroup nowGrp = m_scene.GetSceneObjectGroup("grp1-Part3");
181  Assert.That(nowGrp, Is.Not.Null);
182  Assert.That(nowGrp.Parts.Length, Is.EqualTo(1));
183  }
184  }
185  }
186 }
Contains all LSL ll-functions. This class will be in Default AppDomain.
Definition: LSL_Api.cs:95
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
Represents an item in a task inventory
static UUID ParseTail(int tail)
Parse tail section into full UUID.
Definition: TestHelpers.cs:140
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60