SceneObjectBasicTests.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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.Region.Framework.Scenes;
  36. using OpenSim.Services.Interfaces;
  37. using OpenSim.Tests.Common;
  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 : OpenSimTestCase
  45. {
  46. // [TearDown]
  47. // public void TearDown()
  48. // {
  49. // Console.WriteLine("TearDown");
  50. // GC.Collect();
  51. // Thread.Sleep(3000);
  52. // }
  53. // public class GcNotify
  54. // {
  55. // public static AutoResetEvent gcEvent = new AutoResetEvent(false);
  56. // private static bool _initialized = false;
  57. //
  58. // public static void Initialize()
  59. // {
  60. // if (!_initialized)
  61. // {
  62. // _initialized = true;
  63. // new GcNotify();
  64. // }
  65. // }
  66. //
  67. // private GcNotify(){}
  68. //
  69. // ~GcNotify()
  70. // {
  71. // if (!Environment.HasShutdownStarted &&
  72. // !AppDomain.CurrentDomain.IsFinalizingForUnload())
  73. // {
  74. // Console.WriteLine("GcNotify called");
  75. // gcEvent.Set();
  76. // new GcNotify();
  77. // }
  78. // }
  79. // }
  80. /// <summary>
  81. /// Test adding an object to a scene.
  82. /// </summary>
  83. [Test]
  84. public void TestAddSceneObject()
  85. {
  86. TestHelpers.InMethod();
  87. Scene scene = new SceneHelpers().SetupScene();
  88. int partsToTestCount = 3;
  89. SceneObjectGroup so
  90. = SceneHelpers.CreateSceneObject(partsToTestCount, TestHelpers.ParseTail(0x1), "obj1", 0x10);
  91. SceneObjectPart[] parts = so.Parts;
  92. Assert.That(scene.AddNewSceneObject(so, false), Is.True);
  93. SceneObjectGroup retrievedSo = scene.GetSceneObjectGroup(so.UUID);
  94. SceneObjectPart[] retrievedParts = retrievedSo.Parts;
  95. //m_log.Debug("retrievedPart : {0}", retrievedPart);
  96. // If the parts have the same UUID then we will consider them as one and the same
  97. Assert.That(retrievedSo.PrimCount, Is.EqualTo(partsToTestCount));
  98. for (int i = 0; i < partsToTestCount; i++)
  99. {
  100. Assert.That(retrievedParts[i].Name, Is.EqualTo(parts[i].Name));
  101. Assert.That(retrievedParts[i].UUID, Is.EqualTo(parts[i].UUID));
  102. }
  103. }
  104. [Test]
  105. /// <summary>
  106. /// It shouldn't be possible to add a scene object if one with that uuid already exists in the scene.
  107. /// </summary>
  108. public void TestAddExistingSceneObjectUuid()
  109. {
  110. TestHelpers.InMethod();
  111. Scene scene = new SceneHelpers().SetupScene();
  112. string obj1Name = "Alfred";
  113. string obj2Name = "Betty";
  114. UUID objUuid = new UUID("00000000-0000-0000-0000-000000000001");
  115. SceneObjectPart part1
  116. = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
  117. { Name = obj1Name, UUID = objUuid };
  118. Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part1), false), Is.True);
  119. SceneObjectPart part2
  120. = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
  121. { Name = obj2Name, UUID = objUuid };
  122. Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part2), false), Is.False);
  123. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(objUuid);
  124. //m_log.Debug("retrievedPart : {0}", retrievedPart);
  125. // If the parts have the same UUID then we will consider them as one and the same
  126. Assert.That(retrievedPart.Name, Is.EqualTo(obj1Name));
  127. Assert.That(retrievedPart.UUID, Is.EqualTo(objUuid));
  128. }
  129. /// <summary>
  130. /// Test retrieving a scene object via the local id of one of its parts.
  131. /// </summary>
  132. [Test]
  133. public void TestGetSceneObjectByPartLocalId()
  134. {
  135. TestHelpers.InMethod();
  136. Scene scene = new SceneHelpers().SetupScene();
  137. int partsToTestCount = 3;
  138. SceneObjectGroup so
  139. = SceneHelpers.CreateSceneObject(partsToTestCount, TestHelpers.ParseTail(0x1), "obj1", 0x10);
  140. SceneObjectPart[] parts = so.Parts;
  141. scene.AddNewSceneObject(so, false);
  142. // Test getting via the root part's local id
  143. Assert.That(scene.GetGroupByPrim(so.LocalId), Is.Not.Null);
  144. // Test getting via a non root part's local id
  145. Assert.That(scene.GetGroupByPrim(parts[partsToTestCount - 1].LocalId), Is.Not.Null);
  146. // Test that we don't get back an object for a local id that doesn't exist
  147. Assert.That(scene.GetGroupByPrim(999), Is.Null);
  148. uint soid = so.LocalId;
  149. uint spid = parts[partsToTestCount - 1].LocalId;
  150. // Now delete the scene object and check again
  151. scene.DeleteSceneObject(so, false);
  152. Assert.That(scene.GetGroupByPrim(soid), Is.Null);
  153. Assert.That(scene.GetGroupByPrim(spid), 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. uint retrievedPartID = so.LocalId;
  170. scene.DeleteSceneObject(so, false);
  171. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(retrievedPartID);
  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. }