SceneObjectCrossingTests.cs 13 KB

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