SceneObjectCrossingTests.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. sceneA.Update(4);
  134. sceneB.Update(4);
  135. // Cross
  136. sceneA.SceneGraph.UpdatePrimGroupPosition(
  137. so1.LocalId, new Vector3(so1StartPos.X, so1StartPos.Y - 20, so1StartPos.Z), sp1SceneA.ControllingClient);
  138. // crossing is async
  139. sceneA.Update(4);
  140. sceneB.Update(4);
  141. Thread.Sleep(500);
  142. SceneObjectGroup so1PostCross;
  143. ScenePresence sp1SceneAPostCross = sceneA.GetScenePresence(userId);
  144. Assert.IsTrue(sp1SceneAPostCross.IsChildAgent, "sp1SceneAPostCross.IsChildAgent unexpectedly false");
  145. ScenePresence sp1SceneBPostCross = sceneB.GetScenePresence(userId);
  146. TestClient sceneBTc = ((TestClient)sp1SceneBPostCross.ControllingClient);
  147. sceneBTc.CompleteMovement();
  148. sceneA.Update(4);
  149. sceneB.Update(4);
  150. Assert.IsFalse(sp1SceneBPostCross.IsChildAgent, "sp1SceneAPostCross.IsChildAgent unexpectedly true");
  151. Assert.IsTrue(sp1SceneBPostCross.IsSatOnObject);
  152. Assert.IsNull(sceneA.GetSceneObjectGroup(so1Id), "uck");
  153. so1PostCross = sceneB.GetSceneObjectGroup(so1Id);
  154. Assert.NotNull(so1PostCross);
  155. Assert.AreEqual(1, so1PostCross.GetSittingAvatarsCount());
  156. Vector3 so1PostCrossPos = so1PostCross.AbsolutePosition;
  157. // Console.WriteLine("CRISSCROSS");
  158. // Recross
  159. sceneB.SceneGraph.UpdatePrimGroupPosition(
  160. so1PostCross.LocalId, new Vector3(so1PostCrossPos.X, so1PostCrossPos.Y + 20, so1PostCrossPos.Z), sp1SceneBPostCross.ControllingClient);
  161. sceneA.Update(4);
  162. sceneB.Update(4);
  163. // crossing is async
  164. Thread.Sleep(500);
  165. {
  166. ScenePresence sp1SceneBPostReCross = sceneB.GetScenePresence(userId);
  167. Assert.IsTrue(sp1SceneBPostReCross.IsChildAgent, "sp1SceneBPostReCross.IsChildAgent unexpectedly false");
  168. ScenePresence sp1SceneAPostReCross = sceneA.GetScenePresence(userId);
  169. TestClient sceneATc = ((TestClient)sp1SceneAPostReCross.ControllingClient);
  170. sceneATc.CompleteMovement();
  171. Assert.IsFalse(sp1SceneAPostReCross.IsChildAgent, "sp1SceneAPostCross.IsChildAgent unexpectedly true");
  172. Assert.IsTrue(sp1SceneAPostReCross.IsSatOnObject);
  173. Assert.IsNull(sceneB.GetSceneObjectGroup(so1Id), "uck2");
  174. SceneObjectGroup so1PostReCross = sceneA.GetSceneObjectGroup(so1Id);
  175. Assert.NotNull(so1PostReCross);
  176. Assert.AreEqual(1, so1PostReCross.GetSittingAvatarsCount());
  177. }
  178. }
  179. /// <summary>
  180. /// Test cross with no prim limit module.
  181. /// </summary>
  182. /// <remarks>
  183. /// XXX: This test may FCbe better off in a specific PrimLimitsModuleTest class in optional module tests in the
  184. /// future (though it is configured as active by default, so not really optional).
  185. /// </remarks>
  186. [Test]
  187. public void TestCrossOnSameSimulatorPrimLimitsOkay()
  188. {
  189. TestHelpers.InMethod();
  190. // TestHelpers.EnableLogging();
  191. UUID userId = TestHelpers.ParseTail(0x1);
  192. int sceneObjectIdTail = 0x2;
  193. EntityTransferModule etmA = new EntityTransferModule();
  194. EntityTransferModule etmB = new EntityTransferModule();
  195. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  196. LandManagementModule lmmA = new LandManagementModule();
  197. LandManagementModule lmmB = new LandManagementModule();
  198. IConfigSource config = new IniConfigSource();
  199. IConfig modulesConfig = config.AddConfig("Modules");
  200. modulesConfig.Set("EntityTransferModule", etmA.Name);
  201. modulesConfig.Set("SimulationServices", lscm.Name);
  202. IConfig permissionsConfig = config.AddConfig("Permissions");
  203. permissionsConfig.Set("permissionmodules", "PrimLimitsModule");
  204. SceneHelpers sh = new SceneHelpers();
  205. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
  206. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999);
  207. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
  208. SceneHelpers.SetupSceneModules(
  209. sceneA, config, etmA, lmmA, new PrimLimitsModule(), new PrimCountModule());
  210. SceneHelpers.SetupSceneModules(
  211. sceneB, config, etmB, lmmB, new PrimLimitsModule(), new PrimCountModule());
  212. // We must set up the parcel for this to work. Normally this is taken care of by OpenSimulator startup
  213. // code which is not yet easily invoked by tests.
  214. lmmA.EventManagerOnNoLandDataFromStorage();
  215. lmmB.EventManagerOnNoLandDataFromStorage();
  216. AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId);
  217. TestClient tc = new TestClient(acd, sceneA);
  218. List<TestClient> destinationTestClients = new List<TestClient>();
  219. EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients);
  220. ScenePresence sp1SceneA = SceneHelpers.AddScenePresence(sceneA, tc, acd);
  221. SceneObjectGroup so1 = SceneHelpers.AddSceneObject(sceneA, 1, userId, "", sceneObjectIdTail);
  222. UUID so1Id = so1.UUID;
  223. so1.AbsolutePosition = new Vector3(128, 10, 20);
  224. // Cross with a negative value. We must make this call rather than setting AbsolutePosition directly
  225. // because only this will execute permission checks in the source region.
  226. sceneA.SceneGraph.UpdatePrimGroupPosition(so1.LocalId, new Vector3(128, -10, 20), sp1SceneA.ControllingClient);
  227. // crossing is async
  228. Thread.Sleep(500);
  229. Assert.IsNull(sceneA.GetSceneObjectGroup(so1Id));
  230. Assert.NotNull(sceneB.GetSceneObjectGroup(so1Id));
  231. }
  232. }
  233. }