SceneObjectDeRezTests.cs 12 KB

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