aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs430
1 files changed, 395 insertions, 35 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs
index 0ee01c7..0ac3add 100644
--- a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs
@@ -37,7 +37,8 @@ using Nini.Config;
37using NUnit.Framework; 37using NUnit.Framework;
38using OpenMetaverse; 38using OpenMetaverse;
39using OpenSim.Framework; 39using OpenSim.Framework;
40using OpenSim.Framework.Communications; 40using OpenSim.Framework.Servers;
41using OpenSim.Framework.Servers.HttpServer;
41using OpenSim.Region.CoreModules.Avatar.Attachments; 42using OpenSim.Region.CoreModules.Avatar.Attachments;
42using OpenSim.Region.CoreModules.Framework; 43using OpenSim.Region.CoreModules.Framework;
43using OpenSim.Region.CoreModules.Framework.EntityTransfer; 44using OpenSim.Region.CoreModules.Framework.EntityTransfer;
@@ -51,7 +52,6 @@ using OpenSim.Region.ScriptEngine.Interfaces;
51using OpenSim.Region.ScriptEngine.XEngine; 52using OpenSim.Region.ScriptEngine.XEngine;
52using OpenSim.Services.Interfaces; 53using OpenSim.Services.Interfaces;
53using OpenSim.Tests.Common; 54using OpenSim.Tests.Common;
54using OpenSim.Tests.Common.Mock;
55 55
56namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests 56namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
57{ 57{
@@ -130,7 +130,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
130 config.AddConfig("Modules"); 130 config.AddConfig("Modules");
131 config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); 131 config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
132 132
133 modules.Add(new AttachmentsModule()); 133 AttachmentsModule attMod = new AttachmentsModule();
134 attMod.DebugLevel = 1;
135 modules.Add(attMod);
134 modules.Add(new BasicInventoryAccessModule()); 136 modules.Add(new BasicInventoryAccessModule());
135 } 137 }
136 138
@@ -195,9 +197,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
195 string attName = "att"; 197 string attName = "att";
196 198
197 SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, attName, sp.UUID); 199 SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, attName, sp.UUID);
200 Assert.That(so.Backup, Is.True);
198 201
199 m_numberOfAttachEventsFired = 0; 202 m_numberOfAttachEventsFired = 0;
200 scene.AttachmentsModule.AttachObject(sp, so, (uint)AttachmentPoint.Chest, false, false); 203 scene.AttachmentsModule.AttachObject(sp, so, (uint)AttachmentPoint.Chest, false, true, false);
201 204
202 // Check status on scene presence 205 // Check status on scene presence
203 Assert.That(sp.HasAttachments(), Is.True); 206 Assert.That(sp.HasAttachments(), Is.True);
@@ -209,6 +212,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
209 Assert.That(attSo.IsAttachment); 212 Assert.That(attSo.IsAttachment);
210 Assert.That(attSo.UsesPhysics, Is.False); 213 Assert.That(attSo.UsesPhysics, Is.False);
211 Assert.That(attSo.IsTemporary, Is.False); 214 Assert.That(attSo.IsTemporary, Is.False);
215 Assert.That(attSo.Backup, Is.False);
212 216
213 // Check item status 217 // Check item status
214 Assert.That( 218 Assert.That(
@@ -219,7 +223,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
219 Assert.That(attachmentItem, Is.Not.Null); 223 Assert.That(attachmentItem, Is.Not.Null);
220 Assert.That(attachmentItem.Name, Is.EqualTo(attName)); 224 Assert.That(attachmentItem.Name, Is.EqualTo(attName));
221 225
222 InventoryFolderBase targetFolder = scene.InventoryService.GetFolderForType(sp.UUID, AssetType.Object); 226 InventoryFolderBase targetFolder = scene.InventoryService.GetFolderForType(sp.UUID, FolderType.Object);
223 Assert.That(attachmentItem.Folder, Is.EqualTo(targetFolder.ID)); 227 Assert.That(attachmentItem.Folder, Is.EqualTo(targetFolder.ID));
224 228
225 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1)); 229 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
@@ -228,6 +232,120 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
228 Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(1)); 232 Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(1));
229 } 233 }
230 234
235 [Test]
236 public void TestWearAttachmentFromGround()
237 {
238 TestHelpers.InMethod();
239// TestHelpers.EnableLogging();
240
241 Scene scene = CreateTestScene();
242 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
243 ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1);
244
245 SceneObjectGroup so2 = SceneHelpers.AddSceneObject(scene, "att2", sp.UUID);
246
247 {
248 SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, "att1", sp.UUID);
249
250 m_numberOfAttachEventsFired = 0;
251 scene.AttachmentsModule.AttachObject(sp, so, (uint)AttachmentPoint.Default, false, true, false);
252
253 // Check status on scene presence
254 Assert.That(sp.HasAttachments(), Is.True);
255 List<SceneObjectGroup> attachments = sp.GetAttachments();
256 Assert.That(attachments.Count, Is.EqualTo(1));
257 SceneObjectGroup attSo = attachments[0];
258 Assert.That(attSo.Name, Is.EqualTo(so.Name));
259 Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.LeftHand));
260 Assert.That(attSo.IsAttachment);
261 Assert.That(attSo.UsesPhysics, Is.False);
262 Assert.That(attSo.IsTemporary, Is.False);
263
264 // Check item status
265 Assert.That(
266 sp.Appearance.GetAttachpoint(attSo.FromItemID),
267 Is.EqualTo((int)AttachmentPoint.LeftHand));
268
269 InventoryItemBase attachmentItem = scene.InventoryService.GetItem(new InventoryItemBase(attSo.FromItemID));
270 Assert.That(attachmentItem, Is.Not.Null);
271 Assert.That(attachmentItem.Name, Is.EqualTo(so.Name));
272
273 InventoryFolderBase targetFolder = scene.InventoryService.GetFolderForType(sp.UUID, FolderType.Object);
274 Assert.That(attachmentItem.Folder, Is.EqualTo(targetFolder.ID));
275
276 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(2));
277
278 // Check events
279 Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(1));
280 }
281
282 // Test wearing a different attachment from the ground.
283 {
284 scene.AttachmentsModule.AttachObject(sp, so2, (uint)AttachmentPoint.Default, false, true, false);
285
286 // Check status on scene presence
287 Assert.That(sp.HasAttachments(), Is.True);
288 List<SceneObjectGroup> attachments = sp.GetAttachments();
289 Assert.That(attachments.Count, Is.EqualTo(1));
290 SceneObjectGroup attSo = attachments[0];
291 Assert.That(attSo.Name, Is.EqualTo(so2.Name));
292 Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.LeftHand));
293 Assert.That(attSo.IsAttachment);
294 Assert.That(attSo.UsesPhysics, Is.False);
295 Assert.That(attSo.IsTemporary, Is.False);
296
297 // Check item status
298 Assert.That(
299 sp.Appearance.GetAttachpoint(attSo.FromItemID),
300 Is.EqualTo((int)AttachmentPoint.LeftHand));
301
302 InventoryItemBase attachmentItem = scene.InventoryService.GetItem(new InventoryItemBase(attSo.FromItemID));
303 Assert.That(attachmentItem, Is.Not.Null);
304 Assert.That(attachmentItem.Name, Is.EqualTo(so2.Name));
305
306 InventoryFolderBase targetFolder = scene.InventoryService.GetFolderForType(sp.UUID, FolderType.Object);
307 Assert.That(attachmentItem.Folder, Is.EqualTo(targetFolder.ID));
308
309 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
310
311 // Check events
312 Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(3));
313 }
314
315 // Test rewearing an already worn attachment from ground. Nothing should happen.
316 {
317 scene.AttachmentsModule.AttachObject(sp, so2, (uint)AttachmentPoint.Default, false, true, false);
318
319 // Check status on scene presence
320 Assert.That(sp.HasAttachments(), Is.True);
321 List<SceneObjectGroup> attachments = sp.GetAttachments();
322 Assert.That(attachments.Count, Is.EqualTo(1));
323 SceneObjectGroup attSo = attachments[0];
324 Assert.That(attSo.Name, Is.EqualTo(so2.Name));
325 Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.LeftHand));
326 Assert.That(attSo.IsAttachment);
327 Assert.That(attSo.UsesPhysics, Is.False);
328 Assert.That(attSo.IsTemporary, Is.False);
329
330 // Check item status
331 Assert.That(
332 sp.Appearance.GetAttachpoint(attSo.FromItemID),
333 Is.EqualTo((int)AttachmentPoint.LeftHand));
334
335 InventoryItemBase attachmentItem = scene.InventoryService.GetItem(new InventoryItemBase(attSo.FromItemID));
336 Assert.That(attachmentItem, Is.Not.Null);
337 Assert.That(attachmentItem.Name, Is.EqualTo(so2.Name));
338
339 InventoryFolderBase targetFolder = scene.InventoryService.GetFolderForType(sp.UUID, FolderType.Object);
340 Assert.That(attachmentItem.Folder, Is.EqualTo(targetFolder.ID));
341
342 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
343
344 // Check events
345 Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(3));
346 }
347 }
348
231 /// <summary> 349 /// <summary>
232 /// Test that we do not attempt to attach an in-world object that someone else is sitting on. 350 /// Test that we do not attempt to attach an in-world object that someone else is sitting on.
233 /// </summary> 351 /// </summary>
@@ -254,7 +372,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
254 sp2.AbsolutePosition = new Vector3(0, 0, 0); 372 sp2.AbsolutePosition = new Vector3(0, 0, 0);
255 sp2.HandleAgentRequestSit(sp2.ControllingClient, sp2.UUID, so.UUID, Vector3.Zero); 373 sp2.HandleAgentRequestSit(sp2.ControllingClient, sp2.UUID, so.UUID, Vector3.Zero);
256 374
257 scene.AttachmentsModule.AttachObject(sp, so, (uint)AttachmentPoint.Chest, false, false); 375 scene.AttachmentsModule.AttachObject(sp, so, (uint)AttachmentPoint.Chest, false, true, false);
258 376
259 Assert.That(sp.HasAttachments(), Is.False); 377 Assert.That(sp.HasAttachments(), Is.False);
260 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1)); 378 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
@@ -267,7 +385,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
267 public void TestRezAttachmentFromInventory() 385 public void TestRezAttachmentFromInventory()
268 { 386 {
269 TestHelpers.InMethod(); 387 TestHelpers.InMethod();
270// log4net.Config.XmlConfigurator.Configure(); 388// TestHelpers.EnableLogging();
271 389
272 Scene scene = CreateTestScene(); 390 Scene scene = CreateTestScene();
273 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); 391 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
@@ -275,29 +393,141 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
275 393
276 InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20); 394 InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20);
277 395
278 m_numberOfAttachEventsFired = 0; 396 {
279 scene.AttachmentsModule.RezSingleAttachmentFromInventory( 397 scene.AttachmentsModule.RezSingleAttachmentFromInventory(
280 sp, attItem.ID, (uint)AttachmentPoint.Chest); 398 sp, attItem.ID, (uint)AttachmentPoint.Chest);
281 399
282 // Check scene presence status 400 // Check scene presence status
283 Assert.That(sp.HasAttachments(), Is.True); 401 Assert.That(sp.HasAttachments(), Is.True);
284 List<SceneObjectGroup> attachments = sp.GetAttachments(); 402 List<SceneObjectGroup> attachments = sp.GetAttachments();
285 Assert.That(attachments.Count, Is.EqualTo(1)); 403 Assert.That(attachments.Count, Is.EqualTo(1));
286 SceneObjectGroup attSo = attachments[0]; 404 SceneObjectGroup attSo = attachments[0];
287 Assert.That(attSo.Name, Is.EqualTo(attItem.Name)); 405 Assert.That(attSo.Name, Is.EqualTo(attItem.Name));
288 Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest)); 406 Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest));
289 Assert.That(attSo.IsAttachment); 407 Assert.That(attSo.IsAttachment);
290 Assert.That(attSo.UsesPhysics, Is.False); 408 Assert.That(attSo.UsesPhysics, Is.False);
291 Assert.That(attSo.IsTemporary, Is.False); 409 Assert.That(attSo.IsTemporary, Is.False);
410 Assert.IsFalse(attSo.Backup);
411
412 // Check appearance status
413 Assert.That(sp.Appearance.GetAttachments().Count, Is.EqualTo(1));
414 Assert.That(sp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest));
415 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
416
417 // Check events
418 Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(1));
419 }
420
421 // Test attaching an already attached attachment
422 {
423 scene.AttachmentsModule.RezSingleAttachmentFromInventory(
424 sp, attItem.ID, (uint)AttachmentPoint.Chest);
292 425
293 // Check appearance status 426 // Check scene presence status
294 Assert.That(sp.Appearance.GetAttachments().Count, Is.EqualTo(1)); 427 Assert.That(sp.HasAttachments(), Is.True);
295 Assert.That(sp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest)); 428 List<SceneObjectGroup> attachments = sp.GetAttachments();
429 Assert.That(attachments.Count, Is.EqualTo(1));
430 SceneObjectGroup attSo = attachments[0];
431 Assert.That(attSo.Name, Is.EqualTo(attItem.Name));
432 Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest));
433 Assert.That(attSo.IsAttachment);
434 Assert.That(attSo.UsesPhysics, Is.False);
435 Assert.That(attSo.IsTemporary, Is.False);
436
437 // Check appearance status
438 Assert.That(sp.Appearance.GetAttachments().Count, Is.EqualTo(1));
439 Assert.That(sp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest));
440 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
441
442 // Check events
443 Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(1));
444 }
445 }
296 446
297 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1)); 447 /// <summary>
448 /// Test wearing an attachment from inventory, as opposed to explicit choosing the rez point
449 /// </summary>
450 [Test]
451 public void TestWearAttachmentFromInventory()
452 {
453 TestHelpers.InMethod();
454// TestHelpers.EnableLogging();
298 455
299 // Check events 456 Scene scene = CreateTestScene();
300 Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(1)); 457 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
458 ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID);
459
460 InventoryItemBase attItem1 = CreateAttachmentItem(scene, ua1.PrincipalID, "att1", 0x10, 0x20);
461 InventoryItemBase attItem2 = CreateAttachmentItem(scene, ua1.PrincipalID, "att2", 0x11, 0x21);
462
463 {
464 m_numberOfAttachEventsFired = 0;
465 scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, attItem1.ID, (uint)AttachmentPoint.Default);
466
467 // default attachment point is currently the left hand.
468 Assert.That(sp.HasAttachments(), Is.True);
469 List<SceneObjectGroup> attachments = sp.GetAttachments();
470 Assert.That(attachments.Count, Is.EqualTo(1));
471 SceneObjectGroup attSo = attachments[0];
472 Assert.That(attSo.Name, Is.EqualTo(attItem1.Name));
473 Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.LeftHand));
474 Assert.That(attSo.IsAttachment);
475
476 // Check appearance status
477 Assert.That(sp.Appearance.GetAttachments().Count, Is.EqualTo(1));
478 Assert.That(sp.Appearance.GetAttachpoint(attItem1.ID), Is.EqualTo((int)AttachmentPoint.LeftHand));
479 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
480
481 // Check events
482 Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(1));
483 }
484
485 // Test wearing a second attachment at the same position
486 // Until multiple attachments at one point is implemented, this will remove the first attachment
487 // This test relies on both attachments having the same default attachment point (in this case LeftHand
488 // since none other has been set).
489 {
490 scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, attItem2.ID, (uint)AttachmentPoint.Default);
491
492 // default attachment point is currently the left hand.
493 Assert.That(sp.HasAttachments(), Is.True);
494 List<SceneObjectGroup> attachments = sp.GetAttachments();
495 Assert.That(attachments.Count, Is.EqualTo(1));
496 SceneObjectGroup attSo = attachments[0];
497 Assert.That(attSo.Name, Is.EqualTo(attItem2.Name));
498 Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.LeftHand));
499 Assert.That(attSo.IsAttachment);
500
501 // Check appearance status
502 Assert.That(sp.Appearance.GetAttachments().Count, Is.EqualTo(1));
503 Assert.That(sp.Appearance.GetAttachpoint(attItem2.ID), Is.EqualTo((int)AttachmentPoint.LeftHand));
504 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
505
506 // Check events
507 Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(3));
508 }
509
510 // Test wearing an already attached attachment
511 {
512 scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, attItem2.ID, (uint)AttachmentPoint.Default);
513
514 // default attachment point is currently the left hand.
515 Assert.That(sp.HasAttachments(), Is.True);
516 List<SceneObjectGroup> attachments = sp.GetAttachments();
517 Assert.That(attachments.Count, Is.EqualTo(1));
518 SceneObjectGroup attSo = attachments[0];
519 Assert.That(attSo.Name, Is.EqualTo(attItem2.Name));
520 Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.LeftHand));
521 Assert.That(attSo.IsAttachment);
522
523 // Check appearance status
524 Assert.That(sp.Appearance.GetAttachments().Count, Is.EqualTo(1));
525 Assert.That(sp.Appearance.GetAttachpoint(attItem2.ID), Is.EqualTo((int)AttachmentPoint.LeftHand));
526 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
527
528 // Check events
529 Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(3));
530 }
301 } 531 }
302 532
303 /// <summary> 533 /// <summary>
@@ -315,7 +545,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
315 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, sp.UUID, "att-name", 0x10); 545 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, sp.UUID, "att-name", 0x10);
316 TaskInventoryItem scriptItem 546 TaskInventoryItem scriptItem
317 = TaskInventoryHelpers.AddScript( 547 = TaskInventoryHelpers.AddScript(
318 scene, 548 scene.AssetService,
319 so.RootPart, 549 so.RootPart,
320 "scriptItem", 550 "scriptItem",
321 "default { attach(key id) { if (id != NULL_KEY) { llSay(0, \"Hello World\"); } } }"); 551 "default { attach(key id) { if (id != NULL_KEY) { llSay(0, \"Hello World\"); } } }");
@@ -372,7 +602,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
372 Assert.That(scene.InventoryService.GetItem(new InventoryItemBase(attItem.ID)), Is.Null); 602 Assert.That(scene.InventoryService.GetItem(new InventoryItemBase(attItem.ID)), Is.Null);
373 603
374 // Check object in scene 604 // Check object in scene
375 Assert.That(scene.GetSceneObjectGroup("att"), Is.Not.Null); 605 SceneObjectGroup soInScene = scene.GetSceneObjectGroup("att");
606 Assert.That(soInScene, Is.Not.Null);
607 Assert.IsTrue(soInScene.Backup);
376 608
377 // Check events 609 // Check events
378 Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(1)); 610 Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(1));
@@ -426,7 +658,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
426 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, sp.UUID, "att-name", 0x10); 658 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, sp.UUID, "att-name", 0x10);
427 TaskInventoryItem scriptTaskItem 659 TaskInventoryItem scriptTaskItem
428 = TaskInventoryHelpers.AddScript( 660 = TaskInventoryHelpers.AddScript(
429 scene, 661 scene.AssetService,
430 so.RootPart, 662 so.RootPart,
431 "scriptItem", 663 "scriptItem",
432 "default { attach(key id) { if (id != NULL_KEY) { llSay(0, \"Hello World\"); } } }"); 664 "default { attach(key id) { if (id != NULL_KEY) { llSay(0, \"Hello World\"); } } }");
@@ -490,7 +722,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
490 SceneObjectGroup rezzedAtt = presence.GetAttachments()[0]; 722 SceneObjectGroup rezzedAtt = presence.GetAttachments()[0];
491 723
492 m_numberOfAttachEventsFired = 0; 724 m_numberOfAttachEventsFired = 0;
493 scene.IncomingCloseAgent(presence.UUID, false); 725 scene.CloseAgent(presence.UUID, false);
494 726
495 // Check that we can't retrieve this attachment from the scene. 727 // Check that we can't retrieve this attachment from the scene.
496 Assert.That(scene.GetSceneObjectGroup(rezzedAtt.UUID), Is.Null); 728 Assert.That(scene.GetSceneObjectGroup(rezzedAtt.UUID), Is.Null);
@@ -503,7 +735,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
503 public void TestRezAttachmentsOnAvatarEntrance() 735 public void TestRezAttachmentsOnAvatarEntrance()
504 { 736 {
505 TestHelpers.InMethod(); 737 TestHelpers.InMethod();
506// log4net.Config.XmlConfigurator.Configure(); 738// TestHelpers.EnableLogging();
507 739
508 Scene scene = CreateTestScene(); 740 Scene scene = CreateTestScene();
509 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); 741 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
@@ -526,6 +758,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
526 Assert.That(attSo.IsAttachment); 758 Assert.That(attSo.IsAttachment);
527 Assert.That(attSo.UsesPhysics, Is.False); 759 Assert.That(attSo.UsesPhysics, Is.False);
528 Assert.That(attSo.IsTemporary, Is.False); 760 Assert.That(attSo.IsTemporary, Is.False);
761 Assert.IsFalse(attSo.Backup);
529 762
530 // Check appearance status 763 // Check appearance status
531 List<AvatarAttachment> retreivedAttachments = presence.Appearance.GetAttachments(); 764 List<AvatarAttachment> retreivedAttachments = presence.Appearance.GetAttachments();
@@ -569,12 +802,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
569 Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(0)); 802 Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(0));
570 } 803 }
571 804
805/*
572 [Test] 806 [Test]
573 public void TestSameSimulatorNeighbouringRegionsTeleport() 807 public void TestSameSimulatorNeighbouringRegionsTeleportV1()
574 { 808 {
575 TestHelpers.InMethod(); 809 TestHelpers.InMethod();
576// TestHelpers.EnableLogging(); 810// TestHelpers.EnableLogging();
577 811
812 BaseHttpServer httpServer = new BaseHttpServer(99999);
813 MainServer.AddHttpServer(httpServer);
814 MainServer.Instance = httpServer;
815
578 AttachmentsModule attModA = new AttachmentsModule(); 816 AttachmentsModule attModA = new AttachmentsModule();
579 AttachmentsModule attModB = new AttachmentsModule(); 817 AttachmentsModule attModB = new AttachmentsModule();
580 EntityTransferModule etmA = new EntityTransferModule(); 818 EntityTransferModule etmA = new EntityTransferModule();
@@ -603,8 +841,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
603 SceneHelpers.SetupSceneModules( 841 SceneHelpers.SetupSceneModules(
604 sceneB, config, new CapabilitiesModule(), etmB, attModB, new BasicInventoryAccessModule()); 842 sceneB, config, new CapabilitiesModule(), etmB, attModB, new BasicInventoryAccessModule());
605 843
844 // FIXME: Hack - this is here temporarily to revert back to older entity transfer behaviour
845 lscm.ServiceVersion = 0.1f;
846
606 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(sceneA, 0x1); 847 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(sceneA, 0x1);
607 ScenePresence beforeTeleportSp = SceneHelpers.AddScenePresence(sceneA, ua1.PrincipalID, sh.SceneManager); 848
849 AgentCircuitData acd = SceneHelpers.GenerateAgentData(ua1.PrincipalID);
850 TestClient tc = new TestClient(acd, sceneA);
851 List<TestClient> destinationTestClients = new List<TestClient>();
852 EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients);
853
854 ScenePresence beforeTeleportSp = SceneHelpers.AddScenePresence(sceneA, tc, acd);
608 beforeTeleportSp.AbsolutePosition = new Vector3(30, 31, 32); 855 beforeTeleportSp.AbsolutePosition = new Vector3(30, 31, 32);
609 856
610 InventoryItemBase attItem = CreateAttachmentItem(sceneA, ua1.PrincipalID, "att", 0x10, 0x20); 857 InventoryItemBase attItem = CreateAttachmentItem(sceneA, ua1.PrincipalID, "att", 0x10, 0x20);
@@ -623,7 +870,119 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
623 teleportLookAt, 870 teleportLookAt,
624 (uint)TeleportFlags.ViaLocation); 871 (uint)TeleportFlags.ViaLocation);
625 872
626 ((TestClient)beforeTeleportSp.ControllingClient).CompleteTeleportClientSide(); 873 destinationTestClients[0].CompleteMovement();
874
875 // Check attachments have made it into sceneB
876 ScenePresence afterTeleportSceneBSp = sceneB.GetScenePresence(ua1.PrincipalID);
877
878 // This is appearance data, as opposed to actually rezzed attachments
879 List<AvatarAttachment> sceneBAttachments = afterTeleportSceneBSp.Appearance.GetAttachments();
880 Assert.That(sceneBAttachments.Count, Is.EqualTo(1));
881 Assert.That(sceneBAttachments[0].AttachPoint, Is.EqualTo((int)AttachmentPoint.Chest));
882 Assert.That(sceneBAttachments[0].ItemID, Is.EqualTo(attItem.ID));
883 Assert.That(sceneBAttachments[0].AssetID, Is.EqualTo(attItem.AssetID));
884 Assert.That(afterTeleportSceneBSp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest));
885
886 // This is the actual attachment
887 List<SceneObjectGroup> actualSceneBAttachments = afterTeleportSceneBSp.GetAttachments();
888 Assert.That(actualSceneBAttachments.Count, Is.EqualTo(1));
889 SceneObjectGroup actualSceneBAtt = actualSceneBAttachments[0];
890 Assert.That(actualSceneBAtt.Name, Is.EqualTo(attItem.Name));
891 Assert.That(actualSceneBAtt.AttachmentPoint, Is.EqualTo((uint)AttachmentPoint.Chest));
892 Assert.IsFalse(actualSceneBAtt.Backup);
893
894 Assert.That(sceneB.GetSceneObjectGroups().Count, Is.EqualTo(1));
895
896 // Check attachments have been removed from sceneA
897 ScenePresence afterTeleportSceneASp = sceneA.GetScenePresence(ua1.PrincipalID);
898
899 // Since this is appearance data, it is still present on the child avatar!
900 List<AvatarAttachment> sceneAAttachments = afterTeleportSceneASp.Appearance.GetAttachments();
901 Assert.That(sceneAAttachments.Count, Is.EqualTo(1));
902 Assert.That(afterTeleportSceneASp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest));
903
904 // This is the actual attachment, which should no longer exist
905 List<SceneObjectGroup> actualSceneAAttachments = afterTeleportSceneASp.GetAttachments();
906 Assert.That(actualSceneAAttachments.Count, Is.EqualTo(0));
907
908 Assert.That(sceneA.GetSceneObjectGroups().Count, Is.EqualTo(0));
909
910 // Check events
911 Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(0));
912 }
913*/
914
915 [Test]
916 public void TestSameSimulatorNeighbouringRegionsTeleportV2()
917 {
918 TestHelpers.InMethod();
919// TestHelpers.EnableLogging();
920
921 BaseHttpServer httpServer = new BaseHttpServer(99999);
922 MainServer.AddHttpServer(httpServer);
923 MainServer.Instance = httpServer;
924
925 AttachmentsModule attModA = new AttachmentsModule();
926 AttachmentsModule attModB = new AttachmentsModule();
927 EntityTransferModule etmA = new EntityTransferModule();
928 EntityTransferModule etmB = new EntityTransferModule();
929 LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
930
931 IConfigSource config = new IniConfigSource();
932 IConfig modulesConfig = config.AddConfig("Modules");
933 modulesConfig.Set("EntityTransferModule", etmA.Name);
934 modulesConfig.Set("SimulationServices", lscm.Name);
935
936 modulesConfig.Set("InventoryAccessModule", "BasicInventoryAccessModule");
937
938 SceneHelpers sh = new SceneHelpers();
939 TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
940 TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1001, 1000);
941
942 SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
943 SceneHelpers.SetupSceneModules(
944 sceneA, config, new CapabilitiesModule(), etmA, attModA, new BasicInventoryAccessModule());
945 SceneHelpers.SetupSceneModules(
946 sceneB, config, new CapabilitiesModule(), etmB, attModB, new BasicInventoryAccessModule());
947
948 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(sceneA, 0x1);
949
950 AgentCircuitData acd = SceneHelpers.GenerateAgentData(ua1.PrincipalID);
951 TestClient tc = new TestClient(acd, sceneA);
952 List<TestClient> destinationTestClients = new List<TestClient>();
953 EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients);
954
955 ScenePresence beforeTeleportSp = SceneHelpers.AddScenePresence(sceneA, tc, acd);
956 beforeTeleportSp.AbsolutePosition = new Vector3(30, 31, 32);
957
958 Assert.That(destinationTestClients.Count, Is.EqualTo(1));
959 Assert.That(destinationTestClients[0], Is.Not.Null);
960
961 InventoryItemBase attItem = CreateAttachmentItem(sceneA, ua1.PrincipalID, "att", 0x10, 0x20);
962
963 sceneA.AttachmentsModule.RezSingleAttachmentFromInventory(
964 beforeTeleportSp, attItem.ID, (uint)AttachmentPoint.Chest);
965
966 Vector3 teleportPosition = new Vector3(10, 11, 12);
967 Vector3 teleportLookAt = new Vector3(20, 21, 22);
968
969 // Here, we need to make clientA's receipt of SendRegionTeleport trigger clientB's CompleteMovement(). This
970 // is to operate the teleport V2 mechanism where the EntityTransferModule will first request the client to
971 // CompleteMovement to the region and then call UpdateAgent to the destination region to confirm the receipt
972 // Both these operations will occur on different threads and will wait for each other.
973 // We have to do this via ThreadPool directly since FireAndForget has been switched to sync for the V1
974 // test protocol, where we are trying to avoid unpredictable async operations in regression tests.
975 tc.OnTestClientSendRegionTeleport
976 += (regionHandle, simAccess, regionExternalEndPoint, locationID, flags, capsURL)
977 => ThreadPool.UnsafeQueueUserWorkItem(o => destinationTestClients[0].CompleteMovement(), null);
978
979 m_numberOfAttachEventsFired = 0;
980 sceneA.RequestTeleportLocation(
981 beforeTeleportSp.ControllingClient,
982 sceneB.RegionInfo.RegionHandle,
983 teleportPosition,
984 teleportLookAt,
985 (uint)TeleportFlags.ViaLocation);
627 986
628 // Check attachments have made it into sceneB 987 // Check attachments have made it into sceneB
629 ScenePresence afterTeleportSceneBSp = sceneB.GetScenePresence(ua1.PrincipalID); 988 ScenePresence afterTeleportSceneBSp = sceneB.GetScenePresence(ua1.PrincipalID);
@@ -642,6 +1001,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
642 SceneObjectGroup actualSceneBAtt = actualSceneBAttachments[0]; 1001 SceneObjectGroup actualSceneBAtt = actualSceneBAttachments[0];
643 Assert.That(actualSceneBAtt.Name, Is.EqualTo(attItem.Name)); 1002 Assert.That(actualSceneBAtt.Name, Is.EqualTo(attItem.Name));
644 Assert.That(actualSceneBAtt.AttachmentPoint, Is.EqualTo((uint)AttachmentPoint.Chest)); 1003 Assert.That(actualSceneBAtt.AttachmentPoint, Is.EqualTo((uint)AttachmentPoint.Chest));
1004 Assert.IsFalse(actualSceneBAtt.Backup);
645 1005
646 Assert.That(sceneB.GetSceneObjectGroups().Count, Is.EqualTo(1)); 1006 Assert.That(sceneB.GetSceneObjectGroups().Count, Is.EqualTo(1));
647 1007
@@ -663,4 +1023,4 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
663 Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(0)); 1023 Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(0));
664 } 1024 }
665 } 1025 }
666} \ No newline at end of file 1026}