SceneObjectBasicTests.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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 OpenMetaverse;
  31. using OpenSim.Framework;
  32. using OpenSim.Framework.Communications;
  33. using OpenSim.Region.Framework.Scenes;
  34. using OpenSim.Tests.Common;
  35. using OpenSim.Tests.Common.Mock;
  36. namespace OpenSim.Region.Framework.Scenes.Tests
  37. {
  38. /// <summary>
  39. /// Basic scene object tests (create, read and delete but not update).
  40. /// </summary>
  41. [TestFixture]
  42. public class SceneObjectBasicTests
  43. {
  44. /// <summary>
  45. /// Test adding an object to a scene.
  46. /// </summary>
  47. [Test]
  48. public void TestAddSceneObject()
  49. {
  50. TestHelpers.InMethod();
  51. Scene scene = SceneHelpers.SetupScene();
  52. int partsToTestCount = 3;
  53. SceneObjectGroup so
  54. = SceneHelpers.CreateSceneObject(partsToTestCount, TestHelpers.ParseTail(0x1), "obj1", 0x10);
  55. SceneObjectPart[] parts = so.Parts;
  56. Assert.That(scene.AddNewSceneObject(so, false), Is.True);
  57. SceneObjectGroup retrievedSo = scene.GetSceneObjectGroup(so.UUID);
  58. SceneObjectPart[] retrievedParts = retrievedSo.Parts;
  59. //m_log.Debug("retrievedPart : {0}", retrievedPart);
  60. // If the parts have the same UUID then we will consider them as one and the same
  61. Assert.That(retrievedSo.PrimCount, Is.EqualTo(partsToTestCount));
  62. for (int i = 0; i < partsToTestCount; i++)
  63. {
  64. Assert.That(retrievedParts[i].Name, Is.EqualTo(parts[i].Name));
  65. Assert.That(retrievedParts[i].UUID, Is.EqualTo(parts[i].UUID));
  66. }
  67. }
  68. [Test]
  69. /// <summary>
  70. /// It shouldn't be possible to add a scene object if one with that uuid already exists in the scene.
  71. /// </summary>
  72. public void TestAddExistingSceneObjectUuid()
  73. {
  74. TestHelpers.InMethod();
  75. Scene scene = SceneHelpers.SetupScene();
  76. string obj1Name = "Alfred";
  77. string obj2Name = "Betty";
  78. UUID objUuid = new UUID("00000000-0000-0000-0000-000000000001");
  79. SceneObjectPart part1
  80. = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
  81. { Name = obj1Name, UUID = objUuid };
  82. Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part1), false), Is.True);
  83. SceneObjectPart part2
  84. = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
  85. { Name = obj2Name, UUID = objUuid };
  86. Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part2), false), Is.False);
  87. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(objUuid);
  88. //m_log.Debug("retrievedPart : {0}", retrievedPart);
  89. // If the parts have the same UUID then we will consider them as one and the same
  90. Assert.That(retrievedPart.Name, Is.EqualTo(obj1Name));
  91. Assert.That(retrievedPart.UUID, Is.EqualTo(objUuid));
  92. }
  93. /// <summary>
  94. /// Test retrieving a scene object via the local id of one of its parts.
  95. /// </summary>
  96. [Test]
  97. public void TestGetSceneObjectByPartLocalId()
  98. {
  99. TestHelpers.InMethod();
  100. Scene scene = SceneHelpers.SetupScene();
  101. int partsToTestCount = 3;
  102. SceneObjectGroup so
  103. = SceneHelpers.CreateSceneObject(partsToTestCount, TestHelpers.ParseTail(0x1), "obj1", 0x10);
  104. SceneObjectPart[] parts = so.Parts;
  105. scene.AddNewSceneObject(so, false);
  106. // Test getting via the root part's local id
  107. Assert.That(scene.GetGroupByPrim(so.LocalId), Is.Not.Null);
  108. // Test getting via a non root part's local id
  109. Assert.That(scene.GetGroupByPrim(parts[partsToTestCount - 1].LocalId), Is.Not.Null);
  110. // Test that we don't get back an object for a local id that doesn't exist
  111. Assert.That(scene.GetGroupByPrim(999), Is.Null);
  112. // Now delete the scene object and check again
  113. scene.DeleteSceneObject(so, false);
  114. Assert.That(scene.GetGroupByPrim(so.LocalId), Is.Null);
  115. Assert.That(scene.GetGroupByPrim(parts[partsToTestCount - 1].LocalId), Is.Null);
  116. }
  117. /// <summary>
  118. /// Test deleting an object from a scene.
  119. /// </summary>
  120. [Test]
  121. public void TestDeleteSceneObject()
  122. {
  123. TestHelpers.InMethod();
  124. TestScene scene = SceneHelpers.SetupScene();
  125. SceneObjectPart part = SceneHelpers.AddSceneObject(scene);
  126. scene.DeleteSceneObject(part.ParentGroup, false);
  127. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
  128. Assert.That(retrievedPart, Is.Null);
  129. }
  130. /// <summary>
  131. /// Test deleting an object asynchronously
  132. /// </summary>
  133. [Test]
  134. public void TestDeleteSceneObjectAsync()
  135. {
  136. TestHelpers.InMethod();
  137. //log4net.Config.XmlConfigurator.Configure();
  138. UUID agentId = UUID.Parse("00000000-0000-0000-0000-000000000001");
  139. TestScene scene = SceneHelpers.SetupScene();
  140. // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
  141. AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
  142. sogd.Enabled = false;
  143. SceneObjectPart part = SceneHelpers.AddSceneObject(scene);
  144. IClientAPI client = SceneHelpers.AddScenePresence(scene, agentId).ControllingClient;
  145. scene.DeRezObjects(client, new System.Collections.Generic.List<uint>() { part.LocalId }, UUID.Zero, DeRezAction.Delete, UUID.Zero);
  146. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
  147. Assert.That(retrievedPart, Is.Not.Null);
  148. sogd.InventoryDeQueueAndDelete();
  149. SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(part.LocalId);
  150. Assert.That(retrievedPart2, Is.Null);
  151. }
  152. /// <summary>
  153. /// Test deleting an object asynchronously to user inventory.
  154. /// </summary>
  155. //[Test]
  156. //public void TestDeleteSceneObjectAsyncToUserInventory()
  157. //{
  158. // TestHelper.InMethod();
  159. // //log4net.Config.XmlConfigurator.Configure();
  160. // UUID agentId = UUID.Parse("00000000-0000-0000-0000-000000000001");
  161. // string myObjectName = "Fred";
  162. // TestScene scene = SceneSetupHelpers.SetupScene();
  163. // SceneObjectPart part = SceneSetupHelpers.AddSceneObject(scene, myObjectName);
  164. // Assert.That(
  165. // scene.CommsManager.UserAdminService.AddUser(
  166. // "Bob", "Hoskins", "test", "[email protected]", 1000, 1000, agentId),
  167. // Is.EqualTo(agentId));
  168. // IClientAPI client = SceneSetupHelpers.AddRootAgent(scene, agentId);
  169. // CachedUserInfo userInfo = scene.CommsManager.UserProfileCacheService.GetUserDetails(agentId);
  170. // Assert.That(userInfo, Is.Not.Null);
  171. // Assert.That(userInfo.RootFolder, Is.Not.Null);
  172. // SceneSetupHelpers.DeleteSceneObjectAsync(scene, part, DeRezAction.Take, userInfo.RootFolder.ID, client);
  173. // // Check that we now have the taken part in our inventory
  174. // Assert.That(myObjectName, Is.EqualTo(userInfo.RootFolder.FindItemByPath(myObjectName).Name));
  175. // // Check that the taken part has actually disappeared
  176. // SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
  177. // Assert.That(retrievedPart, Is.Null);
  178. //}
  179. /// <summary>
  180. /// Changing a scene object uuid changes the root part uuid. This is a valid operation if the object is not
  181. /// in a scene and is useful if one wants to supply a UUID directly rather than use the one generated by
  182. /// OpenSim.
  183. /// </summary>
  184. [Test]
  185. public void TestChangeSceneObjectUuid()
  186. {
  187. string rootPartName = "rootpart";
  188. UUID rootPartUuid = new UUID("00000000-0000-0000-0000-000000000001");
  189. string childPartName = "childPart";
  190. UUID childPartUuid = new UUID("00000000-0000-0000-0001-000000000000");
  191. SceneObjectPart rootPart
  192. = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
  193. { Name = rootPartName, UUID = rootPartUuid };
  194. SceneObjectPart linkPart
  195. = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
  196. { Name = childPartName, UUID = childPartUuid };
  197. SceneObjectGroup sog = new SceneObjectGroup(rootPart);
  198. sog.AddPart(linkPart);
  199. Assert.That(sog.UUID, Is.EqualTo(rootPartUuid));
  200. Assert.That(sog.RootPart.UUID, Is.EqualTo(rootPartUuid));
  201. Assert.That(sog.Parts.Length, Is.EqualTo(2));
  202. UUID newRootPartUuid = new UUID("00000000-0000-0000-0000-000000000002");
  203. sog.UUID = newRootPartUuid;
  204. Assert.That(sog.UUID, Is.EqualTo(newRootPartUuid));
  205. Assert.That(sog.RootPart.UUID, Is.EqualTo(newRootPartUuid));
  206. Assert.That(sog.Parts.Length, Is.EqualTo(2));
  207. }
  208. }
  209. }