aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs
diff options
context:
space:
mode:
authorDr Scofield2009-02-06 16:55:34 +0000
committerDr Scofield2009-02-06 16:55:34 +0000
commit9b66108081a8c8cf79faaa6c541554091c40850e (patch)
tree095a232ae5a9de3a9244bcd34da08294f61eeea5 /OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs
parent* removed superfluous constants class (diff)
downloadopensim-SC_OLD-9b66108081a8c8cf79faaa6c541554091c40850e.zip
opensim-SC_OLD-9b66108081a8c8cf79faaa6c541554091c40850e.tar.gz
opensim-SC_OLD-9b66108081a8c8cf79faaa6c541554091c40850e.tar.bz2
opensim-SC_OLD-9b66108081a8c8cf79faaa6c541554091c40850e.tar.xz
This changeset is the step 1 of 2 in refactoring
OpenSim.Region.Environment into a "framework" part and a modules only part. This first changeset refactors OpenSim.Region.Environment.Scenes, OpenSim.Region.Environment.Interfaces, and OpenSim.Region.Interfaces into OpenSim.Region.Framework.{Interfaces,Scenes} leaving only region modules in OpenSim.Region.Environment. The next step will be to move region modules up from OpenSim.Region.Environment.Modules to OpenSim.Region.CoreModules and then sort out which modules are really core modules and which should move out to forge. I've been very careful to NOT BREAK anything. i hope i've succeeded. as this is the work of a whole week i hope i managed to keep track with the applied patches of the last week --- could any of you that did check in stuff have a look at whether it survived? thx!
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs292
1 files changed, 292 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..dc8df32
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs
@@ -0,0 +1,292 @@
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 OpenSim 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 Nini.Config;
29using System;
30using System.Collections.Generic;
31using System.Text;
32using NUnit.Framework;
33using NUnit.Framework.SyntaxHelpers;
34using OpenMetaverse;
35using OpenSim.Framework;
36using OpenSim.Framework.Communications;
37using OpenSim.Region.Framework.Scenes;
38using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Region.Environment.Modules.Communications.Local;
40using OpenSim.Region.Environment.Modules.World.Serialiser;
41using OpenSim.Tests.Common.Mock;
42using OpenSim.Tests.Common.Setup;
43
44namespace OpenSim.Region.Framework.Scenes.Tests
45{
46 /// <summary>
47 /// Scene presence tests
48 /// </summary>
49 [TestFixture]
50 public class ScenePresenceTests
51 {
52 public Scene scene, scene2, scene3;
53 public UUID agent1, agent2, agent3;
54 public static Random random;
55 public ulong region1,region2,region3;
56 public CommunicationsManager cm;
57 public AgentCircuitData acd1;
58 public SceneObjectGroup sog1, sog2, sog3;
59 public TestClient testclient;
60
61 [TestFixtureSetUp]
62 public void Init()
63 {
64 cm = new TestCommunicationsManager();
65 scene = SceneSetupHelpers.SetupScene("Neighbour x", UUID.Random(), 1000, 1000, cm);
66 scene2 = SceneSetupHelpers.SetupScene("Neighbour x+1", UUID.Random(), 1001, 1000, cm);
67 scene3 = SceneSetupHelpers.SetupScene("Neighbour x-1", UUID.Random(), 999, 1000, cm);
68
69 agent1 = UUID.Random();
70 agent2 = UUID.Random();
71 agent3 = UUID.Random();
72 random = new Random();
73 sog1 = NewSOG(UUID.Random(), scene, agent1);
74 sog2 = NewSOG(UUID.Random(), scene, agent1);
75 sog3 = NewSOG(UUID.Random(), scene, agent1);
76
77 //ulong neighbourHandle = Utils.UIntsToLong((uint)(neighbourx * Constants.RegionSize), (uint)(neighboury * Constants.RegionSize));
78 region1 = scene.RegionInfo.RegionHandle;
79 region2 = scene2.RegionInfo.RegionHandle;
80 region3 = scene3.RegionInfo.RegionHandle;
81 }
82
83 /// <summary>
84 /// Test adding a root agent to a scene. Doesn't yet actually complete crossing the agent into the scene.
85 /// </summary>
86 [Test]
87 public void T010_TestAddRootAgent()
88 {
89 string firstName = "testfirstname";
90
91 AgentCircuitData agent = new AgentCircuitData();
92 agent.AgentID = agent1;
93 agent.firstname = firstName;
94 agent.lastname = "testlastname";
95 agent.SessionID = UUID.Zero;
96 agent.SecureSessionID = UUID.Zero;
97 agent.circuitcode = 123;
98 agent.BaseFolder = UUID.Zero;
99 agent.InventoryFolder = UUID.Zero;
100 agent.startpos = Vector3.Zero;
101 agent.CapsPath = GetRandomCapsObjectPath();
102
103 scene.NewUserConnection(agent);
104 testclient = new TestClient(agent, scene);
105 scene.AddNewClient(testclient);
106
107 ScenePresence presence = scene.GetScenePresence(agent1);
108
109 Assert.That(presence, Is.Not.Null, "presence is null");
110 Assert.That(presence.Firstname, Is.EqualTo(firstName), "First name not same");
111 acd1 = agent;
112 }
113
114 /// <summary>
115 /// Test removing an uncrossed root agent from a scene.
116 /// </summary>
117 [Test]
118 public void T011_TestRemoveRootAgent()
119 {
120 scene.RemoveClient(agent1);
121
122 ScenePresence presence = scene.GetScenePresence(agent1);
123
124 Assert.That(presence, Is.Null, "presence is not null");
125 }
126
127 [Test]
128 public void T012_TestAddNeighbourRegion()
129 {
130 SceneSetupHelpers.AddRootAgent(scene,agent1);
131
132 ScenePresence presence = scene.GetScenePresence(agent1);
133
134 string cap = presence.ControllingClient.RequestClientInfo().CapsPath;
135
136 presence.AddNeighbourRegion(region2, cap);
137 presence.AddNeighbourRegion(region3, cap);
138
139 List<ulong> neighbours = presence.GetKnownRegionList();
140
141 Assert.That(neighbours.Count, Is.EqualTo(2));
142 }
143
144 [Test]
145 public void T013_TestRemoveNeighbourRegion()
146 {
147 ScenePresence presence = scene.GetScenePresence(agent1);
148 presence.RemoveNeighbourRegion(region3);
149
150 List<ulong> neighbours = presence.GetKnownRegionList();
151 Assert.That(neighbours.Count,Is.EqualTo(1));
152 /*
153 presence.MakeChildAgent;
154 presence.MakeRootAgent;
155 CompleteAvatarMovement
156 */
157 }
158
159 [Test]
160 public void T020_TestMakeRootAgent()
161 {
162 ScenePresence presence = scene.GetScenePresence(agent1);
163 Assert.That(presence.IsChildAgent, Is.False, "Starts out as a root agent");
164
165 presence.MakeChildAgent();
166 Assert.That(presence.IsChildAgent, Is.True, "Did not change to child agent after MakeChildAgent");
167
168 // Accepts 0 but rejects Constants.RegionSize
169 Vector3 pos = new Vector3(0,Constants.RegionSize-1,0);
170 presence.MakeRootAgent(pos,true);
171 Assert.That(presence.IsChildAgent, Is.False, "Did not go back to root agent");
172 Assert.That(presence.AbsolutePosition, Is.EqualTo(pos), "Position is not the same one entered");
173 }
174
175 [Test]
176 public void T021_TestCrossToNewRegion()
177 {
178 // Adding child agent to region 1001
179 scene2.NewUserConnection(acd1);
180 scene2.AddNewClient(testclient);
181
182 ScenePresence presence = scene.GetScenePresence(agent1);
183 ScenePresence presence2 = scene2.GetScenePresence(agent1);
184
185 // Adding neighbour region caps info to presence2
186 string cap = presence.ControllingClient.RequestClientInfo().CapsPath;
187 presence2.AddNeighbourRegion(region1, cap);
188
189 Assert.That(presence.IsChildAgent, Is.False, "Did not start root in origin region.");
190 Assert.That(presence2.IsChildAgent, Is.True, "Is not a child on destination region.");
191
192 // Cross to x+1
193 presence.AbsolutePosition = new Vector3(Constants.RegionSize+1,3,100);
194 scene.RegisterRegionWithGrid();
195 scene2.RegisterRegionWithGrid();
196 presence.Update();
197
198 Assert.That(presence.IsChildAgent, Is.True, "Did not complete region cross as expected.");
199 Assert.That(presence2.IsChildAgent, Is.False, "Did not receive root status after receiving agent.");
200
201 // Cross Back
202 presence2.AbsolutePosition = new Vector3(-1, 3, 100);
203 presence2.Update();
204
205 Assert.That(presence2.IsChildAgent, Is.True, "Did not return from region as expected.");
206 Assert.That(presence.IsChildAgent, Is.False, "Presence was not made root in old region again.");
207 }
208
209 [Test]
210 public void T030_TestAddAttachments()
211 {
212 ScenePresence presence = scene.GetScenePresence(agent1);
213
214 presence.AddAttachment(sog1);
215 presence.AddAttachment(sog2);
216 presence.AddAttachment(sog3);
217
218 Assert.That(presence.HasAttachments(), Is.True);
219 Assert.That(presence.ValidateAttachments(), Is.True);
220 }
221
222 [Test]
223 public void T031_RemoveAttachments()
224 {
225 ScenePresence presence = scene.GetScenePresence(agent1);
226 presence.RemoveAttachment(sog1);
227 presence.RemoveAttachment(sog2);
228 presence.RemoveAttachment(sog3);
229 Assert.That(presence.HasAttachments(), Is.False);
230 }
231
232 [Test]
233 public void T032_CrossAttachments()
234 {
235 ScenePresence presence = scene.GetScenePresence(agent1);
236 ScenePresence presence2 = scene2.GetScenePresence(agent1);
237 presence2.AddAttachment(sog1);
238 presence2.AddAttachment(sog2);
239
240 IRegionModule serialiser = new SerialiserModule();
241 SceneSetupHelpers.SetupSceneModules(scene, new IniConfigSource(), serialiser);
242 SceneSetupHelpers.SetupSceneModules(scene2, new IniConfigSource(), serialiser);
243
244 Assert.That(presence.HasAttachments(), Is.False, "Presence has attachments before cross");
245
246 Assert.That(presence2.CrossAttachmentsIntoNewRegion(region1, true), Is.True, "Cross was not successful");
247 Assert.That(presence2.HasAttachments(), Is.False, "Presence2 objects were not deleted");
248 Assert.That(presence.HasAttachments(), Is.True, "Presence has not received new objects");
249 }
250
251 public static string GetRandomCapsObjectPath()
252 {
253 UUID caps = UUID.Random();
254 string capsPath = caps.ToString();
255 capsPath = capsPath.Remove(capsPath.Length - 4, 4);
256 return capsPath;
257 }
258
259 private SceneObjectGroup NewSOG(UUID uuid, Scene scene, UUID agent)
260 {
261 SceneObjectPart sop = new SceneObjectPart();
262 sop.Name = RandomName();
263 sop.Description = RandomName();
264 sop.Text = RandomName();
265 sop.SitName = RandomName();
266 sop.TouchName = RandomName();
267 sop.UUID = uuid;
268 sop.Shape = PrimitiveBaseShape.Default;
269 sop.Shape.State = 1;
270 sop.OwnerID = agent;
271
272 SceneObjectGroup sog = new SceneObjectGroup();
273 sog.SetScene(scene);
274 sog.SetRootPart(sop);
275
276 return sog;
277 }
278
279 private static string RandomName()
280 {
281 StringBuilder name = new StringBuilder();
282 int size = random.Next(5,12);
283 char ch ;
284 for (int i=0; i<size; i++)
285 {
286 ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ;
287 name.Append(ch);
288 }
289 return name.ToString();
290 }
291 }
292}