opensim-development – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 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 Nini.Config;
32 using NUnit.Framework;
33 using OpenMetaverse;
34 using OpenSim.Framework;
35 using OpenSim.Framework.Communications;
36 using OpenSim.Region.CoreModules.Framework.EntityTransfer;
37 using OpenSim.Region.CoreModules.Framework.InventoryAccess;
38 using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
39 using OpenSim.Region.CoreModules.World.Permissions;
40 using OpenSim.Region.Framework.Scenes;
41 using OpenSim.Services.Interfaces;
42 using OpenSim.Tests.Common;
43 using OpenSim.Tests.Common.Mock;
44  
45 namespace OpenSim.Region.Framework.Scenes.Tests
46 {
47 /// <summary>
48 /// Tests derez of scene objects.
49 /// </summary>
50 /// <remarks>
51 /// This is at a level above the SceneObjectBasicTests, which act on the scene directly.
52 /// TODO: These tests are incomplete - need to test more kinds of derez (e.g. return object).
53 /// </remarks>
54 [TestFixture]
55 public class SceneObjectDeRezTests : OpenSimTestCase
56 {
57 [TestFixtureSetUp]
58 public void FixtureInit()
59 {
60 // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
61 // This facility was added after the original async delete tests were written, so it may be possible now
62 // to not bother explicitly disabling their async (since everything will be running sync).
63 Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
64 }
65  
66 [TestFixtureTearDown]
67 public void TearDown()
68 {
69 // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
70 // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
71 // tests really shouldn't).
72 Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
73 }
74  
75 /// <summary>
76 /// Test deleting an object from a scene.
77 /// </summary>
78 [Test]
79 public void TestDeRezSceneObject()
80 {
81 TestHelpers.InMethod();
82  
83 UUID userId = UUID.Parse("10000000-0000-0000-0000-000000000001");
84  
85 TestScene scene = new SceneHelpers().SetupScene();
86 SceneHelpers.SetupSceneModules(scene, new PermissionsModule());
87 TestClient client = (TestClient)SceneHelpers.AddScenePresence(scene, userId).ControllingClient;
88  
89 // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
90 AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
91 sogd.Enabled = false;
92  
93 SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, "so1", userId);
94 uint soLocalId = so.LocalId;
95  
96 List<uint> localIds = new List<uint>();
97 localIds.Add(so.LocalId);
98 scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.Delete, UUID.Zero);
99  
100 // Check that object isn't deleted until we crank the sogd handle.
101 SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId);
102 Assert.That(retrievedPart, Is.Not.Null);
103 Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False);
104  
105 sogd.InventoryDeQueueAndDelete();
106  
107 SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId);
108 Assert.That(retrievedPart2, Is.Null);
109  
110 Assert.That(client.ReceivedKills.Count, Is.EqualTo(1));
111 Assert.That(client.ReceivedKills[0], Is.EqualTo(soLocalId));
112 }
113  
114 /// <summary>
115 /// Test that child and root agents correctly receive KillObject notifications.
116 /// </summary>
117 [Test]
118 public void TestDeRezSceneObjectToAgents()
119 {
120 TestHelpers.InMethod();
121 // TestHelpers.EnableLogging();
122  
123 SceneHelpers sh = new SceneHelpers();
124 TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
125 TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999);
126  
127 // We need this so that the creation of the root client for userB in sceneB can trigger the creation of a child client in sceneA
128 LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
129 EntityTransferModule etmB = new EntityTransferModule();
130 IConfigSource config = new IniConfigSource();
131 IConfig modulesConfig = config.AddConfig("Modules");
132 modulesConfig.Set("EntityTransferModule", etmB.Name);
133 modulesConfig.Set("SimulationServices", lscm.Name);
134 SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
135 SceneHelpers.SetupSceneModules(sceneB, config, etmB);
136  
137 // We need this for derez
138 SceneHelpers.SetupSceneModules(sceneA, new PermissionsModule());
139  
140 UserAccount uaA = UserAccountHelpers.CreateUserWithInventory(sceneA, "Andy", "AAA", 0x1, "");
141 UserAccount uaB = UserAccountHelpers.CreateUserWithInventory(sceneA, "Brian", "BBB", 0x2, "");
142  
143 TestClient clientA = (TestClient)SceneHelpers.AddScenePresence(sceneA, uaA).ControllingClient;
144  
145 // This is the more long-winded route we have to take to get a child client created for userB in sceneA
146 // rather than just calling AddScenePresence() as for userA
147 AgentCircuitData acd = SceneHelpers.GenerateAgentData(uaB);
148 TestClient clientB = new TestClient(acd, sceneB);
149 List<TestClient> childClientsB = new List<TestClient>();
150 EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(clientB, childClientsB);
151  
152 SceneHelpers.AddScenePresence(sceneB, clientB, acd);
153  
154 SceneObjectGroup so = SceneHelpers.AddSceneObject(sceneA);
155 uint soLocalId = so.LocalId;
156  
157 sceneA.DeleteSceneObject(so, false);
158  
159 Assert.That(clientA.ReceivedKills.Count, Is.EqualTo(1));
160 Assert.That(clientA.ReceivedKills[0], Is.EqualTo(soLocalId));
161  
162 Assert.That(childClientsB[0].ReceivedKills.Count, Is.EqualTo(1));
163 Assert.That(childClientsB[0].ReceivedKills[0], Is.EqualTo(soLocalId));
164 }
165  
166 /// <summary>
167 /// Test deleting an object from a scene where the deleter is not the owner
168 /// </summary>
169 /// <remarks>
170 /// This test assumes that the deleter is not a god.
171 /// </remarks>
172 [Test]
173 public void TestDeRezSceneObjectNotOwner()
174 {
175 TestHelpers.InMethod();
176 // log4net.Config.XmlConfigurator.Configure();
177  
178 UUID userId = UUID.Parse("10000000-0000-0000-0000-000000000001");
179 UUID objectOwnerId = UUID.Parse("20000000-0000-0000-0000-000000000001");
180  
181 TestScene scene = new SceneHelpers().SetupScene();
182 SceneHelpers.SetupSceneModules(scene, new PermissionsModule());
183 IClientAPI client = SceneHelpers.AddScenePresence(scene, userId).ControllingClient;
184  
185 // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
186 AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
187 sogd.Enabled = false;
188  
189 SceneObjectPart part
190 = new SceneObjectPart(objectOwnerId, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero);
191 part.Name = "obj1";
192 scene.AddNewSceneObject(new SceneObjectGroup(part), false);
193 List<uint> localIds = new List<uint>();
194 localIds.Add(part.LocalId);
195  
196 scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.Delete, UUID.Zero);
197 sogd.InventoryDeQueueAndDelete();
198  
199 // Object should still be in the scene.
200 SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
201 Assert.That(retrievedPart.UUID, Is.EqualTo(part.UUID));
202 }
203  
204 /// <summary>
205 /// Test deleting an object asynchronously to user inventory.
206 /// </summary>
207 [Test]
208 public void TestDeleteSceneObjectAsyncToUserInventory()
209 {
210 TestHelpers.InMethod();
211 // TestHelpers.EnableLogging();
212  
213 UUID agentId = UUID.Parse("00000000-0000-0000-0000-000000000001");
214 string myObjectName = "Fred";
215  
216 TestScene scene = new SceneHelpers().SetupScene();
217  
218 IConfigSource configSource = new IniConfigSource();
219 IConfig config = configSource.AddConfig("Modules");
220 config.Set("InventoryAccessModule", "BasicInventoryAccessModule");
221 SceneHelpers.SetupSceneModules(
222 scene, configSource, new object[] { new BasicInventoryAccessModule() });
223  
224 SceneHelpers.SetupSceneModules(scene, new object[] { });
225  
226 // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
227 AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
228 sogd.Enabled = false;
229  
230 SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, myObjectName, agentId);
231  
232 UserAccount ua = UserAccountHelpers.CreateUserWithInventory(scene, agentId);
233 InventoryFolderBase folder1
234 = UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, ua.PrincipalID, "folder1", false);
235  
236 IClientAPI client = SceneHelpers.AddScenePresence(scene, agentId).ControllingClient;
237 scene.DeRezObjects(client, new List<uint>() { so.LocalId }, UUID.Zero, DeRezAction.Take, folder1.ID);
238  
239 SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId);
240  
241 Assert.That(retrievedPart, Is.Not.Null);
242 Assert.That(so.IsDeleted, Is.False);
243  
244 sogd.InventoryDeQueueAndDelete();
245  
246 Assert.That(so.IsDeleted, Is.True);
247  
248 SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId);
249 Assert.That(retrievedPart2, Is.Null);
250  
251 // SceneSetupHelpers.DeleteSceneObjectAsync(scene, part, DeRezAction.Take, userInfo.RootFolder.ID, client);
252  
253 InventoryItemBase retrievedItem
254 = UserInventoryHelpers.GetInventoryItem(
255 scene.InventoryService, ua.PrincipalID, "folder1/" + myObjectName);
256  
257 // Check that we now have the taken part in our inventory
258 Assert.That(retrievedItem, Is.Not.Null);
259  
260 // Check that the taken part has actually disappeared
261 // SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
262 // Assert.That(retrievedPart, Is.Null);
263 }
264 }
265 }