OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
XEnginePersistenceTests.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.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  /*
47  [TestFixture]
48  public class XEnginePersistenceTests : OpenSimTestCase
49  {
50  private AutoResetEvent m_chatEvent = new AutoResetEvent(false);
51 
52  private void OnChatFromWorld(object sender, OSChatMessage oscm)
53  {
54  // Console.WriteLine("Got chat [{0}]", oscm.Message);
55 
56  // m_osChatMessageReceived = oscm;
57  m_chatEvent.Set();
58  }
59 
60  private void AddCommonConfig(IConfigSource config, List<object> modules)
61  {
62  config.AddConfig("Modules");
63  config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
64 
65  AttachmentsModule attMod = new AttachmentsModule();
66  attMod.DebugLevel = 1;
67  modules.Add(attMod);
68  modules.Add(new BasicInventoryAccessModule());
69  }
70 
71  private void AddScriptingConfig(IConfigSource config, XEngine.XEngine xEngine, List<object> modules)
72  {
73  IConfig startupConfig = config.AddConfig("Startup");
74  startupConfig.Set("DefaultScriptEngine", "XEngine");
75 
76  IConfig xEngineConfig = config.AddConfig("XEngine");
77  xEngineConfig.Set("Enabled", "true");
78  xEngineConfig.Set("StartDelay", "0");
79 
80  // These tests will not run with AppDomainLoading = true, at least on mono. For unknown reasons, the call
81  // to AssemblyResolver.OnAssemblyResolve fails.
82  xEngineConfig.Set("AppDomainLoading", "false");
83 
84  modules.Add(xEngine);
85  }
86 
87  private Scene CreateScriptingEnabledTestScene(XEngine.XEngine xEngine)
88  {
89  IConfigSource config = new IniConfigSource();
90  List<object> modules = new List<object>();
91 
92  AddCommonConfig(config, modules);
93  AddScriptingConfig(config, xEngine, modules);
94 
95  Scene scene
96  = new SceneHelpers().SetupScene(
97  "attachments-test-scene", TestHelpers.ParseTail(999), 1000, 1000, config);
98  SceneHelpers.SetupSceneModules(scene, config, modules.ToArray());
99 
100  scene.StartScripts();
101 
102  return scene;
103  }
104 
105  [Test]
106  public void TestScriptedAttachmentPersistence()
107  {
108  TestHelpers.InMethod();
109 // TestHelpers.EnableLogging();
110 
111  XEngine.XEngine xEngine = new XEngine.XEngine();
112  Scene scene = CreateScriptingEnabledTestScene(xEngine);
113  UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
114  ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1);
115 
116  SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, sp.UUID, "att-name", 0x10);
117  TaskInventoryHelpers.AddScript(
118  scene.AssetService,
119  so.RootPart,
120  "scriptItem",
121  "default { attach(key id) { if (id != NULL_KEY) { llSay(0, \"Hello World\"); } } }");
122 
123  InventoryItemBase userItem = UserInventoryHelpers.AddInventoryItem(scene, so, 0x100, 0x1000);
124 
125  // FIXME: Right now, we have to do a tricksy chat listen to make sure we know when the script is running.
126  // In the future, we need to be able to do this programatically more predicably.
127  scene.EventManager.OnChatFromWorld += OnChatFromWorld;
128 
129  SceneObjectGroup rezzedSo
130  = scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest);
131  TaskInventoryItem rezzedScriptItem = rezzedSo.RootPart.Inventory.GetInventoryItem("scriptItem");
132 
133  // Wait for chat to signal rezzed script has been started.
134  m_chatEvent.WaitOne(60000);
135 
136  // Force save
137  xEngine.DoBackup(new Object[] { 0 });
138 
139 // Console.WriteLine("ItemID {0}", rezzedScriptItem.ItemID);
140 //
141 // foreach (
142 // string s in Directory.EnumerateFileSystemEntries(
143 // string.Format("ScriptEngines/{0}", scene.RegionInfo.RegionID)))
144 // Console.WriteLine(s);
145 
146  Assert.IsFalse(
147  File.Exists(
148  string.Format("ScriptEngines/{0}/{1}.state", scene.RegionInfo.RegionID, rezzedScriptItem.ItemID)));
149 
150  scene.AttachmentsModule.DetachSingleAttachmentToInv(sp, rezzedSo);
151  }
152  }
153  */
154 }
Interactive OpenSim region server
Definition: OpenSim.cs:55