StandaloneTeleportTests.cs 7.9 KB

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