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