aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2011-08-06 02:01:25 +0100
committerJustin Clark-Casey (justincc)2011-08-06 02:01:25 +0100
commit83ba35a26bbbc844f4fd0f4964f3bc6155561e31 (patch)
tree172bfbe943241ab30f13fc224bb1238031803e5d /OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs
parentprevent "create region" console command from being able to create a region wi... (diff)
downloadopensim-SC_OLD-83ba35a26bbbc844f4fd0f4964f3bc6155561e31.zip
opensim-SC_OLD-83ba35a26bbbc844f4fd0f4964f3bc6155561e31.tar.gz
opensim-SC_OLD-83ba35a26bbbc844f4fd0f4964f3bc6155561e31.tar.bz2
opensim-SC_OLD-83ba35a26bbbc844f4fd0f4964f3bc6155561e31.tar.xz
rip out sog generation methods in ScenePresenceAgentTests and use SceneHelpers instead
Not that it matters, since these tests are pretty bogus anyway. Also, renames some test classes for consistency.
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs385
1 files changed, 0 insertions, 385 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs
deleted file mode 100644
index 9b5f52f..0000000
--- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs
+++ /dev/null
@@ -1,385 +0,0 @@
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 OpenMetaverse;
38using OpenSim.Framework;
39using OpenSim.Framework.Communications;
40using OpenSim.Region.Framework.Scenes;
41using OpenSim.Region.Framework.Interfaces;
42using OpenSim.Region.CoreModules.Framework.EntityTransfer;
43using OpenSim.Region.CoreModules.World.Serialiser;
44using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
45using OpenSim.Tests.Common;
46using OpenSim.Tests.Common.Mock;
47
48namespace OpenSim.Region.Framework.Scenes.Tests
49{
50 /// <summary>
51 /// Scene presence tests
52 /// </summary>
53 [TestFixture]
54 public class ScenePresenceTests
55 {
56 public Scene scene, scene2, scene3;
57 public UUID agent1, agent2, agent3;
58 public static Random random;
59 public ulong region1,region2,region3;
60 public AgentCircuitData acd1;
61 public SceneObjectGroup sog1, sog2, sog3;
62 public TestClient testclient;
63
64 [TestFixtureSetUp]
65 public void Init()
66 {
67 TestHelpers.InMethod();
68
69 scene = SceneHelpers.SetupScene("Neighbour x", UUID.Random(), 1000, 1000);
70 scene2 = SceneHelpers.SetupScene("Neighbour x+1", UUID.Random(), 1001, 1000);
71 scene3 = SceneHelpers.SetupScene("Neighbour x-1", UUID.Random(), 999, 1000);
72
73 ISharedRegionModule interregionComms = new LocalSimulationConnectorModule();
74 interregionComms.Initialise(new IniConfigSource());
75 interregionComms.PostInitialise();
76 SceneHelpers.SetupSceneModules(scene, new IniConfigSource(), interregionComms);
77 SceneHelpers.SetupSceneModules(scene2, new IniConfigSource(), interregionComms);
78 SceneHelpers.SetupSceneModules(scene3, new IniConfigSource(), interregionComms);
79
80 agent1 = UUID.Random();
81 agent2 = UUID.Random();
82 agent3 = UUID.Random();
83 random = new Random();
84 sog1 = NewSOG(UUID.Random(), scene, agent1);
85 sog2 = NewSOG(UUID.Random(), scene, agent1);
86 sog3 = NewSOG(UUID.Random(), scene, agent1);
87
88 //ulong neighbourHandle = Utils.UIntsToLong((uint)(neighbourx * Constants.RegionSize), (uint)(neighboury * Constants.RegionSize));
89 region1 = scene.RegionInfo.RegionHandle;
90 region2 = scene2.RegionInfo.RegionHandle;
91 region3 = scene3.RegionInfo.RegionHandle;
92 }
93
94 /// <summary>
95 /// Test adding a root agent to a scene. Doesn't yet actually complete crossing the agent into the scene.
96 /// </summary>
97 [Test]
98 public void T010_TestAddRootAgent()
99 {
100 TestHelpers.InMethod();
101
102 string firstName = "testfirstname";
103
104 AgentCircuitData agent = new AgentCircuitData();
105 agent.AgentID = agent1;
106 agent.firstname = firstName;
107 agent.lastname = "testlastname";
108 agent.SessionID = UUID.Random();
109 agent.SecureSessionID = UUID.Random();
110 agent.circuitcode = 123;
111 agent.BaseFolder = UUID.Zero;
112 agent.InventoryFolder = UUID.Zero;
113 agent.startpos = Vector3.Zero;
114 agent.CapsPath = GetRandomCapsObjectPath();
115 agent.ChildrenCapSeeds = new Dictionary<ulong, string>();
116 agent.child = true;
117
118 scene.PresenceService.LoginAgent(agent.AgentID.ToString(), agent.SessionID, agent.SecureSessionID);
119
120 string reason;
121 scene.NewUserConnection(agent, (uint)TeleportFlags.ViaLogin, out reason);
122 testclient = new TestClient(agent, scene);
123 scene.AddNewClient(testclient);
124
125 ScenePresence presence = scene.GetScenePresence(agent1);
126
127 Assert.That(presence, Is.Not.Null, "presence is null");
128 Assert.That(presence.Firstname, Is.EqualTo(firstName), "First name not same");
129 acd1 = agent;
130 }
131
132 /// <summary>
133 /// Test removing an uncrossed root agent from a scene.
134 /// </summary>
135 [Test]
136 public void T011_TestRemoveRootAgent()
137 {
138 TestHelpers.InMethod();
139
140 scene.RemoveClient(agent1);
141
142 ScenePresence presence = scene.GetScenePresence(agent1);
143
144 Assert.That(presence, Is.Null, "presence is not null");
145 }
146
147 [Test]
148 public void T012_TestAddNeighbourRegion()
149 {
150 TestHelpers.InMethod();
151
152 string reason;
153
154 if (acd1 == null)
155 fixNullPresence();
156
157 scene.NewUserConnection(acd1, 0, out reason);
158 if (testclient == null)
159 testclient = new TestClient(acd1, scene);
160 scene.AddNewClient(testclient);
161
162 ScenePresence presence = scene.GetScenePresence(agent1);
163 presence.MakeRootAgent(new Vector3(90,90,90),false);
164
165 string cap = presence.ControllingClient.RequestClientInfo().CapsPath;
166
167 presence.AddNeighbourRegion(region2, cap);
168 presence.AddNeighbourRegion(region3, cap);
169
170 List<ulong> neighbours = presence.GetKnownRegionList();
171
172 Assert.That(neighbours.Count, Is.EqualTo(2));
173 }
174
175 [Test]
176 public void T013_TestRemoveNeighbourRegion()
177 {
178 TestHelpers.InMethod();
179
180 ScenePresence presence = scene.GetScenePresence(agent1);
181 presence.RemoveNeighbourRegion(region3);
182
183 List<ulong> neighbours = presence.GetKnownRegionList();
184 Assert.That(neighbours.Count,Is.EqualTo(1));
185 /*
186 presence.MakeChildAgent;
187 presence.MakeRootAgent;
188 CompleteAvatarMovement
189 */
190 }
191
192 /// <summary>
193 /// Test that if a root agent logs into a region, a child agent is also established in the neighbouring region
194 /// </summary>
195 /// <remarks>
196 /// Please note that unlike the other tests here, this doesn't rely on structures
197 /// </remarks>
198 [Test]
199 public void TestChildAgentEstablished()
200 {
201 TestHelpers.InMethod();
202// log4net.Config.XmlConfigurator.Configure();
203
204 UUID agent1Id = UUID.Parse("00000000-0000-0000-0000-000000000001");
205
206 TestScene myScene1 = SceneHelpers.SetupScene("Neighbour y", UUID.Random(), 1000, 1000);
207 TestScene myScene2 = SceneHelpers.SetupScene("Neighbour y + 1", UUID.Random(), 1001, 1000);
208
209 IConfigSource configSource = new IniConfigSource();
210 configSource.AddConfig("Modules").Set("EntityTransferModule", "BasicEntityTransferModule");
211 EntityTransferModule etm = new EntityTransferModule();
212
213 SceneHelpers.SetupSceneModules(myScene1, configSource, etm);
214
215 SceneHelpers.AddClient(myScene1, agent1Id);
216 ScenePresence childPresence = myScene2.GetScenePresence(agent1);
217
218 // TODO: Need to do a fair amount of work to allow synchronous establishment of child agents
219// Assert.That(childPresence, Is.Not.Null);
220// Assert.That(childPresence.IsChildAgent, Is.True);
221 }
222
223 // I'm commenting this test because it does not represent
224 // crossings. The Thread.Sleep's in here are not meaningful mocks,
225 // and they sometimes fail in panda.
226 // We need to talk in order to develop a test
227 // that really tests region crossings. There are 3 async components,
228 // but things are synchronous among them. So there should be
229 // 3 threads in here.
230 //[Test]
231 public void T021_TestCrossToNewRegion()
232 {
233 TestHelpers.InMethod();
234
235 scene.RegisterRegionWithGrid();
236 scene2.RegisterRegionWithGrid();
237
238 // Adding child agent to region 1001
239 string reason;
240 scene2.NewUserConnection(acd1,0, out reason);
241 scene2.AddNewClient(testclient);
242
243 ScenePresence presence = scene.GetScenePresence(agent1);
244 presence.MakeRootAgent(new Vector3(0,unchecked(Constants.RegionSize-1),0), true);
245
246 ScenePresence presence2 = scene2.GetScenePresence(agent1);
247
248 // Adding neighbour region caps info to presence2
249
250 string cap = presence.ControllingClient.RequestClientInfo().CapsPath;
251 presence2.AddNeighbourRegion(region1, cap);
252
253 Assert.That(presence.IsChildAgent, Is.False, "Did not start root in origin region.");
254 Assert.That(presence2.IsChildAgent, Is.True, "Is not a child on destination region.");
255
256 // Cross to x+1
257 presence.AbsolutePosition = new Vector3(Constants.RegionSize+1,3,100);
258 presence.Update();
259
260 EventWaitHandle wh = new EventWaitHandle (false, EventResetMode.AutoReset, "Crossing");
261
262 // Mimicking communication between client and server, by waiting OK from client
263 // sent by TestClient.CrossRegion call. Originally, this is network comm.
264 if (!wh.WaitOne(5000,false))
265 {
266 presence.Update();
267 if (!wh.WaitOne(8000,false))
268 throw new ArgumentException("1 - Timeout waiting for signal/variable.");
269 }
270
271 // This is a TestClient specific method that fires OnCompleteMovementToRegion event, which
272 // would normally be fired after receiving the reply packet from comm. done on the last line.
273 testclient.CompleteMovement();
274
275 // Crossings are asynchronous
276 int timer = 10;
277
278 // Make sure cross hasn't already finished
279 if (!presence.IsInTransit && !presence.IsChildAgent)
280 {
281 // If not and not in transit yet, give it some more time
282 Thread.Sleep(5000);
283 }
284
285 // Enough time, should at least be in transit by now.
286 while (presence.IsInTransit && timer > 0)
287 {
288 Thread.Sleep(1000);
289 timer-=1;
290 }
291
292 Assert.That(timer,Is.GreaterThan(0),"Timed out waiting to cross 2->1.");
293 Assert.That(presence.IsChildAgent, Is.True, "Did not complete region cross as expected.");
294 Assert.That(presence2.IsChildAgent, Is.False, "Did not receive root status after receiving agent.");
295
296 // Cross Back
297 presence2.AbsolutePosition = new Vector3(-10, 3, 100);
298 presence2.Update();
299
300 if (!wh.WaitOne(5000,false))
301 {
302 presence2.Update();
303 if (!wh.WaitOne(8000,false))
304 throw new ArgumentException("2 - Timeout waiting for signal/variable.");
305 }
306 testclient.CompleteMovement();
307
308 if (!presence2.IsInTransit && !presence2.IsChildAgent)
309 {
310 // If not and not in transit yet, give it some more time
311 Thread.Sleep(5000);
312 }
313
314 // Enough time, should at least be in transit by now.
315 while (presence2.IsInTransit && timer > 0)
316 {
317 Thread.Sleep(1000);
318 timer-=1;
319 }
320
321 Assert.That(timer,Is.GreaterThan(0),"Timed out waiting to cross 1->2.");
322 Assert.That(presence2.IsChildAgent, Is.True, "Did not return from region as expected.");
323 Assert.That(presence.IsChildAgent, Is.False, "Presence was not made root in old region again.");
324 }
325
326 public void fixNullPresence()
327 {
328 string firstName = "testfirstname";
329
330 AgentCircuitData agent = new AgentCircuitData();
331 agent.AgentID = agent1;
332 agent.firstname = firstName;
333 agent.lastname = "testlastname";
334 agent.SessionID = UUID.Zero;
335 agent.SecureSessionID = UUID.Zero;
336 agent.circuitcode = 123;
337 agent.BaseFolder = UUID.Zero;
338 agent.InventoryFolder = UUID.Zero;
339 agent.startpos = Vector3.Zero;
340 agent.CapsPath = GetRandomCapsObjectPath();
341
342 acd1 = agent;
343 }
344
345 public static string GetRandomCapsObjectPath()
346 {
347 UUID caps = UUID.Random();
348 string capsPath = caps.ToString();
349 capsPath = capsPath.Remove(capsPath.Length - 4, 4);
350 return capsPath;
351 }
352
353 private SceneObjectGroup NewSOG(UUID uuid, Scene scene, UUID agent)
354 {
355 SceneObjectPart sop = new SceneObjectPart();
356 sop.Name = RandomName();
357 sop.Description = RandomName();
358 sop.Text = RandomName();
359 sop.SitName = RandomName();
360 sop.TouchName = RandomName();
361 sop.UUID = uuid;
362 sop.Shape = PrimitiveBaseShape.Default;
363 sop.Shape.State = 1;
364 sop.OwnerID = agent;
365
366 SceneObjectGroup sog = new SceneObjectGroup(sop);
367 sog.SetScene(scene);
368
369 return sog;
370 }
371
372 private static string RandomName()
373 {
374 StringBuilder name = new StringBuilder();
375 int size = random.Next(5,12);
376 char ch ;
377 for (int i=0; i<size; i++)
378 {
379 ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ;
380 name.Append(ch);
381 }
382 return name.ToString();
383 }
384 }
385} \ No newline at end of file