SceneObjectDeRezTests.cs 12 KB

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