SceneObjectDeRezTests.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. namespace OpenSim.Region.Framework.Scenes.Tests
  43. {
  44. /// <summary>
  45. /// Tests derez of scene objects.
  46. /// </summary>
  47. /// <remarks>
  48. /// This is at a level above the SceneObjectBasicTests, which act on the scene directly.
  49. /// TODO: These tests are incomplete - need to test more kinds of derez (e.g. return object).
  50. /// </remarks>
  51. [TestFixture]
  52. public class SceneObjectDeRezTests : OpenSimTestCase
  53. {
  54. [TestFixtureSetUp]
  55. public void FixtureInit()
  56. {
  57. // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
  58. // This facility was added after the original async delete tests were written, so it may be possible now
  59. // to not bother explicitly disabling their async (since everything will be running sync).
  60. Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
  61. }
  62. [TestFixtureTearDown]
  63. public void TearDown()
  64. {
  65. // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
  66. // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
  67. // tests really shouldn't).
  68. Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
  69. }
  70. /// <summary>
  71. /// Test deleting an object from a scene.
  72. /// </summary>
  73. [Test]
  74. public void TestDeRezSceneObject()
  75. {
  76. TestHelpers.InMethod();
  77. UUID userId = UUID.Parse("10000000-0000-0000-0000-000000000001");
  78. TestScene scene = new SceneHelpers().SetupScene();
  79. SceneHelpers.SetupSceneModules(scene, new PermissionsModule());
  80. TestClient client = (TestClient)SceneHelpers.AddScenePresence(scene, userId).ControllingClient;
  81. // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
  82. AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
  83. sogd.Enabled = false;
  84. SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, "so1", userId);
  85. uint soLocalId = so.LocalId;
  86. List<uint> localIds = new List<uint>();
  87. localIds.Add(so.LocalId);
  88. scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.Delete, UUID.Zero);
  89. // Check that object isn't deleted until we crank the sogd handle.
  90. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId);
  91. Assert.That(retrievedPart, Is.Not.Null);
  92. Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False);
  93. sogd.InventoryDeQueueAndDelete();
  94. SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId);
  95. Assert.That(retrievedPart2, Is.Null);
  96. Assert.That(client.ReceivedKills.Count, Is.EqualTo(1));
  97. Assert.That(client.ReceivedKills[0], Is.EqualTo(soLocalId));
  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. Assert.That(clientA.ReceivedKills.Count, Is.EqualTo(1));
  135. Assert.That(clientA.ReceivedKills[0], Is.EqualTo(soLocalId));
  136. Assert.That(childClientsB[0].ReceivedKills.Count, Is.EqualTo(1));
  137. Assert.That(childClientsB[0].ReceivedKills[0], Is.EqualTo(soLocalId));
  138. }
  139. /// <summary>
  140. /// Test deleting an object from a scene where the deleter is not the owner
  141. /// </summary>
  142. /// <remarks>
  143. /// This test assumes that the deleter is not a god.
  144. /// </remarks>
  145. [Test]
  146. public void TestDeRezSceneObjectNotOwner()
  147. {
  148. TestHelpers.InMethod();
  149. // log4net.Config.XmlConfigurator.Configure();
  150. UUID userId = UUID.Parse("10000000-0000-0000-0000-000000000001");
  151. UUID objectOwnerId = UUID.Parse("20000000-0000-0000-0000-000000000001");
  152. TestScene scene = new SceneHelpers().SetupScene();
  153. SceneHelpers.SetupSceneModules(scene, new PermissionsModule());
  154. IClientAPI client = SceneHelpers.AddScenePresence(scene, userId).ControllingClient;
  155. // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
  156. AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
  157. sogd.Enabled = false;
  158. SceneObjectPart part
  159. = new SceneObjectPart(objectOwnerId, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero);
  160. part.Name = "obj1";
  161. scene.AddNewSceneObject(new SceneObjectGroup(part), false);
  162. List<uint> localIds = new List<uint>();
  163. localIds.Add(part.LocalId);
  164. scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.Delete, UUID.Zero);
  165. sogd.InventoryDeQueueAndDelete();
  166. // Object should still be in the scene.
  167. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
  168. Assert.That(retrievedPart.UUID, Is.EqualTo(part.UUID));
  169. }
  170. /// <summary>
  171. /// Test deleting an object asynchronously to user inventory.
  172. /// </summary>
  173. [Test]
  174. public void TestDeleteSceneObjectAsyncToUserInventory()
  175. {
  176. TestHelpers.InMethod();
  177. // TestHelpers.EnableLogging();
  178. UUID agentId = UUID.Parse("00000000-0000-0000-0000-000000000001");
  179. string myObjectName = "Fred";
  180. TestScene scene = new SceneHelpers().SetupScene();
  181. IConfigSource configSource = new IniConfigSource();
  182. IConfig config = configSource.AddConfig("Modules");
  183. config.Set("InventoryAccessModule", "BasicInventoryAccessModule");
  184. SceneHelpers.SetupSceneModules(
  185. scene, configSource, new object[] { new BasicInventoryAccessModule() });
  186. SceneHelpers.SetupSceneModules(scene, new object[] { });
  187. // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
  188. AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
  189. sogd.Enabled = false;
  190. SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, myObjectName, agentId);
  191. UserAccount ua = UserAccountHelpers.CreateUserWithInventory(scene, agentId);
  192. InventoryFolderBase folder1
  193. = UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, ua.PrincipalID, "folder1", false);
  194. IClientAPI client = SceneHelpers.AddScenePresence(scene, agentId).ControllingClient;
  195. scene.DeRezObjects(client, new List<uint>() { so.LocalId }, UUID.Zero, DeRezAction.Take, folder1.ID);
  196. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId);
  197. Assert.That(retrievedPart, Is.Not.Null);
  198. Assert.That(so.IsDeleted, Is.False);
  199. sogd.InventoryDeQueueAndDelete();
  200. Assert.That(so.IsDeleted, Is.True);
  201. SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId);
  202. Assert.That(retrievedPart2, Is.Null);
  203. // SceneSetupHelpers.DeleteSceneObjectAsync(scene, part, DeRezAction.Take, userInfo.RootFolder.ID, client);
  204. InventoryItemBase retrievedItem
  205. = UserInventoryHelpers.GetInventoryItem(
  206. scene.InventoryService, ua.PrincipalID, "folder1/" + myObjectName);
  207. // Check that we now have the taken part in our inventory
  208. Assert.That(retrievedItem, Is.Not.Null);
  209. // Check that the taken part has actually disappeared
  210. // SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
  211. // Assert.That(retrievedPart, Is.Null);
  212. }
  213. }
  214. }