ScenePresenceSitTests.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 Nini.Config;
  31. using NUnit.Framework;
  32. using OpenMetaverse;
  33. using OpenSim.Framework;
  34. using OpenSim.Framework.Communications;
  35. using OpenSim.Framework.Servers;
  36. using OpenSim.Region.Framework.Interfaces;
  37. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
  38. using OpenSim.Tests.Common;
  39. using OpenSim.Tests.Common.Mock;
  40. using System.Threading;
  41. namespace OpenSim.Region.Framework.Scenes.Tests
  42. {
  43. [TestFixture]
  44. public class ScenePresenceSitTests : OpenSimTestCase
  45. {
  46. private TestScene m_scene;
  47. private ScenePresence m_sp;
  48. [SetUp]
  49. public void Init()
  50. {
  51. m_scene = new SceneHelpers().SetupScene();
  52. m_sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
  53. }
  54. [Test]
  55. public void TestSitOutsideRangeNoTarget()
  56. {
  57. TestHelpers.InMethod();
  58. // log4net.Config.XmlConfigurator.Configure();
  59. // More than 10 meters away from 0, 0, 0 (default part position)
  60. Vector3 startPos = new Vector3(10.1f, 0, 0);
  61. m_sp.AbsolutePosition = startPos;
  62. SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
  63. m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
  64. Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
  65. Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0));
  66. Assert.That(part.GetSittingAvatars(), Is.Null);
  67. Assert.That(m_sp.ParentID, Is.EqualTo(0));
  68. }
  69. [Test]
  70. public void TestSitWithinRangeNoTarget()
  71. {
  72. TestHelpers.InMethod();
  73. // log4net.Config.XmlConfigurator.Configure();
  74. // Less than 10 meters away from 0, 0, 0 (default part position)
  75. Vector3 startPos = new Vector3(9.9f, 0, 0);
  76. m_sp.AbsolutePosition = startPos;
  77. SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
  78. m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
  79. Assert.That(m_sp.PhysicsActor, Is.Null);
  80. Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
  81. Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1));
  82. HashSet<UUID> sittingAvatars = part.GetSittingAvatars();
  83. Assert.That(sittingAvatars.Count, Is.EqualTo(1));
  84. Assert.That(sittingAvatars.Contains(m_sp.UUID));
  85. Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId));
  86. }
  87. [Test]
  88. public void TestSitAndStandWithNoSitTarget()
  89. {
  90. TestHelpers.InMethod();
  91. // log4net.Config.XmlConfigurator.Configure();
  92. // Make sure we're within range to sit
  93. Vector3 startPos = new Vector3(1, 1, 1);
  94. m_sp.AbsolutePosition = startPos;
  95. SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
  96. m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
  97. // FIXME: This is different for live avatars - z position is adjusted. This is half the height of the
  98. // default avatar.
  99. // Curiously, Vector3.ToString() will not display the last two places of the float. For example,
  100. // printing out npc.AbsolutePosition will give <0, 0, 0.8454993> not <0, 0, 0.845499337>
  101. Assert.That(
  102. m_sp.AbsolutePosition,
  103. Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, 0.845499337f)));
  104. m_sp.StandUp();
  105. Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
  106. Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0));
  107. Assert.That(part.GetSittingAvatars(), Is.Null);
  108. Assert.That(m_sp.ParentID, Is.EqualTo(0));
  109. Assert.That(m_sp.PhysicsActor, Is.Not.Null);
  110. }
  111. [Test]
  112. public void TestSitAndStandWithSitTarget()
  113. {
  114. TestHelpers.InMethod();
  115. // log4net.Config.XmlConfigurator.Configure();
  116. // If a prim has a sit target then we can sit from any distance away
  117. Vector3 startPos = new Vector3(128, 128, 30);
  118. m_sp.AbsolutePosition = startPos;
  119. SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
  120. part.SitTargetPosition = new Vector3(0, 0, 1);
  121. m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
  122. Assert.That(part.SitTargetAvatar, Is.EqualTo(m_sp.UUID));
  123. Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId));
  124. Assert.That(
  125. m_sp.AbsolutePosition,
  126. Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition + ScenePresence.SIT_TARGET_ADJUSTMENT));
  127. Assert.That(m_sp.PhysicsActor, Is.Null);
  128. Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1));
  129. HashSet<UUID> sittingAvatars = part.GetSittingAvatars();
  130. Assert.That(sittingAvatars.Count, Is.EqualTo(1));
  131. Assert.That(sittingAvatars.Contains(m_sp.UUID));
  132. m_sp.StandUp();
  133. Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
  134. Assert.That(m_sp.ParentID, Is.EqualTo(0));
  135. Assert.That(m_sp.PhysicsActor, Is.Not.Null);
  136. Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
  137. Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0));
  138. Assert.That(part.GetSittingAvatars(), Is.Null);
  139. }
  140. [Test]
  141. public void TestSitAndStandOnGround()
  142. {
  143. TestHelpers.InMethod();
  144. // log4net.Config.XmlConfigurator.Configure();
  145. // If a prim has a sit target then we can sit from any distance away
  146. // Vector3 startPos = new Vector3(128, 128, 30);
  147. // sp.AbsolutePosition = startPos;
  148. m_sp.HandleAgentSitOnGround();
  149. Assert.That(m_sp.SitGround, Is.True);
  150. Assert.That(m_sp.PhysicsActor, Is.Null);
  151. m_sp.StandUp();
  152. Assert.That(m_sp.SitGround, Is.False);
  153. Assert.That(m_sp.PhysicsActor, Is.Not.Null);
  154. }
  155. }
  156. }