aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/Chat/Tests/ChatModuleTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Chat/Tests/ChatModuleTests.cs')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Chat/Tests/ChatModuleTests.cs286
1 files changed, 286 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Chat/Tests/ChatModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Chat/Tests/ChatModuleTests.cs
new file mode 100644
index 0000000..7b8c418
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Avatar/Chat/Tests/ChatModuleTests.cs
@@ -0,0 +1,286 @@
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 log4net.Config;
31using Nini.Config;
32using NUnit.Framework;
33using OpenMetaverse;
34using OpenSim.Framework;
35using OpenSim.Framework.Servers;
36using OpenSim.Framework.Servers.HttpServer;
37using OpenSim.Region.CoreModules.Avatar.Chat;
38using OpenSim.Region.CoreModules.Framework;
39using OpenSim.Region.CoreModules.Framework.EntityTransfer;
40using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Services.Interfaces;
43using OpenSim.Tests.Common;
44using OpenSim.Tests.Common.Mock;
45
46namespace OpenSim.Region.CoreModules.Avatar.Chat.Tests
47{
48 [TestFixture]
49 public class ChatModuleTests : OpenSimTestCase
50 {
51 [TestFixtureSetUp]
52 public void FixtureInit()
53 {
54 // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
55 // We must do this here so that child agent positions are updated in a predictable manner.
56 Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
57 }
58
59 [TestFixtureTearDown]
60 public void TearDown()
61 {
62 // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
63 // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
64 // tests really shouldn't).
65 Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
66 }
67
68 private void SetupNeighbourRegions(TestScene sceneA, TestScene sceneB)
69 {
70 // XXX: HTTP server is not (and should not be) necessary for this test, though it's absence makes the
71 // CapabilitiesModule complain when it can't set up HTTP endpoints.
72 // BaseHttpServer httpServer = new BaseHttpServer(99999);
73 // MainServer.AddHttpServer(httpServer);
74 // MainServer.Instance = httpServer;
75
76 // We need entity transfer modules so that when sp2 logs into the east region, the region calls
77 // EntityTransferModuleto set up a child agent on the west region.
78 // XXX: However, this is not an entity transfer so is misleading.
79 EntityTransferModule etmA = new EntityTransferModule();
80 EntityTransferModule etmB = new EntityTransferModule();
81 LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
82
83 IConfigSource config = new IniConfigSource();
84 config.AddConfig("Chat");
85 IConfig modulesConfig = config.AddConfig("Modules");
86 modulesConfig.Set("EntityTransferModule", etmA.Name);
87 modulesConfig.Set("SimulationServices", lscm.Name);
88
89 SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
90 SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA, new ChatModule());
91 SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), etmB, new ChatModule());
92 }
93
94 /// <summary>
95 /// Tests chat between neighbour regions on the east-west axis
96 /// </summary>
97 /// <remarks>
98 /// Really, this is a combination of a child agent position update test and a chat range test. These need
99 /// to be separated later on.
100 /// </remarks>
101 [Test]
102 public void TestInterRegionChatDistanceEastWest()
103 {
104 TestHelpers.InMethod();
105// TestHelpers.EnableLogging();
106
107 UUID sp1Uuid = TestHelpers.ParseTail(0x11);
108 UUID sp2Uuid = TestHelpers.ParseTail(0x12);
109
110 Vector3 sp1Position = new Vector3(6, 128, 20);
111 Vector3 sp2Position = new Vector3(250, 128, 20);
112
113 SceneHelpers sh = new SceneHelpers();
114 TestScene sceneWest = sh.SetupScene("sceneWest", TestHelpers.ParseTail(0x1), 1000, 1000);
115 TestScene sceneEast = sh.SetupScene("sceneEast", TestHelpers.ParseTail(0x2), 1001, 1000);
116
117 SetupNeighbourRegions(sceneWest, sceneEast);
118
119 ScenePresence sp1 = SceneHelpers.AddScenePresence(sceneEast, sp1Uuid);
120 TestClient sp1Client = (TestClient)sp1.ControllingClient;
121
122 // If we don't set agents to flying, test will go wrong as they instantly fall to z = 0.
123 // TODO: May need to create special complete no-op test physics module rather than basic physics, since
124 // physics is irrelevant to this test.
125 sp1.Flying = true;
126
127 // When sp1 logs in to sceneEast, it sets up a child agent in sceneWest and informs the sp2 client to
128 // make the connection. For this test, will simplify this chain by making the connection directly.
129 ScenePresence sp1Child = SceneHelpers.AddChildScenePresence(sceneWest, sp1Uuid);
130 TestClient sp1ChildClient = (TestClient)sp1Child.ControllingClient;
131
132 sp1.AbsolutePosition = sp1Position;
133
134 ScenePresence sp2 = SceneHelpers.AddScenePresence(sceneWest, sp2Uuid);
135 TestClient sp2Client = (TestClient)sp2.ControllingClient;
136 sp2.Flying = true;
137
138 ScenePresence sp2Child = SceneHelpers.AddChildScenePresence(sceneEast, sp2Uuid);
139 TestClient sp2ChildClient = (TestClient)sp2Child.ControllingClient;
140
141 sp2.AbsolutePosition = sp2Position;
142
143 // We must update the scenes in order to make the root new root agents trigger position updates in their
144 // children.
145 sceneWest.Update(1);
146 sceneEast.Update(1);
147
148 // Check child positions are correct.
149 Assert.AreEqual(
150 new Vector3(sp1Position.X + sceneEast.RegionInfo.RegionSizeX, sp1Position.Y, sp1Position.Z),
151 sp1ChildClient.SceneAgent.AbsolutePosition);
152
153 Assert.AreEqual(
154 new Vector3(sp2Position.X - sceneWest.RegionInfo.RegionSizeX, sp2Position.Y, sp2Position.Z),
155 sp2ChildClient.SceneAgent.AbsolutePosition);
156
157 string receivedSp1ChatMessage = "";
158 string receivedSp2ChatMessage = "";
159
160 sp1ChildClient.OnReceivedChatMessage
161 += (message, type, fromPos, fromName, fromAgentID, ownerID, source, audible) => receivedSp1ChatMessage = message;
162 sp2ChildClient.OnReceivedChatMessage
163 += (message, type, fromPos, fromName, fromAgentID, ownerID, source, audible) => receivedSp2ChatMessage = message;
164
165 TestUserInRange(sp1Client, "ello darling", ref receivedSp2ChatMessage);
166 TestUserInRange(sp2Client, "fantastic cats", ref receivedSp1ChatMessage);
167
168 sp1Position = new Vector3(30, 128, 20);
169 sp1.AbsolutePosition = sp1Position;
170 sceneEast.Update(1);
171
172 // Check child position is correct.
173 Assert.AreEqual(
174 new Vector3(sp1Position.X + sceneEast.RegionInfo.RegionSizeX, sp1Position.Y, sp1Position.Z),
175 sp1ChildClient.SceneAgent.AbsolutePosition);
176
177 TestUserOutOfRange(sp1Client, "beef", ref receivedSp2ChatMessage);
178 TestUserOutOfRange(sp2Client, "lentils", ref receivedSp1ChatMessage);
179 }
180
181 /// <summary>
182 /// Tests chat between neighbour regions on the north-south axis
183 /// </summary>
184 /// <remarks>
185 /// Really, this is a combination of a child agent position update test and a chat range test. These need
186 /// to be separated later on.
187 /// </remarks>
188 [Test]
189 public void TestInterRegionChatDistanceNorthSouth()
190 {
191 TestHelpers.InMethod();
192 // TestHelpers.EnableLogging();
193
194 UUID sp1Uuid = TestHelpers.ParseTail(0x11);
195 UUID sp2Uuid = TestHelpers.ParseTail(0x12);
196
197 Vector3 sp1Position = new Vector3(128, 250, 20);
198 Vector3 sp2Position = new Vector3(128, 6, 20);
199
200 SceneHelpers sh = new SceneHelpers();
201 TestScene sceneNorth = sh.SetupScene("sceneNorth", TestHelpers.ParseTail(0x1), 1000, 1000);
202 TestScene sceneSouth = sh.SetupScene("sceneSouth", TestHelpers.ParseTail(0x2), 1000, 1001);
203
204 SetupNeighbourRegions(sceneNorth, sceneSouth);
205
206 ScenePresence sp1 = SceneHelpers.AddScenePresence(sceneNorth, sp1Uuid);
207 TestClient sp1Client = (TestClient)sp1.ControllingClient;
208
209 // If we don't set agents to flying, test will go wrong as they instantly fall to z = 0.
210 // TODO: May need to create special complete no-op test physics module rather than basic physics, since
211 // physics is irrelevant to this test.
212 sp1.Flying = true;
213
214 // When sp1 logs in to sceneEast, it sets up a child agent in sceneNorth and informs the sp2 client to
215 // make the connection. For this test, will simplify this chain by making the connection directly.
216 ScenePresence sp1Child = SceneHelpers.AddChildScenePresence(sceneSouth, sp1Uuid);
217 TestClient sp1ChildClient = (TestClient)sp1Child.ControllingClient;
218
219 sp1.AbsolutePosition = sp1Position;
220
221 ScenePresence sp2 = SceneHelpers.AddScenePresence(sceneSouth, sp2Uuid);
222 TestClient sp2Client = (TestClient)sp2.ControllingClient;
223 sp2.Flying = true;
224
225 ScenePresence sp2Child = SceneHelpers.AddChildScenePresence(sceneNorth, sp2Uuid);
226 TestClient sp2ChildClient = (TestClient)sp2Child.ControllingClient;
227
228 sp2.AbsolutePosition = sp2Position;
229
230 // We must update the scenes in order to make the root new root agents trigger position updates in their
231 // children.
232 sceneNorth.Update(1);
233 sceneSouth.Update(1);
234
235 // Check child positions are correct.
236 Assert.AreEqual(
237 new Vector3(sp1Position.X, sp1Position.Y - sceneNorth.RegionInfo.RegionSizeY, sp1Position.Z),
238 sp1ChildClient.SceneAgent.AbsolutePosition);
239
240 Assert.AreEqual(
241 new Vector3(sp2Position.X, sp2Position.Y + sceneSouth.RegionInfo.RegionSizeY, sp2Position.Z),
242 sp2ChildClient.SceneAgent.AbsolutePosition);
243
244 string receivedSp1ChatMessage = "";
245 string receivedSp2ChatMessage = "";
246
247 sp1ChildClient.OnReceivedChatMessage
248 += (message, type, fromPos, fromName, fromAgentID, ownerID, source, audible) => receivedSp1ChatMessage = message;
249 sp2ChildClient.OnReceivedChatMessage
250 += (message, type, fromPos, fromName, fromAgentID, ownerID, source, audible) => receivedSp2ChatMessage = message;
251
252 TestUserInRange(sp1Client, "ello darling", ref receivedSp2ChatMessage);
253 TestUserInRange(sp2Client, "fantastic cats", ref receivedSp1ChatMessage);
254
255 sp1Position = new Vector3(30, 128, 20);
256 sp1.AbsolutePosition = sp1Position;
257 sceneNorth.Update(1);
258
259 // Check child position is correct.
260 Assert.AreEqual(
261 new Vector3(sp1Position.X, sp1Position.Y - sceneNorth.RegionInfo.RegionSizeY, sp1Position.Z),
262 sp1ChildClient.SceneAgent.AbsolutePosition);
263
264 TestUserOutOfRange(sp1Client, "beef", ref receivedSp2ChatMessage);
265 TestUserOutOfRange(sp2Client, "lentils", ref receivedSp1ChatMessage);
266 }
267
268 private void TestUserInRange(TestClient speakClient, string testMessage, ref string receivedMessage)
269 {
270 receivedMessage = "";
271
272 speakClient.Chat(0, ChatTypeEnum.Say, testMessage);
273
274 Assert.AreEqual(testMessage, receivedMessage);
275 }
276
277 private void TestUserOutOfRange(TestClient speakClient, string testMessage, ref string receivedMessage)
278 {
279 receivedMessage = "";
280
281 speakClient.Chat(0, ChatTypeEnum.Say, testMessage);
282
283 Assert.AreNotEqual(testMessage, receivedMessage);
284 }
285 }
286} \ No newline at end of file