SceneObjectBasicTests.cs 9.7 KB

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