SceneObjectBasicTests.cs 12 KB

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