aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Tests')
-rw-r--r--OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs91
-rw-r--r--OpenSim/Tests/Common/Helpers/SceneHelpers.cs37
-rw-r--r--OpenSim/Tests/Common/Mock/TestClient.cs29
3 files changed, 126 insertions, 31 deletions
diff --git a/OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs b/OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs
new file mode 100644
index 0000000..6cc7ff2
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs
@@ -0,0 +1,91 @@
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.IO;
31using System.Net;
32using System.Reflection;
33using System.Text;
34using log4net;
35using Nini.Config;
36using NUnit.Framework;
37using OpenMetaverse;
38using OpenSim.Framework;
39using OpenSim.Framework.Communications;
40using OpenSim.Framework.Servers;
41using OpenSim.Region.Framework.Interfaces;
42using OpenSim.Region.Framework.Scenes;
43using OpenSim.Region.CoreModules.Framework;
44using OpenSim.Tests.Common;
45using OpenSim.Tests.Common.Mock;
46
47namespace OpenSim.Tests.Common
48{
49 public static class EntityTransferHelpers
50 {
51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52
53 /// <summary>
54 /// Set up correct handling of the InformClientOfNeighbour call from the source region that triggers the
55 /// viewer to setup a connection with the destination region.
56 /// </summary>
57 /// <param name='tc'></param>
58 /// <param name='neighbourTcs'>
59 /// A list that will be populated with any TestClients set up in response to
60 /// being informed about a destination region.
61 /// </param>
62 public static void SetUpInformClientOfNeighbour(TestClient tc, List<TestClient> neighbourTcs)
63 {
64 // XXX: Confusingly, this is also used for non-neighbour notification (as in teleports that do not use the
65 // event queue).
66
67 tc.OnTestClientInformClientOfNeighbour += (neighbourHandle, neighbourExternalEndPoint) =>
68 {
69 uint x, y;
70 Utils.LongToUInts(neighbourHandle, out x, out y);
71 x /= Constants.RegionSize;
72 y /= Constants.RegionSize;
73
74 m_log.DebugFormat(
75 "[TEST CLIENT]: Processing inform client of neighbour located at {0},{1} at {2}",
76 x, y, neighbourExternalEndPoint);
77
78 // In response to this message, we are going to make a teleport to the scene we've previous been told
79 // about by test code (this needs to be improved).
80 AgentCircuitData newAgent = tc.RequestClientInfo();
81
82 Scene neighbourScene;
83 SceneManager.Instance.TryGetScene(x, y, out neighbourScene);
84
85 TestClient neighbourTc = new TestClient(newAgent, neighbourScene, SceneManager.Instance);
86 neighbourTcs.Add(neighbourTc);
87 neighbourScene.AddNewClient(neighbourTc, PresenceType.User);
88 };
89 }
90 }
91} \ No newline at end of file
diff --git a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs
index dc20f13..bdd9093 100644
--- a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs
+++ b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs
@@ -532,6 +532,31 @@ namespace OpenSim.Tests.Common
532 /// <returns></returns> 532 /// <returns></returns>
533 public static ScenePresence AddScenePresence(Scene scene, AgentCircuitData agentData, SceneManager sceneManager) 533 public static ScenePresence AddScenePresence(Scene scene, AgentCircuitData agentData, SceneManager sceneManager)
534 { 534 {
535 return AddScenePresence(scene, new TestClient(agentData, scene, sceneManager), agentData, sceneManager);
536 }
537
538 /// <summary>
539 /// Add a root agent.
540 /// </summary>
541 /// <remarks>
542 /// This function
543 ///
544 /// 1) Tells the scene that an agent is coming. Normally, the login service (local if standalone, from the
545 /// userserver if grid) would give initial login data back to the client and separately tell the scene that the
546 /// agent was coming.
547 ///
548 /// 2) Connects the agent with the scene
549 ///
550 /// This function performs actions equivalent with notifying the scene that an agent is
551 /// coming and then actually connecting the agent to the scene. The one step missed out is the very first
552 /// </remarks>
553 /// <param name="scene"></param>
554 /// <param name="agentData"></param>
555 /// <param name="sceneManager"></param>
556 /// <returns></returns>
557 public static ScenePresence AddScenePresence(
558 Scene scene, IClientAPI client, AgentCircuitData agentData, SceneManager sceneManager)
559 {
535 // We emulate the proper login sequence here by doing things in four stages 560 // We emulate the proper login sequence here by doing things in four stages
536 561
537 // Stage 0: login 562 // Stage 0: login
@@ -541,7 +566,7 @@ namespace OpenSim.Tests.Common
541 lpsc.m_PresenceService.LoginAgent(agentData.AgentID.ToString(), agentData.SessionID, agentData.SecureSessionID); 566 lpsc.m_PresenceService.LoginAgent(agentData.AgentID.ToString(), agentData.SessionID, agentData.SecureSessionID);
542 567
543 // Stages 1 & 2 568 // Stages 1 & 2
544 ScenePresence sp = IntroduceClientToScene(scene, sceneManager, agentData, TeleportFlags.ViaLogin); 569 ScenePresence sp = IntroduceClientToScene(scene, client, agentData, TeleportFlags.ViaLogin);
545 570
546 // Stage 3: Complete the entrance into the region. This converts the child agent into a root agent. 571 // Stage 3: Complete the entrance into the region. This converts the child agent into a root agent.
547 sp.CompleteMovement(sp.ControllingClient, true); 572 sp.CompleteMovement(sp.ControllingClient, true);
@@ -558,11 +583,11 @@ namespace OpenSim.Tests.Common
558 /// neighbours and where no teleporting takes place. 583 /// neighbours and where no teleporting takes place.
559 /// </param> 584 /// </param>
560 /// <param name='scene'></param> 585 /// <param name='scene'></param>
561 /// <param name='sceneManager></param> 586 /// <param name='testClient'></param>
562 /// <param name='agentData'></param> 587 /// <param name='agentData'></param>
563 /// <param name='tf'></param> 588 /// <param name='tf'></param>
564 private static ScenePresence IntroduceClientToScene( 589 private static ScenePresence IntroduceClientToScene(
565 Scene scene, SceneManager sceneManager, AgentCircuitData agentData, TeleportFlags tf) 590 Scene scene, IClientAPI client, AgentCircuitData agentData, TeleportFlags tf)
566 { 591 {
567 string reason; 592 string reason;
568 593
@@ -571,10 +596,9 @@ namespace OpenSim.Tests.Common
571 Console.WriteLine("NewUserConnection failed: " + reason); 596 Console.WriteLine("NewUserConnection failed: " + reason);
572 597
573 // Stage 2: add the new client as a child agent to the scene 598 // Stage 2: add the new client as a child agent to the scene
574 TestClient client = new TestClient(agentData, scene, sceneManager);
575 scene.AddNewClient(client, PresenceType.User); 599 scene.AddNewClient(client, PresenceType.User);
576 600
577 return scene.GetScenePresence(agentData.AgentID); 601 return scene.GetScenePresence(client.AgentId);
578 } 602 }
579 603
580 public static ScenePresence AddChildScenePresence(Scene scene, UUID agentId) 604 public static ScenePresence AddChildScenePresence(Scene scene, UUID agentId)
@@ -583,7 +607,8 @@ namespace OpenSim.Tests.Common
583 acd.child = true; 607 acd.child = true;
584 608
585 // XXX: ViaLogin may not be correct for child agents 609 // XXX: ViaLogin may not be correct for child agents
586 return IntroduceClientToScene(scene, null, acd, TeleportFlags.ViaLogin); 610 TestClient client = new TestClient(acd, scene, null);
611 return IntroduceClientToScene(scene, client, acd, TeleportFlags.ViaLogin);
587 } 612 }
588 613
589 /// <summary> 614 /// <summary>
diff --git a/OpenSim/Tests/Common/Mock/TestClient.cs b/OpenSim/Tests/Common/Mock/TestClient.cs
index e892a53..4a1380d 100644
--- a/OpenSim/Tests/Common/Mock/TestClient.cs
+++ b/OpenSim/Tests/Common/Mock/TestClient.cs
@@ -46,8 +46,6 @@ namespace OpenSim.Tests.Common.Mock
46 46
47 EventWaitHandle wh = new EventWaitHandle (false, EventResetMode.AutoReset, "Crossing"); 47 EventWaitHandle wh = new EventWaitHandle (false, EventResetMode.AutoReset, "Crossing");
48 48
49 private TestClient TeleportSceneClient;
50
51 private Scene m_scene; 49 private Scene m_scene;
52 private SceneManager m_sceneManager; 50 private SceneManager m_sceneManager;
53 51
@@ -60,7 +58,9 @@ namespace OpenSim.Tests.Common.Mock
60 public List<ImagePacketPacket> SentImagePacketPackets { get; private set; } 58 public List<ImagePacketPacket> SentImagePacketPackets { get; private set; }
61 public List<ImageNotInDatabasePacket> SentImageNotInDatabasePackets { get; private set; } 59 public List<ImageNotInDatabasePacket> SentImageNotInDatabasePackets { get; private set; }
62 60
61 // Test client specific events - for use by tests to implement some IClientAPI behaviour.
63 public event Action<RegionInfo, Vector3, Vector3> OnReceivedMoveAgentIntoRegion; 62 public event Action<RegionInfo, Vector3, Vector3> OnReceivedMoveAgentIntoRegion;
63 public event Action<ulong, IPEndPoint> OnTestClientInformClientOfNeighbour;
64 64
65// disable warning: public events, part of the public API 65// disable warning: public events, part of the public API
66#pragma warning disable 67 66#pragma warning disable 67
@@ -604,23 +604,8 @@ namespace OpenSim.Tests.Common.Mock
604 604
605 public virtual void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourExternalEndPoint) 605 public virtual void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourExternalEndPoint)
606 { 606 {
607 m_log.DebugFormat("[TEST CLIENT]: Processing inform client of neighbour"); 607 if (OnTestClientInformClientOfNeighbour != null)
608 608 OnTestClientInformClientOfNeighbour(neighbourHandle, neighbourExternalEndPoint);
609 // In response to this message, we are going to make a teleport to the scene we've previous been told
610 // about by test code (this needs to be improved).
611 AgentCircuitData newAgent = RequestClientInfo();
612
613 // Stage 2: add the new client as a child agent to the scene
614 uint x, y;
615 Utils.LongToUInts(neighbourHandle, out x, out y);
616 x /= Constants.RegionSize;
617 y /= Constants.RegionSize;
618
619 Scene neighbourScene;
620 m_sceneManager.TryGetScene(x, y, out neighbourScene);
621
622 TeleportSceneClient = new TestClient(newAgent, neighbourScene, m_sceneManager);
623 neighbourScene.AddNewClient(TeleportSceneClient, PresenceType.User);
624 } 609 }
625 610
626 public virtual void SendRegionTeleport(ulong regionHandle, byte simAccess, IPEndPoint regionExternalEndPoint, 611 public virtual void SendRegionTeleport(ulong regionHandle, byte simAccess, IPEndPoint regionExternalEndPoint,
@@ -635,12 +620,6 @@ namespace OpenSim.Tests.Common.Mock
635 // CompleteTeleportClientSide(); 620 // CompleteTeleportClientSide();
636 } 621 }
637 622
638 public void CompleteTeleportClientSide()
639 {
640 TeleportSceneClient.CompleteMovement();
641 //TeleportTargetScene.AgentCrossing(newAgent.AgentID, new Vector3(90, 90, 90), false);
642 }
643
644 public virtual void SendTeleportFailed(string reason) 623 public virtual void SendTeleportFailed(string reason)
645 { 624 {
646 m_log.DebugFormat("[TEST CLIENT]: Teleport failed with reason {0}", reason); 625 m_log.DebugFormat("[TEST CLIENT]: Teleport failed with reason {0}", reason);