XEnginePersistenceTests.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. using System;
  28. using System.Collections.Generic;
  29. using System.IO;
  30. using System.Linq;
  31. using System.Threading;
  32. using Nini.Config;
  33. using NUnit.Framework;
  34. using OpenMetaverse;
  35. using OpenSim.Framework;
  36. using OpenSim.Region.CoreModules.Avatar.Attachments;
  37. using OpenSim.Region.CoreModules.Framework.InventoryAccess;
  38. using OpenSim.Region.Framework.Scenes;
  39. using OpenSim.Region.ScriptEngine.XEngine;
  40. using OpenSim.Services.Interfaces;
  41. using OpenSim.Tests.Common;
  42. namespace OpenSim.Region.ScriptEngine.Tests
  43. {
  44. /*
  45. [TestFixture]
  46. public class XEnginePersistenceTests : OpenSimTestCase
  47. {
  48. private AutoResetEvent m_chatEvent = new AutoResetEvent(false);
  49. private void OnChatFromWorld(object sender, OSChatMessage oscm)
  50. {
  51. // Console.WriteLine("Got chat [{0}]", oscm.Message);
  52. // m_osChatMessageReceived = oscm;
  53. m_chatEvent.Set();
  54. }
  55. private void AddCommonConfig(IConfigSource config, List<object> modules)
  56. {
  57. config.AddConfig("Modules");
  58. config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
  59. AttachmentsModule attMod = new AttachmentsModule();
  60. attMod.DebugLevel = 1;
  61. modules.Add(attMod);
  62. modules.Add(new BasicInventoryAccessModule());
  63. }
  64. private void AddScriptingConfig(IConfigSource config, XEngine.XEngine xEngine, List<object> modules)
  65. {
  66. IConfig startupConfig = config.AddConfig("Startup");
  67. startupConfig.Set("DefaultScriptEngine", "XEngine");
  68. IConfig xEngineConfig = config.AddConfig("XEngine");
  69. xEngineConfig.Set("Enabled", "true");
  70. xEngineConfig.Set("StartDelay", "0");
  71. // These tests will not run with AppDomainLoading = true, at least on mono. For unknown reasons, the call
  72. // to AssemblyResolver.OnAssemblyResolve fails.
  73. xEngineConfig.Set("AppDomainLoading", "false");
  74. modules.Add(xEngine);
  75. }
  76. private Scene CreateScriptingEnabledTestScene(XEngine.XEngine xEngine)
  77. {
  78. IConfigSource config = new IniConfigSource();
  79. List<object> modules = new List<object>();
  80. AddCommonConfig(config, modules);
  81. AddScriptingConfig(config, xEngine, modules);
  82. Scene scene
  83. = new SceneHelpers().SetupScene(
  84. "attachments-test-scene", TestHelpers.ParseTail(999), 1000, 1000, config);
  85. SceneHelpers.SetupSceneModules(scene, config, modules.ToArray());
  86. scene.StartScripts();
  87. return scene;
  88. }
  89. [Test]
  90. public void TestScriptedAttachmentPersistence()
  91. {
  92. TestHelpers.InMethod();
  93. // TestHelpers.EnableLogging();
  94. XEngine.XEngine xEngine = new XEngine.XEngine();
  95. Scene scene = CreateScriptingEnabledTestScene(xEngine);
  96. UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
  97. ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1);
  98. SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, sp.UUID, "att-name", 0x10);
  99. TaskInventoryHelpers.AddScript(
  100. scene.AssetService,
  101. so.RootPart,
  102. "scriptItem",
  103. "default { attach(key id) { if (id != NULL_KEY) { llSay(0, \"Hello World\"); } } }");
  104. InventoryItemBase userItem = UserInventoryHelpers.AddInventoryItem(scene, so, 0x100, 0x1000);
  105. // FIXME: Right now, we have to do a tricksy chat listen to make sure we know when the script is running.
  106. // In the future, we need to be able to do this programatically more predicably.
  107. scene.EventManager.OnChatFromWorld += OnChatFromWorld;
  108. SceneObjectGroup rezzedSo
  109. = scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest);
  110. TaskInventoryItem rezzedScriptItem = rezzedSo.RootPart.Inventory.GetInventoryItem("scriptItem");
  111. // Wait for chat to signal rezzed script has been started.
  112. m_chatEvent.WaitOne(60000);
  113. // Force save
  114. xEngine.DoBackup(new Object[] { 0 });
  115. // Console.WriteLine("ItemID {0}", rezzedScriptItem.ItemID);
  116. //
  117. // foreach (
  118. // string s in Directory.EnumerateFileSystemEntries(
  119. // string.Format("ScriptEngines/{0}", scene.RegionInfo.RegionID)))
  120. // Console.WriteLine(s);
  121. Assert.IsFalse(
  122. File.Exists(
  123. string.Format("ScriptEngines/{0}/{1}.state", scene.RegionInfo.RegionID, rezzedScriptItem.ItemID)));
  124. scene.AttachmentsModule.DetachSingleAttachmentToInv(sp, rezzedSo);
  125. }
  126. }
  127. */
  128. }