ScenePresenceTeleportTests.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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.Reflection;
  29. using Nini.Config;
  30. using NUnit.Framework;
  31. using OpenMetaverse;
  32. using OpenSim.Framework;
  33. using OpenSim.Framework.Communications;
  34. using OpenSim.Region.Framework.Interfaces;
  35. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
  36. using OpenSim.Tests.Common;
  37. using OpenSim.Tests.Common.Mock;
  38. using System.Threading;
  39. namespace OpenSim.Region.Framework.Scenes.Tests
  40. {
  41. /// <summary>
  42. /// Teleport tests in a standalone OpenSim
  43. /// </summary>
  44. [TestFixture]
  45. public class ScenePresenceTeleportTests
  46. {
  47. /// <summary>
  48. /// Test a teleport between two regions that are not neighbours and do not share any neighbours in common.
  49. /// </summary>
  50. /// Does not yet do what is says on the tin.
  51. /// Commenting for now
  52. //[Test, LongRunning]
  53. public void TestSimpleNotNeighboursTeleport()
  54. {
  55. TestHelpers.InMethod();
  56. ThreadRunResults results = new ThreadRunResults();
  57. results.Result = false;
  58. results.Message = "Test did not run";
  59. TestRunning testClass = new TestRunning(results);
  60. Thread testThread = new Thread(testClass.run);
  61. try
  62. {
  63. // Seems kind of redundant to start a thread and then join it, however.. We need to protect against
  64. // A thread abort exception in the simulator code.
  65. testThread.Start();
  66. testThread.Join();
  67. }
  68. catch (ThreadAbortException)
  69. {
  70. }
  71. Assert.That(testClass.results.Result, Is.EqualTo(true), testClass.results.Message);
  72. // Console.WriteLine("Beginning test {0}", MethodBase.GetCurrentMethod());
  73. }
  74. [TearDown]
  75. public void TearDown()
  76. {
  77. try
  78. {
  79. if (MainServer.Instance != null) MainServer.Instance.Stop();
  80. }
  81. catch (NullReferenceException)
  82. { }
  83. }
  84. }
  85. public class ThreadRunResults
  86. {
  87. public bool Result = false;
  88. public string Message = string.Empty;
  89. }
  90. public class TestRunning
  91. {
  92. public ThreadRunResults results;
  93. public TestRunning(ThreadRunResults t)
  94. {
  95. results = t;
  96. }
  97. public void run(object o)
  98. {
  99. //results.Result = true;
  100. log4net.Config.XmlConfigurator.Configure();
  101. UUID sceneAId = UUID.Parse("00000000-0000-0000-0000-000000000100");
  102. UUID sceneBId = UUID.Parse("00000000-0000-0000-0000-000000000200");
  103. // shared module
  104. ISharedRegionModule interregionComms = new LocalSimulationConnectorModule();
  105. Scene sceneB = SceneHelpers.SetupScene("sceneB", sceneBId, 1010, 1010);
  106. SceneHelpers.SetupSceneModules(sceneB, new IniConfigSource(), interregionComms);
  107. sceneB.RegisterRegionWithGrid();
  108. Scene sceneA = SceneHelpers.SetupScene("sceneA", sceneAId, 1000, 1000);
  109. SceneHelpers.SetupSceneModules(sceneA, new IniConfigSource(), interregionComms);
  110. sceneA.RegisterRegionWithGrid();
  111. UUID agentId = UUID.Parse("00000000-0000-0000-0000-000000000041");
  112. TestClient client = (TestClient)SceneHelpers.AddScenePresence(sceneA, agentId).ControllingClient;
  113. ICapabilitiesModule sceneACapsModule = sceneA.RequestModuleInterface<ICapabilitiesModule>();
  114. results.Result = (sceneACapsModule.GetCapsPath(agentId) == client.CapsSeedUrl);
  115. if (!results.Result)
  116. {
  117. results.Message = "Incorrect caps object path set up in sceneA";
  118. return;
  119. }
  120. /*
  121. Assert.That(
  122. sceneACapsModule.GetCapsPath(agentId),
  123. Is.EqualTo(client.CapsSeedUrl),
  124. "Incorrect caps object path set up in sceneA");
  125. */
  126. // FIXME: This is a hack to get the test working - really the normal OpenSim mechanisms should be used.
  127. client.TeleportTargetScene = sceneB;
  128. client.Teleport(sceneB.RegionInfo.RegionHandle, new Vector3(100, 100, 100), new Vector3(40, 40, 40));
  129. results.Result = (sceneB.GetScenePresence(agentId) != null);
  130. if (!results.Result)
  131. {
  132. results.Message = "Client does not have an agent in sceneB";
  133. return;
  134. }
  135. //Assert.That(sceneB.GetScenePresence(agentId), Is.Not.Null, "Client does not have an agent in sceneB");
  136. //Assert.That(sceneA.GetScenePresence(agentId), Is.Null, "Client still had an agent in sceneA");
  137. results.Result = (sceneA.GetScenePresence(agentId) == null);
  138. if (!results.Result)
  139. {
  140. results.Message = "Client still had an agent in sceneA";
  141. return;
  142. }
  143. ICapabilitiesModule sceneBCapsModule = sceneB.RequestModuleInterface<ICapabilitiesModule>();
  144. results.Result = ("http://" + sceneB.RegionInfo.ExternalHostName + ":" + sceneB.RegionInfo.HttpPort +
  145. "/CAPS/" + sceneBCapsModule.GetCapsPath(agentId) + "0000/" == client.CapsSeedUrl);
  146. if (!results.Result)
  147. {
  148. results.Message = "Incorrect caps object path set up in sceneB";
  149. return;
  150. }
  151. // Temporary assertion - caps url construction should at least be doable through a method.
  152. /*
  153. Assert.That(
  154. "http://" + sceneB.RegionInfo.ExternalHostName + ":" + sceneB.RegionInfo.HttpPort + "/CAPS/" + sceneBCapsModule.GetCapsPath(agentId) + "0000/",
  155. Is.EqualTo(client.CapsSeedUrl),
  156. "Incorrect caps object path set up in sceneB");
  157. */
  158. // This assertion will currently fail since we don't remove the caps paths when no longer needed
  159. //Assert.That(sceneACapsModule.GetCapsPath(agentId), Is.Null, "sceneA still had a caps object path");
  160. // TODO: Check that more of everything is as it should be
  161. // TODO: test what happens if we try to teleport to a region that doesn't exist
  162. }
  163. }
  164. }