ScenePresenceAutopilotTests.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 log4net;
  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.Interfaces;
  37. using OpenSim.Region.Framework.Scenes;
  38. using OpenSim.Tests.Common;
  39. using OpenSim.Tests.Common.Mock;
  40. namespace OpenSim.Region.Framework.Scenes.Tests
  41. {
  42. [TestFixture]
  43. public class ScenePresenceAutopilotTests : OpenSimTestCase
  44. {
  45. private TestScene m_scene;
  46. [TestFixtureSetUp]
  47. public void FixtureInit()
  48. {
  49. // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
  50. Util.FireAndForgetMethod = FireAndForgetMethod.None;
  51. }
  52. [TestFixtureTearDown]
  53. public void TearDown()
  54. {
  55. // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
  56. // threads. Possibly, later tests should be rewritten not to worry about such things.
  57. Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
  58. }
  59. [SetUp]
  60. public void Init()
  61. {
  62. m_scene = new SceneHelpers().SetupScene();
  63. }
  64. [Test]
  65. public void TestMove()
  66. {
  67. TestHelpers.InMethod();
  68. // log4net.Config.XmlConfigurator.Configure();
  69. ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
  70. Vector3 startPos = sp.AbsolutePosition;
  71. // Vector3 startPos = new Vector3(128, 128, 30);
  72. // For now, we'll make the scene presence fly to simplify this test, but this needs to change.
  73. sp.Flying = true;
  74. m_scene.Update(1);
  75. Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos));
  76. Vector3 targetPos = startPos + new Vector3(0, 10, 0);
  77. sp.MoveToTarget(targetPos, false, false);
  78. Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos));
  79. Assert.That(
  80. sp.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0.7071068f, 0.7071068f), 0.000001));
  81. m_scene.Update(1);
  82. // We should really check the exact figure.
  83. Assert.That(sp.AbsolutePosition.X, Is.EqualTo(startPos.X));
  84. Assert.That(sp.AbsolutePosition.Y, Is.GreaterThan(startPos.Y));
  85. Assert.That(sp.AbsolutePosition.Z, Is.EqualTo(startPos.Z));
  86. Assert.That(sp.AbsolutePosition.Z, Is.LessThan(targetPos.X));
  87. m_scene.Update(10);
  88. double distanceToTarget = Util.GetDistanceTo(sp.AbsolutePosition, targetPos);
  89. Assert.That(distanceToTarget, Is.LessThan(1), "Avatar not within 1 unit of target position on first move");
  90. Assert.That(sp.AbsolutePosition, Is.EqualTo(targetPos));
  91. Assert.That(sp.AgentControlFlags, Is.EqualTo((uint)AgentManager.ControlFlags.NONE));
  92. // Try a second movement
  93. startPos = sp.AbsolutePosition;
  94. targetPos = startPos + new Vector3(10, 0, 0);
  95. sp.MoveToTarget(targetPos, false, false);
  96. Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos));
  97. Assert.That(
  98. sp.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0, 1), 0.000001));
  99. m_scene.Update(1);
  100. // We should really check the exact figure.
  101. Assert.That(sp.AbsolutePosition.X, Is.GreaterThan(startPos.X));
  102. Assert.That(sp.AbsolutePosition.X, Is.LessThan(targetPos.X));
  103. Assert.That(sp.AbsolutePosition.Y, Is.EqualTo(startPos.Y));
  104. Assert.That(sp.AbsolutePosition.Z, Is.EqualTo(startPos.Z));
  105. m_scene.Update(10);
  106. distanceToTarget = Util.GetDistanceTo(sp.AbsolutePosition, targetPos);
  107. Assert.That(distanceToTarget, Is.LessThan(1), "Avatar not within 1 unit of target position on second move");
  108. Assert.That(sp.AbsolutePosition, Is.EqualTo(targetPos));
  109. }
  110. }
  111. }