diff options
author | Justin Clark-Casey (justincc) | 2012-07-11 21:43:35 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-07-11 21:43:35 +0100 |
commit | fc2456320646df66b95a06d4cd292c3b2385a8ea (patch) | |
tree | c1f7eaf2c679a9e7d039240146510ffc6a744cd1 /OpenSim/Region/CoreModules/Avatar/Attachments/Tests | |
parent | Add regression TestRezScriptedAttachmentsFromInventory() though this currentl... (diff) | |
download | opensim-SC-fc2456320646df66b95a06d4cd292c3b2385a8ea.zip opensim-SC-fc2456320646df66b95a06d4cd292c3b2385a8ea.tar.gz opensim-SC-fc2456320646df66b95a06d4cd292c3b2385a8ea.tar.bz2 opensim-SC-fc2456320646df66b95a06d4cd292c3b2385a8ea.tar.xz |
Add regression TestDetachScriptedAttachmentToInventory()
This currently only does a relatively crude check for a ScriptState node in the serialized xml
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Attachments/Tests')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs | 131 |
1 files changed, 116 insertions, 15 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs index 416aa6f..81e889d 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs | |||
@@ -31,6 +31,7 @@ using System.Reflection; | |||
31 | using System.Text; | 31 | using System.Text; |
32 | using System.Threading; | 32 | using System.Threading; |
33 | using System.Timers; | 33 | using System.Timers; |
34 | using System.Xml; | ||
34 | using Timer=System.Timers.Timer; | 35 | using Timer=System.Timers.Timer; |
35 | using Nini.Config; | 36 | using Nini.Config; |
36 | using NUnit.Framework; | 37 | using NUnit.Framework; |
@@ -41,10 +42,12 @@ using OpenSim.Region.CoreModules.Avatar.Attachments; | |||
41 | using OpenSim.Region.CoreModules.Framework; | 42 | using OpenSim.Region.CoreModules.Framework; |
42 | using OpenSim.Region.CoreModules.Framework.EntityTransfer; | 43 | using OpenSim.Region.CoreModules.Framework.EntityTransfer; |
43 | using OpenSim.Region.CoreModules.Framework.InventoryAccess; | 44 | using OpenSim.Region.CoreModules.Framework.InventoryAccess; |
44 | using OpenSim.Region.CoreModules.World.Serialiser; | 45 | using OpenSim.Region.CoreModules.Scripting.WorldComm; |
45 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; | 46 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; |
47 | using OpenSim.Region.CoreModules.World.Serialiser; | ||
46 | using OpenSim.Region.Framework.Scenes; | 48 | using OpenSim.Region.Framework.Scenes; |
47 | using OpenSim.Region.Framework.Interfaces; | 49 | using OpenSim.Region.Framework.Interfaces; |
50 | using OpenSim.Region.ScriptEngine.XEngine; | ||
48 | using OpenSim.Services.Interfaces; | 51 | using OpenSim.Services.Interfaces; |
49 | using OpenSim.Tests.Common; | 52 | using OpenSim.Tests.Common; |
50 | using OpenSim.Tests.Common.Mock; | 53 | using OpenSim.Tests.Common.Mock; |
@@ -57,6 +60,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
57 | [TestFixture] | 60 | [TestFixture] |
58 | public class AttachmentsModuleTests : OpenSimTestCase | 61 | public class AttachmentsModuleTests : OpenSimTestCase |
59 | { | 62 | { |
63 | private AutoResetEvent m_chatEvent = new AutoResetEvent(false); | ||
64 | private OSChatMessage m_osChatMessageReceived; | ||
65 | |||
60 | [TestFixtureSetUp] | 66 | [TestFixtureSetUp] |
61 | public void FixtureInit() | 67 | public void FixtureInit() |
62 | { | 68 | { |
@@ -72,16 +78,73 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
72 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; | 78 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; |
73 | } | 79 | } |
74 | 80 | ||
75 | private Scene CreateDefaultTestScene() | 81 | private void OnChatFromWorld(object sender, OSChatMessage oscm) |
82 | { | ||
83 | // Console.WriteLine("Got chat [{0}]", oscm.Message); | ||
84 | |||
85 | m_osChatMessageReceived = oscm; | ||
86 | m_chatEvent.Set(); | ||
87 | } | ||
88 | |||
89 | private Scene CreateTestScene() | ||
90 | { | ||
91 | IConfigSource config = new IniConfigSource(); | ||
92 | List<object> modules = new List<object>(); | ||
93 | |||
94 | AddCommonConfig(config, modules); | ||
95 | |||
96 | Scene scene | ||
97 | = new SceneHelpers().SetupScene( | ||
98 | "attachments-test-scene", TestHelpers.ParseTail(999), 1000, 1000, config); | ||
99 | SceneHelpers.SetupSceneModules(scene, config, modules.ToArray()); | ||
100 | |||
101 | return scene; | ||
102 | } | ||
103 | |||
104 | private Scene CreateScriptingEnabledTestScene() | ||
76 | { | 105 | { |
77 | IConfigSource config = new IniConfigSource(); | 106 | IConfigSource config = new IniConfigSource(); |
107 | List<object> modules = new List<object>(); | ||
108 | |||
109 | AddCommonConfig(config, modules); | ||
110 | AddScriptingConfig(config, modules); | ||
111 | |||
112 | Scene scene | ||
113 | = new SceneHelpers().SetupScene( | ||
114 | "attachments-test-scene", TestHelpers.ParseTail(999), 1000, 1000, config); | ||
115 | SceneHelpers.SetupSceneModules(scene, config, modules.ToArray()); | ||
116 | |||
117 | scene.StartScripts(); | ||
118 | |||
119 | return scene; | ||
120 | } | ||
121 | |||
122 | private void AddCommonConfig(IConfigSource config, List<object> modules) | ||
123 | { | ||
78 | config.AddConfig("Modules"); | 124 | config.AddConfig("Modules"); |
79 | config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); | 125 | config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); |
80 | 126 | ||
81 | Scene scene = new SceneHelpers().SetupScene(); | 127 | modules.Add(new AttachmentsModule()); |
82 | SceneHelpers.SetupSceneModules(scene, config, new AttachmentsModule(), new BasicInventoryAccessModule()); | 128 | modules.Add(new BasicInventoryAccessModule()); |
129 | } | ||
83 | 130 | ||
84 | return scene; | 131 | private void AddScriptingConfig(IConfigSource config, List<object> modules) |
132 | { | ||
133 | IConfig startupConfig = config.AddConfig("Startup"); | ||
134 | startupConfig.Set("DefaultScriptEngine", "XEngine"); | ||
135 | |||
136 | IConfig xEngineConfig = config.AddConfig("XEngine"); | ||
137 | xEngineConfig.Set("Enabled", "true"); | ||
138 | |||
139 | // These tests will not run with AppDomainLoading = true, at least on mono. For unknown reasons, the call | ||
140 | // to AssemblyResolver.OnAssemblyResolve fails. | ||
141 | xEngineConfig.Set("AppDomainLoading", "false"); | ||
142 | |||
143 | modules.Add(new XEngine()); | ||
144 | |||
145 | // Necessary to stop serialization complaining | ||
146 | // FIXME: Stop this being necessary if at all possible | ||
147 | // modules.Add(new WorldCommModule()); | ||
85 | } | 148 | } |
86 | 149 | ||
87 | /// <summary> | 150 | /// <summary> |
@@ -116,7 +179,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
116 | TestHelpers.InMethod(); | 179 | TestHelpers.InMethod(); |
117 | // TestHelpers.EnableLogging(); | 180 | // TestHelpers.EnableLogging(); |
118 | 181 | ||
119 | Scene scene = CreateDefaultTestScene(); | 182 | Scene scene = CreateTestScene(); |
120 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); | 183 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); |
121 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1); | 184 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1); |
122 | 185 | ||
@@ -163,7 +226,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
163 | TestHelpers.InMethod(); | 226 | TestHelpers.InMethod(); |
164 | // TestHelpers.EnableLogging(); | 227 | // TestHelpers.EnableLogging(); |
165 | 228 | ||
166 | Scene scene = CreateDefaultTestScene(); | 229 | Scene scene = CreateTestScene(); |
167 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); | 230 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); |
168 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1); | 231 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1); |
169 | 232 | ||
@@ -190,7 +253,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
190 | TestHelpers.InMethod(); | 253 | TestHelpers.InMethod(); |
191 | // log4net.Config.XmlConfigurator.Configure(); | 254 | // log4net.Config.XmlConfigurator.Configure(); |
192 | 255 | ||
193 | Scene scene = CreateDefaultTestScene(); | 256 | Scene scene = CreateTestScene(); |
194 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); | 257 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); |
195 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID); | 258 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID); |
196 | 259 | ||
@@ -225,7 +288,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
225 | { | 288 | { |
226 | TestHelpers.InMethod(); | 289 | TestHelpers.InMethod(); |
227 | 290 | ||
228 | Scene scene = CreateDefaultTestScene(); | 291 | Scene scene = CreateTestScene(); |
229 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); | 292 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); |
230 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID); | 293 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID); |
231 | 294 | ||
@@ -248,7 +311,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
248 | TestHelpers.InMethod(); | 311 | TestHelpers.InMethod(); |
249 | // log4net.Config.XmlConfigurator.Configure(); | 312 | // log4net.Config.XmlConfigurator.Configure(); |
250 | 313 | ||
251 | Scene scene = CreateDefaultTestScene(); | 314 | Scene scene = CreateTestScene(); |
252 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); | 315 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); |
253 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID); | 316 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID); |
254 | 317 | ||
@@ -278,9 +341,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
278 | public void TestDetachAttachmentToInventory() | 341 | public void TestDetachAttachmentToInventory() |
279 | { | 342 | { |
280 | TestHelpers.InMethod(); | 343 | TestHelpers.InMethod(); |
281 | // log4net.Config.XmlConfigurator.Configure(); | ||
282 | 344 | ||
283 | Scene scene = CreateDefaultTestScene(); | 345 | Scene scene = CreateTestScene(); |
284 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); | 346 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); |
285 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID); | 347 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID); |
286 | 348 | ||
@@ -303,6 +365,45 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
303 | } | 365 | } |
304 | 366 | ||
305 | /// <summary> | 367 | /// <summary> |
368 | /// Test specific conditions associated with detaching a scripted attachment from inventory. | ||
369 | /// </summary> | ||
370 | [Test] | ||
371 | public void TestDetachScriptedAttachmentToInventory() | ||
372 | { | ||
373 | TestHelpers.InMethod(); | ||
374 | TestHelpers.EnableLogging(); | ||
375 | |||
376 | Scene scene = CreateScriptingEnabledTestScene(); | ||
377 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); | ||
378 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1); | ||
379 | |||
380 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, sp.UUID, "att-name", 0x10); | ||
381 | TaskInventoryHelpers.AddScript(scene, so.RootPart); | ||
382 | InventoryItemBase userItem = UserInventoryHelpers.AddInventoryItem(scene, so, 0x100, 0x1000); | ||
383 | |||
384 | // FIXME: Right now, we have to do a tricksy chat listen to make sure we know when the script is running. | ||
385 | // In the future, we need to be able to do this programatically more predicably. | ||
386 | scene.EventManager.OnChatFromWorld += OnChatFromWorld; | ||
387 | |||
388 | SceneObjectGroup soRezzed | ||
389 | = scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest); | ||
390 | |||
391 | // Wait for chat to signal rezzed script has been started. | ||
392 | m_chatEvent.WaitOne(60000); | ||
393 | |||
394 | scene.AttachmentsModule.DetachSingleAttachmentToInv(sp, soRezzed); | ||
395 | |||
396 | InventoryItemBase userItemUpdated = scene.InventoryService.GetItem(userItem); | ||
397 | AssetBase asset = scene.AssetService.Get(userItemUpdated.AssetID.ToString()); | ||
398 | |||
399 | XmlDocument soXml = new XmlDocument(); | ||
400 | soXml.LoadXml(Encoding.UTF8.GetString(asset.Data)); | ||
401 | |||
402 | XmlNodeList scriptStateNodes = soXml.GetElementsByTagName("ScriptState"); | ||
403 | Assert.That(scriptStateNodes.Count, Is.EqualTo(1)); | ||
404 | } | ||
405 | |||
406 | /// <summary> | ||
306 | /// Test that attachments don't hang about in the scene when the agent is closed | 407 | /// Test that attachments don't hang about in the scene when the agent is closed |
307 | /// </summary> | 408 | /// </summary> |
308 | [Test] | 409 | [Test] |
@@ -311,7 +412,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
311 | TestHelpers.InMethod(); | 412 | TestHelpers.InMethod(); |
312 | // log4net.Config.XmlConfigurator.Configure(); | 413 | // log4net.Config.XmlConfigurator.Configure(); |
313 | 414 | ||
314 | Scene scene = CreateDefaultTestScene(); | 415 | Scene scene = CreateTestScene(); |
315 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); | 416 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); |
316 | InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20); | 417 | InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20); |
317 | 418 | ||
@@ -334,7 +435,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
334 | TestHelpers.InMethod(); | 435 | TestHelpers.InMethod(); |
335 | // log4net.Config.XmlConfigurator.Configure(); | 436 | // log4net.Config.XmlConfigurator.Configure(); |
336 | 437 | ||
337 | Scene scene = CreateDefaultTestScene(); | 438 | Scene scene = CreateTestScene(); |
338 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); | 439 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); |
339 | InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20); | 440 | InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20); |
340 | 441 | ||
@@ -370,7 +471,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
370 | { | 471 | { |
371 | TestHelpers.InMethod(); | 472 | TestHelpers.InMethod(); |
372 | 473 | ||
373 | Scene scene = CreateDefaultTestScene(); | 474 | Scene scene = CreateTestScene(); |
374 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); | 475 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); |
375 | InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20); | 476 | InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20); |
376 | 477 | ||