diff options
author | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
commit | 134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch) | |
tree | 216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Region/ScriptEngine/XEngine/Tests | |
parent | More changing to production grid. Double oops. (diff) | |
download | opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2 opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz |
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineBasicTests.cs (renamed from OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs) | 7 | ||||
-rw-r--r-- | OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineCrossingTests.cs | 195 | ||||
-rw-r--r-- | OpenSim/Region/ScriptEngine/XEngine/Tests/XEnginePersistenceTests.cs | 152 |
3 files changed, 350 insertions, 4 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineBasicTests.cs index 5abfe9a..878e571 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineBasicTests.cs | |||
@@ -36,15 +36,14 @@ using OpenSim.Region.CoreModules.Scripting.WorldComm; | |||
36 | using OpenSim.Region.Framework.Scenes; | 36 | using OpenSim.Region.Framework.Scenes; |
37 | using OpenSim.Region.Framework.Interfaces; | 37 | using OpenSim.Region.Framework.Interfaces; |
38 | using OpenSim.Tests.Common; | 38 | using OpenSim.Tests.Common; |
39 | using OpenSim.Tests.Common.Mock; | ||
40 | 39 | ||
41 | namespace OpenSim.Region.ScriptEngine.XEngine.Tests | 40 | namespace OpenSim.Region.ScriptEngine.XEngine.Tests |
42 | { | 41 | { |
43 | /// <summary> | 42 | /// <summary> |
44 | /// XEngine tests. | 43 | /// Basic XEngine tests. |
45 | /// </summary> | 44 | /// </summary> |
46 | [TestFixture] | 45 | [TestFixture] |
47 | public class XEngineTest : OpenSimTestCase | 46 | public class XEngineBasicTests : OpenSimTestCase |
48 | { | 47 | { |
49 | private TestScene m_scene; | 48 | private TestScene m_scene; |
50 | private XEngine m_xEngine; | 49 | private XEngine m_xEngine; |
@@ -87,7 +86,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine.Tests | |||
87 | public void TestCompileAndStartScript() | 86 | public void TestCompileAndStartScript() |
88 | { | 87 | { |
89 | TestHelpers.InMethod(); | 88 | TestHelpers.InMethod(); |
90 | // log4net.Config.XmlConfigurator.Configure(); | 89 | TestHelpers.EnableLogging(); |
91 | 90 | ||
92 | UUID userId = TestHelpers.ParseTail(0x1); | 91 | UUID userId = TestHelpers.ParseTail(0x1); |
93 | // UUID objectId = TestHelpers.ParseTail(0x100); | 92 | // UUID objectId = TestHelpers.ParseTail(0x100); |
diff --git a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineCrossingTests.cs b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineCrossingTests.cs new file mode 100644 index 0000000..587695f --- /dev/null +++ b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineCrossingTests.cs | |||
@@ -0,0 +1,195 @@ | |||
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 | { | ||
42 | /// <summary> | ||
43 | /// XEngine tests connected with crossing scripts between regions. | ||
44 | /// </summary> | ||
45 | [TestFixture] | ||
46 | public class XEngineCrossingTests : OpenSimTestCase | ||
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 | |||
64 | /// <summary> | ||
65 | /// Test script state preservation when a script crosses between regions on the same simulator. | ||
66 | /// </summary> | ||
67 | [Test] | ||
68 | public void TestScriptCrossOnSameSimulator() | ||
69 | { | ||
70 | TestHelpers.InMethod(); | ||
71 | // TestHelpers.EnableLogging(); | ||
72 | |||
73 | UUID userId = TestHelpers.ParseTail(0x1); | ||
74 | int sceneObjectIdTail = 0x2; | ||
75 | |||
76 | EntityTransferModule etmA = new EntityTransferModule(); | ||
77 | EntityTransferModule etmB = new EntityTransferModule(); | ||
78 | LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule(); | ||
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 | |||
89 | IConfig xEngineConfig = configSource.AddConfig("XEngine"); | ||
90 | xEngineConfig.Set("Enabled", "true"); | ||
91 | xEngineConfig.Set("StartDelay", "0"); | ||
92 | |||
93 | // These tests will not run with AppDomainLoading = true, at least on mono. For unknown reasons, the call | ||
94 | // to AssemblyResolver.OnAssemblyResolve fails. | ||
95 | xEngineConfig.Set("AppDomainLoading", "false"); | ||
96 | |||
97 | IConfig modulesConfig = configSource.AddConfig("Modules"); | ||
98 | modulesConfig.Set("EntityTransferModule", etmA.Name); | ||
99 | modulesConfig.Set("SimulationServices", lscm.Name); | ||
100 | |||
101 | SceneHelpers sh = new SceneHelpers(); | ||
102 | TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000, configSource); | ||
103 | TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999, configSource); | ||
104 | |||
105 | SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, configSource, lscm); | ||
106 | SceneHelpers.SetupSceneModules(sceneA, configSource, etmA, xEngineA); | ||
107 | SceneHelpers.SetupSceneModules(sceneB, configSource, etmB, xEngineB); | ||
108 | sceneA.StartScripts(); | ||
109 | sceneB.StartScripts(); | ||
110 | |||
111 | SceneObjectGroup soSceneA = SceneHelpers.AddSceneObject(sceneA, 1, userId, "so1-", sceneObjectIdTail); | ||
112 | soSceneA.AbsolutePosition = new Vector3(128, 10, 20); | ||
113 | |||
114 | // CREATE SCRIPT TODO | ||
115 | InventoryItemBase scriptItemSceneA = new InventoryItemBase(); | ||
116 | // itemTemplate.ID = itemId; | ||
117 | scriptItemSceneA.Name = "script1"; | ||
118 | scriptItemSceneA.Folder = soSceneA.UUID; | ||
119 | scriptItemSceneA.InvType = (int)InventoryType.LSL; | ||
120 | |||
121 | AutoResetEvent chatEvent = new AutoResetEvent(false); | ||
122 | OSChatMessage messageReceived = null; | ||
123 | sceneA.EventManager.OnChatFromWorld += (s, m) => { messageReceived = m; chatEvent.Set(); }; | ||
124 | |||
125 | sceneA.RezNewScript(userId, scriptItemSceneA, | ||
126 | @"integer c = 0; | ||
127 | |||
128 | default | ||
129 | { | ||
130 | state_entry() | ||
131 | { | ||
132 | llSay(0, ""Script running""); | ||
133 | } | ||
134 | |||
135 | changed(integer change) | ||
136 | { | ||
137 | llSay(0, ""Changed""); | ||
138 | } | ||
139 | |||
140 | touch_start(integer n) | ||
141 | { | ||
142 | c = c + 1; | ||
143 | llSay(0, (string)c); | ||
144 | } | ||
145 | }"); | ||
146 | |||
147 | chatEvent.WaitOne(60000); | ||
148 | |||
149 | Assert.That(messageReceived, Is.Not.Null, "No chat message received."); | ||
150 | Assert.That(messageReceived.Message, Is.EqualTo("Script running")); | ||
151 | |||
152 | { | ||
153 | // XXX: Should not be doing this so directly. Should call some variant of EventManager.touch() instead. | ||
154 | DetectParams[] det = new DetectParams[1]; | ||
155 | det[0] = new DetectParams(); | ||
156 | det[0].Key = userId; | ||
157 | det[0].Populate(sceneA); | ||
158 | |||
159 | EventParams ep = new EventParams("touch_start", new Object[] { new LSL_Types.LSLInteger(1) }, det); | ||
160 | |||
161 | xEngineA.PostObjectEvent(soSceneA.LocalId, ep); | ||
162 | chatEvent.WaitOne(60000); | ||
163 | |||
164 | Assert.That(messageReceived.Message, Is.EqualTo("1")); | ||
165 | } | ||
166 | |||
167 | sceneB.EventManager.OnChatFromWorld += (s, m) => { messageReceived = m; chatEvent.Set(); }; | ||
168 | |||
169 | // Cross with a negative value | ||
170 | soSceneA.AbsolutePosition = new Vector3(128, -10, 20); | ||
171 | |||
172 | chatEvent.WaitOne(60000); | ||
173 | Assert.That(messageReceived.Message, Is.EqualTo("Changed")); | ||
174 | |||
175 | // TEST sending event to moved prim and output | ||
176 | { | ||
177 | SceneObjectGroup soSceneB = sceneB.GetSceneObjectGroup(soSceneA.Name); | ||
178 | TaskInventoryItem scriptItemSceneB = soSceneB.RootPart.Inventory.GetInventoryItem(scriptItemSceneA.Name); | ||
179 | |||
180 | // XXX: Should not be doing this so directly. Should call some variant of EventManager.touch() instead. | ||
181 | DetectParams[] det = new DetectParams[1]; | ||
182 | det[0] = new DetectParams(); | ||
183 | det[0].Key = userId; | ||
184 | det[0].Populate(sceneB); | ||
185 | |||
186 | EventParams ep = new EventParams("touch_start", new Object[] { new LSL_Types.LSLInteger(1) }, det); | ||
187 | |||
188 | xEngineB.PostObjectEvent(soSceneB.LocalId, ep); | ||
189 | chatEvent.WaitOne(60000); | ||
190 | |||
191 | Assert.That(messageReceived.Message, Is.EqualTo("2")); | ||
192 | } | ||
193 | } | ||
194 | } | ||
195 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEnginePersistenceTests.cs b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEnginePersistenceTests.cs new file mode 100644 index 0000000..2ef4058 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEnginePersistenceTests.cs | |||
@@ -0,0 +1,152 @@ | |||
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.IO; | ||
31 | using System.Linq; | ||
32 | using System.Threading; | ||
33 | using Nini.Config; | ||
34 | using NUnit.Framework; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Region.CoreModules.Avatar.Attachments; | ||
38 | using OpenSim.Region.CoreModules.Framework.InventoryAccess; | ||
39 | using OpenSim.Region.Framework.Scenes; | ||
40 | using OpenSim.Region.ScriptEngine.XEngine; | ||
41 | using OpenSim.Services.Interfaces; | ||
42 | using OpenSim.Tests.Common; | ||
43 | |||
44 | namespace OpenSim.Region.ScriptEngine.Tests | ||
45 | { | ||
46 | [TestFixture] | ||
47 | public class XEnginePersistenceTests : OpenSimTestCase | ||
48 | { | ||
49 | private AutoResetEvent m_chatEvent = new AutoResetEvent(false); | ||
50 | |||
51 | private void OnChatFromWorld(object sender, OSChatMessage oscm) | ||
52 | { | ||
53 | // Console.WriteLine("Got chat [{0}]", oscm.Message); | ||
54 | |||
55 | // m_osChatMessageReceived = oscm; | ||
56 | m_chatEvent.Set(); | ||
57 | } | ||
58 | |||
59 | private void AddCommonConfig(IConfigSource config, List<object> modules) | ||
60 | { | ||
61 | config.AddConfig("Modules"); | ||
62 | config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); | ||
63 | |||
64 | AttachmentsModule attMod = new AttachmentsModule(); | ||
65 | attMod.DebugLevel = 1; | ||
66 | modules.Add(attMod); | ||
67 | modules.Add(new BasicInventoryAccessModule()); | ||
68 | } | ||
69 | |||
70 | private void AddScriptingConfig(IConfigSource config, XEngine.XEngine xEngine, List<object> modules) | ||
71 | { | ||
72 | IConfig startupConfig = config.AddConfig("Startup"); | ||
73 | startupConfig.Set("DefaultScriptEngine", "XEngine"); | ||
74 | |||
75 | IConfig xEngineConfig = config.AddConfig("XEngine"); | ||
76 | xEngineConfig.Set("Enabled", "true"); | ||
77 | xEngineConfig.Set("StartDelay", "0"); | ||
78 | |||
79 | // These tests will not run with AppDomainLoading = true, at least on mono. For unknown reasons, the call | ||
80 | // to AssemblyResolver.OnAssemblyResolve fails. | ||
81 | xEngineConfig.Set("AppDomainLoading", "false"); | ||
82 | |||
83 | modules.Add(xEngine); | ||
84 | } | ||
85 | |||
86 | private Scene CreateScriptingEnabledTestScene(XEngine.XEngine xEngine) | ||
87 | { | ||
88 | IConfigSource config = new IniConfigSource(); | ||
89 | List<object> modules = new List<object>(); | ||
90 | |||
91 | AddCommonConfig(config, modules); | ||
92 | AddScriptingConfig(config, xEngine, modules); | ||
93 | |||
94 | Scene scene | ||
95 | = new SceneHelpers().SetupScene( | ||
96 | "attachments-test-scene", TestHelpers.ParseTail(999), 1000, 1000, config); | ||
97 | SceneHelpers.SetupSceneModules(scene, config, modules.ToArray()); | ||
98 | |||
99 | scene.StartScripts(); | ||
100 | |||
101 | return scene; | ||
102 | } | ||
103 | |||
104 | [Test] | ||
105 | public void TestScriptedAttachmentPersistence() | ||
106 | { | ||
107 | TestHelpers.InMethod(); | ||
108 | // TestHelpers.EnableLogging(); | ||
109 | |||
110 | XEngine.XEngine xEngine = new XEngine.XEngine(); | ||
111 | Scene scene = CreateScriptingEnabledTestScene(xEngine); | ||
112 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); | ||
113 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1); | ||
114 | |||
115 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, sp.UUID, "att-name", 0x10); | ||
116 | TaskInventoryHelpers.AddScript( | ||
117 | scene.AssetService, | ||
118 | so.RootPart, | ||
119 | "scriptItem", | ||
120 | "default { attach(key id) { if (id != NULL_KEY) { llSay(0, \"Hello World\"); } } }"); | ||
121 | |||
122 | InventoryItemBase userItem = UserInventoryHelpers.AddInventoryItem(scene, so, 0x100, 0x1000); | ||
123 | |||
124 | // FIXME: Right now, we have to do a tricksy chat listen to make sure we know when the script is running. | ||
125 | // In the future, we need to be able to do this programatically more predicably. | ||
126 | scene.EventManager.OnChatFromWorld += OnChatFromWorld; | ||
127 | |||
128 | SceneObjectGroup rezzedSo | ||
129 | = scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest); | ||
130 | TaskInventoryItem rezzedScriptItem = rezzedSo.RootPart.Inventory.GetInventoryItem("scriptItem"); | ||
131 | |||
132 | // Wait for chat to signal rezzed script has been started. | ||
133 | m_chatEvent.WaitOne(60000); | ||
134 | |||
135 | // Force save | ||
136 | xEngine.DoBackup(new Object[] { 0 }); | ||
137 | |||
138 | // Console.WriteLine("ItemID {0}", rezzedScriptItem.ItemID); | ||
139 | // | ||
140 | // foreach ( | ||
141 | // string s in Directory.EnumerateFileSystemEntries( | ||
142 | // string.Format("ScriptEngines/{0}", scene.RegionInfo.RegionID))) | ||
143 | // Console.WriteLine(s); | ||
144 | |||
145 | Assert.IsFalse( | ||
146 | File.Exists( | ||
147 | string.Format("ScriptEngines/{0}/{1}.state", scene.RegionInfo.RegionID, rezzedScriptItem.ItemID))); | ||
148 | |||
149 | scene.AttachmentsModule.DetachSingleAttachmentToInv(sp, rezzedSo); | ||
150 | } | ||
151 | } | ||
152 | } \ No newline at end of file | ||