opensim – Blame information for rev 1

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