diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine/XEngine/Tests')
-rw-r--r-- | OpenSim/Region/ScriptEngine/XEngine/Tests/XEnginePersistenceTests.cs | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEnginePersistenceTests.cs b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEnginePersistenceTests.cs new file mode 100644 index 0000000..5b7e5f7 --- /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, | ||
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 | ||