clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
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.Framework.InventoryAccess;
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.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 attachment functions
53 /// </summary>
54 /// <remarks>
55 /// TODO: Add tests for all functions
56 /// </remarks>
57 [TestFixture]
58 public class OSSL_ApiAttachmentTests : OpenSimTestCase
59 {
60 protected Scene m_scene;
61 protected XEngine.XEngine m_engine;
62  
63 [SetUp]
64 public override void SetUp()
65 {
66 base.SetUp();
67  
68 IConfigSource initConfigSource = new IniConfigSource();
69  
70 IConfig xengineConfig = initConfigSource.AddConfig("XEngine");
71 xengineConfig.Set("Enabled", "true");
72 xengineConfig.Set("AllowOSFunctions", "true");
73 xengineConfig.Set("OSFunctionThreatLevel", "Severe");
74  
75 IConfig modulesConfig = initConfigSource.AddConfig("Modules");
76 modulesConfig.Set("InventoryAccessModule", "BasicInventoryAccessModule");
77  
78 m_scene = new SceneHelpers().SetupScene();
79 SceneHelpers.SetupSceneModules(
80 m_scene, initConfigSource, new AttachmentsModule(), new BasicInventoryAccessModule());
81  
82 m_engine = new XEngine.XEngine();
83 m_engine.Initialise(initConfigSource);
84 m_engine.AddRegion(m_scene);
85 }
86  
87 [Test]
88 public void TestOsForceAttachToAvatarFromInventory()
89 {
90 TestHelpers.InMethod();
91 // TestHelpers.EnableLogging();
92  
93 string taskInvObjItemName = "sphere";
94 UUID taskInvObjItemId = UUID.Parse("00000000-0000-0000-0000-100000000000");
95 AttachmentPoint attachPoint = AttachmentPoint.Chin;
96  
97 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(m_scene, 0x1);
98 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, ua1.PrincipalID);
99 SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID);
100 TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, inWorldObj.RootPart);
101  
102 new LSL_Api().Initialize(m_engine, inWorldObj.RootPart, scriptItem, null);
103 OSSL_Api osslApi = new OSSL_Api();
104 osslApi.Initialize(m_engine, inWorldObj.RootPart, scriptItem, null);
105  
106 // SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, ua1.PrincipalID);
107  
108 // Create an object embedded inside the first
109 TaskInventoryHelpers.AddSceneObject(m_scene, inWorldObj.RootPart, taskInvObjItemName, taskInvObjItemId, ua1.PrincipalID);
110  
111 osslApi.osForceAttachToAvatarFromInventory(taskInvObjItemName, (int)attachPoint);
112  
113 // Check scene presence status
114 Assert.That(sp.HasAttachments(), Is.True);
115 List<SceneObjectGroup> attachments = sp.GetAttachments();
116 Assert.That(attachments.Count, Is.EqualTo(1));
117 SceneObjectGroup attSo = attachments[0];
118 Assert.That(attSo.Name, Is.EqualTo(taskInvObjItemName));
119 Assert.That(attSo.AttachmentPoint, Is.EqualTo((uint)attachPoint));
120 Assert.That(attSo.IsAttachment);
121 Assert.That(attSo.UsesPhysics, Is.False);
122 Assert.That(attSo.IsTemporary, Is.False);
123  
124 // Check appearance status
125 List<AvatarAttachment> attachmentsInAppearance = sp.Appearance.GetAttachments();
126 Assert.That(attachmentsInAppearance.Count, Is.EqualTo(1));
127 Assert.That(sp.Appearance.GetAttachpoint(attachmentsInAppearance[0].ItemID), Is.EqualTo((uint)attachPoint));
128 }
129  
130 /// <summary>
131 /// Make sure we can't force attach anything other than objects.
132 /// </summary>
133 [Test]
134 public void TestOsForceAttachToAvatarFromInventoryNotObject()
135 {
136 TestHelpers.InMethod();
137 // TestHelpers.EnableLogging();
138  
139 string taskInvObjItemName = "sphere";
140 UUID taskInvObjItemId = UUID.Parse("00000000-0000-0000-0000-100000000000");
141 AttachmentPoint attachPoint = AttachmentPoint.Chin;
142  
143 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(m_scene, 0x1);
144 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, ua1.PrincipalID);
145 SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID);
146 TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, inWorldObj.RootPart);
147  
148 new LSL_Api().Initialize(m_engine, inWorldObj.RootPart, scriptItem, null);
149 OSSL_Api osslApi = new OSSL_Api();
150 osslApi.Initialize(m_engine, inWorldObj.RootPart, scriptItem, null);
151  
152 // Create an object embedded inside the first
153 TaskInventoryHelpers.AddNotecard(
154 m_scene, inWorldObj.RootPart, taskInvObjItemName, taskInvObjItemId, TestHelpers.ParseTail(0x900), "Hello World!");
155  
156 bool exceptionCaught = false;
157  
158 try
159 {
160 osslApi.osForceAttachToAvatarFromInventory(taskInvObjItemName, (int)attachPoint);
161 }
162 catch (Exception)
163 {
164 exceptionCaught = true;
165 }
166  
167 Assert.That(exceptionCaught, Is.True);
168  
169 // Check scene presence status
170 Assert.That(sp.HasAttachments(), Is.False);
171 List<SceneObjectGroup> attachments = sp.GetAttachments();
172 Assert.That(attachments.Count, Is.EqualTo(0));
173  
174 // Check appearance status
175 List<AvatarAttachment> attachmentsInAppearance = sp.Appearance.GetAttachments();
176 Assert.That(attachmentsInAppearance.Count, Is.EqualTo(0));
177 }
178  
179 [Test]
180 public void TestOsForceAttachToOtherAvatarFromInventory()
181 {
182 TestHelpers.InMethod();
183 // TestHelpers.EnableLogging();
184  
185 string taskInvObjItemName = "sphere";
186 UUID taskInvObjItemId = UUID.Parse("00000000-0000-0000-0000-100000000000");
187 AttachmentPoint attachPoint = AttachmentPoint.Chin;
188  
189 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(m_scene, "user", "one", 0x1, "pass");
190 UserAccount ua2 = UserAccountHelpers.CreateUserWithInventory(m_scene, "user", "two", 0x2, "pass");
191  
192 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, ua1);
193 SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID);
194 TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, inWorldObj.RootPart);
195  
196 new LSL_Api().Initialize(m_engine, inWorldObj.RootPart, scriptItem, null);
197 OSSL_Api osslApi = new OSSL_Api();
198 osslApi.Initialize(m_engine, inWorldObj.RootPart, scriptItem, null);
199  
200 // Create an object embedded inside the first
201 TaskInventoryHelpers.AddSceneObject(
202 m_scene, inWorldObj.RootPart, taskInvObjItemName, taskInvObjItemId, ua1.PrincipalID);
203  
204 ScenePresence sp2 = SceneHelpers.AddScenePresence(m_scene, ua2);
205  
206 osslApi.osForceAttachToOtherAvatarFromInventory(sp2.UUID.ToString(), taskInvObjItemName, (int)attachPoint);
207  
208 // Check scene presence status
209 Assert.That(sp.HasAttachments(), Is.False);
210 List<SceneObjectGroup> attachments = sp.GetAttachments();
211 Assert.That(attachments.Count, Is.EqualTo(0));
212  
213 Assert.That(sp2.HasAttachments(), Is.True);
214 List<SceneObjectGroup> attachments2 = sp2.GetAttachments();
215 Assert.That(attachments2.Count, Is.EqualTo(1));
216 SceneObjectGroup attSo = attachments2[0];
217 Assert.That(attSo.Name, Is.EqualTo(taskInvObjItemName));
218 Assert.That(attSo.OwnerID, Is.EqualTo(ua2.PrincipalID));
219 Assert.That(attSo.AttachmentPoint, Is.EqualTo((uint)attachPoint));
220 Assert.That(attSo.IsAttachment);
221 Assert.That(attSo.UsesPhysics, Is.False);
222 Assert.That(attSo.IsTemporary, Is.False);
223  
224 // Check appearance status
225 List<AvatarAttachment> attachmentsInAppearance = sp.Appearance.GetAttachments();
226 Assert.That(attachmentsInAppearance.Count, Is.EqualTo(0));
227  
228 List<AvatarAttachment> attachmentsInAppearance2 = sp2.Appearance.GetAttachments();
229 Assert.That(attachmentsInAppearance2.Count, Is.EqualTo(1));
230 Assert.That(sp2.Appearance.GetAttachpoint(attachmentsInAppearance2[0].ItemID), Is.EqualTo((uint)attachPoint));
231 }
232 }
233 }