ScenePresenceAutopilotTests.cs 5.6 KB

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