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