clockwerk-opensim-stable – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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 Nini.Config;
32 using NUnit.Framework;
33 using OpenMetaverse;
34 using OpenSim.Framework;
35 using OpenSim.Framework.Communications;
36 using OpenSim.Framework.Servers;
37 using OpenSim.Region.Framework.Interfaces;
38 using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
39 using OpenSim.Tests.Common;
40 using OpenSim.Tests.Common.Mock;
41 using System.Threading;
42  
43 namespace OpenSim.Region.Framework.Scenes.Tests
44 {
45 [TestFixture]
46 public class ScenePresenceSitTests : OpenSimTestCase
47 {
48 private TestScene m_scene;
49 private ScenePresence m_sp;
50  
51 [SetUp]
52 public void Init()
53 {
54 m_scene = new SceneHelpers().SetupScene();
55 m_sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
56 }
57  
58 [Test]
59 public void TestSitOutsideRangeNoTarget()
60 {
61 TestHelpers.InMethod();
62 // log4net.Config.XmlConfigurator.Configure();
63  
64 // More than 10 meters away from 0, 0, 0 (default part position)
65 Vector3 startPos = new Vector3(10.1f, 0, 0);
66 m_sp.AbsolutePosition = startPos;
67  
68 SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
69  
70 m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
71  
72 Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
73 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0));
74 Assert.That(part.GetSittingAvatars(), Is.Null);
75 Assert.That(m_sp.ParentID, Is.EqualTo(0));
76 }
77  
78 [Test]
79 public void TestSitWithinRangeNoTarget()
80 {
81 TestHelpers.InMethod();
82 // log4net.Config.XmlConfigurator.Configure();
83  
84 // Less than 10 meters away from 0, 0, 0 (default part position)
85 Vector3 startPos = new Vector3(9.9f, 0, 0);
86 m_sp.AbsolutePosition = startPos;
87  
88 SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
89  
90 m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
91  
92 Assert.That(m_sp.PhysicsActor, Is.Null);
93  
94 Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
95 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1));
96 HashSet<UUID> sittingAvatars = part.GetSittingAvatars();
97 Assert.That(sittingAvatars.Count, Is.EqualTo(1));
98 Assert.That(sittingAvatars.Contains(m_sp.UUID));
99 Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId));
100 }
101  
102 [Test]
103 public void TestSitAndStandWithNoSitTarget()
104 {
105 TestHelpers.InMethod();
106 // log4net.Config.XmlConfigurator.Configure();
107  
108 // Make sure we're within range to sit
109 Vector3 startPos = new Vector3(1, 1, 1);
110 m_sp.AbsolutePosition = startPos;
111  
112 SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
113  
114 m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
115  
116 // FIXME: This is different for live avatars - z position is adjusted. This is half the height of the
117 // default avatar.
118 // Curiously, Vector3.ToString() will not display the last two places of the float. For example,
119 // printing out npc.AbsolutePosition will give <0, 0, 0.8454993> not <0, 0, 0.845499337>
120 Assert.That(
121 m_sp.AbsolutePosition,
122 Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, 0.845499337f)));
123  
124 m_sp.StandUp();
125  
126 Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
127 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0));
128 Assert.That(part.GetSittingAvatars(), Is.Null);
129 Assert.That(m_sp.ParentID, Is.EqualTo(0));
130 Assert.That(m_sp.PhysicsActor, Is.Not.Null);
131 }
132  
133 [Test]
134 public void TestSitAndStandWithSitTarget()
135 {
136 TestHelpers.InMethod();
137 // log4net.Config.XmlConfigurator.Configure();
138  
139 // If a prim has a sit target then we can sit from any distance away
140 Vector3 startPos = new Vector3(128, 128, 30);
141 m_sp.AbsolutePosition = startPos;
142  
143 SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
144 part.SitTargetPosition = new Vector3(0, 0, 1);
145  
146 m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
147  
148 Assert.That(part.SitTargetAvatar, Is.EqualTo(m_sp.UUID));
149 Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId));
150 Assert.That(
151 m_sp.AbsolutePosition,
152 Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition + ScenePresence.SIT_TARGET_ADJUSTMENT));
153 Assert.That(m_sp.PhysicsActor, Is.Null);
154  
155 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1));
156 HashSet<UUID> sittingAvatars = part.GetSittingAvatars();
157 Assert.That(sittingAvatars.Count, Is.EqualTo(1));
158 Assert.That(sittingAvatars.Contains(m_sp.UUID));
159  
160 m_sp.StandUp();
161  
162 Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
163 Assert.That(m_sp.ParentID, Is.EqualTo(0));
164 Assert.That(m_sp.PhysicsActor, Is.Not.Null);
165  
166 Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
167 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0));
168 Assert.That(part.GetSittingAvatars(), Is.Null);
169 }
170  
171 [Test]
172 public void TestSitAndStandOnGround()
173 {
174 TestHelpers.InMethod();
175 // log4net.Config.XmlConfigurator.Configure();
176  
177 // If a prim has a sit target then we can sit from any distance away
178 // Vector3 startPos = new Vector3(128, 128, 30);
179 // sp.AbsolutePosition = startPos;
180  
181 m_sp.HandleAgentSitOnGround();
182  
183 Assert.That(m_sp.SitGround, Is.True);
184 Assert.That(m_sp.PhysicsActor, Is.Null);
185  
186 m_sp.StandUp();
187  
188 Assert.That(m_sp.SitGround, Is.False);
189 Assert.That(m_sp.PhysicsActor, Is.Not.Null);
190 }
191 }
192 }