SceneObjectBasicTests.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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.Reflection;
  29. using NUnit.Framework;
  30. using NUnit.Framework.SyntaxHelpers;
  31. using OpenMetaverse;
  32. using OpenSim.Framework;
  33. using OpenSim.Framework.Communications;
  34. using OpenSim.Region.Framework.Scenes;
  35. using OpenSim.Tests.Common;
  36. using OpenSim.Tests.Common.Mock;
  37. using OpenSim.Tests.Common.Setup;
  38. namespace OpenSim.Region.Framework.Scenes.Tests
  39. {
  40. /// <summary>
  41. /// Basic scene object tests (create, read and delete but not update).
  42. /// </summary>
  43. [TestFixture]
  44. public class SceneObjectBasicTests
  45. {
  46. /// <summary>
  47. /// Test adding an object to a scene.
  48. /// </summary>
  49. [Test]
  50. public void TestAddSceneObject()
  51. {
  52. TestHelper.InMethod();
  53. Scene scene = SceneSetupHelpers.SetupScene();
  54. string objName = "obj1";
  55. UUID objUuid = new UUID("00000000-0000-0000-0000-000000000001");
  56. SceneObjectPart part
  57. = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
  58. { Name = objName, UUID = objUuid };
  59. Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part), false), Is.True);
  60. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(objUuid);
  61. //m_log.Debug("retrievedPart : {0}", retrievedPart);
  62. // If the parts have the same UUID then we will consider them as one and the same
  63. Assert.That(retrievedPart.Name, Is.EqualTo(objName));
  64. Assert.That(retrievedPart.UUID, Is.EqualTo(objUuid));
  65. }
  66. [Test]
  67. /// <summary>
  68. /// It shouldn't be possible to add a scene object if one with that uuid already exists in the scene.
  69. /// </summary>
  70. public void TestAddExistingSceneObjectUuid()
  71. {
  72. TestHelper.InMethod();
  73. Scene scene = SceneSetupHelpers.SetupScene();
  74. string obj1Name = "Alfred";
  75. string obj2Name = "Betty";
  76. UUID objUuid = new UUID("00000000-0000-0000-0000-000000000001");
  77. SceneObjectPart part1
  78. = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
  79. { Name = obj1Name, UUID = objUuid };
  80. Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part1), false), Is.True);
  81. SceneObjectPart part2
  82. = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
  83. { Name = obj2Name, UUID = objUuid };
  84. Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part2), false), Is.False);
  85. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(objUuid);
  86. //m_log.Debug("retrievedPart : {0}", retrievedPart);
  87. // If the parts have the same UUID then we will consider them as one and the same
  88. Assert.That(retrievedPart.Name, Is.EqualTo(obj1Name));
  89. Assert.That(retrievedPart.UUID, Is.EqualTo(objUuid));
  90. }
  91. /// <summary>
  92. /// Test deleting an object from a scene.
  93. /// </summary>
  94. [Test]
  95. public void TestDeleteSceneObject()
  96. {
  97. TestHelper.InMethod();
  98. TestScene scene = SceneSetupHelpers.SetupScene();
  99. SceneObjectPart part = SceneSetupHelpers.AddSceneObject(scene);
  100. scene.DeleteSceneObject(part.ParentGroup, false);
  101. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
  102. Assert.That(retrievedPart, Is.Null);
  103. }
  104. /// <summary>
  105. /// Test deleting an object asynchronously
  106. /// </summary>
  107. [Test]
  108. public void TestDeleteSceneObjectAsync()
  109. {
  110. TestHelper.InMethod();
  111. //log4net.Config.XmlConfigurator.Configure();
  112. UUID agentId = UUID.Parse("00000000-0000-0000-0000-000000000001");
  113. TestScene scene = SceneSetupHelpers.SetupScene();
  114. // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
  115. AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
  116. sogd.Enabled = false;
  117. SceneObjectPart part = SceneSetupHelpers.AddSceneObject(scene);
  118. IClientAPI client = SceneSetupHelpers.AddRootAgent(scene, agentId);
  119. scene.DeRezObject(client, part.LocalId, UUID.Zero, DeRezAction.Delete, UUID.Zero);
  120. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
  121. Assert.That(retrievedPart, Is.Not.Null);
  122. sogd.InventoryDeQueueAndDelete();
  123. SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(part.LocalId);
  124. Assert.That(retrievedPart2, Is.Null);
  125. }
  126. /// <summary>
  127. /// Test deleting an object asynchronously to user inventory.
  128. /// </summary>
  129. //[Test]
  130. //public void TestDeleteSceneObjectAsyncToUserInventory()
  131. //{
  132. // TestHelper.InMethod();
  133. // //log4net.Config.XmlConfigurator.Configure();
  134. // UUID agentId = UUID.Parse("00000000-0000-0000-0000-000000000001");
  135. // string myObjectName = "Fred";
  136. // TestScene scene = SceneSetupHelpers.SetupScene();
  137. // SceneObjectPart part = SceneSetupHelpers.AddSceneObject(scene, myObjectName);
  138. // Assert.That(
  139. // scene.CommsManager.UserAdminService.AddUser(
  140. // "Bob", "Hoskins", "test", "[email protected]", 1000, 1000, agentId),
  141. // Is.EqualTo(agentId));
  142. // IClientAPI client = SceneSetupHelpers.AddRootAgent(scene, agentId);
  143. // CachedUserInfo userInfo = scene.CommsManager.UserProfileCacheService.GetUserDetails(agentId);
  144. // Assert.That(userInfo, Is.Not.Null);
  145. // Assert.That(userInfo.RootFolder, Is.Not.Null);
  146. // SceneSetupHelpers.DeleteSceneObjectAsync(scene, part, DeRezAction.Take, userInfo.RootFolder.ID, client);
  147. // // Check that we now have the taken part in our inventory
  148. // Assert.That(myObjectName, Is.EqualTo(userInfo.RootFolder.FindItemByPath(myObjectName).Name));
  149. // // Check that the taken part has actually disappeared
  150. // SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
  151. // Assert.That(retrievedPart, Is.Null);
  152. //}
  153. }
  154. }