ScenePresenceSitTests.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. // We need to preserve this here because phys actor is removed by the sit.
  97. Vector3 spPhysActorSize = m_sp.PhysicsActor.Size;
  98. m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
  99. Assert.That(
  100. m_sp.AbsolutePosition,
  101. Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, spPhysActorSize.Z / 2)));
  102. m_sp.StandUp();
  103. Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
  104. Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0));
  105. Assert.That(part.GetSittingAvatars(), Is.Null);
  106. Assert.That(m_sp.ParentID, Is.EqualTo(0));
  107. Assert.That(m_sp.PhysicsActor, Is.Not.Null);
  108. }
  109. [Test]
  110. public void TestSitAndStandWithSitTarget()
  111. {
  112. TestHelpers.InMethod();
  113. // log4net.Config.XmlConfigurator.Configure();
  114. // If a prim has a sit target then we can sit from any distance away
  115. Vector3 startPos = new Vector3(128, 128, 30);
  116. m_sp.AbsolutePosition = startPos;
  117. SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
  118. part.SitTargetPosition = new Vector3(0, 0, 1);
  119. m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
  120. Assert.That(part.SitTargetAvatar, Is.EqualTo(m_sp.UUID));
  121. Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId));
  122. // Assert.That(
  123. // m_sp.AbsolutePosition,
  124. // Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition + ScenePresence.SIT_TARGET_ADJUSTMENT));
  125. Assert.That(m_sp.PhysicsActor, Is.Null);
  126. Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1));
  127. HashSet<UUID> sittingAvatars = part.GetSittingAvatars();
  128. Assert.That(sittingAvatars.Count, Is.EqualTo(1));
  129. Assert.That(sittingAvatars.Contains(m_sp.UUID));
  130. m_sp.StandUp();
  131. Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
  132. Assert.That(m_sp.ParentID, Is.EqualTo(0));
  133. Assert.That(m_sp.PhysicsActor, Is.Not.Null);
  134. Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
  135. Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0));
  136. Assert.That(part.GetSittingAvatars(), Is.Null);
  137. }
  138. [Test]
  139. public void TestSitAndStandOnGround()
  140. {
  141. TestHelpers.InMethod();
  142. // log4net.Config.XmlConfigurator.Configure();
  143. // If a prim has a sit target then we can sit from any distance away
  144. // Vector3 startPos = new Vector3(128, 128, 30);
  145. // sp.AbsolutePosition = startPos;
  146. m_sp.HandleAgentSitOnGround();
  147. Assert.That(m_sp.SitGround, Is.True);
  148. Assert.That(m_sp.PhysicsActor, Is.Null);
  149. m_sp.StandUp();
  150. Assert.That(m_sp.SitGround, Is.False);
  151. Assert.That(m_sp.PhysicsActor, Is.Not.Null);
  152. }
  153. }
  154. }