OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
XEngineCrossingTests.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.Threading;
30 using Nini.Config;
31 using NUnit.Framework;
32 using OpenMetaverse;
33 using OpenSim.Framework;
34 using OpenSim.Region.CoreModules.Framework.EntityTransfer;
35 using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
36 using OpenSim.Region.Framework.Scenes;
37 using OpenSim.Region.ScriptEngine.Shared;
38 using OpenSim.Tests.Common;
39 
40 namespace OpenSim.Region.ScriptEngine.XEngine.Tests
41 {
45  [TestFixture]
47  {
48  [TestFixtureSetUp]
49  public void FixtureInit()
50  {
51  // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
52  Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
53  }
54 
55  [TestFixtureTearDown]
56  public void TearDown()
57  {
58  // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
59  // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
60  // tests really shouldn't).
61  Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
62  }
63 
67  [Test]
69  {
70  TestHelpers.InMethod();
71 // TestHelpers.EnableLogging();
72 
73  UUID userId = TestHelpers.ParseTail(0x1);
74  int sceneObjectIdTail = 0x2;
75 
79  XEngine xEngineA = new XEngine();
80  XEngine xEngineB = new XEngine();
81  xEngineA.DebugLevel = 1;
82  xEngineB.DebugLevel = 1;
83 
84  IConfigSource configSource = new IniConfigSource();
85 
86  IConfig startupConfig = configSource.AddConfig("Startup");
87  startupConfig.Set("DefaultScriptEngine", "XEngine");
88  startupConfig.Set("TrustBinaries", "true");
89 
90  IConfig xEngineConfig = configSource.AddConfig("XEngine");
91  xEngineConfig.Set("Enabled", "true");
92  xEngineConfig.Set("StartDelay", "0");
93 
94  // These tests will not run with AppDomainLoading = true, at least on mono. For unknown reasons, the call
95  // to AssemblyResolver.OnAssemblyResolve fails.
96  xEngineConfig.Set("AppDomainLoading", "false");
97 
98  IConfig modulesConfig = configSource.AddConfig("Modules");
99  modulesConfig.Set("EntityTransferModule", etmA.Name);
100  modulesConfig.Set("SimulationServices", lscm.Name);
101 
102  SceneHelpers sh = new SceneHelpers();
103  TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000, configSource);
104  TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999, configSource);
105 
106  SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, configSource, lscm);
107  SceneHelpers.SetupSceneModules(sceneA, configSource, etmA, xEngineA);
108  SceneHelpers.SetupSceneModules(sceneB, configSource, etmB, xEngineB);
109  sceneA.StartScripts();
110  sceneB.StartScripts();
111 
112  SceneObjectGroup soSceneA = SceneHelpers.AddSceneObject(sceneA, 1, userId, "so1-", sceneObjectIdTail);
113  soSceneA.AbsolutePosition = new Vector3(128, 10, 20);
114 
115  string soSceneAName = soSceneA.Name;
116  string scriptItemSceneAName = "script1";
117 
118  // CREATE SCRIPT TODO
119  InventoryItemBase scriptItemSceneA = new InventoryItemBase();
120  // itemTemplate.ID = itemId;
121  scriptItemSceneA.Name = scriptItemSceneAName;
122  scriptItemSceneA.Folder = soSceneA.UUID;
123  scriptItemSceneA.InvType = (int)InventoryType.LSL;
124 
125  AutoResetEvent chatEvent = new AutoResetEvent(false);
126  OSChatMessage messageReceived = null;
127  sceneA.EventManager.OnChatFromWorld += (s, m) => { messageReceived = m; chatEvent.Set(); };
128 
129  sceneA.RezNewScript(userId, scriptItemSceneA,
130 @"integer c = 0;
131 
132 default
133 {
134  state_entry()
135  {
136  llSay(0, ""Script running"");
137  }
138 
139  changed(integer change)
140  {
141  llSay(0, ""Changed"");
142  }
143 
144  touch_start(integer n)
145  {
146  c = c + 1;
147  llSay(0, (string)c);
148  }
149 }");
150 
151  chatEvent.WaitOne(60000);
152 
153  Assert.That(messageReceived, Is.Not.Null, "No chat message received.");
154  Assert.That(messageReceived.Message, Is.EqualTo("Script running"));
155 
156  {
157  // XXX: Should not be doing this so directly. Should call some variant of EventManager.touch() instead.
158  DetectParams[] det = new DetectParams[1];
159  det[0] = new DetectParams();
160  det[0].Key = userId;
161  det[0].Populate(sceneA);
162 
163  EventParams ep = new EventParams("touch_start", new Object[] { new LSL_Types.LSLInteger(1) }, det);
164 
165  messageReceived = null;
166  chatEvent.Reset();
167  xEngineA.PostObjectEvent(soSceneA.LocalId, ep);
168  chatEvent.WaitOne(60000);
169 
170  Assert.That(messageReceived.Message, Is.EqualTo("1"));
171  }
172 
173  AutoResetEvent chatEventB = new AutoResetEvent(false);
174  sceneB.EventManager.OnChatFromWorld += (s, m) => { messageReceived = m; chatEventB.Set(); };
175 
176  messageReceived = null;
177  chatEventB.Reset();
178  // Cross with a negative value
179  soSceneA.AbsolutePosition = new Vector3(128, -10, 20);
180 
181  chatEventB.WaitOne(60000);
182  Assert.That(messageReceived, Is.Not.Null, "No Changed message received.");
183  Assert.That(messageReceived.Message, Is.Not.Null, "Changed message without content");
184  Assert.That(messageReceived.Message, Is.EqualTo("Changed"));
185 
186  // TEST sending event to moved prim and output
187  {
188  SceneObjectGroup soSceneB = sceneB.GetSceneObjectGroup(soSceneAName);
189  TaskInventoryItem scriptItemSceneB = soSceneB.RootPart.Inventory.GetInventoryItem(scriptItemSceneAName);
190 
191  // XXX: Should not be doing this so directly. Should call some variant of EventManager.touch() instead.
192  DetectParams[] det = new DetectParams[1];
193  det[0] = new DetectParams();
194  det[0].Key = userId;
195  det[0].Populate(sceneB);
196 
197  EventParams ep = new EventParams("touch_start", new Object[] { new LSL_Types.LSLInteger(1) }, det);
198 
199  Thread.Sleep(250); // wait for other change messages to pass
200  messageReceived = null;
201  chatEventB.Reset();
202  xEngineB.PostObjectEvent(soSceneB.LocalId, ep);
203  chatEventB.WaitOne(60000);
204 
205  Assert.That(messageReceived.Message, Is.EqualTo("2"));
206  }
207  }
208  }
209 }
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
Represents an item in a task inventory
ChatFromViewer Arguments
Inventory Item - contains all the properties associated with an individual inventory piece...
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60
Holds all the data required to execute a scripting event.
Definition: Helpers.cs:281
void TestScriptCrossOnSameSimulator()
Test script state preservation when a script crosses between regions on the same simulator.
XEngine tests connected with crossing scripts between regions.