SceneObjectBasicTests.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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.Collections.Generic;
  29. using System.Reflection;
  30. using System.Threading;
  31. using Nini.Config;
  32. using NUnit.Framework;
  33. using OpenMetaverse;
  34. using OpenSim.Framework;
  35. using OpenSim.Framework.Communications;
  36. using OpenSim.Region.Framework.Scenes;
  37. using OpenSim.Services.Interfaces;
  38. using OpenSim.Tests.Common;
  39. using OpenSim.Tests.Common.Mock;
  40. namespace OpenSim.Region.Framework.Scenes.Tests
  41. {
  42. /// <summary>
  43. /// Basic scene object tests (create, read and delete but not update).
  44. /// </summary>
  45. [TestFixture]
  46. public class SceneObjectBasicTests : OpenSimTestCase
  47. {
  48. // [TearDown]
  49. // public void TearDown()
  50. // {
  51. // Console.WriteLine("TearDown");
  52. // GC.Collect();
  53. // Thread.Sleep(3000);
  54. // }
  55. // public class GcNotify
  56. // {
  57. // public static AutoResetEvent gcEvent = new AutoResetEvent(false);
  58. // private static bool _initialized = false;
  59. //
  60. // public static void Initialize()
  61. // {
  62. // if (!_initialized)
  63. // {
  64. // _initialized = true;
  65. // new GcNotify();
  66. // }
  67. // }
  68. //
  69. // private GcNotify(){}
  70. //
  71. // ~GcNotify()
  72. // {
  73. // if (!Environment.HasShutdownStarted &&
  74. // !AppDomain.CurrentDomain.IsFinalizingForUnload())
  75. // {
  76. // Console.WriteLine("GcNotify called");
  77. // gcEvent.Set();
  78. // new GcNotify();
  79. // }
  80. // }
  81. // }
  82. /// <summary>
  83. /// Test adding an object to a scene.
  84. /// </summary>
  85. [Test]
  86. public void TestAddSceneObject()
  87. {
  88. TestHelpers.InMethod();
  89. Scene scene = new SceneHelpers().SetupScene();
  90. int partsToTestCount = 3;
  91. SceneObjectGroup so
  92. = SceneHelpers.CreateSceneObject(partsToTestCount, TestHelpers.ParseTail(0x1), "obj1", 0x10);
  93. SceneObjectPart[] parts = so.Parts;
  94. Assert.That(scene.AddNewSceneObject(so, false), Is.True);
  95. SceneObjectGroup retrievedSo = scene.GetSceneObjectGroup(so.UUID);
  96. SceneObjectPart[] retrievedParts = retrievedSo.Parts;
  97. //m_log.Debug("retrievedPart : {0}", retrievedPart);
  98. // If the parts have the same UUID then we will consider them as one and the same
  99. Assert.That(retrievedSo.PrimCount, Is.EqualTo(partsToTestCount));
  100. for (int i = 0; i < partsToTestCount; i++)
  101. {
  102. Assert.That(retrievedParts[i].Name, Is.EqualTo(parts[i].Name));
  103. Assert.That(retrievedParts[i].UUID, Is.EqualTo(parts[i].UUID));
  104. }
  105. }
  106. [Test]
  107. /// <summary>
  108. /// It shouldn't be possible to add a scene object if one with that uuid already exists in the scene.
  109. /// </summary>
  110. public void TestAddExistingSceneObjectUuid()
  111. {
  112. TestHelpers.InMethod();
  113. Scene scene = new SceneHelpers().SetupScene();
  114. string obj1Name = "Alfred";
  115. string obj2Name = "Betty";
  116. UUID objUuid = new UUID("00000000-0000-0000-0000-000000000001");
  117. SceneObjectPart part1
  118. = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
  119. { Name = obj1Name, UUID = objUuid };
  120. Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part1), false), Is.True);
  121. SceneObjectPart part2
  122. = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
  123. { Name = obj2Name, UUID = objUuid };
  124. Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part2), false), Is.False);
  125. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(objUuid);
  126. //m_log.Debug("retrievedPart : {0}", retrievedPart);
  127. // If the parts have the same UUID then we will consider them as one and the same
  128. Assert.That(retrievedPart.Name, Is.EqualTo(obj1Name));
  129. Assert.That(retrievedPart.UUID, Is.EqualTo(objUuid));
  130. }
  131. /// <summary>
  132. /// Test retrieving a scene object via the local id of one of its parts.
  133. /// </summary>
  134. [Test]
  135. public void TestGetSceneObjectByPartLocalId()
  136. {
  137. TestHelpers.InMethod();
  138. Scene scene = new SceneHelpers().SetupScene();
  139. int partsToTestCount = 3;
  140. SceneObjectGroup so
  141. = SceneHelpers.CreateSceneObject(partsToTestCount, TestHelpers.ParseTail(0x1), "obj1", 0x10);
  142. SceneObjectPart[] parts = so.Parts;
  143. scene.AddNewSceneObject(so, false);
  144. // Test getting via the root part's local id
  145. Assert.That(scene.GetGroupByPrim(so.LocalId), Is.Not.Null);
  146. // Test getting via a non root part's local id
  147. Assert.That(scene.GetGroupByPrim(parts[partsToTestCount - 1].LocalId), Is.Not.Null);
  148. // Test that we don't get back an object for a local id that doesn't exist
  149. Assert.That(scene.GetGroupByPrim(999), Is.Null);
  150. // Now delete the scene object and check again
  151. scene.DeleteSceneObject(so, false);
  152. Assert.That(scene.GetGroupByPrim(so.LocalId), Is.Null);
  153. Assert.That(scene.GetGroupByPrim(parts[partsToTestCount - 1].LocalId), Is.Null);
  154. }
  155. /// <summary>
  156. /// Test deleting an object from a scene.
  157. /// </summary>
  158. /// <remarks>
  159. /// This is the most basic form of delete. For all more sophisticated forms of derez (done asynchrnously
  160. /// and where object can be taken to user inventory, etc.), see SceneObjectDeRezTests.
  161. /// </remarks>
  162. [Test]
  163. public void TestDeleteSceneObject()
  164. {
  165. TestHelpers.InMethod();
  166. TestScene scene = new SceneHelpers().SetupScene();
  167. SceneObjectGroup so = SceneHelpers.AddSceneObject(scene);
  168. Assert.That(so.IsDeleted, Is.False);
  169. scene.DeleteSceneObject(so, false);
  170. Assert.That(so.IsDeleted, Is.True);
  171. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId);
  172. Assert.That(retrievedPart, Is.Null);
  173. }
  174. /// <summary>
  175. /// Changing a scene object uuid changes the root part uuid. This is a valid operation if the object is not
  176. /// in a scene and is useful if one wants to supply a UUID directly rather than use the one generated by
  177. /// OpenSim.
  178. /// </summary>
  179. [Test]
  180. public void TestChangeSceneObjectUuid()
  181. {
  182. string rootPartName = "rootpart";
  183. UUID rootPartUuid = new UUID("00000000-0000-0000-0000-000000000001");
  184. string childPartName = "childPart";
  185. UUID childPartUuid = new UUID("00000000-0000-0000-0001-000000000000");
  186. SceneObjectPart rootPart
  187. = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
  188. { Name = rootPartName, UUID = rootPartUuid };
  189. SceneObjectPart linkPart
  190. = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
  191. { Name = childPartName, UUID = childPartUuid };
  192. SceneObjectGroup sog = new SceneObjectGroup(rootPart);
  193. sog.AddPart(linkPart);
  194. Assert.That(sog.UUID, Is.EqualTo(rootPartUuid));
  195. Assert.That(sog.RootPart.UUID, Is.EqualTo(rootPartUuid));
  196. Assert.That(sog.Parts.Length, Is.EqualTo(2));
  197. UUID newRootPartUuid = new UUID("00000000-0000-0000-0000-000000000002");
  198. sog.UUID = newRootPartUuid;
  199. Assert.That(sog.UUID, Is.EqualTo(newRootPartUuid));
  200. Assert.That(sog.RootPart.UUID, Is.EqualTo(newRootPartUuid));
  201. Assert.That(sog.Parts.Length, Is.EqualTo(2));
  202. }
  203. }
  204. }