1
0

XEngineCrossingTests.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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.Threading;
  29. using Nini.Config;
  30. using NUnit.Framework;
  31. using OpenMetaverse;
  32. using OpenSim.Framework;
  33. using OpenSim.Region.CoreModules.Framework.EntityTransfer;
  34. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
  35. using OpenSim.Region.Framework.Scenes;
  36. using OpenSim.Region.ScriptEngine.Shared;
  37. using OpenSim.Tests.Common;
  38. namespace OpenSim.Region.ScriptEngine.XEngine.Tests
  39. {
  40. /// <summary>
  41. /// XEngine tests connected with crossing scripts between regions.
  42. /// </summary>
  43. [TestFixture]
  44. public class XEngineCrossingTests : OpenSimTestCase
  45. {
  46. [TestFixtureSetUp]
  47. public void FixtureInit()
  48. {
  49. // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
  50. Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
  51. }
  52. [TestFixtureTearDown]
  53. public void TearDown()
  54. {
  55. // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
  56. // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
  57. // tests really shouldn't).
  58. Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
  59. }
  60. /// <summary>
  61. /// Test script state preservation when a script crosses between regions on the same simulator.
  62. /// </summary>
  63. [Test]
  64. public void TestScriptCrossOnSameSimulator()
  65. {
  66. TestHelpers.InMethod();
  67. // TestHelpers.EnableLogging();
  68. UUID userId = TestHelpers.ParseTail(0x1);
  69. int sceneObjectIdTail = 0x2;
  70. EntityTransferModule etmA = new EntityTransferModule();
  71. EntityTransferModule etmB = new EntityTransferModule();
  72. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  73. XEngine xEngineA = new XEngine();
  74. XEngine xEngineB = new XEngine();
  75. xEngineA.DebugLevel = 1;
  76. xEngineB.DebugLevel = 1;
  77. IConfigSource configSource = new IniConfigSource();
  78. IConfig startupConfig = configSource.AddConfig("Startup");
  79. startupConfig.Set("DefaultScriptEngine", "XEngine");
  80. IConfig xEngineConfig = configSource.AddConfig("XEngine");
  81. xEngineConfig.Set("Enabled", "true");
  82. xEngineConfig.Set("StartDelay", "0");
  83. // These tests will not run with AppDomainLoading = true, at least on mono. For unknown reasons, the call
  84. // to AssemblyResolver.OnAssemblyResolve fails.
  85. xEngineConfig.Set("AppDomainLoading", "false");
  86. IConfig modulesConfig = configSource.AddConfig("Modules");
  87. modulesConfig.Set("EntityTransferModule", etmA.Name);
  88. modulesConfig.Set("SimulationServices", lscm.Name);
  89. SceneHelpers sh = new SceneHelpers();
  90. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000, configSource);
  91. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999, configSource);
  92. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, configSource, lscm);
  93. SceneHelpers.SetupSceneModules(sceneA, configSource, etmA, xEngineA);
  94. SceneHelpers.SetupSceneModules(sceneB, configSource, etmB, xEngineB);
  95. sceneA.StartScripts();
  96. sceneB.StartScripts();
  97. SceneObjectGroup soSceneA = SceneHelpers.AddSceneObject(sceneA, 1, userId, "so1-", sceneObjectIdTail);
  98. soSceneA.AbsolutePosition = new Vector3(128, 10, 20);
  99. // CREATE SCRIPT TODO
  100. InventoryItemBase scriptItemSceneA = new InventoryItemBase();
  101. // itemTemplate.ID = itemId;
  102. scriptItemSceneA.Name = "script1";
  103. scriptItemSceneA.Folder = soSceneA.UUID;
  104. scriptItemSceneA.InvType = (int)InventoryType.LSL;
  105. AutoResetEvent chatEvent = new AutoResetEvent(false);
  106. OSChatMessage messageReceived = null;
  107. sceneA.EventManager.OnChatFromWorld += (s, m) => { messageReceived = m; chatEvent.Set(); };
  108. sceneA.RezNewScript(userId, scriptItemSceneA,
  109. @"integer c = 0;
  110. default
  111. {
  112. state_entry()
  113. {
  114. llSay(0, ""Script running"");
  115. }
  116. changed(integer change)
  117. {
  118. llSay(0, ""Changed"");
  119. }
  120. touch_start(integer n)
  121. {
  122. c = c + 1;
  123. llSay(0, (string)c);
  124. }
  125. }");
  126. chatEvent.WaitOne(60000);
  127. Assert.That(messageReceived, Is.Not.Null, "No chat message received.");
  128. Assert.That(messageReceived.Message, Is.EqualTo("Script running"));
  129. {
  130. // XXX: Should not be doing this so directly. Should call some variant of EventManager.touch() instead.
  131. DetectParams[] det = new DetectParams[1];
  132. det[0] = new DetectParams();
  133. det[0].Key = userId;
  134. det[0].Populate(sceneA);
  135. EventParams ep = new EventParams("touch_start", new Object[] { new LSL_Types.LSLInteger(1) }, det);
  136. xEngineA.PostObjectEvent(soSceneA.LocalId, ep);
  137. chatEvent.WaitOne(60000);
  138. Assert.That(messageReceived.Message, Is.EqualTo("1"));
  139. }
  140. sceneB.EventManager.OnChatFromWorld += (s, m) => { messageReceived = m; chatEvent.Set(); };
  141. // Cross with a negative value
  142. soSceneA.AbsolutePosition = new Vector3(128, -10, 20);
  143. chatEvent.WaitOne(60000);
  144. Assert.That(messageReceived.Message, Is.EqualTo("Changed"));
  145. // TEST sending event to moved prim and output
  146. {
  147. SceneObjectGroup soSceneB = sceneB.GetSceneObjectGroup(soSceneA.Name);
  148. TaskInventoryItem scriptItemSceneB = soSceneB.RootPart.Inventory.GetInventoryItem(scriptItemSceneA.Name);
  149. // XXX: Should not be doing this so directly. Should call some variant of EventManager.touch() instead.
  150. DetectParams[] det = new DetectParams[1];
  151. det[0] = new DetectParams();
  152. det[0].Key = userId;
  153. det[0].Populate(sceneB);
  154. EventParams ep = new EventParams("touch_start", new Object[] { new LSL_Types.LSLInteger(1) }, det);
  155. xEngineB.PostObjectEvent(soSceneB.LocalId, ep);
  156. chatEvent.WaitOne(60000);
  157. Assert.That(messageReceived.Message, Is.EqualTo("2"));
  158. }
  159. }
  160. }
  161. }