aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAttachmentTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAttachmentTests.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAttachmentTests.cs231
1 files changed, 231 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAttachmentTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAttachmentTests.cs
new file mode 100644
index 0000000..5ed1f3d
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAttachmentTests.cs
@@ -0,0 +1,231 @@
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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Text;
32using log4net;
33using Nini.Config;
34using NUnit.Framework;
35using OpenMetaverse;
36using OpenMetaverse.Assets;
37using OpenMetaverse.StructuredData;
38using OpenSim.Framework;
39using OpenSim.Region.CoreModules.Avatar.Attachments;
40using OpenSim.Region.CoreModules.Framework.InventoryAccess;
41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.ScriptEngine.Shared;
43using OpenSim.Region.ScriptEngine.Shared.Api;
44using OpenSim.Services.Interfaces;
45using OpenSim.Tests.Common;
46using OpenSim.Tests.Common.Mock;
47
48namespace OpenSim.Region.ScriptEngine.Shared.Tests
49{
50 /// <summary>
51 /// Tests for OSSL attachment functions
52 /// </summary>
53 /// <remarks>
54 /// TODO: Add tests for all functions
55 /// </remarks>
56 [TestFixture]
57 public class OSSL_ApiAttachmentTests : 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
69 IConfig xengineConfig = initConfigSource.AddConfig("XEngine");
70 xengineConfig.Set("Enabled", "true");
71 xengineConfig.Set("AllowOSFunctions", "true");
72 xengineConfig.Set("OSFunctionThreatLevel", "Severe");
73
74 IConfig modulesConfig = initConfigSource.AddConfig("Modules");
75 modulesConfig.Set("InventoryAccessModule", "BasicInventoryAccessModule");
76
77 m_scene = new SceneHelpers().SetupScene();
78 SceneHelpers.SetupSceneModules(
79 m_scene, initConfigSource, new AttachmentsModule(), new BasicInventoryAccessModule());
80
81 m_engine = new XEngine.XEngine();
82 m_engine.Initialise(initConfigSource);
83 m_engine.AddRegion(m_scene);
84 }
85
86 [Test]
87 public void TestOsForceAttachToAvatarFromInventory()
88 {
89 TestHelpers.InMethod();
90// TestHelpers.EnableLogging();
91
92 string taskInvObjItemName = "sphere";
93 UUID taskInvObjItemId = UUID.Parse("00000000-0000-0000-0000-100000000000");
94 AttachmentPoint attachPoint = AttachmentPoint.Chin;
95
96 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(m_scene, 0x1);
97 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, ua1.PrincipalID);
98 SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID);
99 TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, inWorldObj.RootPart);
100
101 new LSL_Api().Initialize(m_engine, inWorldObj.RootPart, scriptItem);
102 OSSL_Api osslApi = new OSSL_Api();
103 osslApi.Initialize(m_engine, inWorldObj.RootPart, scriptItem);
104
105// SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, ua1.PrincipalID);
106
107 // Create an object embedded inside the first
108 TaskInventoryHelpers.AddSceneObject(m_scene, inWorldObj.RootPart, taskInvObjItemName, taskInvObjItemId, ua1.PrincipalID);
109
110 osslApi.osForceAttachToAvatarFromInventory(taskInvObjItemName, (int)attachPoint);
111
112 // Check scene presence status
113 Assert.That(sp.HasAttachments(), Is.True);
114 List<SceneObjectGroup> attachments = sp.GetAttachments();
115 Assert.That(attachments.Count, Is.EqualTo(1));
116 SceneObjectGroup attSo = attachments[0];
117 Assert.That(attSo.Name, Is.EqualTo(taskInvObjItemName));
118 Assert.That(attSo.AttachmentPoint, Is.EqualTo((uint)attachPoint));
119 Assert.That(attSo.IsAttachment);
120 Assert.That(attSo.UsesPhysics, Is.False);
121 Assert.That(attSo.IsTemporary, Is.False);
122
123 // Check appearance status
124 List<AvatarAttachment> attachmentsInAppearance = sp.Appearance.GetAttachments();
125 Assert.That(attachmentsInAppearance.Count, Is.EqualTo(1));
126 Assert.That(sp.Appearance.GetAttachpoint(attachmentsInAppearance[0].ItemID), Is.EqualTo((uint)attachPoint));
127 }
128
129 /// <summary>
130 /// Make sure we can't force attach anything other than objects.
131 /// </summary>
132 [Test]
133 public void TestOsForceAttachToAvatarFromInventoryNotObject()
134 {
135 TestHelpers.InMethod();
136// TestHelpers.EnableLogging();
137
138 string taskInvObjItemName = "sphere";
139 UUID taskInvObjItemId = UUID.Parse("00000000-0000-0000-0000-100000000000");
140 AttachmentPoint attachPoint = AttachmentPoint.Chin;
141
142 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(m_scene, 0x1);
143 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, ua1.PrincipalID);
144 SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID);
145 TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, inWorldObj.RootPart);
146
147 new LSL_Api().Initialize(m_engine, inWorldObj.RootPart, scriptItem);
148 OSSL_Api osslApi = new OSSL_Api();
149 osslApi.Initialize(m_engine, inWorldObj.RootPart, scriptItem);
150
151 // Create an object embedded inside the first
152 TaskInventoryHelpers.AddNotecard(
153 m_scene, inWorldObj.RootPart, taskInvObjItemName, taskInvObjItemId, TestHelpers.ParseTail(0x900));
154
155 bool exceptionCaught = false;
156
157 try
158 {
159 osslApi.osForceAttachToAvatarFromInventory(taskInvObjItemName, (int)attachPoint);
160 }
161 catch (Exception)
162 {
163 exceptionCaught = true;
164 }
165
166 Assert.That(exceptionCaught, Is.True);
167
168 // Check scene presence status
169 Assert.That(sp.HasAttachments(), Is.False);
170 List<SceneObjectGroup> attachments = sp.GetAttachments();
171 Assert.That(attachments.Count, Is.EqualTo(0));
172
173 // Check appearance status
174 List<AvatarAttachment> attachmentsInAppearance = sp.Appearance.GetAttachments();
175 Assert.That(attachmentsInAppearance.Count, Is.EqualTo(0));
176 }
177
178 [Test]
179 public void TestOsForceAttachToOtherAvatarFromInventory()
180 {
181 TestHelpers.InMethod();
182// TestHelpers.EnableLogging();
183
184 string taskInvObjItemName = "sphere";
185 UUID taskInvObjItemId = UUID.Parse("00000000-0000-0000-0000-100000000000");
186 AttachmentPoint attachPoint = AttachmentPoint.Chin;
187
188 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(m_scene, "user", "one", 0x1, "pass");
189 UserAccount ua2 = UserAccountHelpers.CreateUserWithInventory(m_scene, "user", "two", 0x2, "pass");
190
191 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, ua1);
192 SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID);
193 TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, inWorldObj.RootPart);
194
195 new LSL_Api().Initialize(m_engine, inWorldObj.RootPart, scriptItem);
196 OSSL_Api osslApi = new OSSL_Api();
197 osslApi.Initialize(m_engine, inWorldObj.RootPart, scriptItem);
198
199 // Create an object embedded inside the first
200 TaskInventoryHelpers.AddSceneObject(m_scene, inWorldObj.RootPart, taskInvObjItemName, taskInvObjItemId, ua1.PrincipalID);
201
202 ScenePresence sp2 = SceneHelpers.AddScenePresence(m_scene, ua2);
203
204 osslApi.osForceAttachToOtherAvatarFromInventory(sp2.UUID.ToString(), taskInvObjItemName, (int)attachPoint);
205
206 // Check scene presence status
207 Assert.That(sp.HasAttachments(), Is.False);
208 List<SceneObjectGroup> attachments = sp.GetAttachments();
209 Assert.That(attachments.Count, Is.EqualTo(0));
210
211 Assert.That(sp2.HasAttachments(), Is.True);
212 List<SceneObjectGroup> attachments2 = sp2.GetAttachments();
213 Assert.That(attachments2.Count, Is.EqualTo(1));
214 SceneObjectGroup attSo = attachments2[0];
215 Assert.That(attSo.Name, Is.EqualTo(taskInvObjItemName));
216 Assert.That(attSo.OwnerID, Is.EqualTo(ua2.PrincipalID));
217 Assert.That(attSo.AttachmentPoint, Is.EqualTo((uint)attachPoint));
218 Assert.That(attSo.IsAttachment);
219 Assert.That(attSo.UsesPhysics, Is.False);
220 Assert.That(attSo.IsTemporary, Is.False);
221
222 // Check appearance status
223 List<AvatarAttachment> attachmentsInAppearance = sp.Appearance.GetAttachments();
224 Assert.That(attachmentsInAppearance.Count, Is.EqualTo(0));
225
226 List<AvatarAttachment> attachmentsInAppearance2 = sp2.Appearance.GetAttachments();
227 Assert.That(attachmentsInAppearance2.Count, Is.EqualTo(1));
228 Assert.That(sp2.Appearance.GetAttachpoint(attachmentsInAppearance2[0].ItemID), Is.EqualTo((uint)attachPoint));
229 }
230 }
231} \ No newline at end of file