XEngineBasicTests.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 System.Threading;
  30. using Nini.Config;
  31. using NUnit.Framework;
  32. using OpenMetaverse;
  33. using OpenSim.Framework;
  34. using OpenSim.Region.CoreModules.Scripting.WorldComm;
  35. using OpenSim.Region.Framework.Scenes;
  36. using OpenSim.Region.Framework.Interfaces;
  37. using OpenSim.Tests.Common;
  38. namespace OpenSim.Region.ScriptEngine.XEngine.Tests
  39. {
  40. /// <summary>
  41. /// Basic XEngine tests.
  42. /// </summary>
  43. [TestFixture]
  44. public class XEngineBasicTests : OpenSimTestCase
  45. {
  46. private TestScene m_scene;
  47. private XEngine m_xEngine;
  48. private AutoResetEvent m_chatEvent = new AutoResetEvent(false);
  49. private OSChatMessage m_osChatMessageReceived;
  50. [TestFixtureSetUp]
  51. public void Init()
  52. {
  53. //AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory + "/bin");
  54. // Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory);
  55. m_xEngine = new XEngine();
  56. IniConfigSource configSource = new IniConfigSource();
  57. IConfig startupConfig = configSource.AddConfig("Startup");
  58. startupConfig.Set("DefaultScriptEngine", "XEngine");
  59. IConfig xEngineConfig = configSource.AddConfig("XEngine");
  60. xEngineConfig.Set("Enabled", "true");
  61. xEngineConfig.Set("StartDelay", "0");
  62. // These tests will not run with AppDomainLoading = true, at least on mono. For unknown reasons, the call
  63. // to AssemblyResolver.OnAssemblyResolve fails.
  64. xEngineConfig.Set("AppDomainLoading", "false");
  65. m_scene = new SceneHelpers().SetupScene("My Test", UUID.Random(), 1000, 1000, configSource);
  66. SceneHelpers.SetupSceneModules(m_scene, configSource, m_xEngine);
  67. m_scene.StartScripts();
  68. }
  69. /// <summary>
  70. /// Test compilation and starting of a script.
  71. /// </summary>
  72. /// <remarks>
  73. /// This is a less than ideal regression test since it involves an asynchronous operation (in this case,
  74. /// compilation of the script).
  75. /// </remarks>
  76. [Test]
  77. public void TestCompileAndStartScript()
  78. {
  79. TestHelpers.InMethod();
  80. TestHelpers.EnableLogging();
  81. UUID userId = TestHelpers.ParseTail(0x1);
  82. // UUID objectId = TestHelpers.ParseTail(0x100);
  83. // UUID itemId = TestHelpers.ParseTail(0x3);
  84. string itemName = "TestStartScript() Item";
  85. SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, "TestStartScriptPart_", 0x100);
  86. m_scene.AddNewSceneObject(so, true);
  87. InventoryItemBase itemTemplate = new InventoryItemBase();
  88. // itemTemplate.ID = itemId;
  89. itemTemplate.Name = itemName;
  90. itemTemplate.Folder = so.UUID;
  91. itemTemplate.InvType = (int)InventoryType.LSL;
  92. m_scene.EventManager.OnChatFromWorld += OnChatFromWorld;
  93. SceneObjectPart partWhereRezzed = m_scene.RezNewScript(userId, itemTemplate, Constants.DefaultScriptText);
  94. m_chatEvent.WaitOne(60000);
  95. Assert.That(m_osChatMessageReceived, Is.Not.Null, "No chat message received in TestStartScript()");
  96. Assert.That(m_osChatMessageReceived.Message, Is.EqualTo("Script running"));
  97. bool running;
  98. TaskInventoryItem scriptItem = partWhereRezzed.Inventory.GetInventoryItem(itemName);
  99. Assert.That(
  100. SceneObjectPartInventory.TryGetScriptInstanceRunning(m_scene, scriptItem, out running), Is.True);
  101. Assert.That(running, Is.True);
  102. }
  103. private void OnChatFromWorld(object sender, OSChatMessage oscm)
  104. {
  105. // Console.WriteLine("Got chat [{0}]", oscm.Message);
  106. m_osChatMessageReceived = oscm;
  107. m_chatEvent.Set();
  108. }
  109. }
  110. }