aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCrossingTests.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCrossingTests.cs247
1 files changed, 247 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCrossingTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCrossingTests.cs
new file mode 100644
index 0000000..7127644
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCrossingTests.cs
@@ -0,0 +1,247 @@
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 Nini.Config;
32using NUnit.Framework;
33using OpenMetaverse;
34using OpenSim.Framework;
35using OpenSim.Framework.Servers;
36using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.CoreModules.Framework;
38using OpenSim.Region.CoreModules.Framework.EntityTransfer;
39using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
40using OpenSim.Region.CoreModules.World.Permissions;
41using OpenSim.Tests.Common;
42
43namespace OpenSim.Region.Framework.Scenes.Tests
44{
45 [TestFixture]
46 public class ScenePresenceCrossingTests : OpenSimTestCase
47 {
48 [TestFixtureSetUp]
49 public void FixtureInit()
50 {
51 // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
52 Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
53 }
54
55 [TestFixtureTearDown]
56 public void TearDown()
57 {
58 // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
59 // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
60 // tests really shouldn't).
61 Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
62 }
63
64 [Test]
65 public void TestCrossOnSameSimulator()
66 {
67 TestHelpers.InMethod();
68// TestHelpers.EnableLogging();
69
70 UUID userId = TestHelpers.ParseTail(0x1);
71
72// TestEventQueueGetModule eqmA = new TestEventQueueGetModule();
73 EntityTransferModule etmA = new EntityTransferModule();
74 EntityTransferModule etmB = new EntityTransferModule();
75 LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
76
77 IConfigSource config = new IniConfigSource();
78 IConfig modulesConfig = config.AddConfig("Modules");
79 modulesConfig.Set("EntityTransferModule", etmA.Name);
80 modulesConfig.Set("SimulationServices", lscm.Name);
81// IConfig entityTransferConfig = config.AddConfig("EntityTransfer");
82
83 // In order to run a single threaded regression test we do not want the entity transfer module waiting
84 // for a callback from the destination scene before removing its avatar data.
85// entityTransferConfig.Set("wait_for_callback", false);
86
87 SceneHelpers sh = new SceneHelpers();
88 TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
89 TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999);
90
91 SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
92 SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA);
93// SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA, eqmA);
94 SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), etmB);
95
96 AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId);
97 TestClient tc = new TestClient(acd, sceneA);
98 List<TestClient> destinationTestClients = new List<TestClient>();
99 EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients);
100
101 ScenePresence originalSp = SceneHelpers.AddScenePresence(sceneA, tc, acd);
102 originalSp.AbsolutePosition = new Vector3(128, 32, 10);
103
104// originalSp.Flying = true;
105
106// Console.WriteLine("First pos {0}", originalSp.AbsolutePosition);
107
108// eqmA.ClearEvents();
109
110 AgentUpdateArgs moveArgs = new AgentUpdateArgs();
111 //moveArgs.BodyRotation = Quaternion.CreateFromEulers(Vector3.Zero);
112 moveArgs.BodyRotation = Quaternion.CreateFromEulers(new Vector3(0, 0, (float)-(Math.PI / 2)));
113 moveArgs.ControlFlags = (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS;
114 moveArgs.SessionID = acd.SessionID;
115
116 originalSp.HandleAgentUpdate(originalSp.ControllingClient, moveArgs);
117
118 sceneA.Update(1);
119
120// Console.WriteLine("Second pos {0}", originalSp.AbsolutePosition);
121
122 // FIXME: This is a sufficient number of updates to for the presence to reach the northern border.
123 // But really we want to do this in a more robust way.
124 for (int i = 0; i < 100; i++)
125 {
126 sceneA.Update(1);
127// Console.WriteLine("Pos {0}", originalSp.AbsolutePosition);
128 }
129
130 // Need to sort processing of EnableSimulator message on adding scene presences before we can test eqm
131 // messages
132// Dictionary<UUID, List<TestEventQueueGetModule.Event>> eqmEvents = eqmA.Events;
133//
134// Assert.That(eqmEvents.Count, Is.EqualTo(1));
135// Assert.That(eqmEvents.ContainsKey(originalSp.UUID), Is.True);
136//
137// List<TestEventQueueGetModule.Event> spEqmEvents = eqmEvents[originalSp.UUID];
138//
139// Assert.That(spEqmEvents.Count, Is.EqualTo(1));
140// Assert.That(spEqmEvents[0].Name, Is.EqualTo("CrossRegion"));
141
142 // sceneA should now only have a child agent
143 ScenePresence spAfterCrossSceneA = sceneA.GetScenePresence(originalSp.UUID);
144 Assert.That(spAfterCrossSceneA.IsChildAgent, Is.True);
145
146 ScenePresence spAfterCrossSceneB = sceneB.GetScenePresence(originalSp.UUID);
147
148 // Agent remains a child until the client triggers complete movement
149 Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True);
150
151 TestClient sceneBTc = ((TestClient)spAfterCrossSceneB.ControllingClient);
152
153 int agentMovementCompleteReceived = 0;
154 sceneBTc.OnReceivedMoveAgentIntoRegion += (ri, pos, look) => agentMovementCompleteReceived++;
155
156 sceneBTc.CompleteMovement();
157
158 Assert.That(agentMovementCompleteReceived, Is.EqualTo(1));
159 Assert.That(spAfterCrossSceneB.IsChildAgent, Is.False);
160 }
161
162 /// <summary>
163 /// Test a cross attempt where the user can see into the neighbour but does not have permission to become
164 /// root there.
165 /// </summary>
166 [Test]
167 public void TestCrossOnSameSimulatorNoRootDestPerm()
168 {
169 TestHelpers.InMethod();
170// TestHelpers.EnableLogging();
171
172 UUID userId = TestHelpers.ParseTail(0x1);
173
174 EntityTransferModule etmA = new EntityTransferModule();
175 EntityTransferModule etmB = new EntityTransferModule();
176 LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
177
178 IConfigSource config = new IniConfigSource();
179 IConfig modulesConfig = config.AddConfig("Modules");
180 modulesConfig.Set("EntityTransferModule", etmA.Name);
181 modulesConfig.Set("SimulationServices", lscm.Name);
182
183 SceneHelpers sh = new SceneHelpers();
184 TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
185 TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999);
186
187 SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
188 SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA);
189
190 // We need to set up the permisions module on scene B so that our later use of agent limit to deny
191 // QueryAccess won't succeed anyway because administrators are always allowed in and the default
192 // IsAdministrator if no permissions module is present is true.
193 SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), new PermissionsModule(), etmB);
194
195 AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId);
196 TestClient tc = new TestClient(acd, sceneA);
197 List<TestClient> destinationTestClients = new List<TestClient>();
198 EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients);
199
200 // Make sure sceneB will not accept this avatar.
201 sceneB.RegionInfo.EstateSettings.PublicAccess = false;
202
203 ScenePresence originalSp = SceneHelpers.AddScenePresence(sceneA, tc, acd);
204 originalSp.AbsolutePosition = new Vector3(128, 32, 10);
205
206 AgentUpdateArgs moveArgs = new AgentUpdateArgs();
207 //moveArgs.BodyRotation = Quaternion.CreateFromEulers(Vector3.Zero);
208 moveArgs.BodyRotation = Quaternion.CreateFromEulers(new Vector3(0, 0, (float)-(Math.PI / 2)));
209 moveArgs.ControlFlags = (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS;
210 moveArgs.SessionID = acd.SessionID;
211
212 originalSp.HandleAgentUpdate(originalSp.ControllingClient, moveArgs);
213
214 sceneA.Update(1);
215
216// Console.WriteLine("Second pos {0}", originalSp.AbsolutePosition);
217
218 // FIXME: This is a sufficient number of updates to for the presence to reach the northern border.
219 // But really we want to do this in a more robust way.
220 for (int i = 0; i < 100; i++)
221 {
222 sceneA.Update(1);
223// Console.WriteLine("Pos {0}", originalSp.AbsolutePosition);
224 }
225
226 // sceneA agent should still be root
227 ScenePresence spAfterCrossSceneA = sceneA.GetScenePresence(originalSp.UUID);
228 Assert.That(spAfterCrossSceneA.IsChildAgent, Is.False);
229
230 ScenePresence spAfterCrossSceneB = sceneB.GetScenePresence(originalSp.UUID);
231
232 // sceneB agent should also still be root
233 Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True);
234
235 // sceneB should ignore unauthorized attempt to upgrade agent to root
236 TestClient sceneBTc = ((TestClient)spAfterCrossSceneB.ControllingClient);
237
238 int agentMovementCompleteReceived = 0;
239 sceneBTc.OnReceivedMoveAgentIntoRegion += (ri, pos, look) => agentMovementCompleteReceived++;
240
241 sceneBTc.CompleteMovement();
242
243 Assert.That(agentMovementCompleteReceived, Is.EqualTo(0));
244 Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True);
245 }
246 }
247} \ No newline at end of file