1
0

XEngineBasicTests.cs 5.4 KB

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