diff options
Merge branch 'master' into careminster
Conflicts:
OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Attachments/Tests')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs index cd1e1c1..273e290 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs | |||
@@ -47,6 +47,7 @@ using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; | |||
47 | using OpenSim.Region.CoreModules.World.Serialiser; | 47 | using OpenSim.Region.CoreModules.World.Serialiser; |
48 | using OpenSim.Region.Framework.Scenes; | 48 | using OpenSim.Region.Framework.Scenes; |
49 | using OpenSim.Region.Framework.Interfaces; | 49 | using OpenSim.Region.Framework.Interfaces; |
50 | using OpenSim.Region.ScriptEngine.Interfaces; | ||
50 | using OpenSim.Region.ScriptEngine.XEngine; | 51 | using OpenSim.Region.ScriptEngine.XEngine; |
51 | using OpenSim.Services.Interfaces; | 52 | using OpenSim.Services.Interfaces; |
52 | using OpenSim.Tests.Common; | 53 | using OpenSim.Tests.Common; |
@@ -289,21 +290,37 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
289 | { | 290 | { |
290 | TestHelpers.InMethod(); | 291 | TestHelpers.InMethod(); |
291 | 292 | ||
292 | Scene scene = CreateTestScene(); | 293 | Scene scene = CreateScriptingEnabledTestScene(); |
293 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); | 294 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); |
294 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID); | 295 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1); |
295 | 296 | ||
296 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, sp.UUID, "att-name", 0x10); | 297 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, sp.UUID, "att-name", 0x10); |
297 | TaskInventoryHelpers.AddScript(scene, so.RootPart); | 298 | TaskInventoryItem scriptItem |
299 | = TaskInventoryHelpers.AddScript( | ||
300 | scene, | ||
301 | so.RootPart, | ||
302 | "scriptItem", | ||
303 | "default { attach(key id) { if (id != NULL_KEY) { llSay(0, \"Hello World\"); } } }"); | ||
304 | |||
298 | InventoryItemBase userItem = UserInventoryHelpers.AddInventoryItem(scene, so, 0x100, 0x1000); | 305 | InventoryItemBase userItem = UserInventoryHelpers.AddInventoryItem(scene, so, 0x100, 0x1000); |
299 | 306 | ||
307 | // FIXME: Right now, we have to do a tricksy chat listen to make sure we know when the script is running. | ||
308 | // In the future, we need to be able to do this programatically more predicably. | ||
309 | scene.EventManager.OnChatFromWorld += OnChatFromWorld; | ||
310 | |||
300 | scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest); | 311 | scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest); |
301 | 312 | ||
313 | m_chatEvent.WaitOne(60000); | ||
314 | |||
302 | // TODO: Need to have a test that checks the script is actually started but this involves a lot more | 315 | // TODO: Need to have a test that checks the script is actually started but this involves a lot more |
303 | // plumbing of the script engine and either pausing for events or more infrastructure to turn off various | 316 | // plumbing of the script engine and either pausing for events or more infrastructure to turn off various |
304 | // script engine delays/asychronicity that isn't helpful in an automated regression testing context. | 317 | // script engine delays/asychronicity that isn't helpful in an automated regression testing context. |
305 | SceneObjectGroup attSo = scene.GetSceneObjectGroup(so.Name); | 318 | SceneObjectGroup attSo = scene.GetSceneObjectGroup(so.Name); |
306 | Assert.That(attSo.ContainsScripts(), Is.True); | 319 | Assert.That(attSo.ContainsScripts(), Is.True); |
320 | |||
321 | TaskInventoryItem reRezzedScriptItem = attSo.RootPart.Inventory.GetInventoryItem(scriptItem.Name); | ||
322 | IScriptModule xengine = scene.RequestModuleInterface<IScriptModule>(); | ||
323 | Assert.That(xengine.GetScriptState(reRezzedScriptItem.ItemID), Is.True); | ||
307 | } | 324 | } |
308 | 325 | ||
309 | [Test] | 326 | [Test] |
@@ -379,29 +396,49 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
379 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1); | 396 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1); |
380 | 397 | ||
381 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, sp.UUID, "att-name", 0x10); | 398 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, sp.UUID, "att-name", 0x10); |
382 | TaskInventoryHelpers.AddScript(scene, so.RootPart); | 399 | TaskInventoryItem scriptTaskItem |
400 | = TaskInventoryHelpers.AddScript( | ||
401 | scene, | ||
402 | so.RootPart, | ||
403 | "scriptItem", | ||
404 | "default { attach(key id) { if (id != NULL_KEY) { llSay(0, \"Hello World\"); } } }"); | ||
405 | |||
383 | InventoryItemBase userItem = UserInventoryHelpers.AddInventoryItem(scene, so, 0x100, 0x1000); | 406 | InventoryItemBase userItem = UserInventoryHelpers.AddInventoryItem(scene, so, 0x100, 0x1000); |
384 | 407 | ||
385 | // FIXME: Right now, we have to do a tricksy chat listen to make sure we know when the script is running. | 408 | // FIXME: Right now, we have to do a tricksy chat listen to make sure we know when the script is running. |
386 | // In the future, we need to be able to do this programatically more predicably. | 409 | // In the future, we need to be able to do this programatically more predicably. |
387 | scene.EventManager.OnChatFromWorld += OnChatFromWorld; | 410 | scene.EventManager.OnChatFromWorld += OnChatFromWorld; |
388 | 411 | ||
389 | SceneObjectGroup soRezzed | 412 | SceneObjectGroup rezzedSo |
390 | = (SceneObjectGroup)scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest); | 413 | = (SceneObjectGroup)(scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest)); |
391 | 414 | ||
392 | // Wait for chat to signal rezzed script has been started. | 415 | // Wait for chat to signal rezzed script has been started. |
393 | m_chatEvent.WaitOne(60000); | 416 | m_chatEvent.WaitOne(60000); |
394 | 417 | ||
395 | scene.AttachmentsModule.DetachSingleAttachmentToInv(sp, soRezzed); | 418 | scene.AttachmentsModule.DetachSingleAttachmentToInv(sp, rezzedSo); |
396 | 419 | ||
397 | InventoryItemBase userItemUpdated = scene.InventoryService.GetItem(userItem); | 420 | InventoryItemBase userItemUpdated = scene.InventoryService.GetItem(userItem); |
398 | AssetBase asset = scene.AssetService.Get(userItemUpdated.AssetID.ToString()); | 421 | AssetBase asset = scene.AssetService.Get(userItemUpdated.AssetID.ToString()); |
399 | 422 | ||
423 | // TODO: It would probably be better here to check script state via the saving and retrieval of state | ||
424 | // information at a higher level, rather than having to inspect the serialization. | ||
400 | XmlDocument soXml = new XmlDocument(); | 425 | XmlDocument soXml = new XmlDocument(); |
401 | soXml.LoadXml(Encoding.UTF8.GetString(asset.Data)); | 426 | soXml.LoadXml(Encoding.UTF8.GetString(asset.Data)); |
402 | 427 | ||
403 | XmlNodeList scriptStateNodes = soXml.GetElementsByTagName("ScriptState"); | 428 | XmlNodeList scriptStateNodes = soXml.GetElementsByTagName("ScriptState"); |
404 | Assert.That(scriptStateNodes.Count, Is.EqualTo(1)); | 429 | Assert.That(scriptStateNodes.Count, Is.EqualTo(1)); |
430 | |||
431 | // Re-rez the attachment to check script running state | ||
432 | SceneObjectGroup reRezzedSo = (SceneObjectGroup)(scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest)); | ||
433 | |||
434 | // Wait for chat to signal rezzed script has been started. | ||
435 | m_chatEvent.WaitOne(60000); | ||
436 | |||
437 | TaskInventoryItem reRezzedScriptItem = reRezzedSo.RootPart.Inventory.GetInventoryItem(scriptTaskItem.Name); | ||
438 | IScriptModule xengine = scene.RequestModuleInterface<IScriptModule>(); | ||
439 | Assert.That(xengine.GetScriptState(reRezzedScriptItem.ItemID), Is.True); | ||
440 | |||
441 | // Console.WriteLine(soXml.OuterXml); | ||
405 | } | 442 | } |
406 | 443 | ||
407 | /// <summary> | 444 | /// <summary> |