aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs387
1 files changed, 387 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs
new file mode 100644
index 0000000..5b828c5
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs
@@ -0,0 +1,387 @@
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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Text;
32using System.Threading;
33using System.Timers;
34using Timer=System.Timers.Timer;
35using Nini.Config;
36using NUnit.Framework;
37using NUnit.Framework.SyntaxHelpers;
38using OpenMetaverse;
39using OpenSim.Framework;
40using OpenSim.Framework.Communications;
41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.Framework.Interfaces;
43using OpenSim.Region.CoreModules.ServiceConnectors.Interregion;
44using OpenSim.Region.CoreModules.World.Serialiser;
45using OpenSim.Tests.Common;
46using OpenSim.Tests.Common.Mock;
47using OpenSim.Tests.Common.Setup;
48
49namespace OpenSim.Region.Framework.Scenes.Tests
50{
51 /// <summary>
52 /// Scene presence tests
53 /// </summary>
54 [TestFixture]
55 public class ScenePresenceTests
56 {
57 public Scene scene, scene2, scene3;
58 public UUID agent1, agent2, agent3;
59 public static Random random;
60 public ulong region1,region2,region3;
61 public TestCommunicationsManager cm;
62 public AgentCircuitData acd1;
63 public SceneObjectGroup sog1, sog2, sog3;
64 public TestClient testclient;
65
66 [TestFixtureSetUp]
67 public void Init()
68 {
69 cm = new TestCommunicationsManager();
70 scene = SceneSetupHelpers.SetupScene("Neighbour x", UUID.Random(), 1000, 1000, cm);
71 scene2 = SceneSetupHelpers.SetupScene("Neighbour x+1", UUID.Random(), 1001, 1000, cm);
72 scene3 = SceneSetupHelpers.SetupScene("Neighbour x-1", UUID.Random(), 999, 1000, cm);
73
74 IRegionModule interregionComms = new RESTInterregionComms();
75 interregionComms.Initialise(scene, new IniConfigSource());
76 interregionComms.Initialise(scene2, new IniConfigSource());
77 interregionComms.Initialise(scene3, new IniConfigSource());
78 interregionComms.PostInitialise();
79 SceneSetupHelpers.SetupSceneModules(scene, new IniConfigSource(), interregionComms);
80 SceneSetupHelpers.SetupSceneModules(scene2, new IniConfigSource(), interregionComms);
81 SceneSetupHelpers.SetupSceneModules(scene3, new IniConfigSource(), interregionComms);
82
83 agent1 = UUID.Random();
84 agent2 = UUID.Random();
85 agent3 = UUID.Random();
86 random = new Random();
87 sog1 = NewSOG(UUID.Random(), scene, agent1);
88 sog2 = NewSOG(UUID.Random(), scene, agent1);
89 sog3 = NewSOG(UUID.Random(), scene, agent1);
90
91 //ulong neighbourHandle = Utils.UIntsToLong((uint)(neighbourx * Constants.RegionSize), (uint)(neighboury * Constants.RegionSize));
92 region1 = scene.RegionInfo.RegionHandle;
93 region2 = scene2.RegionInfo.RegionHandle;
94 region3 = scene3.RegionInfo.RegionHandle;
95 }
96
97 /// <summary>
98 /// Test adding a root agent to a scene. Doesn't yet actually complete crossing the agent into the scene.
99 /// </summary>
100 [Test]
101 public void T010_TestAddRootAgent()
102 {
103 TestHelper.InMethod();
104
105 string firstName = "testfirstname";
106
107 AgentCircuitData agent = new AgentCircuitData();
108 agent.AgentID = agent1;
109 agent.firstname = firstName;
110 agent.lastname = "testlastname";
111 agent.SessionID = UUID.Zero;
112 agent.SecureSessionID = UUID.Zero;
113 agent.circuitcode = 123;
114 agent.BaseFolder = UUID.Zero;
115 agent.InventoryFolder = UUID.Zero;
116 agent.startpos = Vector3.Zero;
117 agent.CapsPath = GetRandomCapsObjectPath();
118
119 string reason;
120 scene.NewUserConnection(agent, out reason);
121 testclient = new TestClient(agent, scene);
122 scene.AddNewClient(testclient);
123
124 ScenePresence presence = scene.GetScenePresence(agent1);
125
126 Assert.That(presence, Is.Not.Null, "presence is null");
127 Assert.That(presence.Firstname, Is.EqualTo(firstName), "First name not same");
128 acd1 = agent;
129 }
130
131 /// <summary>
132 /// Test removing an uncrossed root agent from a scene.
133 /// </summary>
134 [Test]
135 public void T011_TestRemoveRootAgent()
136 {
137 TestHelper.InMethod();
138
139 scene.RemoveClient(agent1);
140
141 ScenePresence presence = scene.GetScenePresence(agent1);
142
143 Assert.That(presence, Is.Null, "presence is not null");
144 }
145
146 [Test]
147 public void T012_TestAddNeighbourRegion()
148 {
149 TestHelper.InMethod();
150
151 string reason;
152 scene.NewUserConnection(acd1, out reason);
153 scene.AddNewClient(testclient);
154
155 ScenePresence presence = scene.GetScenePresence(agent1);
156 presence.MakeRootAgent(new Vector3(90,90,90),false);
157
158 string cap = presence.ControllingClient.RequestClientInfo().CapsPath;
159
160 presence.AddNeighbourRegion(region2, cap);
161 presence.AddNeighbourRegion(region3, cap);
162
163 List<ulong> neighbours = presence.GetKnownRegionList();
164
165 Assert.That(neighbours.Count, Is.EqualTo(2));
166 }
167
168 [Test]
169 public void T013_TestRemoveNeighbourRegion()
170 {
171 TestHelper.InMethod();
172
173 ScenePresence presence = scene.GetScenePresence(agent1);
174 presence.RemoveNeighbourRegion(region3);
175
176 List<ulong> neighbours = presence.GetKnownRegionList();
177 Assert.That(neighbours.Count,Is.EqualTo(1));
178 /*
179 presence.MakeChildAgent;
180 presence.MakeRootAgent;
181 CompleteAvatarMovement
182 */
183 }
184
185 [Test]
186 public void T020_TestMakeRootAgent()
187 {
188 TestHelper.InMethod();
189
190 ScenePresence presence = scene.GetScenePresence(agent1);
191 Assert.That(presence.IsChildAgent, Is.False, "Starts out as a root agent");
192
193 presence.MakeChildAgent();
194 Assert.That(presence.IsChildAgent, Is.True, "Did not change to child agent after MakeChildAgent");
195
196 // Accepts 0 but rejects Constants.RegionSize
197 Vector3 pos = new Vector3(0,Constants.RegionSize-1,0);
198 presence.MakeRootAgent(pos,true);
199 Assert.That(presence.IsChildAgent, Is.False, "Did not go back to root agent");
200 Assert.That(presence.AbsolutePosition, Is.EqualTo(pos), "Position is not the same one entered");
201 }
202
203 [Test]
204 public void T021_TestCrossToNewRegion()
205 {
206 TestHelper.InMethod();
207
208 // Adding child agent to region 1001
209 string reason;
210 scene2.NewUserConnection(acd1, out reason);
211 scene2.AddNewClient(testclient);
212
213 ScenePresence presence = scene.GetScenePresence(agent1);
214 ScenePresence presence2 = scene2.GetScenePresence(agent1);
215
216 // Adding neighbour region caps info to presence2
217 string cap = presence.ControllingClient.RequestClientInfo().CapsPath;
218 presence2.AddNeighbourRegion(region1, cap);
219
220 scene.RegisterRegionWithGrid();
221 scene2.RegisterRegionWithGrid();
222
223 Assert.That(presence.IsChildAgent, Is.False, "Did not start root in origin region.");
224 Assert.That(presence2.IsChildAgent, Is.True, "Is not a child on destination region.");
225
226 // Cross to x+1
227 presence.AbsolutePosition = new Vector3(Constants.RegionSize+1,3,100);
228 presence.Update();
229
230 EventWaitHandle wh = new EventWaitHandle (false, EventResetMode.AutoReset, "Crossing");
231
232 // Mimicking communication between client and server, by waiting OK from client
233 // sent by TestClient.CrossRegion call. Originally, this is network comm.
234 if (!wh.WaitOne(5000,false))
235 {
236 presence.Update();
237 if (!wh.WaitOne(8000,false))
238 throw new ArgumentException("1 - Timeout waiting for signal/variable.");
239 }
240
241 // This is a TestClient specific method that fires OnCompleteMovementToRegion event, which
242 // would normally be fired after receiving the reply packet from comm. done on the last line.
243 testclient.CompleteMovement();
244
245 // Crossings are asynchronous
246 int timer = 10;
247
248 // Make sure cross hasn't already finished
249 if (!presence.IsInTransit && !presence.IsChildAgent)
250 {
251 // If not and not in transit yet, give it some more time
252 Thread.Sleep(5000);
253 }
254
255 // Enough time, should at least be in transit by now.
256 while (presence.IsInTransit && timer > 0)
257 {
258 Thread.Sleep(1000);
259 timer-=1;
260 }
261
262 Assert.That(timer,Is.GreaterThan(0),"Timed out waiting to cross 2->1.");
263 Assert.That(presence.IsChildAgent, Is.True, "Did not complete region cross as expected.");
264 Assert.That(presence2.IsChildAgent, Is.False, "Did not receive root status after receiving agent.");
265
266 // Cross Back
267 presence2.AbsolutePosition = new Vector3(-10, 3, 100);
268 presence2.Update();
269
270 if (!wh.WaitOne(5000,false))
271 {
272 presence2.Update();
273 if (!wh.WaitOne(8000,false))
274 throw new ArgumentException("2 - Timeout waiting for signal/variable.");
275 }
276 testclient.CompleteMovement();
277
278 if (!presence2.IsInTransit && !presence2.IsChildAgent)
279 {
280 // If not and not in transit yet, give it some more time
281 Thread.Sleep(5000);
282 }
283
284 // Enough time, should at least be in transit by now.
285 while (presence2.IsInTransit && timer > 0)
286 {
287 Thread.Sleep(1000);
288 timer-=1;
289 }
290
291 Assert.That(timer,Is.GreaterThan(0),"Timed out waiting to cross 1->2.");
292 Assert.That(presence2.IsChildAgent, Is.True, "Did not return from region as expected.");
293 Assert.That(presence.IsChildAgent, Is.False, "Presence was not made root in old region again.");
294 }
295
296 [Test]
297 public void T030_TestAddAttachments()
298 {
299 TestHelper.InMethod();
300
301 ScenePresence presence = scene.GetScenePresence(agent1);
302
303 presence.AddAttachment(sog1);
304 presence.AddAttachment(sog2);
305 presence.AddAttachment(sog3);
306
307 Assert.That(presence.HasAttachments(), Is.True);
308 Assert.That(presence.ValidateAttachments(), Is.True);
309 }
310
311 [Test]
312 public void T031_RemoveAttachments()
313 {
314 TestHelper.InMethod();
315
316 ScenePresence presence = scene.GetScenePresence(agent1);
317 presence.RemoveAttachment(sog1);
318 presence.RemoveAttachment(sog2);
319 presence.RemoveAttachment(sog3);
320 Assert.That(presence.HasAttachments(), Is.False);
321 }
322
323 [Test]
324 public void T032_CrossAttachments()
325 {
326 TestHelper.InMethod();
327
328 ScenePresence presence = scene.GetScenePresence(agent1);
329 ScenePresence presence2 = scene2.GetScenePresence(agent1);
330 presence2.AddAttachment(sog1);
331 presence2.AddAttachment(sog2);
332
333 IRegionModule serialiser = new SerialiserModule();
334 SceneSetupHelpers.SetupSceneModules(scene, new IniConfigSource(), serialiser);
335 SceneSetupHelpers.SetupSceneModules(scene2, new IniConfigSource(), serialiser);
336
337 Assert.That(presence.HasAttachments(), Is.False, "Presence has attachments before cross");
338
339 Assert.That(presence2.CrossAttachmentsIntoNewRegion(region1, true), Is.True, "Cross was not successful");
340 Assert.That(presence2.HasAttachments(), Is.False, "Presence2 objects were not deleted");
341 Assert.That(presence.HasAttachments(), Is.True, "Presence has not received new objects");
342 }
343
344 public static string GetRandomCapsObjectPath()
345 {
346 TestHelper.InMethod();
347
348 UUID caps = UUID.Random();
349 string capsPath = caps.ToString();
350 capsPath = capsPath.Remove(capsPath.Length - 4, 4);
351 return capsPath;
352 }
353
354 private SceneObjectGroup NewSOG(UUID uuid, Scene scene, UUID agent)
355 {
356 SceneObjectPart sop = new SceneObjectPart();
357 sop.Name = RandomName();
358 sop.Description = RandomName();
359 sop.Text = RandomName();
360 sop.SitName = RandomName();
361 sop.TouchName = RandomName();
362 sop.UUID = uuid;
363 sop.Shape = PrimitiveBaseShape.Default;
364 sop.Shape.State = 1;
365 sop.OwnerID = agent;
366
367 SceneObjectGroup sog = new SceneObjectGroup();
368 sog.SetScene(scene);
369 sog.SetRootPart(sop);
370
371 return sog;
372 }
373
374 private static string RandomName()
375 {
376 StringBuilder name = new StringBuilder();
377 int size = random.Next(5,12);
378 char ch ;
379 for (int i=0; i<size; i++)
380 {
381 ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ;
382 name.Append(ch);
383 }
384 return name.ToString();
385 }
386 }
387}