ScenePresenceAutopilotTests.cs 5.5 KB

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