OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
XEngineBasicTests.cs
Go to the documentation of this file.
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 
28 using System;
29 using System.Collections.Generic;
30 using System.Threading;
31 using Nini.Config;
32 using NUnit.Framework;
33 using OpenMetaverse;
34 using OpenSim.Framework;
35 using OpenSim.Region.CoreModules.Scripting.WorldComm;
36 using OpenSim.Region.Framework.Scenes;
37 using OpenSim.Region.Framework.Interfaces;
38 using OpenSim.Tests.Common;
39 
40 namespace OpenSim.Region.ScriptEngine.XEngine.Tests
41 {
45  [TestFixture]
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 
85  [Test]
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 }
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
Represents an item in a task inventory
void TestCompileAndStartScript()
Test compilation and starting of a script.
ChatFromViewer Arguments
Inventory Item - contains all the properties associated with an individual inventory piece...
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60
Interactive OpenSim region server
Definition: OpenSim.cs:55