SceneObjectCrossingTests.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 Nini.Config;
  30. using NUnit.Framework;
  31. using OpenMetaverse;
  32. using OpenSim.Framework;
  33. using OpenSim.Region.CoreModules.Framework;
  34. using OpenSim.Region.CoreModules.Framework.EntityTransfer;
  35. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
  36. using OpenSim.Region.CoreModules.World.Land;
  37. using OpenSim.Region.OptionalModules;
  38. using OpenSim.Tests.Common;
  39. namespace OpenSim.Region.Framework.Scenes.Tests
  40. {
  41. public class SceneObjectCrossingTests : OpenSimTestCase
  42. {
  43. [TestFixtureSetUp]
  44. public void FixtureInit()
  45. {
  46. // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
  47. Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
  48. }
  49. [TestFixtureTearDown]
  50. public void TearDown()
  51. {
  52. // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
  53. // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
  54. // tests really shouldn't).
  55. Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
  56. }
  57. /// <summary>
  58. /// Test cross with no prim limit module.
  59. /// </summary>
  60. [Test]
  61. public void TestCrossOnSameSimulator()
  62. {
  63. TestHelpers.InMethod();
  64. // TestHelpers.EnableLogging();
  65. UUID userId = TestHelpers.ParseTail(0x1);
  66. int sceneObjectIdTail = 0x2;
  67. EntityTransferModule etmA = new EntityTransferModule();
  68. EntityTransferModule etmB = new EntityTransferModule();
  69. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  70. IConfigSource config = new IniConfigSource();
  71. IConfig modulesConfig = config.AddConfig("Modules");
  72. modulesConfig.Set("EntityTransferModule", etmA.Name);
  73. modulesConfig.Set("SimulationServices", lscm.Name);
  74. SceneHelpers sh = new SceneHelpers();
  75. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
  76. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999);
  77. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
  78. SceneHelpers.SetupSceneModules(sceneA, config, etmA);
  79. SceneHelpers.SetupSceneModules(sceneB, config, etmB);
  80. SceneObjectGroup so1 = SceneHelpers.AddSceneObject(sceneA, 1, userId, "", sceneObjectIdTail);
  81. UUID so1Id = so1.UUID;
  82. so1.AbsolutePosition = new Vector3(128, 10, 20);
  83. // Cross with a negative value
  84. so1.AbsolutePosition = new Vector3(128, -10, 20);
  85. Assert.IsNull(sceneA.GetSceneObjectGroup(so1Id));
  86. Assert.NotNull(sceneB.GetSceneObjectGroup(so1Id));
  87. }
  88. /// <summary>
  89. /// Test cross with no prim limit module.
  90. /// </summary>
  91. /// <remarks>
  92. /// Possibly this should belong in ScenePresenceCrossingTests, though here it is the object that is being moved
  93. /// where the avatar is just a passenger.
  94. /// </remarks>
  95. [Test]
  96. public void TestCrossOnSameSimulatorWithSittingAvatar()
  97. {
  98. TestHelpers.InMethod();
  99. // TestHelpers.EnableLogging();
  100. UUID userId = TestHelpers.ParseTail(0x1);
  101. int sceneObjectIdTail = 0x2;
  102. Vector3 so1StartPos = new Vector3(128, 10, 20);
  103. EntityTransferModule etmA = new EntityTransferModule();
  104. EntityTransferModule etmB = new EntityTransferModule();
  105. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  106. IConfigSource config = new IniConfigSource();
  107. IConfig modulesConfig = config.AddConfig("Modules");
  108. modulesConfig.Set("EntityTransferModule", etmA.Name);
  109. modulesConfig.Set("SimulationServices", lscm.Name);
  110. IConfig entityTransferConfig = config.AddConfig("EntityTransfer");
  111. // In order to run a single threaded regression test we do not want the entity transfer module waiting
  112. // for a callback from the destination scene before removing its avatar data.
  113. entityTransferConfig.Set("wait_for_callback", false);
  114. SceneHelpers sh = new SceneHelpers();
  115. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
  116. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999);
  117. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
  118. SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA);
  119. SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), etmB);
  120. SceneObjectGroup so1 = SceneHelpers.AddSceneObject(sceneA, 1, userId, "", sceneObjectIdTail);
  121. UUID so1Id = so1.UUID;
  122. so1.AbsolutePosition = so1StartPos;
  123. AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId);
  124. TestClient tc = new TestClient(acd, sceneA);
  125. List<TestClient> destinationTestClients = new List<TestClient>();
  126. EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients);
  127. ScenePresence sp1SceneA = SceneHelpers.AddScenePresence(sceneA, tc, acd);
  128. sp1SceneA.AbsolutePosition = so1StartPos;
  129. sp1SceneA.HandleAgentRequestSit(sp1SceneA.ControllingClient, sp1SceneA.UUID, so1.UUID, Vector3.Zero);
  130. // Cross
  131. sceneA.SceneGraph.UpdatePrimGroupPosition(
  132. so1.LocalId, new Vector3(so1StartPos.X, so1StartPos.Y - 20, so1StartPos.Z), userId);
  133. SceneObjectGroup so1PostCross;
  134. {
  135. ScenePresence sp1SceneAPostCross = sceneA.GetScenePresence(userId);
  136. Assert.IsTrue(sp1SceneAPostCross.IsChildAgent, "sp1SceneAPostCross.IsChildAgent unexpectedly false");
  137. ScenePresence sp1SceneBPostCross = sceneB.GetScenePresence(userId);
  138. TestClient sceneBTc = ((TestClient)sp1SceneBPostCross.ControllingClient);
  139. sceneBTc.CompleteMovement();
  140. Assert.IsFalse(sp1SceneBPostCross.IsChildAgent, "sp1SceneAPostCross.IsChildAgent unexpectedly true");
  141. Assert.IsTrue(sp1SceneBPostCross.IsSatOnObject);
  142. Assert.IsNull(sceneA.GetSceneObjectGroup(so1Id), "uck");
  143. so1PostCross = sceneB.GetSceneObjectGroup(so1Id);
  144. Assert.NotNull(so1PostCross);
  145. Assert.AreEqual(1, so1PostCross.GetSittingAvatarsCount());
  146. }
  147. Vector3 so1PostCrossPos = so1PostCross.AbsolutePosition;
  148. // Console.WriteLine("CRISSCROSS");
  149. // Recross
  150. sceneB.SceneGraph.UpdatePrimGroupPosition(
  151. so1PostCross.LocalId, new Vector3(so1PostCrossPos.X, so1PostCrossPos.Y + 20, so1PostCrossPos.Z), userId);
  152. {
  153. ScenePresence sp1SceneBPostReCross = sceneB.GetScenePresence(userId);
  154. Assert.IsTrue(sp1SceneBPostReCross.IsChildAgent, "sp1SceneBPostReCross.IsChildAgent unexpectedly false");
  155. ScenePresence sp1SceneAPostReCross = sceneA.GetScenePresence(userId);
  156. TestClient sceneATc = ((TestClient)sp1SceneAPostReCross.ControllingClient);
  157. sceneATc.CompleteMovement();
  158. Assert.IsFalse(sp1SceneAPostReCross.IsChildAgent, "sp1SceneAPostCross.IsChildAgent unexpectedly true");
  159. Assert.IsTrue(sp1SceneAPostReCross.IsSatOnObject);
  160. Assert.IsNull(sceneB.GetSceneObjectGroup(so1Id), "uck2");
  161. SceneObjectGroup so1PostReCross = sceneA.GetSceneObjectGroup(so1Id);
  162. Assert.NotNull(so1PostReCross);
  163. Assert.AreEqual(1, so1PostReCross.GetSittingAvatarsCount());
  164. }
  165. }
  166. /// <summary>
  167. /// Test cross with no prim limit module.
  168. /// </summary>
  169. /// <remarks>
  170. /// XXX: This test may FCbe better off in a specific PrimLimitsModuleTest class in optional module tests in the
  171. /// future (though it is configured as active by default, so not really optional).
  172. /// </remarks>
  173. [Test]
  174. public void TestCrossOnSameSimulatorPrimLimitsOkay()
  175. {
  176. TestHelpers.InMethod();
  177. // TestHelpers.EnableLogging();
  178. UUID userId = TestHelpers.ParseTail(0x1);
  179. int sceneObjectIdTail = 0x2;
  180. EntityTransferModule etmA = new EntityTransferModule();
  181. EntityTransferModule etmB = new EntityTransferModule();
  182. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  183. LandManagementModule lmmA = new LandManagementModule();
  184. LandManagementModule lmmB = new LandManagementModule();
  185. IConfigSource config = new IniConfigSource();
  186. IConfig modulesConfig = config.AddConfig("Modules");
  187. modulesConfig.Set("EntityTransferModule", etmA.Name);
  188. modulesConfig.Set("SimulationServices", lscm.Name);
  189. IConfig permissionsConfig = config.AddConfig("Permissions");
  190. permissionsConfig.Set("permissionmodules", "PrimLimitsModule");
  191. SceneHelpers sh = new SceneHelpers();
  192. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
  193. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999);
  194. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
  195. SceneHelpers.SetupSceneModules(
  196. sceneA, config, etmA, lmmA, new PrimLimitsModule(), new PrimCountModule());
  197. SceneHelpers.SetupSceneModules(
  198. sceneB, config, etmB, lmmB, new PrimLimitsModule(), new PrimCountModule());
  199. // We must set up the parcel for this to work. Normally this is taken care of by OpenSimulator startup
  200. // code which is not yet easily invoked by tests.
  201. lmmA.EventManagerOnNoLandDataFromStorage();
  202. lmmB.EventManagerOnNoLandDataFromStorage();
  203. SceneObjectGroup so1 = SceneHelpers.AddSceneObject(sceneA, 1, userId, "", sceneObjectIdTail);
  204. UUID so1Id = so1.UUID;
  205. so1.AbsolutePosition = new Vector3(128, 10, 20);
  206. // Cross with a negative value. We must make this call rather than setting AbsolutePosition directly
  207. // because only this will execute permission checks in the source region.
  208. sceneA.SceneGraph.UpdatePrimGroupPosition(so1.LocalId, new Vector3(128, -10, 20), userId);
  209. Assert.IsNull(sceneA.GetSceneObjectGroup(so1Id));
  210. Assert.NotNull(sceneB.GetSceneObjectGroup(so1Id));
  211. }
  212. }
  213. }