SceneObjectTests.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 OpenSim 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 NUnit.Framework;
  29. using NUnit.Framework.SyntaxHelpers;
  30. using OpenMetaverse;
  31. using OpenSim.Framework;
  32. using OpenSim.Framework.Communications;
  33. using OpenSim.Framework.Communications.Cache;
  34. using OpenSim.Region.Communications.Local;
  35. using OpenSim.Region.Environment.Scenes;
  36. using OpenSim.Tests.Common.Mock;
  37. namespace OpenSim.Region.Environment.Scenes.Tests
  38. {
  39. /// <summary>
  40. /// Scene object tests
  41. /// </summary>
  42. [TestFixture]
  43. public class SceneObjectTests
  44. {
  45. /// <summary>
  46. /// Test adding an object to a scene.
  47. /// </summary>
  48. [Test]
  49. public void TestAddSceneObject()
  50. {
  51. Scene scene = SceneTestUtils.SetupScene();
  52. SceneObjectPart part = SceneTestUtils.AddSceneObject(scene);
  53. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
  54. //System.Console.WriteLine("retrievedPart : {0}", retrievedPart);
  55. // If the parts have the same UUID then we will consider them as one and the same
  56. Assert.That(retrievedPart.UUID, Is.EqualTo(part.UUID));
  57. }
  58. /// <summary>
  59. /// Test deleting an object from a scene.
  60. /// </summary>
  61. [Test]
  62. public void TestDeleteSceneObject()
  63. {
  64. TestScene scene = SceneTestUtils.SetupScene();
  65. SceneObjectPart part = SceneTestUtils.AddSceneObject(scene);
  66. scene.DeleteSceneObject(part.ParentGroup, false);
  67. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
  68. Assert.That(retrievedPart, Is.Null);
  69. }
  70. /// <summary>
  71. /// Test deleting an object asynchronously
  72. /// </summary>
  73. [Test]
  74. public void TestDeleteSceneObjectAsync()
  75. {
  76. UUID agentId = UUID.Parse("00000000-0000-0000-0000-000000000001");
  77. TestScene scene = SceneTestUtils.SetupScene();
  78. // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
  79. AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
  80. sogd.Enabled = false;
  81. SceneObjectPart part = SceneTestUtils.AddSceneObject(scene);
  82. IClientAPI client = SceneTestUtils.AddRootAgent(scene, agentId);
  83. scene.DeRezObject(client, part.LocalId, UUID.Zero, DeRezAction.Delete, UUID.Zero);
  84. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
  85. Assert.That(retrievedPart, Is.Not.Null);
  86. sogd.InventoryDeQueueAndDelete();
  87. SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(part.LocalId);
  88. Assert.That(retrievedPart2, Is.Null);
  89. }
  90. /// <summary>
  91. /// Test deleting an object asynchronously to user inventory.
  92. /// </summary>
  93. [Test]
  94. public void TestDeleteSceneObjectAsyncToUserInventory()
  95. {
  96. //log4net.Config.XmlConfigurator.Configure();
  97. UUID agentId = UUID.Parse("00000000-0000-0000-0000-000000000001");
  98. string myObjectName = "Fred";
  99. TestScene scene = SceneTestUtils.SetupScene();
  100. SceneObjectPart part = SceneTestUtils.AddSceneObject(scene, myObjectName);
  101. ((LocalUserServices)scene.CommsManager.UserService).AddPlugin(new TestUserDataPlugin());
  102. ((LocalInventoryService)scene.CommsManager.InventoryService).AddPlugin(new TestInventoryDataPlugin());
  103. Assert.That(
  104. scene.CommsManager.UserAdminService.AddUser(
  105. "Bob", "Hoskins", "test", "[email protected]", 1000, 1000, agentId),
  106. Is.EqualTo(agentId));
  107. IClientAPI client = SceneTestUtils.AddRootAgent(scene, agentId);
  108. CachedUserInfo userInfo = scene.CommsManager.UserProfileCacheService.GetUserDetails(agentId);
  109. Assert.That(userInfo, Is.Not.Null);
  110. Assert.That(userInfo.RootFolder, Is.Not.Null);
  111. SceneTestUtils.DeleteSceneObjectAsync(scene, part, DeRezAction.Take, userInfo.RootFolder.ID, client);
  112. // Check that we now have the taken part in our inventory
  113. Assert.That(myObjectName, Is.EqualTo(userInfo.RootFolder.FindItemByPath(myObjectName).Name));
  114. // Check that the taken part has actually disappeared
  115. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
  116. Assert.That(retrievedPart, Is.Null);
  117. }
  118. }
  119. }