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