diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Tests')
30 files changed, 5886 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs b/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs new file mode 100644 index 0000000..e209221 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs | |||
@@ -0,0 +1,340 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Text; | ||
32 | using NUnit.Framework; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Region.Framework.Scenes; | ||
35 | using OpenSim.Tests.Common; | ||
36 | |||
37 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
38 | { | ||
39 | [TestFixture] | ||
40 | public class BorderTests : OpenSimTestCase | ||
41 | { | ||
42 | [Test] | ||
43 | public void TestCross() | ||
44 | { | ||
45 | TestHelpers.InMethod(); | ||
46 | |||
47 | List<Border> testborders = new List<Border>(); | ||
48 | |||
49 | Border NorthBorder = new Border(); | ||
50 | NorthBorder.BorderLine = new Vector3(0, 256, 256); //<--- | ||
51 | NorthBorder.CrossDirection = Cardinals.N; | ||
52 | testborders.Add(NorthBorder); | ||
53 | |||
54 | Border SouthBorder = new Border(); | ||
55 | SouthBorder.BorderLine = new Vector3(0, 256, 0); //---> | ||
56 | SouthBorder.CrossDirection = Cardinals.S; | ||
57 | testborders.Add(SouthBorder); | ||
58 | |||
59 | Border EastBorder = new Border(); | ||
60 | EastBorder.BorderLine = new Vector3(0, 256, 256); //<--- | ||
61 | EastBorder.CrossDirection = Cardinals.E; | ||
62 | testborders.Add(EastBorder); | ||
63 | |||
64 | Border WestBorder = new Border(); | ||
65 | WestBorder.BorderLine = new Vector3(0, 256, 0); //---> | ||
66 | WestBorder.CrossDirection = Cardinals.W; | ||
67 | testborders.Add(WestBorder); | ||
68 | |||
69 | Vector3 position = new Vector3(200,200,21); | ||
70 | |||
71 | foreach (Border b in testborders) | ||
72 | Assert.That(!b.TestCross(position)); | ||
73 | |||
74 | position = new Vector3(200,280,21); | ||
75 | Assert.That(NorthBorder.TestCross(position)); | ||
76 | |||
77 | // Test automatic border crossing | ||
78 | // by setting the border crossing aabb to be the whole region | ||
79 | position = new Vector3(25,25,21); // safely within one 256m region | ||
80 | |||
81 | // The Z value of the BorderLine is reversed, making all positions within the region | ||
82 | // trigger bordercross | ||
83 | |||
84 | SouthBorder.BorderLine = new Vector3(0,256,256); // automatic border cross in the region | ||
85 | Assert.That(SouthBorder.TestCross(position)); | ||
86 | |||
87 | NorthBorder.BorderLine = new Vector3(0, 256, 0); // automatic border cross in the region | ||
88 | Assert.That(NorthBorder.TestCross(position)); | ||
89 | |||
90 | EastBorder.BorderLine = new Vector3(0, 256, 0); // automatic border cross in the region | ||
91 | Assert.That(EastBorder.TestCross(position)); | ||
92 | |||
93 | WestBorder.BorderLine = new Vector3(0, 256, 255); // automatic border cross in the region | ||
94 | Assert.That(WestBorder.TestCross(position)); | ||
95 | } | ||
96 | |||
97 | [Test] | ||
98 | public void TestCrossSquare512() | ||
99 | { | ||
100 | TestHelpers.InMethod(); | ||
101 | |||
102 | List<Border> testborders = new List<Border>(); | ||
103 | |||
104 | Border NorthBorder = new Border(); | ||
105 | NorthBorder.BorderLine = new Vector3(0, 512, 512); | ||
106 | NorthBorder.CrossDirection = Cardinals.N; | ||
107 | testborders.Add(NorthBorder); | ||
108 | |||
109 | Border SouthBorder = new Border(); | ||
110 | SouthBorder.BorderLine = new Vector3(0, 512, 0); | ||
111 | SouthBorder.CrossDirection = Cardinals.S; | ||
112 | testborders.Add(SouthBorder); | ||
113 | |||
114 | Border EastBorder = new Border(); | ||
115 | EastBorder.BorderLine = new Vector3(0, 512, 512); | ||
116 | EastBorder.CrossDirection = Cardinals.E; | ||
117 | testborders.Add(EastBorder); | ||
118 | |||
119 | Border WestBorder = new Border(); | ||
120 | WestBorder.BorderLine = new Vector3(0, 512, 0); | ||
121 | WestBorder.CrossDirection = Cardinals.W; | ||
122 | testborders.Add(WestBorder); | ||
123 | |||
124 | Vector3 position = new Vector3(450,220,21); | ||
125 | |||
126 | foreach (Border b in testborders) | ||
127 | { | ||
128 | Assert.That(!b.TestCross(position)); | ||
129 | |||
130 | } | ||
131 | |||
132 | //Trigger east border | ||
133 | position = new Vector3(513,220,21); | ||
134 | foreach (Border b in testborders) | ||
135 | { | ||
136 | if (b.CrossDirection == Cardinals.E) | ||
137 | Assert.That(b.TestCross(position)); | ||
138 | else | ||
139 | Assert.That(!b.TestCross(position)); | ||
140 | |||
141 | } | ||
142 | |||
143 | //Trigger west border | ||
144 | position = new Vector3(-1, 220, 21); | ||
145 | foreach (Border b in testborders) | ||
146 | { | ||
147 | if (b.CrossDirection == Cardinals.W) | ||
148 | Assert.That(b.TestCross(position)); | ||
149 | else | ||
150 | Assert.That(!b.TestCross(position)); | ||
151 | |||
152 | } | ||
153 | |||
154 | //Trigger north border | ||
155 | position = new Vector3(220, 513, 21); | ||
156 | foreach (Border b in testborders) | ||
157 | { | ||
158 | if (b.CrossDirection == Cardinals.N) | ||
159 | Assert.That(b.TestCross(position)); | ||
160 | else | ||
161 | Assert.That(!b.TestCross(position)); | ||
162 | |||
163 | } | ||
164 | |||
165 | //Trigger south border | ||
166 | position = new Vector3(220, -1, 21); | ||
167 | foreach (Border b in testborders) | ||
168 | { | ||
169 | if (b.CrossDirection == Cardinals.S) | ||
170 | Assert.That(b.TestCross(position)); | ||
171 | else | ||
172 | Assert.That(!b.TestCross(position)); | ||
173 | |||
174 | } | ||
175 | } | ||
176 | |||
177 | [Test] | ||
178 | public void TestCrossRectangle512x256() | ||
179 | { | ||
180 | TestHelpers.InMethod(); | ||
181 | |||
182 | List<Border> testborders = new List<Border>(); | ||
183 | |||
184 | Border NorthBorder = new Border(); | ||
185 | NorthBorder.BorderLine = new Vector3(0, 512, 256); | ||
186 | NorthBorder.CrossDirection = Cardinals.N; | ||
187 | testborders.Add(NorthBorder); | ||
188 | |||
189 | Border SouthBorder = new Border(); | ||
190 | SouthBorder.BorderLine = new Vector3(0, 512, 0); | ||
191 | SouthBorder.CrossDirection = Cardinals.S; | ||
192 | testborders.Add(SouthBorder); | ||
193 | |||
194 | Border EastBorder = new Border(); | ||
195 | EastBorder.BorderLine = new Vector3(0, 256, 512); | ||
196 | EastBorder.CrossDirection = Cardinals.E; | ||
197 | testborders.Add(EastBorder); | ||
198 | |||
199 | Border WestBorder = new Border(); | ||
200 | WestBorder.BorderLine = new Vector3(0, 256, 0); | ||
201 | WestBorder.CrossDirection = Cardinals.W; | ||
202 | testborders.Add(WestBorder); | ||
203 | |||
204 | Vector3 position = new Vector3(450, 220, 21); | ||
205 | |||
206 | foreach (Border b in testborders) | ||
207 | { | ||
208 | Assert.That(!b.TestCross(position)); | ||
209 | |||
210 | } | ||
211 | |||
212 | //Trigger east border | ||
213 | position = new Vector3(513, 220, 21); | ||
214 | foreach (Border b in testborders) | ||
215 | { | ||
216 | if (b.CrossDirection == Cardinals.E) | ||
217 | Assert.That(b.TestCross(position)); | ||
218 | else | ||
219 | Assert.That(!b.TestCross(position)); | ||
220 | |||
221 | } | ||
222 | |||
223 | //Trigger west border | ||
224 | position = new Vector3(-1, 220, 21); | ||
225 | foreach (Border b in testborders) | ||
226 | { | ||
227 | if (b.CrossDirection == Cardinals.W) | ||
228 | Assert.That(b.TestCross(position)); | ||
229 | else | ||
230 | Assert.That(!b.TestCross(position)); | ||
231 | |||
232 | } | ||
233 | |||
234 | //Trigger north border | ||
235 | position = new Vector3(220, 257, 21); | ||
236 | foreach (Border b in testborders) | ||
237 | { | ||
238 | if (b.CrossDirection == Cardinals.N) | ||
239 | Assert.That(b.TestCross(position)); | ||
240 | else | ||
241 | Assert.That(!b.TestCross(position)); | ||
242 | |||
243 | } | ||
244 | |||
245 | //Trigger south border | ||
246 | position = new Vector3(220, -1, 21); | ||
247 | foreach (Border b in testborders) | ||
248 | { | ||
249 | if (b.CrossDirection == Cardinals.S) | ||
250 | Assert.That(b.TestCross(position)); | ||
251 | else | ||
252 | Assert.That(!b.TestCross(position)); | ||
253 | |||
254 | } | ||
255 | } | ||
256 | |||
257 | [Test] | ||
258 | public void TestCrossOdd512x512w256hole() | ||
259 | { | ||
260 | TestHelpers.InMethod(); | ||
261 | |||
262 | List<Border> testborders = new List<Border>(); | ||
263 | // 512____ | ||
264 | // | | | ||
265 | // 256__| |___ | ||
266 | // | | | ||
267 | // |______| | ||
268 | // 0 | 512 | ||
269 | // 256 | ||
270 | |||
271 | // Compound North border since the hole is at the top | ||
272 | Border NorthBorder1 = new Border(); | ||
273 | NorthBorder1.BorderLine = new Vector3(0, 256, 512); | ||
274 | NorthBorder1.CrossDirection = Cardinals.N; | ||
275 | testborders.Add(NorthBorder1); | ||
276 | |||
277 | Border NorthBorder2 = new Border(); | ||
278 | NorthBorder2.BorderLine = new Vector3(256, 512, 256); | ||
279 | NorthBorder2.CrossDirection = Cardinals.N; | ||
280 | testborders.Add(NorthBorder2); | ||
281 | |||
282 | Border SouthBorder = new Border(); | ||
283 | SouthBorder.BorderLine = new Vector3(0, 512, 0); | ||
284 | SouthBorder.CrossDirection = Cardinals.S; | ||
285 | testborders.Add(SouthBorder); | ||
286 | |||
287 | //Compound East border | ||
288 | Border EastBorder1 = new Border(); | ||
289 | EastBorder1.BorderLine = new Vector3(0, 256, 512); | ||
290 | EastBorder1.CrossDirection = Cardinals.E; | ||
291 | testborders.Add(EastBorder1); | ||
292 | |||
293 | Border EastBorder2 = new Border(); | ||
294 | EastBorder2.BorderLine = new Vector3(257, 512, 256); | ||
295 | EastBorder2.CrossDirection = Cardinals.E; | ||
296 | testborders.Add(EastBorder2); | ||
297 | |||
298 | |||
299 | |||
300 | Border WestBorder = new Border(); | ||
301 | WestBorder.BorderLine = new Vector3(0, 512, 0); | ||
302 | WestBorder.CrossDirection = Cardinals.W; | ||
303 | testborders.Add(WestBorder); | ||
304 | |||
305 | Vector3 position = new Vector3(450, 220, 21); | ||
306 | |||
307 | foreach (Border b in testborders) | ||
308 | { | ||
309 | Assert.That(!b.TestCross(position)); | ||
310 | |||
311 | } | ||
312 | |||
313 | position = new Vector3(220, 450, 21); | ||
314 | |||
315 | foreach (Border b in testborders) | ||
316 | { | ||
317 | Assert.That(!b.TestCross(position)); | ||
318 | |||
319 | } | ||
320 | |||
321 | bool result = false; | ||
322 | int bordersTriggered = 0; | ||
323 | |||
324 | position = new Vector3(450, 450, 21); | ||
325 | |||
326 | foreach (Border b in testborders) | ||
327 | { | ||
328 | if (b.TestCross(position)) | ||
329 | { | ||
330 | bordersTriggered++; | ||
331 | result = true; | ||
332 | } | ||
333 | } | ||
334 | |||
335 | Assert.That(result); | ||
336 | Assert.That(bordersTriggered == 2); | ||
337 | |||
338 | } | ||
339 | } | ||
340 | } | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs b/OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs new file mode 100644 index 0000000..766ce83 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs | |||
@@ -0,0 +1,178 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Reflection; | ||
30 | using System.Threading; | ||
31 | using System.Text; | ||
32 | using System.Collections.Generic; | ||
33 | using Nini.Config; | ||
34 | using NUnit.Framework; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Framework.Communications; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Tests.Common; | ||
40 | |||
41 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
42 | { | ||
43 | [TestFixture, LongRunning] | ||
44 | public class EntityManagerTests : OpenSimTestCase | ||
45 | { | ||
46 | static public Random random; | ||
47 | SceneObjectGroup found; | ||
48 | Scene scene = new SceneHelpers().SetupScene(); | ||
49 | |||
50 | [Test] | ||
51 | public void T010_AddObjects() | ||
52 | { | ||
53 | TestHelpers.InMethod(); | ||
54 | |||
55 | random = new Random(); | ||
56 | SceneObjectGroup found; | ||
57 | EntityManager entman = new EntityManager(); | ||
58 | SceneObjectGroup sog = NewSOG(); | ||
59 | UUID obj1 = sog.UUID; | ||
60 | uint li1 = sog.LocalId; | ||
61 | entman.Add(sog); | ||
62 | sog = NewSOG(); | ||
63 | UUID obj2 = sog.UUID; | ||
64 | uint li2 = sog.LocalId; | ||
65 | entman.Add(sog); | ||
66 | |||
67 | found = (SceneObjectGroup)entman[obj1]; | ||
68 | Assert.That(found.UUID ,Is.EqualTo(obj1)); | ||
69 | found = (SceneObjectGroup)entman[li1]; | ||
70 | Assert.That(found.UUID ,Is.EqualTo(obj1)); | ||
71 | found = (SceneObjectGroup)entman[obj2]; | ||
72 | Assert.That(found.UUID ,Is.EqualTo(obj2)); | ||
73 | found = (SceneObjectGroup)entman[li2]; | ||
74 | Assert.That(found.UUID ,Is.EqualTo(obj2)); | ||
75 | |||
76 | entman.Remove(obj1); | ||
77 | entman.Remove(li2); | ||
78 | |||
79 | Assert.That(entman.ContainsKey(obj1), Is.False); | ||
80 | Assert.That(entman.ContainsKey(li1), Is.False); | ||
81 | Assert.That(entman.ContainsKey(obj2), Is.False); | ||
82 | Assert.That(entman.ContainsKey(li2), Is.False); | ||
83 | } | ||
84 | |||
85 | [Test] | ||
86 | public void T011_ThreadAddRemoveTest() | ||
87 | { | ||
88 | TestHelpers.InMethod(); | ||
89 | |||
90 | // This test adds and removes with mutiple threads, attempting to break the | ||
91 | // uuid and localid dictionary coherence. | ||
92 | EntityManager entman = new EntityManager(); | ||
93 | SceneObjectGroup sog = NewSOG(); | ||
94 | for (int j=0; j<20; j++) | ||
95 | { | ||
96 | List<Thread> trdlist = new List<Thread>(); | ||
97 | |||
98 | for (int i=0; i<4; i++) | ||
99 | { | ||
100 | // Adds scene object | ||
101 | NewTestThreads test = new NewTestThreads(entman,sog); | ||
102 | Thread start = new Thread(new ThreadStart(test.TestAddSceneObject)); | ||
103 | start.Start(); | ||
104 | trdlist.Add(start); | ||
105 | |||
106 | // Removes it | ||
107 | test = new NewTestThreads(entman,sog); | ||
108 | start = new Thread(new ThreadStart(test.TestRemoveSceneObject)); | ||
109 | start.Start(); | ||
110 | trdlist.Add(start); | ||
111 | } | ||
112 | foreach (Thread thread in trdlist) | ||
113 | { | ||
114 | thread.Join(); | ||
115 | } | ||
116 | if (entman.ContainsKey(sog.UUID) || entman.ContainsKey(sog.LocalId)) { | ||
117 | found = (SceneObjectGroup)entman[sog.UUID]; | ||
118 | Assert.That(found.UUID,Is.EqualTo(sog.UUID)); | ||
119 | found = (SceneObjectGroup)entman[sog.LocalId]; | ||
120 | Assert.That(found.UUID,Is.EqualTo(sog.UUID)); | ||
121 | } | ||
122 | } | ||
123 | } | ||
124 | |||
125 | private SceneObjectGroup NewSOG() | ||
126 | { | ||
127 | SceneObjectPart sop = new SceneObjectPart(UUID.Random(), PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero); | ||
128 | sop.Name = RandomName(); | ||
129 | sop.Description = sop.Name; | ||
130 | sop.Text = RandomName(); | ||
131 | sop.SitName = RandomName(); | ||
132 | sop.TouchName = RandomName(); | ||
133 | sop.Flags |= PrimFlags.Phantom; | ||
134 | |||
135 | SceneObjectGroup sog = new SceneObjectGroup(sop); | ||
136 | scene.AddNewSceneObject(sog, false); | ||
137 | |||
138 | return sog; | ||
139 | } | ||
140 | |||
141 | private static string RandomName() | ||
142 | { | ||
143 | StringBuilder name = new StringBuilder(); | ||
144 | int size = random.Next(40,80); | ||
145 | char ch ; | ||
146 | for (int i=0; i<size; i++) | ||
147 | { | ||
148 | ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ; | ||
149 | name.Append(ch); | ||
150 | } | ||
151 | return name.ToString(); | ||
152 | } | ||
153 | } | ||
154 | |||
155 | public class NewTestThreads | ||
156 | { | ||
157 | private EntityManager entman; | ||
158 | private SceneObjectGroup sog; | ||
159 | private Random random; | ||
160 | |||
161 | public NewTestThreads(EntityManager entman, SceneObjectGroup sog) | ||
162 | { | ||
163 | this.entman = entman; | ||
164 | this.sog = sog; | ||
165 | this.random = new Random(); | ||
166 | } | ||
167 | public void TestAddSceneObject() | ||
168 | { | ||
169 | Thread.Sleep(random.Next(0,50)); | ||
170 | entman.Add(sog); | ||
171 | } | ||
172 | public void TestRemoveSceneObject() | ||
173 | { | ||
174 | Thread.Sleep(random.Next(0,50)); | ||
175 | entman.Remove(sog.UUID); | ||
176 | } | ||
177 | } | ||
178 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneGraphTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneGraphTests.cs new file mode 100644 index 0000000..b6b3344 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneGraphTests.cs | |||
@@ -0,0 +1,92 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.IO; | ||
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using NUnit.Framework; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Region.Framework.Scenes; | ||
37 | using OpenSim.Tests.Common; | ||
38 | |||
39 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
40 | { | ||
41 | [TestFixture] | ||
42 | public class SceneGraphTests : OpenSimTestCase | ||
43 | { | ||
44 | [Test] | ||
45 | public void TestDuplicateObject() | ||
46 | { | ||
47 | TestHelpers.InMethod(); | ||
48 | // TestHelpers.EnableLogging(); | ||
49 | |||
50 | Scene scene = new SceneHelpers().SetupScene(); | ||
51 | |||
52 | UUID ownerId = new UUID("00000000-0000-0000-0000-000000000010"); | ||
53 | string part1Name = "part1"; | ||
54 | UUID part1Id = new UUID("00000000-0000-0000-0000-000000000001"); | ||
55 | string part2Name = "part2"; | ||
56 | UUID part2Id = new UUID("00000000-0000-0000-0000-000000000002"); | ||
57 | |||
58 | SceneObjectPart part1 | ||
59 | = new SceneObjectPart(ownerId, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) | ||
60 | { Name = part1Name, UUID = part1Id }; | ||
61 | SceneObjectGroup so = new SceneObjectGroup(part1); | ||
62 | SceneObjectPart part2 | ||
63 | = new SceneObjectPart(ownerId, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) | ||
64 | { Name = part2Name, UUID = part2Id }; | ||
65 | so.AddPart(part2); | ||
66 | |||
67 | scene.AddNewSceneObject(so, false); | ||
68 | |||
69 | SceneObjectGroup dupeSo | ||
70 | = scene.SceneGraph.DuplicateObject( | ||
71 | part1.LocalId, new Vector3(10, 0, 0), 0, ownerId, UUID.Zero, Quaternion.Identity); | ||
72 | Assert.That(dupeSo.Parts.Length, Is.EqualTo(2)); | ||
73 | |||
74 | SceneObjectPart dupePart1 = dupeSo.GetLinkNumPart(1); | ||
75 | SceneObjectPart dupePart2 = dupeSo.GetLinkNumPart(2); | ||
76 | Assert.That(dupePart1.LocalId, Is.Not.EqualTo(part1.LocalId)); | ||
77 | Assert.That(dupePart2.LocalId, Is.Not.EqualTo(part2.LocalId)); | ||
78 | |||
79 | Assert.That(dupePart1.Flags, Is.EqualTo(part1.Flags)); | ||
80 | Assert.That(dupePart2.Flags, Is.EqualTo(part2.Flags)); | ||
81 | |||
82 | /* | ||
83 | Assert.That(part1.PhysActor, Is.Not.Null); | ||
84 | Assert.That(part2.PhysActor, Is.Not.Null); | ||
85 | Assert.That(dupePart1.PhysActor, Is.Not.Null); | ||
86 | Assert.That(dupePart2.PhysActor, Is.Not.Null); | ||
87 | */ | ||
88 | |||
89 | // TestHelpers.DisableLogging(); | ||
90 | } | ||
91 | } | ||
92 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneManagerTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneManagerTests.cs new file mode 100644 index 0000000..6118004 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneManagerTests.cs | |||
@@ -0,0 +1,57 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Threading; | ||
32 | using NUnit.Framework; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Region.Framework.Scenes; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using OpenSim.Tests.Common; | ||
39 | |||
40 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
41 | { | ||
42 | [TestFixture] | ||
43 | public class SceneManagerTests : OpenSimTestCase | ||
44 | { | ||
45 | [Test] | ||
46 | public void TestClose() | ||
47 | { | ||
48 | TestHelpers.InMethod(); | ||
49 | |||
50 | SceneHelpers sh = new SceneHelpers(); | ||
51 | Scene scene = sh.SetupScene(); | ||
52 | |||
53 | sh.SceneManager.Close(); | ||
54 | Assert.That(scene.ShuttingDown, Is.True); | ||
55 | } | ||
56 | } | ||
57 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs new file mode 100644 index 0000000..bdf0700 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs | |||
@@ -0,0 +1,242 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Threading; | ||
32 | using Nini.Config; | ||
33 | using NUnit.Framework; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Framework.Communications; | ||
37 | using OpenSim.Region.Framework.Scenes; | ||
38 | using OpenSim.Services.Interfaces; | ||
39 | using OpenSim.Tests.Common; | ||
40 | |||
41 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
42 | { | ||
43 | /// <summary> | ||
44 | /// Basic scene object tests (create, read and delete but not update). | ||
45 | /// </summary> | ||
46 | [TestFixture] | ||
47 | public class SceneObjectBasicTests : OpenSimTestCase | ||
48 | { | ||
49 | // [TearDown] | ||
50 | // public void TearDown() | ||
51 | // { | ||
52 | // Console.WriteLine("TearDown"); | ||
53 | // GC.Collect(); | ||
54 | // Thread.Sleep(3000); | ||
55 | // } | ||
56 | |||
57 | // public class GcNotify | ||
58 | // { | ||
59 | // public static AutoResetEvent gcEvent = new AutoResetEvent(false); | ||
60 | // private static bool _initialized = false; | ||
61 | // | ||
62 | // public static void Initialize() | ||
63 | // { | ||
64 | // if (!_initialized) | ||
65 | // { | ||
66 | // _initialized = true; | ||
67 | // new GcNotify(); | ||
68 | // } | ||
69 | // } | ||
70 | // | ||
71 | // private GcNotify(){} | ||
72 | // | ||
73 | // ~GcNotify() | ||
74 | // { | ||
75 | // if (!Environment.HasShutdownStarted && | ||
76 | // !AppDomain.CurrentDomain.IsFinalizingForUnload()) | ||
77 | // { | ||
78 | // Console.WriteLine("GcNotify called"); | ||
79 | // gcEvent.Set(); | ||
80 | // new GcNotify(); | ||
81 | // } | ||
82 | // } | ||
83 | // } | ||
84 | |||
85 | /// <summary> | ||
86 | /// Test adding an object to a scene. | ||
87 | /// </summary> | ||
88 | [Test] | ||
89 | public void TestAddSceneObject() | ||
90 | { | ||
91 | TestHelpers.InMethod(); | ||
92 | |||
93 | Scene scene = new SceneHelpers().SetupScene(); | ||
94 | int partsToTestCount = 3; | ||
95 | |||
96 | SceneObjectGroup so | ||
97 | = SceneHelpers.CreateSceneObject(partsToTestCount, TestHelpers.ParseTail(0x1), "obj1", 0x10); | ||
98 | SceneObjectPart[] parts = so.Parts; | ||
99 | |||
100 | Assert.That(scene.AddNewSceneObject(so, false), Is.True); | ||
101 | SceneObjectGroup retrievedSo = scene.GetSceneObjectGroup(so.UUID); | ||
102 | SceneObjectPart[] retrievedParts = retrievedSo.Parts; | ||
103 | |||
104 | //m_log.Debug("retrievedPart : {0}", retrievedPart); | ||
105 | // If the parts have the same UUID then we will consider them as one and the same | ||
106 | Assert.That(retrievedSo.PrimCount, Is.EqualTo(partsToTestCount)); | ||
107 | |||
108 | for (int i = 0; i < partsToTestCount; i++) | ||
109 | { | ||
110 | Assert.That(retrievedParts[i].Name, Is.EqualTo(parts[i].Name)); | ||
111 | Assert.That(retrievedParts[i].UUID, Is.EqualTo(parts[i].UUID)); | ||
112 | } | ||
113 | } | ||
114 | |||
115 | [Test] | ||
116 | /// <summary> | ||
117 | /// It shouldn't be possible to add a scene object if one with that uuid already exists in the scene. | ||
118 | /// </summary> | ||
119 | public void TestAddExistingSceneObjectUuid() | ||
120 | { | ||
121 | TestHelpers.InMethod(); | ||
122 | |||
123 | Scene scene = new SceneHelpers().SetupScene(); | ||
124 | |||
125 | string obj1Name = "Alfred"; | ||
126 | string obj2Name = "Betty"; | ||
127 | UUID objUuid = new UUID("00000000-0000-0000-0000-000000000001"); | ||
128 | |||
129 | SceneObjectPart part1 | ||
130 | = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) | ||
131 | { Name = obj1Name, UUID = objUuid }; | ||
132 | |||
133 | Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part1), false), Is.True); | ||
134 | |||
135 | SceneObjectPart part2 | ||
136 | = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) | ||
137 | { Name = obj2Name, UUID = objUuid }; | ||
138 | |||
139 | Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part2), false), Is.False); | ||
140 | |||
141 | SceneObjectPart retrievedPart = scene.GetSceneObjectPart(objUuid); | ||
142 | |||
143 | //m_log.Debug("retrievedPart : {0}", retrievedPart); | ||
144 | // If the parts have the same UUID then we will consider them as one and the same | ||
145 | Assert.That(retrievedPart.Name, Is.EqualTo(obj1Name)); | ||
146 | Assert.That(retrievedPart.UUID, Is.EqualTo(objUuid)); | ||
147 | } | ||
148 | |||
149 | /// <summary> | ||
150 | /// Test retrieving a scene object via the local id of one of its parts. | ||
151 | /// </summary> | ||
152 | [Test] | ||
153 | public void TestGetSceneObjectByPartLocalId() | ||
154 | { | ||
155 | TestHelpers.InMethod(); | ||
156 | |||
157 | Scene scene = new SceneHelpers().SetupScene(); | ||
158 | int partsToTestCount = 3; | ||
159 | |||
160 | SceneObjectGroup so | ||
161 | = SceneHelpers.CreateSceneObject(partsToTestCount, TestHelpers.ParseTail(0x1), "obj1", 0x10); | ||
162 | SceneObjectPart[] parts = so.Parts; | ||
163 | |||
164 | scene.AddNewSceneObject(so, false); | ||
165 | |||
166 | // Test getting via the root part's local id | ||
167 | Assert.That(scene.GetGroupByPrim(so.LocalId), Is.Not.Null); | ||
168 | |||
169 | // Test getting via a non root part's local id | ||
170 | Assert.That(scene.GetGroupByPrim(parts[partsToTestCount - 1].LocalId), Is.Not.Null); | ||
171 | |||
172 | // Test that we don't get back an object for a local id that doesn't exist | ||
173 | Assert.That(scene.GetGroupByPrim(999), Is.Null); | ||
174 | |||
175 | // Now delete the scene object and check again | ||
176 | scene.DeleteSceneObject(so, false); | ||
177 | |||
178 | Assert.That(scene.GetGroupByPrim(so.LocalId), Is.Null); | ||
179 | Assert.That(scene.GetGroupByPrim(parts[partsToTestCount - 1].LocalId), Is.Null); | ||
180 | } | ||
181 | |||
182 | /// <summary> | ||
183 | /// Test deleting an object from a scene. | ||
184 | /// </summary> | ||
185 | /// <remarks> | ||
186 | /// This is the most basic form of delete. For all more sophisticated forms of derez (done asynchrnously | ||
187 | /// and where object can be taken to user inventory, etc.), see SceneObjectDeRezTests. | ||
188 | /// </remarks> | ||
189 | [Test] | ||
190 | public void TestDeleteSceneObject() | ||
191 | { | ||
192 | TestHelpers.InMethod(); | ||
193 | |||
194 | TestScene scene = new SceneHelpers().SetupScene(); | ||
195 | SceneObjectGroup so = SceneHelpers.AddSceneObject(scene); | ||
196 | |||
197 | Assert.That(so.IsDeleted, Is.False); | ||
198 | |||
199 | scene.DeleteSceneObject(so, false); | ||
200 | |||
201 | Assert.That(so.IsDeleted, Is.True); | ||
202 | |||
203 | SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId); | ||
204 | Assert.That(retrievedPart, Is.Null); | ||
205 | } | ||
206 | |||
207 | /// <summary> | ||
208 | /// Changing a scene object uuid changes the root part uuid. This is a valid operation if the object is not | ||
209 | /// in a scene and is useful if one wants to supply a UUID directly rather than use the one generated by | ||
210 | /// OpenSim. | ||
211 | /// </summary> | ||
212 | [Test] | ||
213 | public void TestChangeSceneObjectUuid() | ||
214 | { | ||
215 | string rootPartName = "rootpart"; | ||
216 | UUID rootPartUuid = new UUID("00000000-0000-0000-0000-000000000001"); | ||
217 | string childPartName = "childPart"; | ||
218 | UUID childPartUuid = new UUID("00000000-0000-0000-0001-000000000000"); | ||
219 | |||
220 | SceneObjectPart rootPart | ||
221 | = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) | ||
222 | { Name = rootPartName, UUID = rootPartUuid }; | ||
223 | SceneObjectPart linkPart | ||
224 | = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) | ||
225 | { Name = childPartName, UUID = childPartUuid }; | ||
226 | |||
227 | SceneObjectGroup sog = new SceneObjectGroup(rootPart); | ||
228 | sog.AddPart(linkPart); | ||
229 | |||
230 | Assert.That(sog.UUID, Is.EqualTo(rootPartUuid)); | ||
231 | Assert.That(sog.RootPart.UUID, Is.EqualTo(rootPartUuid)); | ||
232 | Assert.That(sog.Parts.Length, Is.EqualTo(2)); | ||
233 | |||
234 | UUID newRootPartUuid = new UUID("00000000-0000-0000-0000-000000000002"); | ||
235 | sog.UUID = newRootPartUuid; | ||
236 | |||
237 | Assert.That(sog.UUID, Is.EqualTo(newRootPartUuid)); | ||
238 | Assert.That(sog.RootPart.UUID, Is.EqualTo(newRootPartUuid)); | ||
239 | Assert.That(sog.Parts.Length, Is.EqualTo(2)); | ||
240 | } | ||
241 | } | ||
242 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectCopyTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectCopyTests.cs new file mode 100644 index 0000000..1d41d33 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectCopyTests.cs | |||
@@ -0,0 +1,347 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using Nini.Config; | ||
32 | using NUnit.Framework; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Region.CoreModules.Framework.EntityTransfer; | ||
37 | using OpenSim.Region.CoreModules.Framework.InventoryAccess; | ||
38 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; | ||
39 | using OpenSim.Region.CoreModules.World.Permissions; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | using OpenSim.Services.Interfaces; | ||
42 | using OpenSim.Tests.Common; | ||
43 | |||
44 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
45 | { | ||
46 | /// <summary> | ||
47 | /// Test copying of scene objects. | ||
48 | /// </summary> | ||
49 | /// <remarks> | ||
50 | /// This is at a level above the SceneObjectBasicTests, which act on the scene directly. | ||
51 | /// </remarks> | ||
52 | [TestFixture] | ||
53 | public class SceneObjectCopyTests : OpenSimTestCase | ||
54 | { | ||
55 | [TestFixtureSetUp] | ||
56 | public void FixtureInit() | ||
57 | { | ||
58 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. | ||
59 | // This facility was added after the original async delete tests were written, so it may be possible now | ||
60 | // to not bother explicitly disabling their async (since everything will be running sync). | ||
61 | Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest; | ||
62 | } | ||
63 | |||
64 | [TestFixtureTearDown] | ||
65 | public void TearDown() | ||
66 | { | ||
67 | // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple | ||
68 | // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression | ||
69 | // tests really shouldn't). | ||
70 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; | ||
71 | } | ||
72 | |||
73 | [Test] | ||
74 | public void TestTakeCopyWhenCopierIsOwnerWithPerms() | ||
75 | { | ||
76 | TestHelpers.InMethod(); | ||
77 | // TestHelpers.EnableLogging(); | ||
78 | |||
79 | IConfigSource config = new IniConfigSource(); | ||
80 | config.AddConfig("Modules"); | ||
81 | config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); | ||
82 | |||
83 | TestScene scene = new SceneHelpers().SetupScene("s1", TestHelpers.ParseTail(0x99), 1000, 1000, config); | ||
84 | SceneHelpers.SetupSceneModules(scene, config, new PermissionsModule(), new BasicInventoryAccessModule()); | ||
85 | UserAccount ua = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(0x1)); | ||
86 | TestClient client = (TestClient)SceneHelpers.AddScenePresence(scene, ua.PrincipalID).ControllingClient; | ||
87 | |||
88 | // Turn off the timer on the async sog deleter - we'll crank it by hand for this test. | ||
89 | AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter; | ||
90 | sogd.Enabled = false; | ||
91 | |||
92 | SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, "so1", ua.PrincipalID); | ||
93 | uint soLocalId = so.LocalId; | ||
94 | // so.UpdatePermissions( | ||
95 | // ua.PrincipalID, (byte)PermissionWho.Owner, so.LocalId, (uint)OpenMetaverse.PermissionMask.Copy, 1); | ||
96 | // so.UpdatePermissions( | ||
97 | // ua.PrincipalID, (byte)PermissionWho.Owner, so.LocalId, (uint)OpenMetaverse.PermissionMask.Transfer, 0); | ||
98 | // so.UpdatePermissions( | ||
99 | // ua.PrincipalID, (byte)PermissionWho.Base, so.LocalId, (uint)OpenMetaverse.PermissionMask.Transfer, 0); | ||
100 | // scene.HandleObjectPermissionsUpdate(client, client.AgentId, client.SessionId, (byte)PermissionWho.Owner, so.LocalId, (uint)OpenMetaverse.PermissionMask.Transfer, 0); | ||
101 | |||
102 | // Ideally we might change these via client-focussed method calls as commented out above. However, this | ||
103 | // becomes very convoluted so we will set only the copy perm directly. | ||
104 | so.RootPart.BaseMask = (uint)OpenMetaverse.PermissionMask.Copy; | ||
105 | // so.RootPart.OwnerMask = (uint)OpenMetaverse.PermissionMask.Copy; | ||
106 | |||
107 | List<uint> localIds = new List<uint>(); | ||
108 | localIds.Add(so.LocalId); | ||
109 | |||
110 | // Specifying a UUID.Zero in this case will currently plop it in Lost and Found | ||
111 | scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.TakeCopy, UUID.Zero); | ||
112 | |||
113 | // Check that object isn't copied until we crank the sogd handle. | ||
114 | SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId); | ||
115 | Assert.That(retrievedPart, Is.Not.Null); | ||
116 | Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False); | ||
117 | |||
118 | sogd.InventoryDeQueueAndDelete(); | ||
119 | |||
120 | // Check that object is still there. | ||
121 | SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId); | ||
122 | Assert.That(retrievedPart2, Is.Not.Null); | ||
123 | Assert.That(client.ReceivedKills.Count, Is.EqualTo(0)); | ||
124 | |||
125 | // Check that we have a copy in inventory | ||
126 | InventoryItemBase item | ||
127 | = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, ua.PrincipalID, "Lost And Found/so1"); | ||
128 | Assert.That(item, Is.Not.Null); | ||
129 | } | ||
130 | |||
131 | [Test] | ||
132 | public void TestTakeCopyWhenCopierIsOwnerWithoutPerms() | ||
133 | { | ||
134 | TestHelpers.InMethod(); | ||
135 | // TestHelpers.EnableLogging(); | ||
136 | |||
137 | IConfigSource config = new IniConfigSource(); | ||
138 | config.AddConfig("Modules"); | ||
139 | config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); | ||
140 | |||
141 | TestScene scene = new SceneHelpers().SetupScene("s1", TestHelpers.ParseTail(0x99), 1000, 1000, config); | ||
142 | SceneHelpers.SetupSceneModules(scene, config, new PermissionsModule(), new BasicInventoryAccessModule()); | ||
143 | UserAccount ua = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(0x1)); | ||
144 | TestClient client = (TestClient)SceneHelpers.AddScenePresence(scene, ua.PrincipalID).ControllingClient; | ||
145 | |||
146 | // Turn off the timer on the async sog deleter - we'll crank it by hand for this test. | ||
147 | AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter; | ||
148 | sogd.Enabled = false; | ||
149 | |||
150 | SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, "so1", ua.PrincipalID); | ||
151 | uint soLocalId = so.LocalId; | ||
152 | |||
153 | so.RootPart.BaseMask = (uint)(OpenMetaverse.PermissionMask.All & ~OpenMetaverse.PermissionMask.Copy); | ||
154 | //so.RootPart.OwnerMask = (uint)(OpenMetaverse.PermissionMask.Copy & ~OpenMetaverse.PermissionMask.Copy); | ||
155 | |||
156 | List<uint> localIds = new List<uint>(); | ||
157 | localIds.Add(so.LocalId); | ||
158 | |||
159 | // Specifying a UUID.Zero in this case will currently plop it in Lost and Found | ||
160 | scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.TakeCopy, UUID.Zero); | ||
161 | |||
162 | // Check that object isn't copied until we crank the sogd handle. | ||
163 | SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId); | ||
164 | Assert.That(retrievedPart, Is.Not.Null); | ||
165 | Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False); | ||
166 | |||
167 | sogd.InventoryDeQueueAndDelete(); | ||
168 | |||
169 | // Check that object is still there. | ||
170 | SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId); | ||
171 | Assert.That(retrievedPart2, Is.Not.Null); | ||
172 | Assert.That(client.ReceivedKills.Count, Is.EqualTo(0)); | ||
173 | |||
174 | // Check that we do not have a copy in inventory | ||
175 | InventoryItemBase item | ||
176 | = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, ua.PrincipalID, "Lost And Found/so1"); | ||
177 | Assert.That(item, Is.Null); | ||
178 | } | ||
179 | |||
180 | [Test] | ||
181 | public void TestTakeCopyWhenCopierIsNotOwnerWithPerms() | ||
182 | { | ||
183 | TestHelpers.InMethod(); | ||
184 | // TestHelpers.EnableLogging(); | ||
185 | |||
186 | IConfigSource config = new IniConfigSource(); | ||
187 | config.AddConfig("Modules"); | ||
188 | config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); | ||
189 | |||
190 | TestScene scene = new SceneHelpers().SetupScene("s1", TestHelpers.ParseTail(0x99), 1000, 1000, config); | ||
191 | SceneHelpers.SetupSceneModules(scene, config, new PermissionsModule(), new BasicInventoryAccessModule()); | ||
192 | UserAccount ua = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(0x1)); | ||
193 | TestClient client = (TestClient)SceneHelpers.AddScenePresence(scene, ua.PrincipalID).ControllingClient; | ||
194 | |||
195 | // Turn off the timer on the async sog deleter - we'll crank it by hand for this test. | ||
196 | AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter; | ||
197 | sogd.Enabled = false; | ||
198 | |||
199 | SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, "so1", TestHelpers.ParseTail(0x2)); | ||
200 | uint soLocalId = so.LocalId; | ||
201 | |||
202 | // Base must allow transfer and copy | ||
203 | so.RootPart.BaseMask = (uint)(OpenMetaverse.PermissionMask.Copy | OpenMetaverse.PermissionMask.Transfer); | ||
204 | // Must be set so anyone can copy | ||
205 | so.RootPart.EveryoneMask = (uint)OpenMetaverse.PermissionMask.Copy; | ||
206 | |||
207 | List<uint> localIds = new List<uint>(); | ||
208 | localIds.Add(so.LocalId); | ||
209 | |||
210 | // Specifying a UUID.Zero in this case will plop it in the Objects folder | ||
211 | scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.TakeCopy, UUID.Zero); | ||
212 | |||
213 | // Check that object isn't copied until we crank the sogd handle. | ||
214 | SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId); | ||
215 | Assert.That(retrievedPart, Is.Not.Null); | ||
216 | Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False); | ||
217 | |||
218 | sogd.InventoryDeQueueAndDelete(); | ||
219 | |||
220 | // Check that object is still there. | ||
221 | SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId); | ||
222 | Assert.That(retrievedPart2, Is.Not.Null); | ||
223 | Assert.That(client.ReceivedKills.Count, Is.EqualTo(0)); | ||
224 | |||
225 | // Check that we have a copy in inventory | ||
226 | InventoryItemBase item | ||
227 | = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, ua.PrincipalID, "Objects/so1"); | ||
228 | Assert.That(item, Is.Not.Null); | ||
229 | } | ||
230 | |||
231 | [Test] | ||
232 | public void TestTakeCopyWhenCopierIsNotOwnerWithoutPerms() | ||
233 | { | ||
234 | TestHelpers.InMethod(); | ||
235 | // TestHelpers.EnableLogging(); | ||
236 | |||
237 | IConfigSource config = new IniConfigSource(); | ||
238 | config.AddConfig("Modules"); | ||
239 | config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); | ||
240 | |||
241 | TestScene scene = new SceneHelpers().SetupScene("s1", TestHelpers.ParseTail(0x99), 1000, 1000, config); | ||
242 | SceneHelpers.SetupSceneModules(scene, config, new PermissionsModule(), new BasicInventoryAccessModule()); | ||
243 | UserAccount ua = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(0x1)); | ||
244 | TestClient client = (TestClient)SceneHelpers.AddScenePresence(scene, ua.PrincipalID).ControllingClient; | ||
245 | |||
246 | // Turn off the timer on the async sog deleter - we'll crank it by hand for this test. | ||
247 | AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter; | ||
248 | sogd.Enabled = false; | ||
249 | |||
250 | SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, "so1", TestHelpers.ParseTail(0x2)); | ||
251 | uint soLocalId = so.LocalId; | ||
252 | |||
253 | { | ||
254 | // Check that object is not copied if copy base perms is missing. | ||
255 | // Should not allow copy if base does not have this. | ||
256 | so.RootPart.BaseMask = (uint)OpenMetaverse.PermissionMask.Transfer; | ||
257 | // Must be set so anyone can copy | ||
258 | so.RootPart.EveryoneMask = (uint)OpenMetaverse.PermissionMask.Copy; | ||
259 | |||
260 | // Check that object is not copied | ||
261 | List<uint> localIds = new List<uint>(); | ||
262 | localIds.Add(so.LocalId); | ||
263 | |||
264 | // Specifying a UUID.Zero in this case will plop it in the Objects folder if we have perms | ||
265 | scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.TakeCopy, UUID.Zero); | ||
266 | |||
267 | // Check that object isn't copied until we crank the sogd handle. | ||
268 | SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId); | ||
269 | Assert.That(retrievedPart, Is.Not.Null); | ||
270 | Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False); | ||
271 | |||
272 | sogd.InventoryDeQueueAndDelete(); | ||
273 | // Check that object is still there. | ||
274 | SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId); | ||
275 | Assert.That(retrievedPart2, Is.Not.Null); | ||
276 | Assert.That(client.ReceivedKills.Count, Is.EqualTo(0)); | ||
277 | |||
278 | // Check that we have a copy in inventory | ||
279 | InventoryItemBase item | ||
280 | = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, ua.PrincipalID, "Objects/so1"); | ||
281 | Assert.That(item, Is.Null); | ||
282 | } | ||
283 | |||
284 | { | ||
285 | // Check that object is not copied if copy trans perms is missing. | ||
286 | // Should not allow copy if base does not have this. | ||
287 | so.RootPart.BaseMask = (uint)OpenMetaverse.PermissionMask.Copy; | ||
288 | // Must be set so anyone can copy | ||
289 | so.RootPart.EveryoneMask = (uint)OpenMetaverse.PermissionMask.Copy; | ||
290 | |||
291 | // Check that object is not copied | ||
292 | List<uint> localIds = new List<uint>(); | ||
293 | localIds.Add(so.LocalId); | ||
294 | |||
295 | // Specifying a UUID.Zero in this case will plop it in the Objects folder if we have perms | ||
296 | scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.TakeCopy, UUID.Zero); | ||
297 | |||
298 | // Check that object isn't copied until we crank the sogd handle. | ||
299 | SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId); | ||
300 | Assert.That(retrievedPart, Is.Not.Null); | ||
301 | Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False); | ||
302 | |||
303 | sogd.InventoryDeQueueAndDelete(); | ||
304 | // Check that object is still there. | ||
305 | SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId); | ||
306 | Assert.That(retrievedPart2, Is.Not.Null); | ||
307 | Assert.That(client.ReceivedKills.Count, Is.EqualTo(0)); | ||
308 | |||
309 | // Check that we have a copy in inventory | ||
310 | InventoryItemBase item | ||
311 | = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, ua.PrincipalID, "Objects/so1"); | ||
312 | Assert.That(item, Is.Null); | ||
313 | } | ||
314 | |||
315 | { | ||
316 | // Check that object is not copied if everyone copy perms is missing. | ||
317 | // Should not allow copy if base does not have this. | ||
318 | so.RootPart.BaseMask = (uint)(OpenMetaverse.PermissionMask.Copy | OpenMetaverse.PermissionMask.Transfer); | ||
319 | // Make sure everyone perm does not allow copy | ||
320 | so.RootPart.EveryoneMask = (uint)(OpenMetaverse.PermissionMask.All & ~OpenMetaverse.PermissionMask.Copy); | ||
321 | |||
322 | // Check that object is not copied | ||
323 | List<uint> localIds = new List<uint>(); | ||
324 | localIds.Add(so.LocalId); | ||
325 | |||
326 | // Specifying a UUID.Zero in this case will plop it in the Objects folder if we have perms | ||
327 | scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.TakeCopy, UUID.Zero); | ||
328 | |||
329 | // Check that object isn't copied until we crank the sogd handle. | ||
330 | SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId); | ||
331 | Assert.That(retrievedPart, Is.Not.Null); | ||
332 | Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False); | ||
333 | |||
334 | sogd.InventoryDeQueueAndDelete(); | ||
335 | // Check that object is still there. | ||
336 | SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId); | ||
337 | Assert.That(retrievedPart2, Is.Not.Null); | ||
338 | Assert.That(client.ReceivedKills.Count, Is.EqualTo(0)); | ||
339 | |||
340 | // Check that we have a copy in inventory | ||
341 | InventoryItemBase item | ||
342 | = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, ua.PrincipalID, "Objects/so1"); | ||
343 | Assert.That(item, Is.Null); | ||
344 | } | ||
345 | } | ||
346 | } | ||
347 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectCrossingTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectCrossingTests.cs new file mode 100644 index 0000000..5635c20 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectCrossingTests.cs | |||
@@ -0,0 +1,259 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using Nini.Config; | ||
31 | using NUnit.Framework; | ||
32 | using OpenMetaverse; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Region.CoreModules.Framework; | ||
35 | using OpenSim.Region.CoreModules.Framework.EntityTransfer; | ||
36 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; | ||
37 | using OpenSim.Region.CoreModules.World.Land; | ||
38 | using OpenSim.Region.OptionalModules; | ||
39 | using OpenSim.Tests.Common; | ||
40 | |||
41 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
42 | { | ||
43 | public class SceneObjectCrossingTests : OpenSimTestCase | ||
44 | { | ||
45 | [TestFixtureSetUp] | ||
46 | public void FixtureInit() | ||
47 | { | ||
48 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. | ||
49 | Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest; | ||
50 | } | ||
51 | |||
52 | [TestFixtureTearDown] | ||
53 | public void TearDown() | ||
54 | { | ||
55 | // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple | ||
56 | // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression | ||
57 | // tests really shouldn't). | ||
58 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; | ||
59 | } | ||
60 | |||
61 | /// <summary> | ||
62 | /// Test cross with no prim limit module. | ||
63 | /// </summary> | ||
64 | [Test] | ||
65 | public void TestCrossOnSameSimulator() | ||
66 | { | ||
67 | TestHelpers.InMethod(); | ||
68 | // TestHelpers.EnableLogging(); | ||
69 | |||
70 | UUID userId = TestHelpers.ParseTail(0x1); | ||
71 | int sceneObjectIdTail = 0x2; | ||
72 | |||
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 | |||
82 | SceneHelpers sh = new SceneHelpers(); | ||
83 | TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000); | ||
84 | TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999); | ||
85 | |||
86 | SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); | ||
87 | SceneHelpers.SetupSceneModules(sceneA, config, etmA); | ||
88 | SceneHelpers.SetupSceneModules(sceneB, config, etmB); | ||
89 | |||
90 | SceneObjectGroup so1 = SceneHelpers.AddSceneObject(sceneA, 1, userId, "", sceneObjectIdTail); | ||
91 | UUID so1Id = so1.UUID; | ||
92 | so1.AbsolutePosition = new Vector3(128, 10, 20); | ||
93 | |||
94 | // Cross with a negative value | ||
95 | so1.AbsolutePosition = new Vector3(128, -10, 20); | ||
96 | |||
97 | Assert.IsNull(sceneA.GetSceneObjectGroup(so1Id)); | ||
98 | Assert.NotNull(sceneB.GetSceneObjectGroup(so1Id)); | ||
99 | } | ||
100 | |||
101 | /// <summary> | ||
102 | /// Test cross with no prim limit module. | ||
103 | /// </summary> | ||
104 | /// <remarks> | ||
105 | /// Possibly this should belong in ScenePresenceCrossingTests, though here it is the object that is being moved | ||
106 | /// where the avatar is just a passenger. | ||
107 | /// </remarks> | ||
108 | [Test] | ||
109 | public void TestCrossOnSameSimulatorWithSittingAvatar() | ||
110 | { | ||
111 | TestHelpers.InMethod(); | ||
112 | // TestHelpers.EnableLogging(); | ||
113 | |||
114 | UUID userId = TestHelpers.ParseTail(0x1); | ||
115 | int sceneObjectIdTail = 0x2; | ||
116 | Vector3 so1StartPos = new Vector3(128, 10, 20); | ||
117 | |||
118 | EntityTransferModule etmA = new EntityTransferModule(); | ||
119 | EntityTransferModule etmB = new EntityTransferModule(); | ||
120 | LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule(); | ||
121 | |||
122 | IConfigSource config = new IniConfigSource(); | ||
123 | IConfig modulesConfig = config.AddConfig("Modules"); | ||
124 | modulesConfig.Set("EntityTransferModule", etmA.Name); | ||
125 | modulesConfig.Set("SimulationServices", lscm.Name); | ||
126 | IConfig entityTransferConfig = config.AddConfig("EntityTransfer"); | ||
127 | |||
128 | // In order to run a single threaded regression test we do not want the entity transfer module waiting | ||
129 | // for a callback from the destination scene before removing its avatar data. | ||
130 | entityTransferConfig.Set("wait_for_callback", false); | ||
131 | |||
132 | SceneHelpers sh = new SceneHelpers(); | ||
133 | TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000); | ||
134 | TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999); | ||
135 | |||
136 | SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); | ||
137 | SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA); | ||
138 | SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), etmB); | ||
139 | |||
140 | SceneObjectGroup so1 = SceneHelpers.AddSceneObject(sceneA, 1, userId, "", sceneObjectIdTail); | ||
141 | UUID so1Id = so1.UUID; | ||
142 | so1.AbsolutePosition = so1StartPos; | ||
143 | |||
144 | AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId); | ||
145 | TestClient tc = new TestClient(acd, sceneA); | ||
146 | List<TestClient> destinationTestClients = new List<TestClient>(); | ||
147 | EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients); | ||
148 | |||
149 | ScenePresence sp1SceneA = SceneHelpers.AddScenePresence(sceneA, tc, acd); | ||
150 | sp1SceneA.AbsolutePosition = so1StartPos; | ||
151 | sp1SceneA.HandleAgentRequestSit(sp1SceneA.ControllingClient, sp1SceneA.UUID, so1.UUID, Vector3.Zero); | ||
152 | |||
153 | // Cross | ||
154 | sceneA.SceneGraph.UpdatePrimGroupPosition( | ||
155 | so1.LocalId, new Vector3(so1StartPos.X, so1StartPos.Y - 20, so1StartPos.Z), userId); | ||
156 | |||
157 | SceneObjectGroup so1PostCross; | ||
158 | |||
159 | { | ||
160 | ScenePresence sp1SceneAPostCross = sceneA.GetScenePresence(userId); | ||
161 | Assert.IsTrue(sp1SceneAPostCross.IsChildAgent, "sp1SceneAPostCross.IsChildAgent unexpectedly false"); | ||
162 | |||
163 | ScenePresence sp1SceneBPostCross = sceneB.GetScenePresence(userId); | ||
164 | TestClient sceneBTc = ((TestClient)sp1SceneBPostCross.ControllingClient); | ||
165 | sceneBTc.CompleteMovement(); | ||
166 | |||
167 | Assert.IsFalse(sp1SceneBPostCross.IsChildAgent, "sp1SceneAPostCross.IsChildAgent unexpectedly true"); | ||
168 | Assert.IsTrue(sp1SceneBPostCross.IsSatOnObject); | ||
169 | |||
170 | Assert.IsNull(sceneA.GetSceneObjectGroup(so1Id), "uck"); | ||
171 | so1PostCross = sceneB.GetSceneObjectGroup(so1Id); | ||
172 | Assert.NotNull(so1PostCross); | ||
173 | Assert.AreEqual(1, so1PostCross.GetSittingAvatarsCount()); | ||
174 | } | ||
175 | |||
176 | Vector3 so1PostCrossPos = so1PostCross.AbsolutePosition; | ||
177 | |||
178 | // Console.WriteLine("CRISSCROSS"); | ||
179 | |||
180 | // Recross | ||
181 | sceneB.SceneGraph.UpdatePrimGroupPosition( | ||
182 | so1PostCross.LocalId, new Vector3(so1PostCrossPos.X, so1PostCrossPos.Y + 20, so1PostCrossPos.Z), userId); | ||
183 | |||
184 | { | ||
185 | ScenePresence sp1SceneBPostReCross = sceneB.GetScenePresence(userId); | ||
186 | Assert.IsTrue(sp1SceneBPostReCross.IsChildAgent, "sp1SceneBPostReCross.IsChildAgent unexpectedly false"); | ||
187 | |||
188 | ScenePresence sp1SceneAPostReCross = sceneA.GetScenePresence(userId); | ||
189 | TestClient sceneATc = ((TestClient)sp1SceneAPostReCross.ControllingClient); | ||
190 | sceneATc.CompleteMovement(); | ||
191 | |||
192 | Assert.IsFalse(sp1SceneAPostReCross.IsChildAgent, "sp1SceneAPostCross.IsChildAgent unexpectedly true"); | ||
193 | Assert.IsTrue(sp1SceneAPostReCross.IsSatOnObject); | ||
194 | |||
195 | Assert.IsNull(sceneB.GetSceneObjectGroup(so1Id), "uck2"); | ||
196 | SceneObjectGroup so1PostReCross = sceneA.GetSceneObjectGroup(so1Id); | ||
197 | Assert.NotNull(so1PostReCross); | ||
198 | Assert.AreEqual(1, so1PostReCross.GetSittingAvatarsCount()); | ||
199 | } | ||
200 | } | ||
201 | |||
202 | /// <summary> | ||
203 | /// Test cross with no prim limit module. | ||
204 | /// </summary> | ||
205 | /// <remarks> | ||
206 | /// XXX: This test may FCbe better off in a specific PrimLimitsModuleTest class in optional module tests in the | ||
207 | /// future (though it is configured as active by default, so not really optional). | ||
208 | /// </remarks> | ||
209 | [Test] | ||
210 | public void TestCrossOnSameSimulatorPrimLimitsOkay() | ||
211 | { | ||
212 | TestHelpers.InMethod(); | ||
213 | // TestHelpers.EnableLogging(); | ||
214 | |||
215 | UUID userId = TestHelpers.ParseTail(0x1); | ||
216 | int sceneObjectIdTail = 0x2; | ||
217 | |||
218 | EntityTransferModule etmA = new EntityTransferModule(); | ||
219 | EntityTransferModule etmB = new EntityTransferModule(); | ||
220 | LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule(); | ||
221 | LandManagementModule lmmA = new LandManagementModule(); | ||
222 | LandManagementModule lmmB = new LandManagementModule(); | ||
223 | |||
224 | IConfigSource config = new IniConfigSource(); | ||
225 | IConfig modulesConfig = config.AddConfig("Modules"); | ||
226 | modulesConfig.Set("EntityTransferModule", etmA.Name); | ||
227 | modulesConfig.Set("SimulationServices", lscm.Name); | ||
228 | |||
229 | IConfig permissionsConfig = config.AddConfig("Permissions"); | ||
230 | permissionsConfig.Set("permissionmodules", "PrimLimitsModule"); | ||
231 | |||
232 | SceneHelpers sh = new SceneHelpers(); | ||
233 | TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000); | ||
234 | TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999); | ||
235 | |||
236 | SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); | ||
237 | SceneHelpers.SetupSceneModules( | ||
238 | sceneA, config, etmA, lmmA, new PrimLimitsModule(), new PrimCountModule()); | ||
239 | SceneHelpers.SetupSceneModules( | ||
240 | sceneB, config, etmB, lmmB, new PrimLimitsModule(), new PrimCountModule()); | ||
241 | |||
242 | // We must set up the parcel for this to work. Normally this is taken care of by OpenSimulator startup | ||
243 | // code which is not yet easily invoked by tests. | ||
244 | lmmA.EventManagerOnNoLandDataFromStorage(); | ||
245 | lmmB.EventManagerOnNoLandDataFromStorage(); | ||
246 | |||
247 | SceneObjectGroup so1 = SceneHelpers.AddSceneObject(sceneA, 1, userId, "", sceneObjectIdTail); | ||
248 | UUID so1Id = so1.UUID; | ||
249 | so1.AbsolutePosition = new Vector3(128, 10, 20); | ||
250 | |||
251 | // Cross with a negative value. We must make this call rather than setting AbsolutePosition directly | ||
252 | // because only this will execute permission checks in the source region. | ||
253 | sceneA.SceneGraph.UpdatePrimGroupPosition(so1.LocalId, new Vector3(128, -10, 20), userId); | ||
254 | |||
255 | Assert.IsNull(sceneA.GetSceneObjectGroup(so1Id)); | ||
256 | Assert.NotNull(sceneB.GetSceneObjectGroup(so1Id)); | ||
257 | } | ||
258 | } | ||
259 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectDeRezTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectDeRezTests.cs new file mode 100644 index 0000000..558ba2c --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectDeRezTests.cs | |||
@@ -0,0 +1,264 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using Nini.Config; | ||
32 | using NUnit.Framework; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Region.CoreModules.Framework.EntityTransfer; | ||
37 | using OpenSim.Region.CoreModules.Framework.InventoryAccess; | ||
38 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; | ||
39 | using OpenSim.Region.CoreModules.World.Permissions; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | using OpenSim.Services.Interfaces; | ||
42 | using OpenSim.Tests.Common; | ||
43 | |||
44 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
45 | { | ||
46 | /// <summary> | ||
47 | /// Tests derez of scene objects. | ||
48 | /// </summary> | ||
49 | /// <remarks> | ||
50 | /// This is at a level above the SceneObjectBasicTests, which act on the scene directly. | ||
51 | /// TODO: These tests are incomplete - need to test more kinds of derez (e.g. return object). | ||
52 | /// </remarks> | ||
53 | [TestFixture] | ||
54 | public class SceneObjectDeRezTests : OpenSimTestCase | ||
55 | { | ||
56 | [TestFixtureSetUp] | ||
57 | public void FixtureInit() | ||
58 | { | ||
59 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. | ||
60 | // This facility was added after the original async delete tests were written, so it may be possible now | ||
61 | // to not bother explicitly disabling their async (since everything will be running sync). | ||
62 | Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest; | ||
63 | } | ||
64 | |||
65 | [TestFixtureTearDown] | ||
66 | public void TearDown() | ||
67 | { | ||
68 | // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple | ||
69 | // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression | ||
70 | // tests really shouldn't). | ||
71 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; | ||
72 | } | ||
73 | |||
74 | /// <summary> | ||
75 | /// Test deleting an object from a scene. | ||
76 | /// </summary> | ||
77 | [Test] | ||
78 | public void TestDeRezSceneObject() | ||
79 | { | ||
80 | TestHelpers.InMethod(); | ||
81 | |||
82 | UUID userId = UUID.Parse("10000000-0000-0000-0000-000000000001"); | ||
83 | |||
84 | TestScene scene = new SceneHelpers().SetupScene(); | ||
85 | SceneHelpers.SetupSceneModules(scene, new PermissionsModule()); | ||
86 | TestClient client = (TestClient)SceneHelpers.AddScenePresence(scene, userId).ControllingClient; | ||
87 | |||
88 | // Turn off the timer on the async sog deleter - we'll crank it by hand for this test. | ||
89 | AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter; | ||
90 | sogd.Enabled = false; | ||
91 | |||
92 | SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, "so1", userId); | ||
93 | uint soLocalId = so.LocalId; | ||
94 | |||
95 | List<uint> localIds = new List<uint>(); | ||
96 | localIds.Add(so.LocalId); | ||
97 | scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.Delete, UUID.Zero); | ||
98 | |||
99 | // Check that object isn't deleted until we crank the sogd handle. | ||
100 | SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId); | ||
101 | Assert.That(retrievedPart, Is.Not.Null); | ||
102 | Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False); | ||
103 | |||
104 | sogd.InventoryDeQueueAndDelete(); | ||
105 | |||
106 | SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId); | ||
107 | Assert.That(retrievedPart2, Is.Null); | ||
108 | |||
109 | Assert.That(client.ReceivedKills.Count, Is.EqualTo(1)); | ||
110 | Assert.That(client.ReceivedKills[0], Is.EqualTo(soLocalId)); | ||
111 | } | ||
112 | |||
113 | /// <summary> | ||
114 | /// Test that child and root agents correctly receive KillObject notifications. | ||
115 | /// </summary> | ||
116 | [Test] | ||
117 | public void TestDeRezSceneObjectToAgents() | ||
118 | { | ||
119 | TestHelpers.InMethod(); | ||
120 | // TestHelpers.EnableLogging(); | ||
121 | |||
122 | SceneHelpers sh = new SceneHelpers(); | ||
123 | TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000); | ||
124 | TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999); | ||
125 | |||
126 | // We need this so that the creation of the root client for userB in sceneB can trigger the creation of a child client in sceneA | ||
127 | LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule(); | ||
128 | EntityTransferModule etmB = new EntityTransferModule(); | ||
129 | IConfigSource config = new IniConfigSource(); | ||
130 | IConfig modulesConfig = config.AddConfig("Modules"); | ||
131 | modulesConfig.Set("EntityTransferModule", etmB.Name); | ||
132 | modulesConfig.Set("SimulationServices", lscm.Name); | ||
133 | SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); | ||
134 | SceneHelpers.SetupSceneModules(sceneB, config, etmB); | ||
135 | |||
136 | // We need this for derez | ||
137 | SceneHelpers.SetupSceneModules(sceneA, new PermissionsModule()); | ||
138 | |||
139 | UserAccount uaA = UserAccountHelpers.CreateUserWithInventory(sceneA, "Andy", "AAA", 0x1, ""); | ||
140 | UserAccount uaB = UserAccountHelpers.CreateUserWithInventory(sceneA, "Brian", "BBB", 0x2, ""); | ||
141 | |||
142 | TestClient clientA = (TestClient)SceneHelpers.AddScenePresence(sceneA, uaA).ControllingClient; | ||
143 | |||
144 | // This is the more long-winded route we have to take to get a child client created for userB in sceneA | ||
145 | // rather than just calling AddScenePresence() as for userA | ||
146 | AgentCircuitData acd = SceneHelpers.GenerateAgentData(uaB); | ||
147 | TestClient clientB = new TestClient(acd, sceneB); | ||
148 | List<TestClient> childClientsB = new List<TestClient>(); | ||
149 | EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(clientB, childClientsB); | ||
150 | |||
151 | SceneHelpers.AddScenePresence(sceneB, clientB, acd); | ||
152 | |||
153 | SceneObjectGroup so = SceneHelpers.AddSceneObject(sceneA); | ||
154 | uint soLocalId = so.LocalId; | ||
155 | |||
156 | sceneA.DeleteSceneObject(so, false); | ||
157 | |||
158 | Assert.That(clientA.ReceivedKills.Count, Is.EqualTo(1)); | ||
159 | Assert.That(clientA.ReceivedKills[0], Is.EqualTo(soLocalId)); | ||
160 | |||
161 | Assert.That(childClientsB[0].ReceivedKills.Count, Is.EqualTo(1)); | ||
162 | Assert.That(childClientsB[0].ReceivedKills[0], Is.EqualTo(soLocalId)); | ||
163 | } | ||
164 | |||
165 | /// <summary> | ||
166 | /// Test deleting an object from a scene where the deleter is not the owner | ||
167 | /// </summary> | ||
168 | /// <remarks> | ||
169 | /// This test assumes that the deleter is not a god. | ||
170 | /// </remarks> | ||
171 | [Test] | ||
172 | public void TestDeRezSceneObjectNotOwner() | ||
173 | { | ||
174 | TestHelpers.InMethod(); | ||
175 | // log4net.Config.XmlConfigurator.Configure(); | ||
176 | |||
177 | UUID userId = UUID.Parse("10000000-0000-0000-0000-000000000001"); | ||
178 | UUID objectOwnerId = UUID.Parse("20000000-0000-0000-0000-000000000001"); | ||
179 | |||
180 | TestScene scene = new SceneHelpers().SetupScene(); | ||
181 | SceneHelpers.SetupSceneModules(scene, new PermissionsModule()); | ||
182 | IClientAPI client = SceneHelpers.AddScenePresence(scene, userId).ControllingClient; | ||
183 | |||
184 | // Turn off the timer on the async sog deleter - we'll crank it by hand for this test. | ||
185 | AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter; | ||
186 | sogd.Enabled = false; | ||
187 | |||
188 | SceneObjectPart part | ||
189 | = new SceneObjectPart(objectOwnerId, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero); | ||
190 | part.Name = "obj1"; | ||
191 | scene.AddNewSceneObject(new SceneObjectGroup(part), false); | ||
192 | List<uint> localIds = new List<uint>(); | ||
193 | localIds.Add(part.LocalId); | ||
194 | |||
195 | scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.Delete, UUID.Zero); | ||
196 | sogd.InventoryDeQueueAndDelete(); | ||
197 | |||
198 | // Object should still be in the scene. | ||
199 | SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId); | ||
200 | Assert.That(retrievedPart.UUID, Is.EqualTo(part.UUID)); | ||
201 | } | ||
202 | |||
203 | /// <summary> | ||
204 | /// Test deleting an object asynchronously to user inventory. | ||
205 | /// </summary> | ||
206 | [Test] | ||
207 | public void TestDeleteSceneObjectAsyncToUserInventory() | ||
208 | { | ||
209 | TestHelpers.InMethod(); | ||
210 | // TestHelpers.EnableLogging(); | ||
211 | |||
212 | UUID agentId = UUID.Parse("00000000-0000-0000-0000-000000000001"); | ||
213 | string myObjectName = "Fred"; | ||
214 | |||
215 | TestScene scene = new SceneHelpers().SetupScene(); | ||
216 | |||
217 | IConfigSource configSource = new IniConfigSource(); | ||
218 | IConfig config = configSource.AddConfig("Modules"); | ||
219 | config.Set("InventoryAccessModule", "BasicInventoryAccessModule"); | ||
220 | SceneHelpers.SetupSceneModules( | ||
221 | scene, configSource, new object[] { new BasicInventoryAccessModule() }); | ||
222 | |||
223 | SceneHelpers.SetupSceneModules(scene, new object[] { }); | ||
224 | |||
225 | // Turn off the timer on the async sog deleter - we'll crank it by hand for this test. | ||
226 | AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter; | ||
227 | sogd.Enabled = false; | ||
228 | |||
229 | SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, myObjectName, agentId); | ||
230 | |||
231 | UserAccount ua = UserAccountHelpers.CreateUserWithInventory(scene, agentId); | ||
232 | InventoryFolderBase folder1 | ||
233 | = UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, ua.PrincipalID, "folder1", false); | ||
234 | |||
235 | IClientAPI client = SceneHelpers.AddScenePresence(scene, agentId).ControllingClient; | ||
236 | scene.DeRezObjects(client, new List<uint>() { so.LocalId }, UUID.Zero, DeRezAction.Take, folder1.ID); | ||
237 | |||
238 | SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId); | ||
239 | |||
240 | Assert.That(retrievedPart, Is.Not.Null); | ||
241 | Assert.That(so.IsDeleted, Is.False); | ||
242 | |||
243 | sogd.InventoryDeQueueAndDelete(); | ||
244 | |||
245 | Assert.That(so.IsDeleted, Is.True); | ||
246 | |||
247 | SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId); | ||
248 | Assert.That(retrievedPart2, Is.Null); | ||
249 | |||
250 | // SceneSetupHelpers.DeleteSceneObjectAsync(scene, part, DeRezAction.Take, userInfo.RootFolder.ID, client); | ||
251 | |||
252 | InventoryItemBase retrievedItem | ||
253 | = UserInventoryHelpers.GetInventoryItem( | ||
254 | scene.InventoryService, ua.PrincipalID, "folder1/" + myObjectName); | ||
255 | |||
256 | // Check that we now have the taken part in our inventory | ||
257 | Assert.That(retrievedItem, Is.Not.Null); | ||
258 | |||
259 | // Check that the taken part has actually disappeared | ||
260 | // SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId); | ||
261 | // Assert.That(retrievedPart, Is.Null); | ||
262 | } | ||
263 | } | ||
264 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs new file mode 100644 index 0000000..c2e0ae3 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs | |||
@@ -0,0 +1,372 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using NUnit.Framework; | ||
32 | using OpenMetaverse; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Framework.Communications; | ||
35 | using OpenSim.Region.Framework.Scenes; | ||
36 | using OpenSim.Tests.Common; | ||
37 | using log4net; | ||
38 | |||
39 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
40 | { | ||
41 | [TestFixture] | ||
42 | public class SceneObjectLinkingTests : OpenSimTestCase | ||
43 | { | ||
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | |||
46 | /// <summary> | ||
47 | /// Links to self should be ignored. | ||
48 | /// </summary> | ||
49 | [Test] | ||
50 | public void TestLinkToSelf() | ||
51 | { | ||
52 | TestHelpers.InMethod(); | ||
53 | |||
54 | UUID ownerId = TestHelpers.ParseTail(0x1); | ||
55 | int nParts = 3; | ||
56 | |||
57 | TestScene scene = new SceneHelpers().SetupScene(); | ||
58 | SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(nParts, ownerId, "TestLinkToSelf_", 0x10); | ||
59 | scene.AddSceneObject(sog1); | ||
60 | scene.LinkObjects(ownerId, sog1.LocalId, new List<uint>() { sog1.Parts[1].LocalId }); | ||
61 | // sog1.LinkToGroup(sog1); | ||
62 | |||
63 | Assert.That(sog1.Parts.Length, Is.EqualTo(nParts)); | ||
64 | } | ||
65 | |||
66 | [Test] | ||
67 | public void TestLinkDelink2SceneObjects() | ||
68 | { | ||
69 | TestHelpers.InMethod(); | ||
70 | |||
71 | bool debugtest = false; | ||
72 | |||
73 | Scene scene = new SceneHelpers().SetupScene(); | ||
74 | SceneObjectGroup grp1 = SceneHelpers.AddSceneObject(scene); | ||
75 | SceneObjectPart part1 = grp1.RootPart; | ||
76 | SceneObjectGroup grp2 = SceneHelpers.AddSceneObject(scene); | ||
77 | SceneObjectPart part2 = grp2.RootPart; | ||
78 | |||
79 | grp1.AbsolutePosition = new Vector3(10, 10, 10); | ||
80 | grp2.AbsolutePosition = Vector3.Zero; | ||
81 | |||
82 | // <90,0,0> | ||
83 | // grp1.UpdateGroupRotationR(Quaternion.CreateFromEulers(90 * Utils.DEG_TO_RAD, 0, 0)); | ||
84 | |||
85 | // <180,0,0> | ||
86 | grp2.UpdateGroupRotationR(Quaternion.CreateFromEulers(180 * Utils.DEG_TO_RAD, 0, 0)); | ||
87 | |||
88 | // Required for linking | ||
89 | grp1.RootPart.ClearUpdateSchedule(); | ||
90 | grp2.RootPart.ClearUpdateSchedule(); | ||
91 | |||
92 | // Link grp2 to grp1. part2 becomes child prim to grp1. grp2 is eliminated. | ||
93 | Assert.IsFalse(grp1.GroupContainsForeignPrims); | ||
94 | grp1.LinkToGroup(grp2); | ||
95 | Assert.IsTrue(grp1.GroupContainsForeignPrims); | ||
96 | |||
97 | scene.Backup(true); | ||
98 | Assert.IsFalse(grp1.GroupContainsForeignPrims); | ||
99 | |||
100 | // FIXME: Can't do this test yet since group 2 still has its root part! We can't yet null this since | ||
101 | // it might cause SOG.ProcessBackup() to fail due to the race condition. This really needs to be fixed. | ||
102 | Assert.That(grp2.IsDeleted, "SOG 2 was not registered as deleted after link."); | ||
103 | Assert.That(grp2.Parts.Length, Is.EqualTo(0), "Group 2 still contained children after delink."); | ||
104 | Assert.That(grp1.Parts.Length == 2); | ||
105 | |||
106 | if (debugtest) | ||
107 | { | ||
108 | m_log.Debug("parts: " + grp1.Parts.Length); | ||
109 | m_log.Debug("Group1: Pos:"+grp1.AbsolutePosition+", Rot:"+grp1.GroupRotation); | ||
110 | m_log.Debug("Group1: Prim1: OffsetPosition:"+ part1.OffsetPosition+", OffsetRotation:"+part1.RotationOffset); | ||
111 | m_log.Debug("Group1: Prim2: OffsetPosition:"+part2.OffsetPosition+", OffsetRotation:"+part2.RotationOffset); | ||
112 | } | ||
113 | |||
114 | // root part should have no offset position or rotation | ||
115 | Assert.That(part1.OffsetPosition == Vector3.Zero && part1.RotationOffset == Quaternion.Identity, | ||
116 | "root part should have no offset position or rotation"); | ||
117 | |||
118 | // offset position should be root part position - part2.absolute position. | ||
119 | Assert.That(part2.OffsetPosition == new Vector3(-10, -10, -10), | ||
120 | "offset position should be root part position - part2.absolute position."); | ||
121 | |||
122 | float roll = 0; | ||
123 | float pitch = 0; | ||
124 | float yaw = 0; | ||
125 | |||
126 | // There's a euler anomoly at 180, 0, 0 so expect 180 to turn into -180. | ||
127 | part1.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw); | ||
128 | Vector3 rotEuler1 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG); | ||
129 | |||
130 | if (debugtest) | ||
131 | m_log.Debug(rotEuler1); | ||
132 | |||
133 | part2.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw); | ||
134 | Vector3 rotEuler2 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG); | ||
135 | |||
136 | if (debugtest) | ||
137 | m_log.Debug(rotEuler2); | ||
138 | |||
139 | Assert.That(rotEuler2.ApproxEquals(new Vector3(-180, 0, 0), 0.001f) || rotEuler2.ApproxEquals(new Vector3(180, 0, 0), 0.001f), | ||
140 | "Not exactly sure what this is asserting..."); | ||
141 | |||
142 | // Delink part 2 | ||
143 | SceneObjectGroup grp3 = grp1.DelinkFromGroup(part2.LocalId); | ||
144 | |||
145 | if (debugtest) | ||
146 | m_log.Debug("Group2: Prim2: OffsetPosition:" + part2.AbsolutePosition + ", OffsetRotation:" + part2.RotationOffset); | ||
147 | |||
148 | Assert.That(grp1.Parts.Length, Is.EqualTo(1), "Group 1 still contained part2 after delink."); | ||
149 | Assert.That(part2.AbsolutePosition == Vector3.Zero, "The absolute position should be zero"); | ||
150 | Assert.NotNull(grp3); | ||
151 | } | ||
152 | |||
153 | [Test] | ||
154 | public void TestLinkDelink2groups4SceneObjects() | ||
155 | { | ||
156 | TestHelpers.InMethod(); | ||
157 | |||
158 | bool debugtest = false; | ||
159 | |||
160 | Scene scene = new SceneHelpers().SetupScene(); | ||
161 | SceneObjectGroup grp1 = SceneHelpers.AddSceneObject(scene); | ||
162 | SceneObjectPart part1 = grp1.RootPart; | ||
163 | SceneObjectGroup grp2 = SceneHelpers.AddSceneObject(scene); | ||
164 | SceneObjectPart part2 = grp2.RootPart; | ||
165 | SceneObjectGroup grp3 = SceneHelpers.AddSceneObject(scene); | ||
166 | SceneObjectPart part3 = grp3.RootPart; | ||
167 | SceneObjectGroup grp4 = SceneHelpers.AddSceneObject(scene); | ||
168 | SceneObjectPart part4 = grp4.RootPart; | ||
169 | |||
170 | grp1.AbsolutePosition = new Vector3(10, 10, 10); | ||
171 | grp2.AbsolutePosition = Vector3.Zero; | ||
172 | grp3.AbsolutePosition = new Vector3(20, 20, 20); | ||
173 | grp4.AbsolutePosition = new Vector3(40, 40, 40); | ||
174 | |||
175 | // <90,0,0> | ||
176 | // grp1.UpdateGroupRotationR(Quaternion.CreateFromEulers(90 * Utils.DEG_TO_RAD, 0, 0)); | ||
177 | |||
178 | // <180,0,0> | ||
179 | grp2.UpdateGroupRotationR(Quaternion.CreateFromEulers(180 * Utils.DEG_TO_RAD, 0, 0)); | ||
180 | |||
181 | // <270,0,0> | ||
182 | // grp3.UpdateGroupRotationR(Quaternion.CreateFromEulers(270 * Utils.DEG_TO_RAD, 0, 0)); | ||
183 | |||
184 | // <0,90,0> | ||
185 | grp4.UpdateGroupRotationR(Quaternion.CreateFromEulers(0, 90 * Utils.DEG_TO_RAD, 0)); | ||
186 | |||
187 | // Required for linking | ||
188 | grp1.RootPart.ClearUpdateSchedule(); | ||
189 | grp2.RootPart.ClearUpdateSchedule(); | ||
190 | grp3.RootPart.ClearUpdateSchedule(); | ||
191 | grp4.RootPart.ClearUpdateSchedule(); | ||
192 | |||
193 | // Link grp2 to grp1. part2 becomes child prim to grp1. grp2 is eliminated. | ||
194 | grp1.LinkToGroup(grp2); | ||
195 | |||
196 | // Link grp4 to grp3. | ||
197 | grp3.LinkToGroup(grp4); | ||
198 | |||
199 | // At this point we should have 4 parts total in two groups. | ||
200 | Assert.That(grp1.Parts.Length == 2, "Group1 children count should be 2"); | ||
201 | Assert.That(grp2.IsDeleted, "Group 2 was not registered as deleted after link."); | ||
202 | Assert.That(grp2.Parts.Length, Is.EqualTo(0), "Group 2 still contained parts after delink."); | ||
203 | Assert.That(grp3.Parts.Length == 2, "Group3 children count should be 2"); | ||
204 | Assert.That(grp4.IsDeleted, "Group 4 was not registered as deleted after link."); | ||
205 | Assert.That(grp4.Parts.Length, Is.EqualTo(0), "Group 4 still contained parts after delink."); | ||
206 | |||
207 | if (debugtest) | ||
208 | { | ||
209 | m_log.Debug("--------After Link-------"); | ||
210 | m_log.Debug("Group1: parts:" + grp1.Parts.Length); | ||
211 | m_log.Debug("Group1: Pos:"+grp1.AbsolutePosition+", Rot:"+grp1.GroupRotation); | ||
212 | m_log.Debug("Group1: Prim1: OffsetPosition:" + part1.OffsetPosition + ", OffsetRotation:" + part1.RotationOffset); | ||
213 | m_log.Debug("Group1: Prim2: OffsetPosition:"+part2.OffsetPosition+", OffsetRotation:"+ part2.RotationOffset); | ||
214 | |||
215 | m_log.Debug("Group3: parts:" + grp3.Parts.Length); | ||
216 | m_log.Debug("Group3: Pos:"+grp3.AbsolutePosition+", Rot:"+grp3.GroupRotation); | ||
217 | m_log.Debug("Group3: Prim1: OffsetPosition:"+part3.OffsetPosition+", OffsetRotation:"+part3.RotationOffset); | ||
218 | m_log.Debug("Group3: Prim2: OffsetPosition:"+part4.OffsetPosition+", OffsetRotation:"+part4.RotationOffset); | ||
219 | } | ||
220 | |||
221 | // Required for linking | ||
222 | grp1.RootPart.ClearUpdateSchedule(); | ||
223 | grp3.RootPart.ClearUpdateSchedule(); | ||
224 | |||
225 | // root part should have no offset position or rotation | ||
226 | Assert.That(part1.OffsetPosition == Vector3.Zero && part1.RotationOffset == Quaternion.Identity, | ||
227 | "root part should have no offset position or rotation (again)"); | ||
228 | |||
229 | // offset position should be root part position - part2.absolute position. | ||
230 | Assert.That(part2.OffsetPosition == new Vector3(-10, -10, -10), | ||
231 | "offset position should be root part position - part2.absolute position (again)"); | ||
232 | |||
233 | float roll = 0; | ||
234 | float pitch = 0; | ||
235 | float yaw = 0; | ||
236 | |||
237 | // There's a euler anomoly at 180, 0, 0 so expect 180 to turn into -180. | ||
238 | part1.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw); | ||
239 | Vector3 rotEuler1 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG); | ||
240 | |||
241 | if (debugtest) | ||
242 | m_log.Debug(rotEuler1); | ||
243 | |||
244 | part2.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw); | ||
245 | Vector3 rotEuler2 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG); | ||
246 | |||
247 | if (debugtest) | ||
248 | m_log.Debug(rotEuler2); | ||
249 | |||
250 | Assert.That(rotEuler2.ApproxEquals(new Vector3(-180, 0, 0), 0.001f) || rotEuler2.ApproxEquals(new Vector3(180, 0, 0), 0.001f), | ||
251 | "Not sure what this assertion is all about..."); | ||
252 | |||
253 | // Now we're linking the first group to the third group. This will make the first group child parts of the third one. | ||
254 | grp3.LinkToGroup(grp1); | ||
255 | |||
256 | // Delink parts 2 and 3 | ||
257 | grp3.DelinkFromGroup(part2.LocalId); | ||
258 | grp3.DelinkFromGroup(part3.LocalId); | ||
259 | |||
260 | if (debugtest) | ||
261 | { | ||
262 | m_log.Debug("--------After De-Link-------"); | ||
263 | m_log.Debug("Group1: parts:" + grp1.Parts.Length); | ||
264 | m_log.Debug("Group1: Pos:" + grp1.AbsolutePosition + ", Rot:" + grp1.GroupRotation); | ||
265 | m_log.Debug("Group1: Prim1: OffsetPosition:" + part1.OffsetPosition + ", OffsetRotation:" + part1.RotationOffset); | ||
266 | m_log.Debug("Group1: Prim2: OffsetPosition:" + part2.OffsetPosition + ", OffsetRotation:" + part2.RotationOffset); | ||
267 | |||
268 | m_log.Debug("Group3: parts:" + grp3.Parts.Length); | ||
269 | m_log.Debug("Group3: Pos:" + grp3.AbsolutePosition + ", Rot:" + grp3.GroupRotation); | ||
270 | m_log.Debug("Group3: Prim1: OffsetPosition:" + part3.OffsetPosition + ", OffsetRotation:" + part3.RotationOffset); | ||
271 | m_log.Debug("Group3: Prim2: OffsetPosition:" + part4.OffsetPosition + ", OffsetRotation:" + part4.RotationOffset); | ||
272 | } | ||
273 | |||
274 | Assert.That(part2.AbsolutePosition == Vector3.Zero, "Badness 1"); | ||
275 | Assert.That(part4.OffsetPosition == new Vector3(20, 20, 20), "Badness 2"); | ||
276 | Quaternion compareQuaternion = new Quaternion(0, 0.7071068f, 0, 0.7071068f); | ||
277 | Assert.That((part4.RotationOffset.X - compareQuaternion.X < 0.00003) | ||
278 | && (part4.RotationOffset.Y - compareQuaternion.Y < 0.00003) | ||
279 | && (part4.RotationOffset.Z - compareQuaternion.Z < 0.00003) | ||
280 | && (part4.RotationOffset.W - compareQuaternion.W < 0.00003), | ||
281 | "Badness 3"); | ||
282 | } | ||
283 | |||
284 | /// <summary> | ||
285 | /// Test that a new scene object which is already linked is correctly persisted to the persistence layer. | ||
286 | /// </summary> | ||
287 | [Test] | ||
288 | public void TestNewSceneObjectLinkPersistence() | ||
289 | { | ||
290 | TestHelpers.InMethod(); | ||
291 | //log4net.Config.XmlConfigurator.Configure(); | ||
292 | |||
293 | TestScene scene = new SceneHelpers().SetupScene(); | ||
294 | |||
295 | string rootPartName = "rootpart"; | ||
296 | UUID rootPartUuid = new UUID("00000000-0000-0000-0000-000000000001"); | ||
297 | string linkPartName = "linkpart"; | ||
298 | UUID linkPartUuid = new UUID("00000000-0000-0000-0001-000000000000"); | ||
299 | |||
300 | SceneObjectPart rootPart | ||
301 | = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) | ||
302 | { Name = rootPartName, UUID = rootPartUuid }; | ||
303 | SceneObjectPart linkPart | ||
304 | = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) | ||
305 | { Name = linkPartName, UUID = linkPartUuid }; | ||
306 | |||
307 | SceneObjectGroup sog = new SceneObjectGroup(rootPart); | ||
308 | sog.AddPart(linkPart); | ||
309 | scene.AddNewSceneObject(sog, true); | ||
310 | |||
311 | // In a test, we have to crank the backup handle manually. Normally this would be done by the timer invoked | ||
312 | // scene backup thread. | ||
313 | scene.Backup(true); | ||
314 | |||
315 | List<SceneObjectGroup> storedObjects = scene.SimulationDataService.LoadObjects(scene.RegionInfo.RegionID); | ||
316 | |||
317 | Assert.That(storedObjects.Count, Is.EqualTo(1)); | ||
318 | Assert.That(storedObjects[0].Parts.Length, Is.EqualTo(2)); | ||
319 | Assert.That(storedObjects[0].ContainsPart(rootPartUuid)); | ||
320 | Assert.That(storedObjects[0].ContainsPart(linkPartUuid)); | ||
321 | } | ||
322 | |||
323 | /// <summary> | ||
324 | /// Test that a delink of a previously linked object is correctly persisted to the database | ||
325 | /// </summary> | ||
326 | [Test] | ||
327 | public void TestDelinkPersistence() | ||
328 | { | ||
329 | TestHelpers.InMethod(); | ||
330 | //log4net.Config.XmlConfigurator.Configure(); | ||
331 | |||
332 | TestScene scene = new SceneHelpers().SetupScene(); | ||
333 | |||
334 | string rootPartName = "rootpart"; | ||
335 | UUID rootPartUuid = new UUID("00000000-0000-0000-0000-000000000001"); | ||
336 | string linkPartName = "linkpart"; | ||
337 | UUID linkPartUuid = new UUID("00000000-0000-0000-0001-000000000000"); | ||
338 | |||
339 | SceneObjectPart rootPart | ||
340 | = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) | ||
341 | { Name = rootPartName, UUID = rootPartUuid }; | ||
342 | |||
343 | SceneObjectPart linkPart | ||
344 | = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) | ||
345 | { Name = linkPartName, UUID = linkPartUuid }; | ||
346 | SceneObjectGroup linkGroup = new SceneObjectGroup(linkPart); | ||
347 | scene.AddNewSceneObject(linkGroup, true); | ||
348 | |||
349 | SceneObjectGroup sog = new SceneObjectGroup(rootPart); | ||
350 | scene.AddNewSceneObject(sog, true); | ||
351 | |||
352 | Assert.IsFalse(sog.GroupContainsForeignPrims); | ||
353 | sog.LinkToGroup(linkGroup); | ||
354 | Assert.IsTrue(sog.GroupContainsForeignPrims); | ||
355 | |||
356 | scene.Backup(true); | ||
357 | Assert.AreEqual(1, scene.SimulationDataService.LoadObjects(scene.RegionInfo.RegionID).Count); | ||
358 | |||
359 | // These changes should occur immediately without waiting for a backup pass | ||
360 | SceneObjectGroup groupToDelete = sog.DelinkFromGroup(linkPart, false); | ||
361 | Assert.IsFalse(groupToDelete.GroupContainsForeignPrims); | ||
362 | |||
363 | scene.DeleteSceneObject(groupToDelete, false); | ||
364 | |||
365 | List<SceneObjectGroup> storedObjects = scene.SimulationDataService.LoadObjects(scene.RegionInfo.RegionID); | ||
366 | |||
367 | Assert.AreEqual(1, storedObjects.Count); | ||
368 | Assert.AreEqual(1, storedObjects[0].Parts.Length); | ||
369 | Assert.IsTrue(storedObjects[0].ContainsPart(rootPartUuid)); | ||
370 | } | ||
371 | } | ||
372 | } | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs new file mode 100644 index 0000000..11e9084 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs | |||
@@ -0,0 +1,101 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Reflection; | ||
30 | using NUnit.Framework; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Framework.Communications; | ||
34 | using OpenSim.Region.Framework.Scenes; | ||
35 | using OpenSim.Tests.Common; | ||
36 | |||
37 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
38 | { | ||
39 | /// <summary> | ||
40 | /// Basic scene object resize tests | ||
41 | /// </summary> | ||
42 | [TestFixture] | ||
43 | public class SceneObjectResizeTests : OpenSimTestCase | ||
44 | { | ||
45 | /// <summary> | ||
46 | /// Test resizing an object | ||
47 | /// </summary> | ||
48 | [Test] | ||
49 | public void TestResizeSceneObject() | ||
50 | { | ||
51 | TestHelpers.InMethod(); | ||
52 | // log4net.Config.XmlConfigurator.Configure(); | ||
53 | |||
54 | Scene scene = new SceneHelpers().SetupScene(); | ||
55 | SceneObjectGroup g1 = SceneHelpers.AddSceneObject(scene); | ||
56 | |||
57 | g1.GroupResize(new Vector3(2, 3, 4)); | ||
58 | |||
59 | SceneObjectGroup g1Post = scene.GetSceneObjectGroup(g1.UUID); | ||
60 | |||
61 | Assert.That(g1Post.RootPart.Scale.X, Is.EqualTo(2)); | ||
62 | Assert.That(g1Post.RootPart.Scale.Y, Is.EqualTo(3)); | ||
63 | Assert.That(g1Post.RootPart.Scale.Z, Is.EqualTo(4)); | ||
64 | } | ||
65 | |||
66 | /// <summary> | ||
67 | /// Test resizing an individual part in a scene object. | ||
68 | /// </summary> | ||
69 | [Test] | ||
70 | public void TestResizeSceneObjectPart() | ||
71 | { | ||
72 | TestHelpers.InMethod(); | ||
73 | //log4net.Config.XmlConfigurator.Configure(); | ||
74 | |||
75 | Scene scene = new SceneHelpers().SetupScene(); | ||
76 | |||
77 | SceneObjectGroup g1 = SceneHelpers.CreateSceneObject(2, UUID.Zero); | ||
78 | g1.RootPart.Scale = new Vector3(2, 3, 4); | ||
79 | g1.Parts[1].Scale = new Vector3(5, 6, 7); | ||
80 | |||
81 | scene.AddSceneObject(g1); | ||
82 | |||
83 | SceneObjectGroup g1Post = scene.GetSceneObjectGroup(g1.UUID); | ||
84 | |||
85 | g1Post.Parts[1].Resize(new Vector3(8, 9, 10)); | ||
86 | |||
87 | SceneObjectGroup g1PostPost = scene.GetSceneObjectGroup(g1.UUID); | ||
88 | |||
89 | SceneObjectPart g1RootPart = g1PostPost.RootPart; | ||
90 | SceneObjectPart g1ChildPart = g1PostPost.Parts[1]; | ||
91 | |||
92 | Assert.That(g1RootPart.Scale.X, Is.EqualTo(2)); | ||
93 | Assert.That(g1RootPart.Scale.Y, Is.EqualTo(3)); | ||
94 | Assert.That(g1RootPart.Scale.Z, Is.EqualTo(4)); | ||
95 | |||
96 | Assert.That(g1ChildPart.Scale.X, Is.EqualTo(8)); | ||
97 | Assert.That(g1ChildPart.Scale.Y, Is.EqualTo(9)); | ||
98 | Assert.That(g1ChildPart.Scale.Z, Is.EqualTo(10)); | ||
99 | } | ||
100 | } | ||
101 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectScriptTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectScriptTests.cs new file mode 100644 index 0000000..fdbe7ae --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectScriptTests.cs | |||
@@ -0,0 +1,75 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using NUnit.Framework; | ||
32 | using OpenMetaverse; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Framework.Communications; | ||
35 | using OpenSim.Region.Framework.Interfaces; | ||
36 | using OpenSim.Region.Framework.Scenes; | ||
37 | using OpenSim.Tests.Common; | ||
38 | |||
39 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
40 | { | ||
41 | [TestFixture] | ||
42 | public class SceneObjectScriptTests : OpenSimTestCase | ||
43 | { | ||
44 | [Test] | ||
45 | public void TestAddScript() | ||
46 | { | ||
47 | TestHelpers.InMethod(); | ||
48 | // log4net.Config.XmlConfigurator.Configure(); | ||
49 | |||
50 | UUID userId = TestHelpers.ParseTail(0x1); | ||
51 | // UUID itemId = TestHelpers.ParseTail(0x2); | ||
52 | string itemName = "Test Script Item"; | ||
53 | |||
54 | Scene scene = new SceneHelpers().SetupScene(); | ||
55 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId); | ||
56 | scene.AddNewSceneObject(so, true); | ||
57 | |||
58 | InventoryItemBase itemTemplate = new InventoryItemBase(); | ||
59 | itemTemplate.Name = itemName; | ||
60 | itemTemplate.Folder = so.UUID; | ||
61 | itemTemplate.InvType = (int)InventoryType.LSL; | ||
62 | |||
63 | SceneObjectPart partWhereScriptAdded = scene.RezNewScript(userId, itemTemplate); | ||
64 | |||
65 | Assert.That(partWhereScriptAdded, Is.Not.Null); | ||
66 | |||
67 | IEntityInventory primInventory = partWhereScriptAdded.Inventory; | ||
68 | Assert.That(primInventory.GetInventoryList().Count, Is.EqualTo(1)); | ||
69 | Assert.That(primInventory.ContainsScripts(), Is.True); | ||
70 | |||
71 | IList<TaskInventoryItem> primItems = primInventory.GetInventoryItems(itemName); | ||
72 | Assert.That(primItems.Count, Is.EqualTo(1)); | ||
73 | } | ||
74 | } | ||
75 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSerializationTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSerializationTests.cs new file mode 100644 index 0000000..927d8e8 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSerializationTests.cs | |||
@@ -0,0 +1,136 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Threading; | ||
32 | using System.Xml; | ||
33 | using System.Linq; | ||
34 | using Nini.Config; | ||
35 | using NUnit.Framework; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Serialization.External; | ||
39 | using OpenSim.Framework.Communications; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | using OpenSim.Region.Framework.Scenes.Serialization; | ||
42 | using OpenSim.Services.Interfaces; | ||
43 | using OpenSim.Tests.Common; | ||
44 | |||
45 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
46 | { | ||
47 | /// <summary> | ||
48 | /// Basic scene object serialization tests. | ||
49 | /// </summary> | ||
50 | [TestFixture] | ||
51 | public class SceneObjectSerializationTests : OpenSimTestCase | ||
52 | { | ||
53 | |||
54 | /// <summary> | ||
55 | /// Serialize and deserialize. | ||
56 | /// </summary> | ||
57 | [Test] | ||
58 | public void TestSerialDeserial() | ||
59 | { | ||
60 | TestHelpers.InMethod(); | ||
61 | |||
62 | Scene scene = new SceneHelpers().SetupScene(); | ||
63 | int partsToTestCount = 3; | ||
64 | |||
65 | SceneObjectGroup so | ||
66 | = SceneHelpers.CreateSceneObject(partsToTestCount, TestHelpers.ParseTail(0x1), "obj1", 0x10); | ||
67 | SceneObjectPart[] parts = so.Parts; | ||
68 | so.Name = "obj1"; | ||
69 | so.Description = "xpto"; | ||
70 | |||
71 | string xml = SceneObjectSerializer.ToXml2Format(so); | ||
72 | Assert.That(!string.IsNullOrEmpty(xml), "SOG serialization resulted in empty or null string"); | ||
73 | |||
74 | XmlDocument doc = new XmlDocument(); | ||
75 | doc.LoadXml(xml); | ||
76 | XmlNodeList nodes = doc.GetElementsByTagName("SceneObjectPart"); | ||
77 | Assert.That(nodes.Count, Is.EqualTo(3), "SOG serialization resulted in wrong number of SOPs"); | ||
78 | |||
79 | SceneObjectGroup so2 = SceneObjectSerializer.FromXml2Format(xml); | ||
80 | Assert.IsNotNull(so2, "SOG deserialization resulted in null object"); | ||
81 | Assert.That(so2.Name == so.Name, "Name of deserialized object does not match original name"); | ||
82 | Assert.That(so2.Description == so.Description, "Description of deserialized object does not match original name"); | ||
83 | } | ||
84 | |||
85 | /// <summary> | ||
86 | /// This checks for a bug reported in mantis #7514 | ||
87 | /// </summary> | ||
88 | [Test] | ||
89 | public void TestNamespaceAttribute() | ||
90 | { | ||
91 | TestHelpers.InMethod(); | ||
92 | |||
93 | Scene scene = new SceneHelpers().SetupScene(); | ||
94 | UserAccount account = new UserAccount(UUID.Zero, UUID.Random(), "Test", "User", string.Empty); | ||
95 | scene.UserAccountService.StoreUserAccount(account); | ||
96 | int partsToTestCount = 1; | ||
97 | |||
98 | SceneObjectGroup so | ||
99 | = SceneHelpers.CreateSceneObject(partsToTestCount, TestHelpers.ParseTail(0x1), "obj1", 0x10); | ||
100 | SceneObjectPart[] parts = so.Parts; | ||
101 | so.Name = "obj1"; | ||
102 | so.Description = "xpto"; | ||
103 | so.OwnerID = account.PrincipalID; | ||
104 | so.RootPart.CreatorID = so.OwnerID; | ||
105 | |||
106 | string xml = SceneObjectSerializer.ToXml2Format(so); | ||
107 | Assert.That(!string.IsNullOrEmpty(xml), "SOG serialization resulted in empty or null string"); | ||
108 | |||
109 | xml = ExternalRepresentationUtils.RewriteSOP(xml, "Test Scene", "http://localhost", scene.UserAccountService, UUID.Zero); | ||
110 | //Console.WriteLine(xml); | ||
111 | |||
112 | XmlDocument doc = new XmlDocument(); | ||
113 | doc.LoadXml(xml); | ||
114 | |||
115 | XmlNodeList nodes = doc.GetElementsByTagName("SceneObjectPart"); | ||
116 | Assert.That(nodes.Count, Is.GreaterThan(0), "SOG serialization resulted in no SOPs"); | ||
117 | foreach (XmlAttribute a in nodes[0].Attributes) | ||
118 | { | ||
119 | int count = a.Name.Count(c => c == ':'); | ||
120 | Assert.That(count, Is.EqualTo(1), "Cannot have multiple ':' in attribute name in SOP"); | ||
121 | } | ||
122 | nodes = doc.GetElementsByTagName("CreatorData"); | ||
123 | Assert.That(nodes.Count, Is.GreaterThan(0), "SOG serialization resulted in no CreatorData"); | ||
124 | foreach (XmlAttribute a in nodes[0].Attributes) | ||
125 | { | ||
126 | int count = a.Name.Count(c => c == ':'); | ||
127 | Assert.That(count, Is.EqualTo(1), "Cannot have multiple ':' in attribute name in CreatorData"); | ||
128 | } | ||
129 | |||
130 | SceneObjectGroup so2 = SceneObjectSerializer.FromXml2Format(xml); | ||
131 | Assert.IsNotNull(so2, "SOG deserialization resulted in null object"); | ||
132 | Assert.AreNotEqual(so.RootPart.CreatorIdentification, so2.RootPart.CreatorIdentification, "RewriteSOP failed to transform CreatorData."); | ||
133 | Assert.That(so2.RootPart.CreatorIdentification.Contains("http://"), "RewriteSOP failed to add the homeURL to CreatorData"); | ||
134 | } | ||
135 | } | ||
136 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs new file mode 100644 index 0000000..974529a --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs | |||
@@ -0,0 +1,155 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Reflection; | ||
30 | using System.Threading; | ||
31 | using NUnit.Framework; | ||
32 | using OpenMetaverse; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Framework.Communications; | ||
35 | using OpenSim.Region.Framework.Scenes; | ||
36 | using OpenSim.Tests.Common; | ||
37 | |||
38 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// Spatial scene object tests (will eventually cover root and child part position, rotation properties, etc.) | ||
42 | /// </summary> | ||
43 | [TestFixture] | ||
44 | public class SceneObjectSpatialTests : OpenSimTestCase | ||
45 | { | ||
46 | TestScene m_scene; | ||
47 | UUID m_ownerId = TestHelpers.ParseTail(0x1); | ||
48 | |||
49 | [SetUp] | ||
50 | public override void SetUp() | ||
51 | { | ||
52 | base.SetUp(); | ||
53 | |||
54 | m_scene = new SceneHelpers().SetupScene(); | ||
55 | } | ||
56 | |||
57 | [Test] | ||
58 | public void TestGetSceneObjectGroupPosition() | ||
59 | { | ||
60 | TestHelpers.InMethod(); | ||
61 | |||
62 | Vector3 position = new Vector3(10, 20, 30); | ||
63 | |||
64 | SceneObjectGroup so | ||
65 | = SceneHelpers.CreateSceneObject(1, m_ownerId, "obj1", 0x10); | ||
66 | so.AbsolutePosition = position; | ||
67 | m_scene.AddNewSceneObject(so, false); | ||
68 | |||
69 | Assert.That(so.AbsolutePosition, Is.EqualTo(position)); | ||
70 | } | ||
71 | |||
72 | [Test] | ||
73 | public void TestGetRootPartPosition() | ||
74 | { | ||
75 | TestHelpers.InMethod(); | ||
76 | |||
77 | Vector3 partPosition = new Vector3(10, 20, 30); | ||
78 | |||
79 | SceneObjectGroup so | ||
80 | = SceneHelpers.CreateSceneObject(1, m_ownerId, "obj1", 0x10); | ||
81 | so.AbsolutePosition = partPosition; | ||
82 | m_scene.AddNewSceneObject(so, false); | ||
83 | |||
84 | Assert.That(so.RootPart.AbsolutePosition, Is.EqualTo(partPosition)); | ||
85 | Assert.That(so.RootPart.GroupPosition, Is.EqualTo(partPosition)); | ||
86 | Assert.That(so.RootPart.GetWorldPosition(), Is.EqualTo(partPosition)); | ||
87 | Assert.That(so.RootPart.RelativePosition, Is.EqualTo(partPosition)); | ||
88 | Assert.That(so.RootPart.OffsetPosition, Is.EqualTo(Vector3.Zero)); | ||
89 | } | ||
90 | |||
91 | [Test] | ||
92 | public void TestGetChildPartPosition() | ||
93 | { | ||
94 | TestHelpers.InMethod(); | ||
95 | |||
96 | Vector3 rootPartPosition = new Vector3(10, 20, 30); | ||
97 | Vector3 childOffsetPosition = new Vector3(2, 3, 4); | ||
98 | |||
99 | SceneObjectGroup so | ||
100 | = SceneHelpers.CreateSceneObject(2, m_ownerId, "obj1", 0x10); | ||
101 | so.AbsolutePosition = rootPartPosition; | ||
102 | so.Parts[1].OffsetPosition = childOffsetPosition; | ||
103 | |||
104 | m_scene.AddNewSceneObject(so, false); | ||
105 | |||
106 | // Calculate child absolute position. | ||
107 | Vector3 childPosition = new Vector3(rootPartPosition + childOffsetPosition); | ||
108 | |||
109 | SceneObjectPart childPart = so.Parts[1]; | ||
110 | Assert.That(childPart.AbsolutePosition, Is.EqualTo(childPosition)); | ||
111 | Assert.That(childPart.GroupPosition, Is.EqualTo(rootPartPosition)); | ||
112 | Assert.That(childPart.GetWorldPosition(), Is.EqualTo(childPosition)); | ||
113 | Assert.That(childPart.RelativePosition, Is.EqualTo(childOffsetPosition)); | ||
114 | Assert.That(childPart.OffsetPosition, Is.EqualTo(childOffsetPosition)); | ||
115 | } | ||
116 | |||
117 | [Test] | ||
118 | public void TestGetChildPartPositionAfterObjectRotation() | ||
119 | { | ||
120 | TestHelpers.InMethod(); | ||
121 | |||
122 | Vector3 rootPartPosition = new Vector3(10, 20, 30); | ||
123 | Vector3 childOffsetPosition = new Vector3(2, 3, 4); | ||
124 | |||
125 | SceneObjectGroup so | ||
126 | = SceneHelpers.CreateSceneObject(2, m_ownerId, "obj1", 0x10); | ||
127 | so.AbsolutePosition = rootPartPosition; | ||
128 | so.Parts[1].OffsetPosition = childOffsetPosition; | ||
129 | |||
130 | m_scene.AddNewSceneObject(so, false); | ||
131 | |||
132 | so.UpdateGroupRotationR(Quaternion.CreateFromEulers(0, 0, -90 * Utils.DEG_TO_RAD)); | ||
133 | |||
134 | // Calculate child absolute position. | ||
135 | Vector3 rotatedChildOffsetPosition | ||
136 | = new Vector3(childOffsetPosition.Y, -childOffsetPosition.X, childOffsetPosition.Z); | ||
137 | |||
138 | Vector3 childPosition = new Vector3(rootPartPosition + rotatedChildOffsetPosition); | ||
139 | |||
140 | SceneObjectPart childPart = so.Parts[1]; | ||
141 | |||
142 | // FIXME: Should be childPosition after rotation? | ||
143 | Assert.That(childPart.AbsolutePosition, Is.EqualTo(rootPartPosition + childOffsetPosition)); | ||
144 | |||
145 | Assert.That(childPart.GroupPosition, Is.EqualTo(rootPartPosition)); | ||
146 | Assert.That(childPart.GetWorldPosition(), Is.EqualTo(childPosition)); | ||
147 | |||
148 | // Relative to root part as (0, 0, 0) | ||
149 | Assert.That(childPart.RelativePosition, Is.EqualTo(childOffsetPosition)); | ||
150 | |||
151 | // Relative to root part as (0, 0, 0) | ||
152 | Assert.That(childPart.OffsetPosition, Is.EqualTo(childOffsetPosition)); | ||
153 | } | ||
154 | } | ||
155 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectStatusTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectStatusTests.cs new file mode 100644 index 0000000..5ba754c --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectStatusTests.cs | |||
@@ -0,0 +1,241 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using NUnit.Framework; | ||
32 | using OpenMetaverse; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Framework.Communications; | ||
35 | using OpenSim.Region.Framework.Scenes; | ||
36 | using OpenSim.Tests.Common; | ||
37 | |||
38 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// Basic scene object status tests | ||
42 | /// </summary> | ||
43 | [TestFixture] | ||
44 | public class SceneObjectStatusTests : OpenSimTestCase | ||
45 | { | ||
46 | private TestScene m_scene; | ||
47 | private UUID m_ownerId = TestHelpers.ParseTail(0x1); | ||
48 | private SceneObjectGroup m_so1; | ||
49 | private SceneObjectGroup m_so2; | ||
50 | |||
51 | [SetUp] | ||
52 | public void Init() | ||
53 | { | ||
54 | m_scene = new SceneHelpers().SetupScene(); | ||
55 | m_so1 = SceneHelpers.CreateSceneObject(1, m_ownerId, "so1", 0x10); | ||
56 | m_so2 = SceneHelpers.CreateSceneObject(1, m_ownerId, "so2", 0x20); | ||
57 | } | ||
58 | |||
59 | [Test] | ||
60 | public void TestSetTemporary() | ||
61 | { | ||
62 | TestHelpers.InMethod(); | ||
63 | |||
64 | m_scene.AddSceneObject(m_so1); | ||
65 | m_so1.ScriptSetTemporaryStatus(true); | ||
66 | |||
67 | // Is this really the correct flag? | ||
68 | Assert.That(m_so1.RootPart.Flags, Is.EqualTo(PrimFlags.TemporaryOnRez)); | ||
69 | Assert.That(m_so1.Backup, Is.False); | ||
70 | |||
71 | // Test setting back to non-temporary | ||
72 | m_so1.ScriptSetTemporaryStatus(false); | ||
73 | |||
74 | Assert.That(m_so1.RootPart.Flags, Is.EqualTo(PrimFlags.None)); | ||
75 | Assert.That(m_so1.Backup, Is.True); | ||
76 | } | ||
77 | |||
78 | [Test] | ||
79 | public void TestSetPhantomSinglePrim() | ||
80 | { | ||
81 | TestHelpers.InMethod(); | ||
82 | |||
83 | m_scene.AddSceneObject(m_so1); | ||
84 | |||
85 | SceneObjectPart rootPart = m_so1.RootPart; | ||
86 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.None)); | ||
87 | |||
88 | m_so1.ScriptSetPhantomStatus(true); | ||
89 | |||
90 | // Console.WriteLine("so.RootPart.Flags [{0}]", so.RootPart.Flags); | ||
91 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.Phantom)); | ||
92 | |||
93 | m_so1.ScriptSetPhantomStatus(false); | ||
94 | |||
95 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.None)); | ||
96 | } | ||
97 | |||
98 | [Test] | ||
99 | public void TestSetNonPhysicsVolumeDetectSinglePrim() | ||
100 | { | ||
101 | TestHelpers.InMethod(); | ||
102 | |||
103 | m_scene.AddSceneObject(m_so1); | ||
104 | |||
105 | SceneObjectPart rootPart = m_so1.RootPart; | ||
106 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.None)); | ||
107 | |||
108 | m_so1.ScriptSetVolumeDetect(true); | ||
109 | |||
110 | // Console.WriteLine("so.RootPart.Flags [{0}]", so.RootPart.Flags); | ||
111 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.Phantom)); | ||
112 | |||
113 | m_so1.ScriptSetVolumeDetect(false); | ||
114 | |||
115 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.None)); | ||
116 | } | ||
117 | |||
118 | [Test] | ||
119 | public void TestSetPhysicsSinglePrim() | ||
120 | { | ||
121 | TestHelpers.InMethod(); | ||
122 | |||
123 | m_scene.AddSceneObject(m_so1); | ||
124 | |||
125 | SceneObjectPart rootPart = m_so1.RootPart; | ||
126 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.None)); | ||
127 | |||
128 | m_so1.ScriptSetPhysicsStatus(true); | ||
129 | |||
130 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.Physics)); | ||
131 | |||
132 | m_so1.ScriptSetPhysicsStatus(false); | ||
133 | |||
134 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.None)); | ||
135 | } | ||
136 | |||
137 | [Test] | ||
138 | public void TestSetPhysicsVolumeDetectSinglePrim() | ||
139 | { | ||
140 | TestHelpers.InMethod(); | ||
141 | |||
142 | m_scene.AddSceneObject(m_so1); | ||
143 | |||
144 | SceneObjectPart rootPart = m_so1.RootPart; | ||
145 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.None)); | ||
146 | |||
147 | m_so1.ScriptSetPhysicsStatus(true); | ||
148 | m_so1.ScriptSetVolumeDetect(true); | ||
149 | |||
150 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.Phantom | PrimFlags.Physics)); | ||
151 | |||
152 | m_so1.ScriptSetVolumeDetect(false); | ||
153 | |||
154 | Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.Physics)); | ||
155 | } | ||
156 | |||
157 | [Test] | ||
158 | public void TestSetPhysicsLinkset() | ||
159 | { | ||
160 | TestHelpers.InMethod(); | ||
161 | |||
162 | m_scene.AddSceneObject(m_so1); | ||
163 | m_scene.AddSceneObject(m_so2); | ||
164 | |||
165 | m_scene.LinkObjects(m_ownerId, m_so1.LocalId, new List<uint>() { m_so2.LocalId }); | ||
166 | |||
167 | m_so1.ScriptSetPhysicsStatus(true); | ||
168 | |||
169 | Assert.That(m_so1.RootPart.Flags, Is.EqualTo(PrimFlags.Physics)); | ||
170 | Assert.That(m_so1.Parts[1].Flags, Is.EqualTo(PrimFlags.Physics)); | ||
171 | |||
172 | m_so1.ScriptSetPhysicsStatus(false); | ||
173 | |||
174 | Assert.That(m_so1.RootPart.Flags, Is.EqualTo(PrimFlags.None)); | ||
175 | Assert.That(m_so1.Parts[1].Flags, Is.EqualTo(PrimFlags.None)); | ||
176 | |||
177 | m_so1.ScriptSetPhysicsStatus(true); | ||
178 | |||
179 | Assert.That(m_so1.RootPart.Flags, Is.EqualTo(PrimFlags.Physics)); | ||
180 | Assert.That(m_so1.Parts[1].Flags, Is.EqualTo(PrimFlags.Physics)); | ||
181 | } | ||
182 | |||
183 | /// <summary> | ||
184 | /// Test that linking results in the correct physical status for all linkees. | ||
185 | /// </summary> | ||
186 | [Test] | ||
187 | public void TestLinkPhysicsBothPhysical() | ||
188 | { | ||
189 | TestHelpers.InMethod(); | ||
190 | |||
191 | m_scene.AddSceneObject(m_so1); | ||
192 | m_scene.AddSceneObject(m_so2); | ||
193 | |||
194 | m_so1.ScriptSetPhysicsStatus(true); | ||
195 | m_so2.ScriptSetPhysicsStatus(true); | ||
196 | |||
197 | m_scene.LinkObjects(m_ownerId, m_so1.LocalId, new List<uint>() { m_so2.LocalId }); | ||
198 | |||
199 | Assert.That(m_so1.RootPart.Flags, Is.EqualTo(PrimFlags.Physics)); | ||
200 | Assert.That(m_so1.Parts[1].Flags, Is.EqualTo(PrimFlags.Physics)); | ||
201 | } | ||
202 | |||
203 | /// <summary> | ||
204 | /// Test that linking results in the correct physical status for all linkees. | ||
205 | /// </summary> | ||
206 | [Test] | ||
207 | public void TestLinkPhysicsRootPhysicalOnly() | ||
208 | { | ||
209 | TestHelpers.InMethod(); | ||
210 | |||
211 | m_scene.AddSceneObject(m_so1); | ||
212 | m_scene.AddSceneObject(m_so2); | ||
213 | |||
214 | m_so1.ScriptSetPhysicsStatus(true); | ||
215 | |||
216 | m_scene.LinkObjects(m_ownerId, m_so1.LocalId, new List<uint>() { m_so2.LocalId }); | ||
217 | |||
218 | Assert.That(m_so1.RootPart.Flags, Is.EqualTo(PrimFlags.Physics)); | ||
219 | Assert.That(m_so1.Parts[1].Flags, Is.EqualTo(PrimFlags.Physics)); | ||
220 | } | ||
221 | |||
222 | /// <summary> | ||
223 | /// Test that linking results in the correct physical status for all linkees. | ||
224 | /// </summary> | ||
225 | [Test] | ||
226 | public void TestLinkPhysicsChildPhysicalOnly() | ||
227 | { | ||
228 | TestHelpers.InMethod(); | ||
229 | |||
230 | m_scene.AddSceneObject(m_so1); | ||
231 | m_scene.AddSceneObject(m_so2); | ||
232 | |||
233 | m_so2.ScriptSetPhysicsStatus(true); | ||
234 | |||
235 | m_scene.LinkObjects(m_ownerId, m_so1.LocalId, new List<uint>() { m_so2.LocalId }); | ||
236 | |||
237 | Assert.That(m_so1.RootPart.Flags, Is.EqualTo(PrimFlags.None)); | ||
238 | Assert.That(m_so1.Parts[1].Flags, Is.EqualTo(PrimFlags.None)); | ||
239 | } | ||
240 | } | ||
241 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectUndoRedoTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectUndoRedoTests.cs new file mode 100644 index 0000000..cdebe25 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectUndoRedoTests.cs | |||
@@ -0,0 +1,183 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Reflection; | ||
30 | using NUnit.Framework; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Framework.Communications; | ||
34 | using OpenSim.Region.Framework.Scenes; | ||
35 | using OpenSim.Tests.Common; | ||
36 | |||
37 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
38 | { | ||
39 | /// <summary> | ||
40 | /// Tests for undo/redo | ||
41 | /// </summary> | ||
42 | public class SceneObjectUndoRedoTests : OpenSimTestCase | ||
43 | { | ||
44 | [Test] | ||
45 | public void TestUndoRedoResizeSceneObject() | ||
46 | { | ||
47 | TestHelpers.InMethod(); | ||
48 | // TestHelpers.EnableLogging(); | ||
49 | |||
50 | Vector3 firstSize = new Vector3(2, 3, 4); | ||
51 | Vector3 secondSize = new Vector3(5, 6, 7); | ||
52 | |||
53 | Scene scene = new SceneHelpers().SetupScene(); | ||
54 | scene.MaxUndoCount = 20; | ||
55 | SceneObjectGroup g1 = SceneHelpers.AddSceneObject(scene); | ||
56 | |||
57 | // TODO: It happens to be the case that we are not storing undo states for SOPs which are not yet in a SOG, | ||
58 | // which is the way that AddSceneObject() sets up the object (i.e. it creates the SOP first). However, | ||
59 | // this is somewhat by chance. Really, we shouldn't be storing undo states at all if the object is not | ||
60 | // in a scene. | ||
61 | Assert.That(g1.RootPart.UndoCount, Is.EqualTo(0)); | ||
62 | |||
63 | g1.GroupResize(firstSize); | ||
64 | Assert.That(g1.RootPart.UndoCount, Is.EqualTo(1)); | ||
65 | |||
66 | g1.GroupResize(secondSize); | ||
67 | Assert.That(g1.RootPart.UndoCount, Is.EqualTo(2)); | ||
68 | |||
69 | g1.RootPart.Undo(); | ||
70 | Assert.That(g1.RootPart.UndoCount, Is.EqualTo(1)); | ||
71 | Assert.That(g1.GroupScale, Is.EqualTo(firstSize)); | ||
72 | |||
73 | g1.RootPart.Redo(); | ||
74 | Assert.That(g1.RootPart.UndoCount, Is.EqualTo(2)); | ||
75 | Assert.That(g1.GroupScale, Is.EqualTo(secondSize)); | ||
76 | } | ||
77 | |||
78 | [Test] | ||
79 | public void TestUndoLimit() | ||
80 | { | ||
81 | TestHelpers.InMethod(); | ||
82 | |||
83 | Vector3 firstSize = new Vector3(2, 3, 4); | ||
84 | Vector3 secondSize = new Vector3(5, 6, 7); | ||
85 | Vector3 thirdSize = new Vector3(8, 9, 10); | ||
86 | Vector3 fourthSize = new Vector3(11, 12, 13); | ||
87 | |||
88 | Scene scene = new SceneHelpers().SetupScene(); | ||
89 | scene.MaxUndoCount = 2; | ||
90 | SceneObjectGroup g1 = SceneHelpers.AddSceneObject(scene); | ||
91 | |||
92 | g1.GroupResize(firstSize); | ||
93 | g1.GroupResize(secondSize); | ||
94 | g1.GroupResize(thirdSize); | ||
95 | g1.GroupResize(fourthSize); | ||
96 | |||
97 | g1.RootPart.Undo(); | ||
98 | g1.RootPart.Undo(); | ||
99 | g1.RootPart.Undo(); | ||
100 | |||
101 | Assert.That(g1.RootPart.UndoCount, Is.EqualTo(0)); | ||
102 | Assert.That(g1.GroupScale, Is.EqualTo(secondSize)); | ||
103 | } | ||
104 | |||
105 | [Test] | ||
106 | public void TestNoUndoOnObjectsNotInScene() | ||
107 | { | ||
108 | TestHelpers.InMethod(); | ||
109 | |||
110 | Vector3 firstSize = new Vector3(2, 3, 4); | ||
111 | Vector3 secondSize = new Vector3(5, 6, 7); | ||
112 | // Vector3 thirdSize = new Vector3(8, 9, 10); | ||
113 | // Vector3 fourthSize = new Vector3(11, 12, 13); | ||
114 | |||
115 | Scene scene = new SceneHelpers().SetupScene(); | ||
116 | scene.MaxUndoCount = 20; | ||
117 | SceneObjectGroup g1 = SceneHelpers.CreateSceneObject(1, TestHelpers.ParseTail(0x1)); | ||
118 | |||
119 | g1.GroupResize(firstSize); | ||
120 | g1.GroupResize(secondSize); | ||
121 | |||
122 | Assert.That(g1.RootPart.UndoCount, Is.EqualTo(0)); | ||
123 | |||
124 | g1.RootPart.Undo(); | ||
125 | |||
126 | Assert.That(g1.GroupScale, Is.EqualTo(secondSize)); | ||
127 | } | ||
128 | |||
129 | [Test] | ||
130 | public void TestUndoBeyondAvailable() | ||
131 | { | ||
132 | TestHelpers.InMethod(); | ||
133 | |||
134 | Vector3 newSize = new Vector3(2, 3, 4); | ||
135 | |||
136 | Scene scene = new SceneHelpers().SetupScene(); | ||
137 | scene.MaxUndoCount = 20; | ||
138 | SceneObjectGroup g1 = SceneHelpers.AddSceneObject(scene); | ||
139 | Vector3 originalSize = g1.GroupScale; | ||
140 | |||
141 | g1.RootPart.Undo(); | ||
142 | |||
143 | Assert.That(g1.RootPart.UndoCount, Is.EqualTo(0)); | ||
144 | Assert.That(g1.GroupScale, Is.EqualTo(originalSize)); | ||
145 | |||
146 | g1.GroupResize(newSize); | ||
147 | Assert.That(g1.RootPart.UndoCount, Is.EqualTo(1)); | ||
148 | Assert.That(g1.GroupScale, Is.EqualTo(newSize)); | ||
149 | |||
150 | g1.RootPart.Undo(); | ||
151 | g1.RootPart.Undo(); | ||
152 | |||
153 | Assert.That(g1.RootPart.UndoCount, Is.EqualTo(0)); | ||
154 | Assert.That(g1.GroupScale, Is.EqualTo(originalSize)); | ||
155 | } | ||
156 | |||
157 | [Test] | ||
158 | public void TestRedoBeyondAvailable() | ||
159 | { | ||
160 | TestHelpers.InMethod(); | ||
161 | |||
162 | Vector3 newSize = new Vector3(2, 3, 4); | ||
163 | |||
164 | Scene scene = new SceneHelpers().SetupScene(); | ||
165 | scene.MaxUndoCount = 20; | ||
166 | SceneObjectGroup g1 = SceneHelpers.AddSceneObject(scene); | ||
167 | Vector3 originalSize = g1.GroupScale; | ||
168 | |||
169 | g1.RootPart.Redo(); | ||
170 | |||
171 | Assert.That(g1.RootPart.UndoCount, Is.EqualTo(0)); | ||
172 | Assert.That(g1.GroupScale, Is.EqualTo(originalSize)); | ||
173 | |||
174 | g1.GroupResize(newSize); | ||
175 | g1.RootPart.Undo(); | ||
176 | g1.RootPart.Redo(); | ||
177 | g1.RootPart.Redo(); | ||
178 | |||
179 | Assert.That(g1.RootPart.UndoCount, Is.EqualTo(1)); | ||
180 | Assert.That(g1.GroupScale, Is.EqualTo(newSize)); | ||
181 | } | ||
182 | } | ||
183 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectUserGroupTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectUserGroupTests.cs new file mode 100644 index 0000000..fd49c88 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectUserGroupTests.cs | |||
@@ -0,0 +1,83 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using Nini.Config; | ||
32 | using NUnit.Framework; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Region.CoreModules.Avatar.InstantMessage; | ||
37 | using OpenSim.Region.CoreModules.World.Permissions; | ||
38 | using OpenSim.Region.Framework.Interfaces; | ||
39 | using OpenSim.Region.Framework.Scenes; | ||
40 | using OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups; | ||
41 | using OpenSim.Tests.Common; | ||
42 | |||
43 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
44 | { | ||
45 | [TestFixture] | ||
46 | public class SceneObjectUserGroupTests : OpenSimTestCase | ||
47 | { | ||
48 | /// <summary> | ||
49 | /// Test share with group object functionality | ||
50 | /// </summary> | ||
51 | /// <remarks>This test is not yet fully implemented</remarks> | ||
52 | [Test] | ||
53 | public void TestShareWithGroup() | ||
54 | { | ||
55 | TestHelpers.InMethod(); | ||
56 | |||
57 | UUID userId = UUID.Parse("10000000-0000-0000-0000-000000000001"); | ||
58 | |||
59 | TestScene scene = new SceneHelpers().SetupScene(); | ||
60 | IConfigSource configSource = new IniConfigSource(); | ||
61 | |||
62 | IConfig startupConfig = configSource.AddConfig("Startup"); | ||
63 | startupConfig.Set("serverside_object_permissions", true); | ||
64 | |||
65 | IConfig groupsConfig = configSource.AddConfig("Groups"); | ||
66 | groupsConfig.Set("Enabled", true); | ||
67 | groupsConfig.Set("Module", "GroupsModule"); | ||
68 | groupsConfig.Set("DebugEnabled", true); | ||
69 | |||
70 | SceneHelpers.SetupSceneModules( | ||
71 | scene, configSource, new object[] | ||
72 | { new PermissionsModule(), | ||
73 | new GroupsModule(), | ||
74 | new MockGroupsServicesConnector() }); | ||
75 | |||
76 | IClientAPI client = SceneHelpers.AddScenePresence(scene, userId).ControllingClient; | ||
77 | |||
78 | IGroupsModule groupsModule = scene.RequestModuleInterface<IGroupsModule>(); | ||
79 | |||
80 | groupsModule.CreateGroup(client, "group1", "To boldly go", true, UUID.Zero, 5, true, true, true); | ||
81 | } | ||
82 | } | ||
83 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs new file mode 100644 index 0000000..06e6423 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs | |||
@@ -0,0 +1,291 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using System.Threading; | ||
33 | using System.Timers; | ||
34 | using Timer = System.Timers.Timer; | ||
35 | using Nini.Config; | ||
36 | using NUnit.Framework; | ||
37 | using OpenMetaverse; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Communications; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | using OpenSim.Region.Framework.Interfaces; | ||
42 | using OpenSim.Region.ClientStack.Linden; | ||
43 | using OpenSim.Region.CoreModules.Framework.EntityTransfer; | ||
44 | using OpenSim.Region.CoreModules.World.Serialiser; | ||
45 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; | ||
46 | using OpenSim.Tests.Common; | ||
47 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
48 | |||
49 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
50 | { | ||
51 | /// <summary> | ||
52 | /// Scene presence tests | ||
53 | /// </summary> | ||
54 | [TestFixture] | ||
55 | public class ScenePresenceAgentTests : OpenSimTestCase | ||
56 | { | ||
57 | // public Scene scene, scene2, scene3; | ||
58 | // public UUID agent1, agent2, agent3; | ||
59 | // public static Random random; | ||
60 | // public ulong region1, region2, region3; | ||
61 | // public AgentCircuitData acd1; | ||
62 | // public TestClient testclient; | ||
63 | |||
64 | // [TestFixtureSetUp] | ||
65 | // public void Init() | ||
66 | // { | ||
67 | //// TestHelpers.InMethod(); | ||
68 | //// | ||
69 | //// SceneHelpers sh = new SceneHelpers(); | ||
70 | //// | ||
71 | //// scene = sh.SetupScene("Neighbour x", UUID.Random(), 1000, 1000); | ||
72 | //// scene2 = sh.SetupScene("Neighbour x+1", UUID.Random(), 1001, 1000); | ||
73 | //// scene3 = sh.SetupScene("Neighbour x-1", UUID.Random(), 999, 1000); | ||
74 | //// | ||
75 | //// ISharedRegionModule interregionComms = new LocalSimulationConnectorModule(); | ||
76 | //// interregionComms.Initialise(new IniConfigSource()); | ||
77 | //// interregionComms.PostInitialise(); | ||
78 | //// SceneHelpers.SetupSceneModules(scene, new IniConfigSource(), interregionComms); | ||
79 | //// SceneHelpers.SetupSceneModules(scene2, new IniConfigSource(), interregionComms); | ||
80 | //// SceneHelpers.SetupSceneModules(scene3, new IniConfigSource(), interregionComms); | ||
81 | // | ||
82 | //// agent1 = UUID.Random(); | ||
83 | //// agent2 = UUID.Random(); | ||
84 | //// agent3 = UUID.Random(); | ||
85 | // | ||
86 | //// region1 = scene.RegionInfo.RegionHandle; | ||
87 | //// region2 = scene2.RegionInfo.RegionHandle; | ||
88 | //// region3 = scene3.RegionInfo.RegionHandle; | ||
89 | // } | ||
90 | |||
91 | [Test] | ||
92 | public void TestCreateRootScenePresence() | ||
93 | { | ||
94 | TestHelpers.InMethod(); | ||
95 | // TestHelpers.EnableLogging(); | ||
96 | |||
97 | UUID spUuid = TestHelpers.ParseTail(0x1); | ||
98 | |||
99 | TestScene scene = new SceneHelpers().SetupScene(); | ||
100 | SceneHelpers.AddScenePresence(scene, spUuid); | ||
101 | |||
102 | Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(spUuid), Is.Not.Null); | ||
103 | Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1)); | ||
104 | |||
105 | ScenePresence sp = scene.GetScenePresence(spUuid); | ||
106 | Assert.That(sp, Is.Not.Null); | ||
107 | Assert.That(sp.IsChildAgent, Is.False); | ||
108 | Assert.That(sp.UUID, Is.EqualTo(spUuid)); | ||
109 | |||
110 | Assert.That(scene.GetScenePresences().Count, Is.EqualTo(1)); | ||
111 | } | ||
112 | |||
113 | /// <summary> | ||
114 | /// Test that duplicate complete movement calls are ignored. | ||
115 | /// </summary> | ||
116 | /// <remarks> | ||
117 | /// If duplicate calls are not ignored then there is a risk of race conditions or other unexpected effects. | ||
118 | /// </remarks> | ||
119 | [Test] | ||
120 | public void TestDupeCompleteMovementCalls() | ||
121 | { | ||
122 | TestHelpers.InMethod(); | ||
123 | // TestHelpers.EnableLogging(); | ||
124 | |||
125 | UUID spUuid = TestHelpers.ParseTail(0x1); | ||
126 | |||
127 | TestScene scene = new SceneHelpers().SetupScene(); | ||
128 | |||
129 | int makeRootAgentEvents = 0; | ||
130 | scene.EventManager.OnMakeRootAgent += spi => makeRootAgentEvents++; | ||
131 | |||
132 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, spUuid); | ||
133 | |||
134 | Assert.That(makeRootAgentEvents, Is.EqualTo(1)); | ||
135 | |||
136 | // Normally these would be invoked by a CompleteMovement message coming in to the UDP stack. But for | ||
137 | // convenience, here we will invoke it manually. | ||
138 | sp.CompleteMovement(sp.ControllingClient, true); | ||
139 | |||
140 | Assert.That(makeRootAgentEvents, Is.EqualTo(1)); | ||
141 | |||
142 | // Check rest of exepcted parameters. | ||
143 | Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(spUuid), Is.Not.Null); | ||
144 | Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1)); | ||
145 | |||
146 | Assert.That(sp.IsChildAgent, Is.False); | ||
147 | Assert.That(sp.UUID, Is.EqualTo(spUuid)); | ||
148 | |||
149 | Assert.That(scene.GetScenePresences().Count, Is.EqualTo(1)); | ||
150 | } | ||
151 | |||
152 | [Test] | ||
153 | public void TestCreateDuplicateRootScenePresence() | ||
154 | { | ||
155 | TestHelpers.InMethod(); | ||
156 | // TestHelpers.EnableLogging(); | ||
157 | |||
158 | UUID spUuid = TestHelpers.ParseTail(0x1); | ||
159 | |||
160 | // The etm is only invoked by this test to check whether an agent is still in transit if there is a dupe | ||
161 | EntityTransferModule etm = new EntityTransferModule(); | ||
162 | |||
163 | IConfigSource config = new IniConfigSource(); | ||
164 | IConfig modulesConfig = config.AddConfig("Modules"); | ||
165 | modulesConfig.Set("EntityTransferModule", etm.Name); | ||
166 | IConfig entityTransferConfig = config.AddConfig("EntityTransfer"); | ||
167 | |||
168 | // In order to run a single threaded regression test we do not want the entity transfer module waiting | ||
169 | // for a callback from the destination scene before removing its avatar data. | ||
170 | entityTransferConfig.Set("wait_for_callback", false); | ||
171 | |||
172 | TestScene scene = new SceneHelpers().SetupScene(); | ||
173 | SceneHelpers.SetupSceneModules(scene, config, etm); | ||
174 | SceneHelpers.AddScenePresence(scene, spUuid); | ||
175 | SceneHelpers.AddScenePresence(scene, spUuid); | ||
176 | |||
177 | Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(spUuid), Is.Not.Null); | ||
178 | Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1)); | ||
179 | |||
180 | ScenePresence sp = scene.GetScenePresence(spUuid); | ||
181 | Assert.That(sp, Is.Not.Null); | ||
182 | Assert.That(sp.IsChildAgent, Is.False); | ||
183 | Assert.That(sp.UUID, Is.EqualTo(spUuid)); | ||
184 | } | ||
185 | |||
186 | [Test] | ||
187 | public void TestCloseClient() | ||
188 | { | ||
189 | TestHelpers.InMethod(); | ||
190 | // TestHelpers.EnableLogging(); | ||
191 | |||
192 | TestScene scene = new SceneHelpers().SetupScene(); | ||
193 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); | ||
194 | |||
195 | scene.CloseAgent(sp.UUID, false); | ||
196 | |||
197 | Assert.That(scene.GetScenePresence(sp.UUID), Is.Null); | ||
198 | Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(sp.UUID), Is.Null); | ||
199 | Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(0)); | ||
200 | |||
201 | // TestHelpers.DisableLogging(); | ||
202 | } | ||
203 | |||
204 | [Test] | ||
205 | public void TestCreateChildScenePresence() | ||
206 | { | ||
207 | TestHelpers.InMethod(); | ||
208 | // log4net.Config.XmlConfigurator.Configure(); | ||
209 | |||
210 | LocalSimulationConnectorModule lsc = new LocalSimulationConnectorModule(); | ||
211 | |||
212 | IConfigSource configSource = new IniConfigSource(); | ||
213 | IConfig config = configSource.AddConfig("Modules"); | ||
214 | config.Set("SimulationServices", "LocalSimulationConnectorModule"); | ||
215 | |||
216 | SceneHelpers sceneHelpers = new SceneHelpers(); | ||
217 | TestScene scene = sceneHelpers.SetupScene(); | ||
218 | SceneHelpers.SetupSceneModules(scene, configSource, lsc); | ||
219 | |||
220 | UUID agentId = TestHelpers.ParseTail(0x01); | ||
221 | AgentCircuitData acd = SceneHelpers.GenerateAgentData(agentId); | ||
222 | acd.child = true; | ||
223 | |||
224 | GridRegion region = scene.GridService.GetRegionByName(UUID.Zero, scene.RegionInfo.RegionName); | ||
225 | string reason; | ||
226 | |||
227 | // *** This is the first stage, when a neighbouring region is told that a viewer is about to try and | ||
228 | // establish a child scene presence. We pass in the circuit code that the client has to connect with *** | ||
229 | // XXX: ViaLogin may not be correct here. | ||
230 | scene.SimulationService.CreateAgent(null, region, acd, (uint)TeleportFlags.ViaLogin, out reason); | ||
231 | |||
232 | Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(agentId), Is.Not.Null); | ||
233 | Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1)); | ||
234 | |||
235 | // There's no scene presence yet since only an agent circuit has been established. | ||
236 | Assert.That(scene.GetScenePresence(agentId), Is.Null); | ||
237 | |||
238 | // *** This is the second stage, where the client established a child agent/scene presence using the | ||
239 | // circuit code given to the scene in stage 1 *** | ||
240 | TestClient client = new TestClient(acd, scene); | ||
241 | scene.AddNewAgent(client, PresenceType.User); | ||
242 | |||
243 | Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(agentId), Is.Not.Null); | ||
244 | Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1)); | ||
245 | |||
246 | ScenePresence sp = scene.GetScenePresence(agentId); | ||
247 | Assert.That(sp, Is.Not.Null); | ||
248 | Assert.That(sp.UUID, Is.EqualTo(agentId)); | ||
249 | Assert.That(sp.IsChildAgent, Is.True); | ||
250 | } | ||
251 | |||
252 | /// <summary> | ||
253 | /// Test that if a root agent logs into a region, a child agent is also established in the neighbouring region | ||
254 | /// </summary> | ||
255 | /// <remarks> | ||
256 | /// Please note that unlike the other tests here, this doesn't rely on anything set up in the instance fields. | ||
257 | /// INCOMPLETE | ||
258 | /// </remarks> | ||
259 | [Test] | ||
260 | public void TestChildAgentEstablishedInNeighbour() | ||
261 | { | ||
262 | TestHelpers.InMethod(); | ||
263 | // log4net.Config.XmlConfigurator.Configure(); | ||
264 | |||
265 | // UUID agent1Id = UUID.Parse("00000000-0000-0000-0000-000000000001"); | ||
266 | |||
267 | TestScene myScene1 = new SceneHelpers().SetupScene("Neighbour y", UUID.Random(), 1000, 1000); | ||
268 | TestScene myScene2 = new SceneHelpers().SetupScene("Neighbour y + 1", UUID.Random(), 1001, 1000); | ||
269 | |||
270 | IConfigSource configSource = new IniConfigSource(); | ||
271 | IConfig config = configSource.AddConfig("Startup"); | ||
272 | config.Set("serverside_object_permissions", true); | ||
273 | config.Set("EventQueue", true); | ||
274 | |||
275 | EntityTransferModule etm = new EntityTransferModule(); | ||
276 | |||
277 | EventQueueGetModule eqgm1 = new EventQueueGetModule(); | ||
278 | SceneHelpers.SetupSceneModules(myScene1, configSource, etm, eqgm1); | ||
279 | |||
280 | EventQueueGetModule eqgm2 = new EventQueueGetModule(); | ||
281 | SceneHelpers.SetupSceneModules(myScene2, configSource, etm, eqgm2); | ||
282 | |||
283 | // SceneHelpers.AddScenePresence(myScene1, agent1Id); | ||
284 | // ScenePresence childPresence = myScene2.GetScenePresence(agent1); | ||
285 | // | ||
286 | // // TODO: Need to do a fair amount of work to allow synchronous establishment of child agents | ||
287 | // Assert.That(childPresence, Is.Not.Null); | ||
288 | // Assert.That(childPresence.IsChildAgent, Is.True); | ||
289 | } | ||
290 | } | ||
291 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAnimationTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAnimationTests.cs new file mode 100644 index 0000000..42cfa1b --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAnimationTests.cs | |||
@@ -0,0 +1,69 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using System.Threading; | ||
33 | using System.Timers; | ||
34 | using Nini.Config; | ||
35 | using NUnit.Framework; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Communications; | ||
39 | using OpenSim.Region.Framework.Scenes; | ||
40 | using OpenSim.Region.Framework.Interfaces; | ||
41 | using OpenSim.Region.CoreModules.Framework.EntityTransfer; | ||
42 | using OpenSim.Region.CoreModules.World.Serialiser; | ||
43 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; | ||
44 | using OpenSim.Region.Physics.Manager; | ||
45 | using OpenSim.Tests.Common; | ||
46 | |||
47 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
48 | { | ||
49 | /// <summary> | ||
50 | /// Scene presence animation tests | ||
51 | /// </summary> | ||
52 | [TestFixture] | ||
53 | public class ScenePresenceAnimationTests : OpenSimTestCase | ||
54 | { | ||
55 | [Test] | ||
56 | public void TestFlyingAnimation() | ||
57 | { | ||
58 | TestHelpers.InMethod(); | ||
59 | // log4net.Config.XmlConfigurator.Configure(); | ||
60 | |||
61 | TestScene scene = new SceneHelpers().SetupScene(); | ||
62 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); | ||
63 | sp.Flying = true; | ||
64 | sp.PhysicsCollisionUpdate(new CollisionEventUpdate()); | ||
65 | |||
66 | Assert.That(sp.Animator.CurrentMovementAnimation, Is.EqualTo("HOVER")); | ||
67 | } | ||
68 | } | ||
69 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs new file mode 100644 index 0000000..c6e3b8b --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs | |||
@@ -0,0 +1,132 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using log4net; | ||
32 | using Nini.Config; | ||
33 | using NUnit.Framework; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Framework.Communications; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Tests.Common; | ||
40 | |||
41 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
42 | { | ||
43 | [TestFixture] | ||
44 | public class ScenePresenceAutopilotTests : OpenSimTestCase | ||
45 | { | ||
46 | private TestScene m_scene; | ||
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.None; | ||
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 not to worry about such things. | ||
60 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; | ||
61 | } | ||
62 | |||
63 | [SetUp] | ||
64 | public void Init() | ||
65 | { | ||
66 | m_scene = new SceneHelpers().SetupScene(); | ||
67 | } | ||
68 | |||
69 | [Test] | ||
70 | public void TestMove() | ||
71 | { | ||
72 | TestHelpers.InMethod(); | ||
73 | // log4net.Config.XmlConfigurator.Configure(); | ||
74 | |||
75 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); | ||
76 | |||
77 | Vector3 startPos = sp.AbsolutePosition; | ||
78 | // Vector3 startPos = new Vector3(128, 128, 30); | ||
79 | |||
80 | // For now, we'll make the scene presence fly to simplify this test, but this needs to change. | ||
81 | sp.Flying = true; | ||
82 | |||
83 | m_scene.Update(1); | ||
84 | Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos)); | ||
85 | |||
86 | Vector3 targetPos = startPos + new Vector3(0, 10, 0); | ||
87 | sp.MoveToTarget(targetPos, false, false); | ||
88 | |||
89 | Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos)); | ||
90 | Assert.That( | ||
91 | sp.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0.7071068f, 0.7071068f), 0.000001)); | ||
92 | |||
93 | m_scene.Update(1); | ||
94 | |||
95 | // We should really check the exact figure. | ||
96 | Assert.That(sp.AbsolutePosition.X, Is.EqualTo(startPos.X)); | ||
97 | Assert.That(sp.AbsolutePosition.Y, Is.GreaterThan(startPos.Y)); | ||
98 | Assert.That(sp.AbsolutePosition.Z, Is.EqualTo(startPos.Z)); | ||
99 | Assert.That(sp.AbsolutePosition.Z, Is.LessThan(targetPos.X)); | ||
100 | |||
101 | m_scene.Update(10); | ||
102 | |||
103 | double distanceToTarget = Util.GetDistanceTo(sp.AbsolutePosition, targetPos); | ||
104 | Assert.That(distanceToTarget, Is.LessThan(1), "Avatar not within 1 unit of target position on first move"); | ||
105 | Assert.That(sp.AbsolutePosition, Is.EqualTo(targetPos)); | ||
106 | Assert.That(sp.AgentControlFlags, Is.EqualTo((uint)AgentManager.ControlFlags.NONE)); | ||
107 | |||
108 | // Try a second movement | ||
109 | startPos = sp.AbsolutePosition; | ||
110 | targetPos = startPos + new Vector3(10, 0, 0); | ||
111 | sp.MoveToTarget(targetPos, false, false); | ||
112 | |||
113 | Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos)); | ||
114 | Assert.That( | ||
115 | sp.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0, 1), 0.000001)); | ||
116 | |||
117 | m_scene.Update(1); | ||
118 | |||
119 | // We should really check the exact figure. | ||
120 | Assert.That(sp.AbsolutePosition.X, Is.GreaterThan(startPos.X)); | ||
121 | Assert.That(sp.AbsolutePosition.X, Is.LessThan(targetPos.X)); | ||
122 | Assert.That(sp.AbsolutePosition.Y, Is.EqualTo(startPos.Y)); | ||
123 | Assert.That(sp.AbsolutePosition.Z, Is.EqualTo(startPos.Z)); | ||
124 | |||
125 | m_scene.Update(10); | ||
126 | |||
127 | distanceToTarget = Util.GetDistanceTo(sp.AbsolutePosition, targetPos); | ||
128 | Assert.That(distanceToTarget, Is.LessThan(1), "Avatar not within 1 unit of target position on second move"); | ||
129 | Assert.That(sp.AbsolutePosition, Is.EqualTo(targetPos)); | ||
130 | } | ||
131 | } | ||
132 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCapabilityTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCapabilityTests.cs new file mode 100644 index 0000000..cca30db --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCapabilityTests.cs | |||
@@ -0,0 +1,87 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using System.Threading; | ||
33 | using System.Timers; | ||
34 | using Timer = System.Timers.Timer; | ||
35 | using Nini.Config; | ||
36 | using NUnit.Framework; | ||
37 | using OpenMetaverse; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Communications; | ||
40 | using OpenSim.Framework.Servers; | ||
41 | using OpenSim.Framework.Servers.HttpServer; | ||
42 | using OpenSim.Region.ClientStack.Linden; | ||
43 | using OpenSim.Region.CoreModules.Framework; | ||
44 | using OpenSim.Region.CoreModules.Framework.EntityTransfer; | ||
45 | using OpenSim.Region.CoreModules.World.Serialiser; | ||
46 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; | ||
47 | using OpenSim.Region.Framework.Scenes; | ||
48 | using OpenSim.Region.Framework.Interfaces; | ||
49 | using OpenSim.Tests.Common; | ||
50 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
51 | |||
52 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
53 | { | ||
54 | [TestFixture] | ||
55 | public class ScenePresenceCapabilityTests : OpenSimTestCase | ||
56 | { | ||
57 | [Test] | ||
58 | public void TestChildAgentSingleRegionCapabilities() | ||
59 | { | ||
60 | TestHelpers.InMethod(); | ||
61 | // TestHelpers.EnableLogging(); | ||
62 | |||
63 | UUID spUuid = TestHelpers.ParseTail(0x1); | ||
64 | |||
65 | // XXX: This is not great since the use of statics will mean that this has to be manually cleaned up for | ||
66 | // any subsequent test. | ||
67 | // XXX: May replace with a mock IHttpServer later. | ||
68 | BaseHttpServer httpServer = new BaseHttpServer(99999); | ||
69 | MainServer.AddHttpServer(httpServer); | ||
70 | MainServer.Instance = httpServer; | ||
71 | |||
72 | CapabilitiesModule capsMod = new CapabilitiesModule(); | ||
73 | TestScene scene = new SceneHelpers().SetupScene(); | ||
74 | SceneHelpers.SetupSceneModules(scene, capsMod); | ||
75 | |||
76 | ScenePresence sp = SceneHelpers.AddChildScenePresence(scene, spUuid); | ||
77 | Assert.That(capsMod.GetCapsForUser(spUuid), Is.Not.Null); | ||
78 | |||
79 | // TODO: Need to add tests for other ICapabiltiesModule methods. | ||
80 | |||
81 | scene.CloseAgent(sp.UUID, false); | ||
82 | Assert.That(capsMod.GetCapsForUser(spUuid), Is.Null); | ||
83 | |||
84 | // TODO: Need to add tests for other ICapabiltiesModule methods. | ||
85 | } | ||
86 | } | ||
87 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCrossingTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCrossingTests.cs new file mode 100644 index 0000000..e14da8b --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCrossingTests.cs | |||
@@ -0,0 +1,248 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using Nini.Config; | ||
32 | using NUnit.Framework; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Framework.Servers; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.CoreModules.Framework; | ||
39 | using OpenSim.Region.CoreModules.Framework.EntityTransfer; | ||
40 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; | ||
41 | using OpenSim.Region.CoreModules.World.Permissions; | ||
42 | using OpenSim.Tests.Common; | ||
43 | |||
44 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
45 | { | ||
46 | [TestFixture] | ||
47 | public class ScenePresenceCrossingTests : OpenSimTestCase | ||
48 | { | ||
49 | [TestFixtureSetUp] | ||
50 | public void FixtureInit() | ||
51 | { | ||
52 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. | ||
53 | Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest; | ||
54 | } | ||
55 | |||
56 | [TestFixtureTearDown] | ||
57 | public void TearDown() | ||
58 | { | ||
59 | // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple | ||
60 | // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression | ||
61 | // tests really shouldn't). | ||
62 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; | ||
63 | } | ||
64 | |||
65 | [Test] | ||
66 | public void TestCrossOnSameSimulator() | ||
67 | { | ||
68 | TestHelpers.InMethod(); | ||
69 | // TestHelpers.EnableLogging(); | ||
70 | |||
71 | UUID userId = TestHelpers.ParseTail(0x1); | ||
72 | |||
73 | // TestEventQueueGetModule eqmA = new TestEventQueueGetModule(); | ||
74 | EntityTransferModule etmA = new EntityTransferModule(); | ||
75 | EntityTransferModule etmB = new EntityTransferModule(); | ||
76 | LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule(); | ||
77 | |||
78 | IConfigSource config = new IniConfigSource(); | ||
79 | IConfig modulesConfig = config.AddConfig("Modules"); | ||
80 | modulesConfig.Set("EntityTransferModule", etmA.Name); | ||
81 | modulesConfig.Set("SimulationServices", lscm.Name); | ||
82 | // IConfig entityTransferConfig = config.AddConfig("EntityTransfer"); | ||
83 | |||
84 | // In order to run a single threaded regression test we do not want the entity transfer module waiting | ||
85 | // for a callback from the destination scene before removing its avatar data. | ||
86 | // entityTransferConfig.Set("wait_for_callback", false); | ||
87 | |||
88 | SceneHelpers sh = new SceneHelpers(); | ||
89 | TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000); | ||
90 | TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999); | ||
91 | |||
92 | SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); | ||
93 | SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA); | ||
94 | // SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA, eqmA); | ||
95 | SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), etmB); | ||
96 | |||
97 | AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId); | ||
98 | TestClient tc = new TestClient(acd, sceneA); | ||
99 | List<TestClient> destinationTestClients = new List<TestClient>(); | ||
100 | EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients); | ||
101 | |||
102 | ScenePresence originalSp = SceneHelpers.AddScenePresence(sceneA, tc, acd); | ||
103 | originalSp.AbsolutePosition = new Vector3(128, 32, 10); | ||
104 | |||
105 | // originalSp.Flying = true; | ||
106 | |||
107 | // Console.WriteLine("First pos {0}", originalSp.AbsolutePosition); | ||
108 | |||
109 | // eqmA.ClearEvents(); | ||
110 | |||
111 | AgentUpdateArgs moveArgs = new AgentUpdateArgs(); | ||
112 | //moveArgs.BodyRotation = Quaternion.CreateFromEulers(Vector3.Zero); | ||
113 | moveArgs.BodyRotation = Quaternion.CreateFromEulers(new Vector3(0, 0, (float)-(Math.PI / 2))); | ||
114 | moveArgs.ControlFlags = (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS; | ||
115 | moveArgs.SessionID = acd.SessionID; | ||
116 | |||
117 | originalSp.HandleAgentUpdate(originalSp.ControllingClient, moveArgs); | ||
118 | |||
119 | sceneA.Update(1); | ||
120 | |||
121 | // Console.WriteLine("Second pos {0}", originalSp.AbsolutePosition); | ||
122 | |||
123 | // FIXME: This is a sufficient number of updates to for the presence to reach the northern border. | ||
124 | // But really we want to do this in a more robust way. | ||
125 | for (int i = 0; i < 100; i++) | ||
126 | { | ||
127 | sceneA.Update(1); | ||
128 | // Console.WriteLine("Pos {0}", originalSp.AbsolutePosition); | ||
129 | } | ||
130 | |||
131 | // Need to sort processing of EnableSimulator message on adding scene presences before we can test eqm | ||
132 | // messages | ||
133 | // Dictionary<UUID, List<TestEventQueueGetModule.Event>> eqmEvents = eqmA.Events; | ||
134 | // | ||
135 | // Assert.That(eqmEvents.Count, Is.EqualTo(1)); | ||
136 | // Assert.That(eqmEvents.ContainsKey(originalSp.UUID), Is.True); | ||
137 | // | ||
138 | // List<TestEventQueueGetModule.Event> spEqmEvents = eqmEvents[originalSp.UUID]; | ||
139 | // | ||
140 | // Assert.That(spEqmEvents.Count, Is.EqualTo(1)); | ||
141 | // Assert.That(spEqmEvents[0].Name, Is.EqualTo("CrossRegion")); | ||
142 | |||
143 | // sceneA should now only have a child agent | ||
144 | ScenePresence spAfterCrossSceneA = sceneA.GetScenePresence(originalSp.UUID); | ||
145 | Assert.That(spAfterCrossSceneA.IsChildAgent, Is.True); | ||
146 | |||
147 | ScenePresence spAfterCrossSceneB = sceneB.GetScenePresence(originalSp.UUID); | ||
148 | |||
149 | // Agent remains a child until the client triggers complete movement | ||
150 | Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True); | ||
151 | |||
152 | TestClient sceneBTc = ((TestClient)spAfterCrossSceneB.ControllingClient); | ||
153 | |||
154 | int agentMovementCompleteReceived = 0; | ||
155 | sceneBTc.OnReceivedMoveAgentIntoRegion += (ri, pos, look) => agentMovementCompleteReceived++; | ||
156 | |||
157 | sceneBTc.CompleteMovement(); | ||
158 | |||
159 | Assert.That(agentMovementCompleteReceived, Is.EqualTo(1)); | ||
160 | Assert.That(spAfterCrossSceneB.IsChildAgent, Is.False); | ||
161 | } | ||
162 | |||
163 | /// <summary> | ||
164 | /// Test a cross attempt where the user can see into the neighbour but does not have permission to become | ||
165 | /// root there. | ||
166 | /// </summary> | ||
167 | [Test] | ||
168 | public void TestCrossOnSameSimulatorNoRootDestPerm() | ||
169 | { | ||
170 | TestHelpers.InMethod(); | ||
171 | // TestHelpers.EnableLogging(); | ||
172 | |||
173 | UUID userId = TestHelpers.ParseTail(0x1); | ||
174 | |||
175 | EntityTransferModule etmA = new EntityTransferModule(); | ||
176 | EntityTransferModule etmB = new EntityTransferModule(); | ||
177 | LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule(); | ||
178 | |||
179 | IConfigSource config = new IniConfigSource(); | ||
180 | IConfig modulesConfig = config.AddConfig("Modules"); | ||
181 | modulesConfig.Set("EntityTransferModule", etmA.Name); | ||
182 | modulesConfig.Set("SimulationServices", lscm.Name); | ||
183 | |||
184 | SceneHelpers sh = new SceneHelpers(); | ||
185 | TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000); | ||
186 | TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999); | ||
187 | |||
188 | SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); | ||
189 | SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA); | ||
190 | |||
191 | // We need to set up the permisions module on scene B so that our later use of agent limit to deny | ||
192 | // QueryAccess won't succeed anyway because administrators are always allowed in and the default | ||
193 | // IsAdministrator if no permissions module is present is true. | ||
194 | SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), new PermissionsModule(), etmB); | ||
195 | |||
196 | AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId); | ||
197 | TestClient tc = new TestClient(acd, sceneA); | ||
198 | List<TestClient> destinationTestClients = new List<TestClient>(); | ||
199 | EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients); | ||
200 | |||
201 | // Make sure sceneB will not accept this avatar. | ||
202 | sceneB.RegionInfo.EstateSettings.PublicAccess = false; | ||
203 | |||
204 | ScenePresence originalSp = SceneHelpers.AddScenePresence(sceneA, tc, acd); | ||
205 | originalSp.AbsolutePosition = new Vector3(128, 32, 10); | ||
206 | |||
207 | AgentUpdateArgs moveArgs = new AgentUpdateArgs(); | ||
208 | //moveArgs.BodyRotation = Quaternion.CreateFromEulers(Vector3.Zero); | ||
209 | moveArgs.BodyRotation = Quaternion.CreateFromEulers(new Vector3(0, 0, (float)-(Math.PI / 2))); | ||
210 | moveArgs.ControlFlags = (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS; | ||
211 | moveArgs.SessionID = acd.SessionID; | ||
212 | |||
213 | originalSp.HandleAgentUpdate(originalSp.ControllingClient, moveArgs); | ||
214 | |||
215 | sceneA.Update(1); | ||
216 | |||
217 | // Console.WriteLine("Second pos {0}", originalSp.AbsolutePosition); | ||
218 | |||
219 | // FIXME: This is a sufficient number of updates to for the presence to reach the northern border. | ||
220 | // But really we want to do this in a more robust way. | ||
221 | for (int i = 0; i < 100; i++) | ||
222 | { | ||
223 | sceneA.Update(1); | ||
224 | // Console.WriteLine("Pos {0}", originalSp.AbsolutePosition); | ||
225 | } | ||
226 | |||
227 | // sceneA agent should still be root | ||
228 | ScenePresence spAfterCrossSceneA = sceneA.GetScenePresence(originalSp.UUID); | ||
229 | Assert.That(spAfterCrossSceneA.IsChildAgent, Is.False); | ||
230 | |||
231 | ScenePresence spAfterCrossSceneB = sceneB.GetScenePresence(originalSp.UUID); | ||
232 | |||
233 | // sceneB agent should also still be root | ||
234 | Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True); | ||
235 | |||
236 | // sceneB should ignore unauthorized attempt to upgrade agent to root | ||
237 | TestClient sceneBTc = ((TestClient)spAfterCrossSceneB.ControllingClient); | ||
238 | |||
239 | int agentMovementCompleteReceived = 0; | ||
240 | sceneBTc.OnReceivedMoveAgentIntoRegion += (ri, pos, look) => agentMovementCompleteReceived++; | ||
241 | |||
242 | sceneBTc.CompleteMovement(); | ||
243 | |||
244 | Assert.That(agentMovementCompleteReceived, Is.EqualTo(0)); | ||
245 | Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True); | ||
246 | } | ||
247 | } | ||
248 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs new file mode 100644 index 0000000..b775178 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs | |||
@@ -0,0 +1,250 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using Nini.Config; | ||
32 | using NUnit.Framework; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Framework.Servers; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; | ||
39 | using OpenSim.Tests.Common; | ||
40 | using System.Threading; | ||
41 | |||
42 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
43 | { | ||
44 | [TestFixture] | ||
45 | public class ScenePresenceSitTests : OpenSimTestCase | ||
46 | { | ||
47 | private TestScene m_scene; | ||
48 | private ScenePresence m_sp; | ||
49 | |||
50 | [SetUp] | ||
51 | public void Init() | ||
52 | { | ||
53 | m_scene = new SceneHelpers().SetupScene(); | ||
54 | m_sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); | ||
55 | } | ||
56 | |||
57 | [Test] | ||
58 | public void TestSitOutsideRangeNoTarget() | ||
59 | { | ||
60 | TestHelpers.InMethod(); | ||
61 | // log4net.Config.XmlConfigurator.Configure(); | ||
62 | |||
63 | // More than 10 meters away from 0, 0, 0 (default part position) | ||
64 | Vector3 startPos = new Vector3(10.1f, 0, 0); | ||
65 | m_sp.AbsolutePosition = startPos; | ||
66 | |||
67 | SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart; | ||
68 | |||
69 | m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero); | ||
70 | |||
71 | Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); | ||
72 | Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0)); | ||
73 | Assert.That(part.GetSittingAvatars(), Is.Null); | ||
74 | Assert.That(m_sp.ParentID, Is.EqualTo(0)); | ||
75 | Assert.AreEqual(startPos, m_sp.AbsolutePosition); | ||
76 | } | ||
77 | |||
78 | [Test] | ||
79 | public void TestSitWithinRangeNoTarget() | ||
80 | { | ||
81 | TestHelpers.InMethod(); | ||
82 | // log4net.Config.XmlConfigurator.Configure(); | ||
83 | |||
84 | // Less than 10 meters away from 0, 0, 0 (default part position) | ||
85 | Vector3 startPos = new Vector3(9.9f, 0, 0); | ||
86 | m_sp.AbsolutePosition = startPos; | ||
87 | |||
88 | SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart; | ||
89 | |||
90 | // We need to preserve this here because phys actor is removed by the sit. | ||
91 | Vector3 spPhysActorSize = m_sp.PhysicsActor.Size; | ||
92 | m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero); | ||
93 | |||
94 | Assert.That(m_sp.PhysicsActor, Is.Null); | ||
95 | |||
96 | Assert.That( | ||
97 | m_sp.AbsolutePosition, | ||
98 | Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, spPhysActorSize.Z / 2))); | ||
99 | |||
100 | Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); | ||
101 | Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1)); | ||
102 | HashSet<ScenePresence> sittingAvatars = part.GetSittingAvatars(); | ||
103 | Assert.That(sittingAvatars.Count, Is.EqualTo(1)); | ||
104 | Assert.That(sittingAvatars.Contains(m_sp)); | ||
105 | Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId)); | ||
106 | } | ||
107 | |||
108 | [Test] | ||
109 | public void TestSitAndStandWithNoSitTarget() | ||
110 | { | ||
111 | TestHelpers.InMethod(); | ||
112 | // log4net.Config.XmlConfigurator.Configure(); | ||
113 | |||
114 | // Make sure we're within range to sit | ||
115 | Vector3 startPos = new Vector3(1, 1, 1); | ||
116 | m_sp.AbsolutePosition = startPos; | ||
117 | |||
118 | SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart; | ||
119 | |||
120 | // We need to preserve this here because phys actor is removed by the sit. | ||
121 | Vector3 spPhysActorSize = m_sp.PhysicsActor.Size; | ||
122 | m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero); | ||
123 | |||
124 | Assert.That( | ||
125 | m_sp.AbsolutePosition, | ||
126 | Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, spPhysActorSize.Z / 2))); | ||
127 | |||
128 | m_sp.StandUp(); | ||
129 | |||
130 | Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); | ||
131 | Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0)); | ||
132 | Assert.That(part.GetSittingAvatars(), Is.Null); | ||
133 | Assert.That(m_sp.ParentID, Is.EqualTo(0)); | ||
134 | Assert.That(m_sp.PhysicsActor, Is.Not.Null); | ||
135 | } | ||
136 | |||
137 | [Test] | ||
138 | public void TestSitAndStandWithNoSitTargetChildPrim() | ||
139 | { | ||
140 | TestHelpers.InMethod(); | ||
141 | // log4net.Config.XmlConfigurator.Configure(); | ||
142 | |||
143 | // Make sure we're within range to sit | ||
144 | Vector3 startPos = new Vector3(1, 1, 1); | ||
145 | m_sp.AbsolutePosition = startPos; | ||
146 | |||
147 | SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene, 2, m_sp.UUID, "part", 0x10).Parts[1]; | ||
148 | part.OffsetPosition = new Vector3(2, 3, 4); | ||
149 | |||
150 | // We need to preserve this here because phys actor is removed by the sit. | ||
151 | Vector3 spPhysActorSize = m_sp.PhysicsActor.Size; | ||
152 | m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero); | ||
153 | |||
154 | Assert.That( | ||
155 | m_sp.AbsolutePosition, | ||
156 | Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, spPhysActorSize.Z / 2))); | ||
157 | |||
158 | m_sp.StandUp(); | ||
159 | |||
160 | Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); | ||
161 | Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0)); | ||
162 | Assert.That(part.GetSittingAvatars(), Is.Null); | ||
163 | Assert.That(m_sp.ParentID, Is.EqualTo(0)); | ||
164 | Assert.That(m_sp.PhysicsActor, Is.Not.Null); | ||
165 | } | ||
166 | |||
167 | [Test] | ||
168 | public void TestSitAndStandWithSitTarget() | ||
169 | { | ||
170 | TestHelpers.InMethod(); | ||
171 | // log4net.Config.XmlConfigurator.Configure(); | ||
172 | |||
173 | // If a prim has a sit target then we can sit from any distance away | ||
174 | Vector3 startPos = new Vector3(128, 128, 30); | ||
175 | m_sp.AbsolutePosition = startPos; | ||
176 | |||
177 | SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart; | ||
178 | part.SitTargetPosition = new Vector3(0, 0, 1); | ||
179 | |||
180 | m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero); | ||
181 | |||
182 | Assert.That(part.SitTargetAvatar, Is.EqualTo(m_sp.UUID)); | ||
183 | Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId)); | ||
184 | |||
185 | // This section is copied from ScenePresence.HandleAgentSit(). Correctness is not guaranteed. | ||
186 | double x, y, z, m1, m2; | ||
187 | |||
188 | Quaternion r = part.SitTargetOrientation;; | ||
189 | m1 = r.X * r.X + r.Y * r.Y; | ||
190 | m2 = r.Z * r.Z + r.W * r.W; | ||
191 | |||
192 | // Rotate the vector <0, 0, 1> | ||
193 | x = 2 * (r.X * r.Z + r.Y * r.W); | ||
194 | y = 2 * (-r.X * r.W + r.Y * r.Z); | ||
195 | z = m2 - m1; | ||
196 | |||
197 | // Set m to be the square of the norm of r. | ||
198 | double m = m1 + m2; | ||
199 | |||
200 | // This constant is emperically determined to be what is used in SL. | ||
201 | // See also http://opensimulator.org/mantis/view.php?id=7096 | ||
202 | double offset = 0.05; | ||
203 | |||
204 | Vector3 up = new Vector3((float)x, (float)y, (float)z); | ||
205 | Vector3 sitOffset = up * (float)offset; | ||
206 | // End of copied section. | ||
207 | |||
208 | Assert.That( | ||
209 | m_sp.AbsolutePosition, | ||
210 | Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition - sitOffset + ScenePresence.SIT_TARGET_ADJUSTMENT)); | ||
211 | Assert.That(m_sp.PhysicsActor, Is.Null); | ||
212 | |||
213 | Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1)); | ||
214 | HashSet<ScenePresence> sittingAvatars = part.GetSittingAvatars(); | ||
215 | Assert.That(sittingAvatars.Count, Is.EqualTo(1)); | ||
216 | Assert.That(sittingAvatars.Contains(m_sp)); | ||
217 | |||
218 | m_sp.StandUp(); | ||
219 | |||
220 | Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); | ||
221 | Assert.That(m_sp.ParentID, Is.EqualTo(0)); | ||
222 | Assert.That(m_sp.PhysicsActor, Is.Not.Null); | ||
223 | |||
224 | Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); | ||
225 | Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0)); | ||
226 | Assert.That(part.GetSittingAvatars(), Is.Null); | ||
227 | } | ||
228 | |||
229 | [Test] | ||
230 | public void TestSitAndStandOnGround() | ||
231 | { | ||
232 | TestHelpers.InMethod(); | ||
233 | // log4net.Config.XmlConfigurator.Configure(); | ||
234 | |||
235 | // If a prim has a sit target then we can sit from any distance away | ||
236 | // Vector3 startPos = new Vector3(128, 128, 30); | ||
237 | // sp.AbsolutePosition = startPos; | ||
238 | |||
239 | m_sp.HandleAgentSitOnGround(); | ||
240 | |||
241 | Assert.That(m_sp.SitGround, Is.True); | ||
242 | Assert.That(m_sp.PhysicsActor, Is.Null); | ||
243 | |||
244 | m_sp.StandUp(); | ||
245 | |||
246 | Assert.That(m_sp.SitGround, Is.False); | ||
247 | Assert.That(m_sp.PhysicsActor, Is.Not.Null); | ||
248 | } | ||
249 | } | ||
250 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTeleportTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTeleportTests.cs new file mode 100644 index 0000000..da93d44 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTeleportTests.cs | |||
@@ -0,0 +1,662 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Net; | ||
32 | using System.Text; | ||
33 | using System.Threading; | ||
34 | using Nini.Config; | ||
35 | using NUnit.Framework; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Communications; | ||
39 | using OpenSim.Framework.Servers; | ||
40 | using OpenSim.Region.Framework.Interfaces; | ||
41 | using OpenSim.Region.CoreModules.Framework; | ||
42 | using OpenSim.Region.CoreModules.Framework.EntityTransfer; | ||
43 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; | ||
44 | using OpenSim.Region.CoreModules.World.Permissions; | ||
45 | using OpenSim.Tests.Common; | ||
46 | |||
47 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
48 | { | ||
49 | /// <summary> | ||
50 | /// Teleport tests in a standalone OpenSim | ||
51 | /// </summary> | ||
52 | [TestFixture] | ||
53 | public class ScenePresenceTeleportTests : OpenSimTestCase | ||
54 | { | ||
55 | [TestFixtureSetUp] | ||
56 | public void FixtureInit() | ||
57 | { | ||
58 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. | ||
59 | Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest; | ||
60 | } | ||
61 | |||
62 | [TestFixtureTearDown] | ||
63 | public void TearDown() | ||
64 | { | ||
65 | // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple | ||
66 | // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression | ||
67 | // tests really shouldn't). | ||
68 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; | ||
69 | } | ||
70 | |||
71 | [Test] | ||
72 | public void TestSameRegion() | ||
73 | { | ||
74 | TestHelpers.InMethod(); | ||
75 | // log4net.Config.XmlConfigurator.Configure(); | ||
76 | |||
77 | EntityTransferModule etm = new EntityTransferModule(); | ||
78 | |||
79 | IConfigSource config = new IniConfigSource(); | ||
80 | config.AddConfig("Modules"); | ||
81 | // Not strictly necessary since FriendsModule assumes it is the default (!) | ||
82 | config.Configs["Modules"].Set("EntityTransferModule", etm.Name); | ||
83 | |||
84 | TestScene scene = new SceneHelpers().SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000); | ||
85 | SceneHelpers.SetupSceneModules(scene, config, etm); | ||
86 | |||
87 | Vector3 teleportPosition = new Vector3(10, 11, 12); | ||
88 | Vector3 teleportLookAt = new Vector3(20, 21, 22); | ||
89 | |||
90 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); | ||
91 | sp.AbsolutePosition = new Vector3(30, 31, 32); | ||
92 | scene.RequestTeleportLocation( | ||
93 | sp.ControllingClient, | ||
94 | scene.RegionInfo.RegionHandle, | ||
95 | teleportPosition, | ||
96 | teleportLookAt, | ||
97 | (uint)TeleportFlags.ViaLocation); | ||
98 | |||
99 | Assert.That(sp.AbsolutePosition, Is.EqualTo(teleportPosition)); | ||
100 | |||
101 | Assert.That(scene.GetRootAgentCount(), Is.EqualTo(1)); | ||
102 | Assert.That(scene.GetChildAgentCount(), Is.EqualTo(0)); | ||
103 | |||
104 | // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera | ||
105 | // position instead). | ||
106 | // Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt)); | ||
107 | } | ||
108 | |||
109 | [Test] | ||
110 | public void TestSameSimulatorIsolatedRegionsV1() | ||
111 | { | ||
112 | TestHelpers.InMethod(); | ||
113 | // TestHelpers.EnableLogging(); | ||
114 | |||
115 | UUID userId = TestHelpers.ParseTail(0x1); | ||
116 | |||
117 | EntityTransferModule etmA = new EntityTransferModule(); | ||
118 | EntityTransferModule etmB = new EntityTransferModule(); | ||
119 | LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule(); | ||
120 | |||
121 | IConfigSource config = new IniConfigSource(); | ||
122 | IConfig modulesConfig = config.AddConfig("Modules"); | ||
123 | modulesConfig.Set("EntityTransferModule", etmA.Name); | ||
124 | modulesConfig.Set("SimulationServices", lscm.Name); | ||
125 | IConfig entityTransferConfig = config.AddConfig("EntityTransfer"); | ||
126 | |||
127 | // In order to run a single threaded regression test we do not want the entity transfer module waiting | ||
128 | // for a callback from the destination scene before removing its avatar data. | ||
129 | entityTransferConfig.Set("wait_for_callback", false); | ||
130 | |||
131 | SceneHelpers sh = new SceneHelpers(); | ||
132 | TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000); | ||
133 | TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1002, 1000); | ||
134 | |||
135 | SceneHelpers.SetupSceneModules(sceneA, config, etmA); | ||
136 | SceneHelpers.SetupSceneModules(sceneB, config, etmB); | ||
137 | SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); | ||
138 | |||
139 | // FIXME: Hack - this is here temporarily to revert back to older entity transfer behaviour | ||
140 | lscm.ServiceVersion = "SIMULATION/0.1"; | ||
141 | |||
142 | Vector3 teleportPosition = new Vector3(10, 11, 12); | ||
143 | Vector3 teleportLookAt = new Vector3(20, 21, 22); | ||
144 | |||
145 | ScenePresence sp = SceneHelpers.AddScenePresence(sceneA, userId); | ||
146 | sp.AbsolutePosition = new Vector3(30, 31, 32); | ||
147 | |||
148 | List<TestClient> destinationTestClients = new List<TestClient>(); | ||
149 | EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate( | ||
150 | (TestClient)sp.ControllingClient, destinationTestClients); | ||
151 | |||
152 | sceneA.RequestTeleportLocation( | ||
153 | sp.ControllingClient, | ||
154 | sceneB.RegionInfo.RegionHandle, | ||
155 | teleportPosition, | ||
156 | teleportLookAt, | ||
157 | (uint)TeleportFlags.ViaLocation); | ||
158 | |||
159 | // SetupInformClientOfNeighbour() will have handled the callback into the target scene to setup the child | ||
160 | // agent. This call will now complete the movement of the user into the destination and upgrade the agent | ||
161 | // from child to root. | ||
162 | destinationTestClients[0].CompleteMovement(); | ||
163 | |||
164 | Assert.That(sceneA.GetScenePresence(userId), Is.Null); | ||
165 | |||
166 | ScenePresence sceneBSp = sceneB.GetScenePresence(userId); | ||
167 | Assert.That(sceneBSp, Is.Not.Null); | ||
168 | Assert.That(sceneBSp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneB.RegionInfo.RegionName)); | ||
169 | Assert.That(sceneBSp.AbsolutePosition, Is.EqualTo(teleportPosition)); | ||
170 | |||
171 | Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(0)); | ||
172 | Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(0)); | ||
173 | Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(1)); | ||
174 | Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0)); | ||
175 | |||
176 | // TODO: Add assertions to check correct circuit details in both scenes. | ||
177 | |||
178 | // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera | ||
179 | // position instead). | ||
180 | // Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt)); | ||
181 | } | ||
182 | |||
183 | [Test] | ||
184 | public void TestSameSimulatorIsolatedRegionsV2() | ||
185 | { | ||
186 | TestHelpers.InMethod(); | ||
187 | // TestHelpers.EnableLogging(); | ||
188 | |||
189 | UUID userId = TestHelpers.ParseTail(0x1); | ||
190 | |||
191 | EntityTransferModule etmA = new EntityTransferModule(); | ||
192 | EntityTransferModule etmB = new EntityTransferModule(); | ||
193 | LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule(); | ||
194 | |||
195 | IConfigSource config = new IniConfigSource(); | ||
196 | IConfig modulesConfig = config.AddConfig("Modules"); | ||
197 | modulesConfig.Set("EntityTransferModule", etmA.Name); | ||
198 | modulesConfig.Set("SimulationServices", lscm.Name); | ||
199 | |||
200 | SceneHelpers sh = new SceneHelpers(); | ||
201 | TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000); | ||
202 | TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1002, 1000); | ||
203 | |||
204 | SceneHelpers.SetupSceneModules(sceneA, config, etmA); | ||
205 | SceneHelpers.SetupSceneModules(sceneB, config, etmB); | ||
206 | SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); | ||
207 | |||
208 | Vector3 teleportPosition = new Vector3(10, 11, 12); | ||
209 | Vector3 teleportLookAt = new Vector3(20, 21, 22); | ||
210 | |||
211 | ScenePresence sp = SceneHelpers.AddScenePresence(sceneA, userId); | ||
212 | sp.AbsolutePosition = new Vector3(30, 31, 32); | ||
213 | |||
214 | List<TestClient> destinationTestClients = new List<TestClient>(); | ||
215 | EntityTransferHelpers.SetupSendRegionTeleportTriggersDestinationClientCreateAndCompleteMovement( | ||
216 | (TestClient)sp.ControllingClient, destinationTestClients); | ||
217 | |||
218 | sceneA.RequestTeleportLocation( | ||
219 | sp.ControllingClient, | ||
220 | sceneB.RegionInfo.RegionHandle, | ||
221 | teleportPosition, | ||
222 | teleportLookAt, | ||
223 | (uint)TeleportFlags.ViaLocation); | ||
224 | |||
225 | Assert.That(sceneA.GetScenePresence(userId), Is.Null); | ||
226 | |||
227 | ScenePresence sceneBSp = sceneB.GetScenePresence(userId); | ||
228 | Assert.That(sceneBSp, Is.Not.Null); | ||
229 | Assert.That(sceneBSp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneB.RegionInfo.RegionName)); | ||
230 | Assert.That(sceneBSp.AbsolutePosition, Is.EqualTo(teleportPosition)); | ||
231 | |||
232 | Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(0)); | ||
233 | Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(0)); | ||
234 | Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(1)); | ||
235 | Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0)); | ||
236 | |||
237 | // TODO: Add assertions to check correct circuit details in both scenes. | ||
238 | |||
239 | // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera | ||
240 | // position instead). | ||
241 | // Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt)); | ||
242 | } | ||
243 | |||
244 | /// <summary> | ||
245 | /// Test teleport procedures when the target simulator returns false when queried about access. | ||
246 | /// </summary> | ||
247 | [Test] | ||
248 | public void TestSameSimulatorIsolatedRegions_DeniedOnQueryAccess() | ||
249 | { | ||
250 | TestHelpers.InMethod(); | ||
251 | // TestHelpers.EnableLogging(); | ||
252 | |||
253 | UUID userId = TestHelpers.ParseTail(0x1); | ||
254 | Vector3 preTeleportPosition = new Vector3(30, 31, 32); | ||
255 | |||
256 | EntityTransferModule etmA = new EntityTransferModule(); | ||
257 | EntityTransferModule etmB = new EntityTransferModule(); | ||
258 | |||
259 | LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule(); | ||
260 | |||
261 | IConfigSource config = new IniConfigSource(); | ||
262 | config.AddConfig("Modules"); | ||
263 | config.Configs["Modules"].Set("EntityTransferModule", etmA.Name); | ||
264 | config.Configs["Modules"].Set("SimulationServices", lscm.Name); | ||
265 | |||
266 | config.AddConfig("EntityTransfer"); | ||
267 | |||
268 | // In order to run a single threaded regression test we do not want the entity transfer module waiting | ||
269 | // for a callback from the destination scene before removing its avatar data. | ||
270 | config.Configs["EntityTransfer"].Set("wait_for_callback", false); | ||
271 | |||
272 | config.AddConfig("Startup"); | ||
273 | config.Configs["Startup"].Set("serverside_object_permissions", true); | ||
274 | |||
275 | SceneHelpers sh = new SceneHelpers(); | ||
276 | TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000); | ||
277 | TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1002, 1000); | ||
278 | |||
279 | SceneHelpers.SetupSceneModules(sceneA, config, etmA ); | ||
280 | |||
281 | // We need to set up the permisions module on scene B so that our later use of agent limit to deny | ||
282 | // QueryAccess won't succeed anyway because administrators are always allowed in and the default | ||
283 | // IsAdministrator if no permissions module is present is true. | ||
284 | SceneHelpers.SetupSceneModules(sceneB, config, new object[] { new PermissionsModule(), etmB }); | ||
285 | |||
286 | // Shared scene modules | ||
287 | SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); | ||
288 | |||
289 | Vector3 teleportPosition = new Vector3(10, 11, 12); | ||
290 | Vector3 teleportLookAt = new Vector3(20, 21, 22); | ||
291 | |||
292 | ScenePresence sp = SceneHelpers.AddScenePresence(sceneA, userId); | ||
293 | sp.AbsolutePosition = preTeleportPosition; | ||
294 | |||
295 | // Make sceneB return false on query access | ||
296 | sceneB.RegionInfo.RegionSettings.AgentLimit = 0; | ||
297 | |||
298 | sceneA.RequestTeleportLocation( | ||
299 | sp.ControllingClient, | ||
300 | sceneB.RegionInfo.RegionHandle, | ||
301 | teleportPosition, | ||
302 | teleportLookAt, | ||
303 | (uint)TeleportFlags.ViaLocation); | ||
304 | |||
305 | // ((TestClient)sp.ControllingClient).CompleteTeleportClientSide(); | ||
306 | |||
307 | Assert.That(sceneB.GetScenePresence(userId), Is.Null); | ||
308 | |||
309 | ScenePresence sceneASp = sceneA.GetScenePresence(userId); | ||
310 | Assert.That(sceneASp, Is.Not.Null); | ||
311 | Assert.That(sceneASp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneA.RegionInfo.RegionName)); | ||
312 | Assert.That(sceneASp.AbsolutePosition, Is.EqualTo(preTeleportPosition)); | ||
313 | |||
314 | Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(1)); | ||
315 | Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(0)); | ||
316 | Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(0)); | ||
317 | Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0)); | ||
318 | |||
319 | // TODO: Add assertions to check correct circuit details in both scenes. | ||
320 | |||
321 | // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera | ||
322 | // position instead). | ||
323 | // Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt)); | ||
324 | |||
325 | // TestHelpers.DisableLogging(); | ||
326 | } | ||
327 | |||
328 | /// <summary> | ||
329 | /// Test teleport procedures when the target simulator create agent step is refused. | ||
330 | /// </summary> | ||
331 | [Test] | ||
332 | public void TestSameSimulatorIsolatedRegions_DeniedOnCreateAgent() | ||
333 | { | ||
334 | TestHelpers.InMethod(); | ||
335 | // TestHelpers.EnableLogging(); | ||
336 | |||
337 | UUID userId = TestHelpers.ParseTail(0x1); | ||
338 | Vector3 preTeleportPosition = new Vector3(30, 31, 32); | ||
339 | |||
340 | EntityTransferModule etmA = new EntityTransferModule(); | ||
341 | EntityTransferModule etmB = new EntityTransferModule(); | ||
342 | LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule(); | ||
343 | |||
344 | IConfigSource config = new IniConfigSource(); | ||
345 | config.AddConfig("Modules"); | ||
346 | config.Configs["Modules"].Set("EntityTransferModule", etmA.Name); | ||
347 | config.Configs["Modules"].Set("SimulationServices", lscm.Name); | ||
348 | |||
349 | config.AddConfig("EntityTransfer"); | ||
350 | |||
351 | // In order to run a single threaded regression test we do not want the entity transfer module waiting | ||
352 | // for a callback from the destination scene before removing its avatar data. | ||
353 | config.Configs["EntityTransfer"].Set("wait_for_callback", false); | ||
354 | |||
355 | SceneHelpers sh = new SceneHelpers(); | ||
356 | TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000); | ||
357 | TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1002, 1000); | ||
358 | |||
359 | SceneHelpers.SetupSceneModules(sceneA, config, etmA); | ||
360 | SceneHelpers.SetupSceneModules(sceneB, config, etmB); | ||
361 | |||
362 | // Shared scene modules | ||
363 | SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); | ||
364 | |||
365 | Vector3 teleportPosition = new Vector3(10, 11, 12); | ||
366 | Vector3 teleportLookAt = new Vector3(20, 21, 22); | ||
367 | |||
368 | ScenePresence sp = SceneHelpers.AddScenePresence(sceneA, userId); | ||
369 | sp.AbsolutePosition = preTeleportPosition; | ||
370 | |||
371 | // Make sceneB refuse CreateAgent | ||
372 | sceneB.LoginsEnabled = false; | ||
373 | |||
374 | sceneA.RequestTeleportLocation( | ||
375 | sp.ControllingClient, | ||
376 | sceneB.RegionInfo.RegionHandle, | ||
377 | teleportPosition, | ||
378 | teleportLookAt, | ||
379 | (uint)TeleportFlags.ViaLocation); | ||
380 | |||
381 | // ((TestClient)sp.ControllingClient).CompleteTeleportClientSide(); | ||
382 | |||
383 | Assert.That(sceneB.GetScenePresence(userId), Is.Null); | ||
384 | |||
385 | ScenePresence sceneASp = sceneA.GetScenePresence(userId); | ||
386 | Assert.That(sceneASp, Is.Not.Null); | ||
387 | Assert.That(sceneASp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneA.RegionInfo.RegionName)); | ||
388 | Assert.That(sceneASp.AbsolutePosition, Is.EqualTo(preTeleportPosition)); | ||
389 | |||
390 | Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(1)); | ||
391 | Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(0)); | ||
392 | Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(0)); | ||
393 | Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0)); | ||
394 | |||
395 | // TODO: Add assertions to check correct circuit details in both scenes. | ||
396 | |||
397 | // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera | ||
398 | // position instead). | ||
399 | // Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt)); | ||
400 | |||
401 | // TestHelpers.DisableLogging(); | ||
402 | } | ||
403 | |||
404 | /// <summary> | ||
405 | /// Test teleport when the destination region does not process (or does not receive) the connection attempt | ||
406 | /// from the viewer. | ||
407 | /// </summary> | ||
408 | /// <remarks> | ||
409 | /// This could be quite a common case where the source region can connect to a remove destination region | ||
410 | /// (for CreateAgent) but the viewer cannot reach the destination region due to network issues. | ||
411 | /// </remarks> | ||
412 | [Test] | ||
413 | public void TestSameSimulatorIsolatedRegions_DestinationDidNotProcessViewerConnection() | ||
414 | { | ||
415 | TestHelpers.InMethod(); | ||
416 | // TestHelpers.EnableLogging(); | ||
417 | |||
418 | UUID userId = TestHelpers.ParseTail(0x1); | ||
419 | Vector3 preTeleportPosition = new Vector3(30, 31, 32); | ||
420 | |||
421 | EntityTransferModule etmA = new EntityTransferModule(); | ||
422 | EntityTransferModule etmB = new EntityTransferModule(); | ||
423 | |||
424 | LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule(); | ||
425 | |||
426 | IConfigSource config = new IniConfigSource(); | ||
427 | config.AddConfig("Modules"); | ||
428 | config.Configs["Modules"].Set("EntityTransferModule", etmA.Name); | ||
429 | config.Configs["Modules"].Set("SimulationServices", lscm.Name); | ||
430 | |||
431 | config.AddConfig("EntityTransfer"); | ||
432 | |||
433 | // In order to run a single threaded regression test we do not want the entity transfer module waiting | ||
434 | // for a callback from the destination scene before removing its avatar data. | ||
435 | config.Configs["EntityTransfer"].Set("wait_for_callback", false); | ||
436 | |||
437 | // config.AddConfig("Startup"); | ||
438 | // config.Configs["Startup"].Set("serverside_object_permissions", true); | ||
439 | |||
440 | SceneHelpers sh = new SceneHelpers(); | ||
441 | TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000); | ||
442 | TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1002, 1000); | ||
443 | |||
444 | SceneHelpers.SetupSceneModules(sceneA, config, etmA ); | ||
445 | |||
446 | // We need to set up the permisions module on scene B so that our later use of agent limit to deny | ||
447 | // QueryAccess won't succeed anyway because administrators are always allowed in and the default | ||
448 | // IsAdministrator if no permissions module is present is true. | ||
449 | SceneHelpers.SetupSceneModules(sceneB, config, new object[] { new PermissionsModule(), etmB }); | ||
450 | |||
451 | // Shared scene modules | ||
452 | SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); | ||
453 | |||
454 | Vector3 teleportPosition = new Vector3(10, 11, 12); | ||
455 | Vector3 teleportLookAt = new Vector3(20, 21, 22); | ||
456 | |||
457 | ScenePresence sp = SceneHelpers.AddScenePresence(sceneA, userId); | ||
458 | sp.AbsolutePosition = preTeleportPosition; | ||
459 | |||
460 | sceneA.RequestTeleportLocation( | ||
461 | sp.ControllingClient, | ||
462 | sceneB.RegionInfo.RegionHandle, | ||
463 | teleportPosition, | ||
464 | teleportLookAt, | ||
465 | (uint)TeleportFlags.ViaLocation); | ||
466 | |||
467 | // FIXME: Not setting up InformClientOfNeighbour on the TestClient means that it does not initiate | ||
468 | // communication with the destination region. But this is a very non-obvious way of doing it - really we | ||
469 | // should be forced to expicitly set this up. | ||
470 | |||
471 | Assert.That(sceneB.GetScenePresence(userId), Is.Null); | ||
472 | |||
473 | ScenePresence sceneASp = sceneA.GetScenePresence(userId); | ||
474 | Assert.That(sceneASp, Is.Not.Null); | ||
475 | Assert.That(sceneASp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneA.RegionInfo.RegionName)); | ||
476 | Assert.That(sceneASp.AbsolutePosition, Is.EqualTo(preTeleportPosition)); | ||
477 | |||
478 | Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(1)); | ||
479 | Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(0)); | ||
480 | Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(0)); | ||
481 | Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0)); | ||
482 | |||
483 | // TODO: Add assertions to check correct circuit details in both scenes. | ||
484 | |||
485 | // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera | ||
486 | // position instead). | ||
487 | // Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt)); | ||
488 | |||
489 | // TestHelpers.DisableLogging(); | ||
490 | } | ||
491 | |||
492 | [Test] | ||
493 | public void TestSameSimulatorNeighbouringRegionsV1() | ||
494 | { | ||
495 | TestHelpers.InMethod(); | ||
496 | // TestHelpers.EnableLogging(); | ||
497 | |||
498 | UUID userId = TestHelpers.ParseTail(0x1); | ||
499 | |||
500 | EntityTransferModule etmA = new EntityTransferModule(); | ||
501 | EntityTransferModule etmB = new EntityTransferModule(); | ||
502 | LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule(); | ||
503 | |||
504 | IConfigSource config = new IniConfigSource(); | ||
505 | IConfig modulesConfig = config.AddConfig("Modules"); | ||
506 | modulesConfig.Set("EntityTransferModule", etmA.Name); | ||
507 | modulesConfig.Set("SimulationServices", lscm.Name); | ||
508 | IConfig entityTransferConfig = config.AddConfig("EntityTransfer"); | ||
509 | |||
510 | // In order to run a single threaded regression test we do not want the entity transfer module waiting | ||
511 | // for a callback from the destination scene before removing its avatar data. | ||
512 | entityTransferConfig.Set("wait_for_callback", false); | ||
513 | |||
514 | SceneHelpers sh = new SceneHelpers(); | ||
515 | TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000); | ||
516 | TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1001, 1000); | ||
517 | |||
518 | SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); | ||
519 | SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA); | ||
520 | SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), etmB); | ||
521 | |||
522 | // FIXME: Hack - this is here temporarily to revert back to older entity transfer behaviour | ||
523 | lscm.ServiceVersion = "SIMULATION/0.1"; | ||
524 | |||
525 | Vector3 teleportPosition = new Vector3(10, 11, 12); | ||
526 | Vector3 teleportLookAt = new Vector3(20, 21, 22); | ||
527 | |||
528 | AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId); | ||
529 | TestClient tc = new TestClient(acd, sceneA); | ||
530 | List<TestClient> destinationTestClients = new List<TestClient>(); | ||
531 | EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients); | ||
532 | |||
533 | ScenePresence beforeSceneASp = SceneHelpers.AddScenePresence(sceneA, tc, acd); | ||
534 | beforeSceneASp.AbsolutePosition = new Vector3(30, 31, 32); | ||
535 | |||
536 | Assert.That(beforeSceneASp, Is.Not.Null); | ||
537 | Assert.That(beforeSceneASp.IsChildAgent, Is.False); | ||
538 | |||
539 | ScenePresence beforeSceneBSp = sceneB.GetScenePresence(userId); | ||
540 | Assert.That(beforeSceneBSp, Is.Not.Null); | ||
541 | Assert.That(beforeSceneBSp.IsChildAgent, Is.True); | ||
542 | |||
543 | // In this case, we will not receieve a second InformClientOfNeighbour since the viewer already knows | ||
544 | // about the neighbour region it is teleporting to. | ||
545 | sceneA.RequestTeleportLocation( | ||
546 | beforeSceneASp.ControllingClient, | ||
547 | sceneB.RegionInfo.RegionHandle, | ||
548 | teleportPosition, | ||
549 | teleportLookAt, | ||
550 | (uint)TeleportFlags.ViaLocation); | ||
551 | |||
552 | destinationTestClients[0].CompleteMovement(); | ||
553 | |||
554 | ScenePresence afterSceneASp = sceneA.GetScenePresence(userId); | ||
555 | Assert.That(afterSceneASp, Is.Not.Null); | ||
556 | Assert.That(afterSceneASp.IsChildAgent, Is.True); | ||
557 | |||
558 | ScenePresence afterSceneBSp = sceneB.GetScenePresence(userId); | ||
559 | Assert.That(afterSceneBSp, Is.Not.Null); | ||
560 | Assert.That(afterSceneBSp.IsChildAgent, Is.False); | ||
561 | Assert.That(afterSceneBSp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneB.RegionInfo.RegionName)); | ||
562 | Assert.That(afterSceneBSp.AbsolutePosition, Is.EqualTo(teleportPosition)); | ||
563 | |||
564 | Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(0)); | ||
565 | Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(1)); | ||
566 | Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(1)); | ||
567 | Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0)); | ||
568 | |||
569 | // TODO: Add assertions to check correct circuit details in both scenes. | ||
570 | |||
571 | // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera | ||
572 | // position instead). | ||
573 | // Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt)); | ||
574 | |||
575 | // TestHelpers.DisableLogging(); | ||
576 | } | ||
577 | |||
578 | [Test] | ||
579 | public void TestSameSimulatorNeighbouringRegionsV2() | ||
580 | { | ||
581 | TestHelpers.InMethod(); | ||
582 | // TestHelpers.EnableLogging(); | ||
583 | |||
584 | UUID userId = TestHelpers.ParseTail(0x1); | ||
585 | |||
586 | EntityTransferModule etmA = new EntityTransferModule(); | ||
587 | EntityTransferModule etmB = new EntityTransferModule(); | ||
588 | LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule(); | ||
589 | |||
590 | IConfigSource config = new IniConfigSource(); | ||
591 | IConfig modulesConfig = config.AddConfig("Modules"); | ||
592 | modulesConfig.Set("EntityTransferModule", etmA.Name); | ||
593 | modulesConfig.Set("SimulationServices", lscm.Name); | ||
594 | |||
595 | SceneHelpers sh = new SceneHelpers(); | ||
596 | TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000); | ||
597 | TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1001, 1000); | ||
598 | |||
599 | SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); | ||
600 | SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA); | ||
601 | SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), etmB); | ||
602 | |||
603 | Vector3 teleportPosition = new Vector3(10, 11, 12); | ||
604 | Vector3 teleportLookAt = new Vector3(20, 21, 22); | ||
605 | |||
606 | AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId); | ||
607 | TestClient tc = new TestClient(acd, sceneA); | ||
608 | List<TestClient> destinationTestClients = new List<TestClient>(); | ||
609 | EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients); | ||
610 | |||
611 | ScenePresence beforeSceneASp = SceneHelpers.AddScenePresence(sceneA, tc, acd); | ||
612 | beforeSceneASp.AbsolutePosition = new Vector3(30, 31, 32); | ||
613 | |||
614 | Assert.That(beforeSceneASp, Is.Not.Null); | ||
615 | Assert.That(beforeSceneASp.IsChildAgent, Is.False); | ||
616 | |||
617 | ScenePresence beforeSceneBSp = sceneB.GetScenePresence(userId); | ||
618 | Assert.That(beforeSceneBSp, Is.Not.Null); | ||
619 | Assert.That(beforeSceneBSp.IsChildAgent, Is.True); | ||
620 | |||
621 | // Here, we need to make clientA's receipt of SendRegionTeleport trigger clientB's CompleteMovement(). This | ||
622 | // is to operate the teleport V2 mechanism where the EntityTransferModule will first request the client to | ||
623 | // CompleteMovement to the region and then call UpdateAgent to the destination region to confirm the receipt | ||
624 | // Both these operations will occur on different threads and will wait for each other. | ||
625 | // We have to do this via ThreadPool directly since FireAndForget has been switched to sync for the V1 | ||
626 | // test protocol, where we are trying to avoid unpredictable async operations in regression tests. | ||
627 | tc.OnTestClientSendRegionTeleport | ||
628 | += (regionHandle, simAccess, regionExternalEndPoint, locationID, flags, capsURL) | ||
629 | => ThreadPool.UnsafeQueueUserWorkItem(o => destinationTestClients[0].CompleteMovement(), null); | ||
630 | |||
631 | sceneA.RequestTeleportLocation( | ||
632 | beforeSceneASp.ControllingClient, | ||
633 | sceneB.RegionInfo.RegionHandle, | ||
634 | teleportPosition, | ||
635 | teleportLookAt, | ||
636 | (uint)TeleportFlags.ViaLocation); | ||
637 | |||
638 | ScenePresence afterSceneASp = sceneA.GetScenePresence(userId); | ||
639 | Assert.That(afterSceneASp, Is.Not.Null); | ||
640 | Assert.That(afterSceneASp.IsChildAgent, Is.True); | ||
641 | |||
642 | ScenePresence afterSceneBSp = sceneB.GetScenePresence(userId); | ||
643 | Assert.That(afterSceneBSp, Is.Not.Null); | ||
644 | Assert.That(afterSceneBSp.IsChildAgent, Is.False); | ||
645 | Assert.That(afterSceneBSp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneB.RegionInfo.RegionName)); | ||
646 | Assert.That(afterSceneBSp.AbsolutePosition, Is.EqualTo(teleportPosition)); | ||
647 | |||
648 | Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(0)); | ||
649 | Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(1)); | ||
650 | Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(1)); | ||
651 | Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0)); | ||
652 | |||
653 | // TODO: Add assertions to check correct circuit details in both scenes. | ||
654 | |||
655 | // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera | ||
656 | // position instead). | ||
657 | // Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt)); | ||
658 | |||
659 | // TestHelpers.DisableLogging(); | ||
660 | } | ||
661 | } | ||
662 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneStatisticsTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneStatisticsTests.cs new file mode 100644 index 0000000..2d36214 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneStatisticsTests.cs | |||
@@ -0,0 +1,70 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using NUnit.Framework; | ||
32 | using OpenMetaverse; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Framework.Communications; | ||
35 | using OpenSim.Region.Framework.Scenes; | ||
36 | using OpenSim.Tests.Common; | ||
37 | |||
38 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
39 | { | ||
40 | [TestFixture] | ||
41 | public class SceneStatisticsTests : OpenSimTestCase | ||
42 | { | ||
43 | private TestScene m_scene; | ||
44 | |||
45 | [SetUp] | ||
46 | public void Init() | ||
47 | { | ||
48 | m_scene = new SceneHelpers().SetupScene(); | ||
49 | } | ||
50 | |||
51 | [Test] | ||
52 | public void TestAddRemovePhysicalLinkset() | ||
53 | { | ||
54 | Assert.That(m_scene.SceneGraph.GetActiveObjectsCount(), Is.EqualTo(0)); | ||
55 | |||
56 | UUID ownerId = TestHelpers.ParseTail(0x1); | ||
57 | SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(3, ownerId, "so1", 0x10); | ||
58 | so1.ScriptSetPhysicsStatus(true); | ||
59 | m_scene.AddSceneObject(so1); | ||
60 | |||
61 | Assert.That(m_scene.SceneGraph.GetTotalObjectsCount(), Is.EqualTo(3)); | ||
62 | Assert.That(m_scene.SceneGraph.GetActiveObjectsCount(), Is.EqualTo(3)); | ||
63 | |||
64 | m_scene.DeleteSceneObject(so1, false); | ||
65 | |||
66 | Assert.That(m_scene.SceneGraph.GetTotalObjectsCount(), Is.EqualTo(0)); | ||
67 | Assert.That(m_scene.SceneGraph.GetActiveObjectsCount(), Is.EqualTo(0)); | ||
68 | } | ||
69 | } | ||
70 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneTelehubTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneTelehubTests.cs new file mode 100644 index 0000000..584a03c --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneTelehubTests.cs | |||
@@ -0,0 +1,118 @@ | |||
1 | /* | ||
2 | * Redistribution and use in source and binary forms, with or without | ||
3 | * modification, are permitted provided that the following conditions are met: | ||
4 | * * Redistributions of source code must retain the above copyright | ||
5 | * notice, this list of conditions and the following disclaimer. | ||
6 | * * Redistributions in binary form must reproduce the above copyright | ||
7 | * notice, this list of conditions and the following disclaimer in the | ||
8 | * documentation and/or other materials provided with the distribution. | ||
9 | * * Neither the name of the OpenSimulator Project nor the | ||
10 | * names of its contributors may be used to endorse or promote products | ||
11 | * derived from this software without specific prior written permission. | ||
12 | * | ||
13 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
16 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
17 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
18 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
19 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
20 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
22 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | |||
25 | using System; | ||
26 | using Nini.Config; | ||
27 | using NUnit.Framework; | ||
28 | using OpenMetaverse; | ||
29 | using OpenSim.Framework; | ||
30 | using OpenSim.Region.CoreModules.World.Estate; | ||
31 | using OpenSim.Region.Framework.Scenes; | ||
32 | using OpenSim.Region.Framework.Interfaces; | ||
33 | using OpenSim.Services.Interfaces; | ||
34 | using OpenSim.Tests.Common; | ||
35 | |||
36 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
37 | { | ||
38 | /// <summary> | ||
39 | /// Scene telehub tests | ||
40 | /// </summary> | ||
41 | /// <remarks> | ||
42 | /// TODO: Tests which run through normal functionality. Currently, the only test is one that checks behaviour | ||
43 | /// in the case of an error condition | ||
44 | /// </remarks> | ||
45 | [TestFixture] | ||
46 | public class SceneTelehubTests : OpenSimTestCase | ||
47 | { | ||
48 | /// <summary> | ||
49 | /// Test for desired behaviour when a telehub has no spawn points | ||
50 | /// </summary> | ||
51 | [Test] | ||
52 | public void TestNoTelehubSpawnPoints() | ||
53 | { | ||
54 | TestHelpers.InMethod(); | ||
55 | // TestHelpers.EnableLogging(); | ||
56 | |||
57 | EstateManagementModule emm = new EstateManagementModule(); | ||
58 | |||
59 | SceneHelpers sh = new SceneHelpers(); | ||
60 | Scene scene = sh.SetupScene(); | ||
61 | SceneHelpers.SetupSceneModules(scene, emm); | ||
62 | |||
63 | UUID telehubSceneObjectOwner = TestHelpers.ParseTail(0x1); | ||
64 | |||
65 | SceneObjectGroup telehubSo = SceneHelpers.AddSceneObject(scene, "telehubObject", telehubSceneObjectOwner); | ||
66 | |||
67 | emm.HandleOnEstateManageTelehub(null, UUID.Zero, UUID.Zero, "connect", telehubSo.LocalId); | ||
68 | scene.RegionInfo.EstateSettings.AllowDirectTeleport = false; | ||
69 | |||
70 | // Must still be possible to successfully log in | ||
71 | UUID loggingInUserId = TestHelpers.ParseTail(0x2); | ||
72 | |||
73 | UserAccount ua | ||
74 | = UserAccountHelpers.CreateUserWithInventory(scene, "Test", "User", loggingInUserId, "password"); | ||
75 | |||
76 | SceneHelpers.AddScenePresence(scene, ua); | ||
77 | |||
78 | Assert.That(scene.GetScenePresence(loggingInUserId), Is.Not.Null); | ||
79 | } | ||
80 | |||
81 | /// <summary> | ||
82 | /// Test for desired behaviour when the scene object nominated as a telehub object does not exist. | ||
83 | /// </summary> | ||
84 | [Test] | ||
85 | public void TestNoTelehubSceneObject() | ||
86 | { | ||
87 | TestHelpers.InMethod(); | ||
88 | // TestHelpers.EnableLogging(); | ||
89 | |||
90 | EstateManagementModule emm = new EstateManagementModule(); | ||
91 | |||
92 | SceneHelpers sh = new SceneHelpers(); | ||
93 | Scene scene = sh.SetupScene(); | ||
94 | SceneHelpers.SetupSceneModules(scene, emm); | ||
95 | |||
96 | UUID telehubSceneObjectOwner = TestHelpers.ParseTail(0x1); | ||
97 | |||
98 | SceneObjectGroup telehubSo = SceneHelpers.AddSceneObject(scene, "telehubObject", telehubSceneObjectOwner); | ||
99 | SceneObjectGroup spawnPointSo = SceneHelpers.AddSceneObject(scene, "spawnpointObject", telehubSceneObjectOwner); | ||
100 | |||
101 | emm.HandleOnEstateManageTelehub(null, UUID.Zero, UUID.Zero, "connect", telehubSo.LocalId); | ||
102 | emm.HandleOnEstateManageTelehub(null, UUID.Zero, UUID.Zero, "spawnpoint add", spawnPointSo.LocalId); | ||
103 | scene.RegionInfo.EstateSettings.AllowDirectTeleport = false; | ||
104 | |||
105 | scene.DeleteSceneObject(telehubSo, false); | ||
106 | |||
107 | // Must still be possible to successfully log in | ||
108 | UUID loggingInUserId = TestHelpers.ParseTail(0x2); | ||
109 | |||
110 | UserAccount ua | ||
111 | = UserAccountHelpers.CreateUserWithInventory(scene, "Test", "User", loggingInUserId, "password"); | ||
112 | |||
113 | SceneHelpers.AddScenePresence(scene, ua); | ||
114 | |||
115 | Assert.That(scene.GetScenePresence(loggingInUserId), Is.Not.Null); | ||
116 | } | ||
117 | } | ||
118 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs new file mode 100644 index 0000000..33ef83b --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs | |||
@@ -0,0 +1,108 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using System.Threading; | ||
33 | using System.Timers; | ||
34 | using Timer=System.Timers.Timer; | ||
35 | using Nini.Config; | ||
36 | using NUnit.Framework; | ||
37 | using OpenMetaverse; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Communications; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | using OpenSim.Region.Framework.Interfaces; | ||
42 | using OpenSim.Region.CoreModules.World.Serialiser; | ||
43 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; | ||
44 | using OpenSim.Tests.Common; | ||
45 | |||
46 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
47 | { | ||
48 | /// <summary> | ||
49 | /// Scene presence tests | ||
50 | /// </summary> | ||
51 | [TestFixture] | ||
52 | public class SceneTests : OpenSimTestCase | ||
53 | { | ||
54 | [Test] | ||
55 | public void TestCreateScene() | ||
56 | { | ||
57 | TestHelpers.InMethod(); | ||
58 | |||
59 | new SceneHelpers().SetupScene(); | ||
60 | } | ||
61 | |||
62 | [Test] | ||
63 | public void TestCreateVarScene() | ||
64 | { | ||
65 | TestHelpers.InMethod(); | ||
66 | UUID regionUuid = TestHelpers.ParseTail(0x1); | ||
67 | uint sizeX = 512; | ||
68 | uint sizeY = 512; | ||
69 | |||
70 | Scene scene | ||
71 | = new SceneHelpers().SetupScene("scene", regionUuid, 1000, 1000, sizeX, sizeY, new IniConfigSource()); | ||
72 | |||
73 | Assert.AreEqual(sizeX, scene.RegionInfo.RegionSizeX); | ||
74 | Assert.AreEqual(sizeY, scene.RegionInfo.RegionSizeY); | ||
75 | } | ||
76 | |||
77 | /// <summary> | ||
78 | /// Very basic scene update test. Should become more elaborate with time. | ||
79 | /// </summary> | ||
80 | [Test] | ||
81 | public void TestUpdateScene() | ||
82 | { | ||
83 | TestHelpers.InMethod(); | ||
84 | |||
85 | Scene scene = new SceneHelpers().SetupScene(); | ||
86 | scene.Update(1); | ||
87 | |||
88 | Assert.That(scene.Frame, Is.EqualTo(1)); | ||
89 | } | ||
90 | |||
91 | [Test] | ||
92 | public void TestShutdownScene() | ||
93 | { | ||
94 | TestHelpers.InMethod(); | ||
95 | |||
96 | Scene scene = new SceneHelpers().SetupScene(); | ||
97 | scene.Close(); | ||
98 | |||
99 | Assert.That(scene.ShuttingDown, Is.True); | ||
100 | Assert.That(scene.Active, Is.False); | ||
101 | |||
102 | // Trying to update a shutdown scene should result in no update | ||
103 | scene.Update(1); | ||
104 | |||
105 | Assert.That(scene.Frame, Is.EqualTo(0)); | ||
106 | } | ||
107 | } | ||
108 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SharedRegionModuleTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SharedRegionModuleTests.cs new file mode 100644 index 0000000..eeda84f --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/SharedRegionModuleTests.cs | |||
@@ -0,0 +1,249 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Net; | ||
31 | using Mono.Addins; | ||
32 | using Nini.Config; | ||
33 | using NUnit.Framework; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim; | ||
36 | using OpenSim.ApplicationPlugins.RegionModulesController; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid; | ||
39 | using OpenSim.Region.Framework.Interfaces; | ||
40 | using OpenSim.Tests.Common; | ||
41 | |||
42 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
43 | { | ||
44 | public class SharedRegionModuleTests : OpenSimTestCase | ||
45 | { | ||
46 | // [Test] | ||
47 | public void TestLifecycle() | ||
48 | { | ||
49 | TestHelpers.InMethod(); | ||
50 | TestHelpers.EnableLogging(); | ||
51 | |||
52 | UUID estateOwnerId = TestHelpers.ParseTail(0x1); | ||
53 | UUID regionId = TestHelpers.ParseTail(0x10); | ||
54 | |||
55 | IConfigSource configSource = new IniConfigSource(); | ||
56 | configSource.AddConfig("Startup"); | ||
57 | configSource.AddConfig("Modules"); | ||
58 | |||
59 | // // We use this to skip estate questions | ||
60 | // Turns out not to be needed is estate owner id is pre-set in region information. | ||
61 | // IConfig estateConfig = configSource.AddConfig(OpenSimBase.ESTATE_SECTION_NAME); | ||
62 | // estateConfig.Set("DefaultEstateOwnerName", "Zaphod Beeblebrox"); | ||
63 | // estateConfig.Set("DefaultEstateOwnerUUID", estateOwnerId); | ||
64 | // estateConfig.Set("DefaultEstateOwnerEMail", "zaphod@galaxy.com"); | ||
65 | // estateConfig.Set("DefaultEstateOwnerPassword", "two heads"); | ||
66 | |||
67 | // For grid servic | ||
68 | configSource.AddConfig("GridService"); | ||
69 | configSource.Configs["Modules"].Set("GridServices", "LocalGridServicesConnector"); | ||
70 | configSource.Configs["GridService"].Set("StorageProvider", "OpenSim.Data.Null.dll:NullRegionData"); | ||
71 | configSource.Configs["GridService"].Set("LocalServiceModule", "OpenSim.Services.GridService.dll:GridService"); | ||
72 | configSource.Configs["GridService"].Set("ConnectionString", "!static"); | ||
73 | |||
74 | LocalGridServicesConnector gridService = new LocalGridServicesConnector(); | ||
75 | // | ||
76 | OpenSim sim = new OpenSim(configSource); | ||
77 | |||
78 | sim.SuppressExit = true; | ||
79 | sim.EnableInitialPluginLoad = false; | ||
80 | sim.LoadEstateDataService = false; | ||
81 | sim.NetServersInfo.HttpListenerPort = 0; | ||
82 | |||
83 | IRegistryCore reg = sim.ApplicationRegistry; | ||
84 | |||
85 | RegionInfo ri = new RegionInfo(); | ||
86 | ri.RegionID = regionId; | ||
87 | ri.EstateSettings.EstateOwner = estateOwnerId; | ||
88 | ri.InternalEndPoint = new IPEndPoint(0, 0); | ||
89 | |||
90 | MockRegionModulesControllerPlugin rmcp = new MockRegionModulesControllerPlugin(); | ||
91 | sim.m_plugins = new List<IApplicationPlugin>() { rmcp }; | ||
92 | reg.RegisterInterface<IRegionModulesController>(rmcp); | ||
93 | |||
94 | // XXX: Have to initialize directly for now | ||
95 | rmcp.Initialise(sim); | ||
96 | |||
97 | rmcp.AddNode(gridService); | ||
98 | |||
99 | TestSharedRegion tsr = new TestSharedRegion(); | ||
100 | rmcp.AddNode(tsr); | ||
101 | |||
102 | // FIXME: Want to use the real one eventually but this is currently directly tied into Mono.Addins | ||
103 | // which has been written in such a way that makes it impossible to use for regression tests. | ||
104 | // RegionModulesControllerPlugin rmcp = new RegionModulesControllerPlugin(); | ||
105 | // rmcp.LoadModulesFromAddins = false; | ||
106 | //// reg.RegisterInterface<IRegionModulesController>(rmcp); | ||
107 | // rmcp.Initialise(sim); | ||
108 | // rmcp.PostInitialise(); | ||
109 | // TypeExtensionNode node = new TypeExtensionNode(); | ||
110 | // node. | ||
111 | // rmcp.AddNode(node, configSource.Configs["Modules"], new Dictionary<RuntimeAddin, IList<int>>()); | ||
112 | |||
113 | sim.Startup(); | ||
114 | IScene scene; | ||
115 | sim.CreateRegion(ri, out scene); | ||
116 | |||
117 | sim.Shutdown(); | ||
118 | |||
119 | List<string> co = tsr.CallOrder; | ||
120 | int expectedEventCount = 6; | ||
121 | |||
122 | Assert.AreEqual( | ||
123 | expectedEventCount, | ||
124 | co.Count, | ||
125 | "Expected {0} events but only got {1} ({2})", | ||
126 | expectedEventCount, co.Count, string.Join(",", co)); | ||
127 | Assert.AreEqual("Initialise", co[0]); | ||
128 | Assert.AreEqual("PostInitialise", co[1]); | ||
129 | Assert.AreEqual("AddRegion", co[2]); | ||
130 | Assert.AreEqual("RegionLoaded", co[3]); | ||
131 | Assert.AreEqual("RemoveRegion", co[4]); | ||
132 | Assert.AreEqual("Close", co[5]); | ||
133 | } | ||
134 | } | ||
135 | |||
136 | class TestSharedRegion : ISharedRegionModule | ||
137 | { | ||
138 | // FIXME: Should really use MethodInfo | ||
139 | public List<string> CallOrder = new List<string>(); | ||
140 | |||
141 | public string Name { get { return "TestSharedRegion"; } } | ||
142 | |||
143 | public Type ReplaceableInterface { get { return null; } } | ||
144 | |||
145 | public void PostInitialise() | ||
146 | { | ||
147 | CallOrder.Add("PostInitialise"); | ||
148 | } | ||
149 | |||
150 | public void Initialise(IConfigSource source) | ||
151 | { | ||
152 | CallOrder.Add("Initialise"); | ||
153 | } | ||
154 | |||
155 | public void Close() | ||
156 | { | ||
157 | CallOrder.Add("Close"); | ||
158 | } | ||
159 | |||
160 | public void AddRegion(Scene scene) | ||
161 | { | ||
162 | CallOrder.Add("AddRegion"); | ||
163 | } | ||
164 | |||
165 | public void RemoveRegion(Scene scene) | ||
166 | { | ||
167 | CallOrder.Add("RemoveRegion"); | ||
168 | } | ||
169 | |||
170 | public void RegionLoaded(Scene scene) | ||
171 | { | ||
172 | CallOrder.Add("RegionLoaded"); | ||
173 | } | ||
174 | } | ||
175 | |||
176 | class MockRegionModulesControllerPlugin : IRegionModulesController, IApplicationPlugin | ||
177 | { | ||
178 | // List of shared module instances, for adding to Scenes | ||
179 | private List<ISharedRegionModule> m_sharedInstances = new List<ISharedRegionModule>(); | ||
180 | |||
181 | // Config access | ||
182 | private OpenSimBase m_openSim; | ||
183 | |||
184 | public string Version { get { return "0"; } } | ||
185 | public string Name { get { return "MockRegionModulesControllerPlugin"; } } | ||
186 | |||
187 | public void Initialise() {} | ||
188 | |||
189 | public void Initialise(OpenSimBase sim) | ||
190 | { | ||
191 | m_openSim = sim; | ||
192 | } | ||
193 | |||
194 | /// <summary> | ||
195 | /// Called when the application loading is completed | ||
196 | /// </summary> | ||
197 | public void PostInitialise() | ||
198 | { | ||
199 | foreach (ISharedRegionModule module in m_sharedInstances) | ||
200 | module.PostInitialise(); | ||
201 | } | ||
202 | |||
203 | public void AddRegionToModules(Scene scene) | ||
204 | { | ||
205 | List<ISharedRegionModule> sharedlist = new List<ISharedRegionModule>(); | ||
206 | |||
207 | foreach (ISharedRegionModule module in m_sharedInstances) | ||
208 | { | ||
209 | module.AddRegion(scene); | ||
210 | scene.AddRegionModule(module.Name, module); | ||
211 | |||
212 | sharedlist.Add(module); | ||
213 | } | ||
214 | |||
215 | foreach (ISharedRegionModule module in sharedlist) | ||
216 | { | ||
217 | module.RegionLoaded(scene); | ||
218 | } | ||
219 | } | ||
220 | |||
221 | public void RemoveRegionFromModules(Scene scene) | ||
222 | { | ||
223 | foreach (IRegionModuleBase module in scene.RegionModules.Values) | ||
224 | { | ||
225 | // m_log.DebugFormat("[REGIONMODULE]: Removing scene {0} from module {1}", | ||
226 | // scene.RegionInfo.RegionName, module.Name); | ||
227 | module.RemoveRegion(scene); | ||
228 | } | ||
229 | |||
230 | scene.RegionModules.Clear(); | ||
231 | } | ||
232 | |||
233 | public void AddNode(ISharedRegionModule module) | ||
234 | { | ||
235 | m_sharedInstances.Add(module); | ||
236 | module.Initialise(m_openSim.ConfigSource.Source); | ||
237 | } | ||
238 | |||
239 | public void Dispose() | ||
240 | { | ||
241 | // We expect that all regions have been removed already | ||
242 | while (m_sharedInstances.Count > 0) | ||
243 | { | ||
244 | m_sharedInstances[0].Close(); | ||
245 | m_sharedInstances.RemoveAt(0); | ||
246 | } | ||
247 | } | ||
248 | } | ||
249 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/TaskInventoryTests.cs b/OpenSim/Region/Framework/Scenes/Tests/TaskInventoryTests.cs new file mode 100644 index 0000000..8ec6974 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/TaskInventoryTests.cs | |||
@@ -0,0 +1,176 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using System.Threading; | ||
33 | using System.Timers; | ||
34 | using Timer=System.Timers.Timer; | ||
35 | using Nini.Config; | ||
36 | using NUnit.Framework; | ||
37 | using OpenMetaverse; | ||
38 | using OpenMetaverse.Assets; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Framework.Communications; | ||
41 | using OpenSim.Region.Framework.Scenes; | ||
42 | using OpenSim.Region.Framework.Interfaces; | ||
43 | using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver; | ||
44 | using OpenSim.Region.CoreModules.World.Serialiser; | ||
45 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; | ||
46 | using OpenSim.Services.Interfaces; | ||
47 | using OpenSim.Tests.Common; | ||
48 | |||
49 | namespace OpenSim.Region.Framework.Tests | ||
50 | { | ||
51 | [TestFixture] | ||
52 | public class TaskInventoryTests : OpenSimTestCase | ||
53 | { | ||
54 | [Test] | ||
55 | public void TestAddTaskInventoryItem() | ||
56 | { | ||
57 | TestHelpers.InMethod(); | ||
58 | // log4net.Config.XmlConfigurator.Configure(); | ||
59 | |||
60 | Scene scene = new SceneHelpers().SetupScene(); | ||
61 | UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene); | ||
62 | SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, user1.PrincipalID); | ||
63 | SceneObjectPart sop1 = sog1.RootPart; | ||
64 | |||
65 | // Create an object embedded inside the first | ||
66 | UUID taskSceneObjectItemId = UUID.Parse("00000000-0000-0000-0000-100000000000"); | ||
67 | TaskInventoryHelpers.AddSceneObject(scene.AssetService, sop1, "tso", taskSceneObjectItemId, user1.PrincipalID); | ||
68 | |||
69 | TaskInventoryItem addedItem = sop1.Inventory.GetInventoryItem(taskSceneObjectItemId); | ||
70 | Assert.That(addedItem.ItemID, Is.EqualTo(taskSceneObjectItemId)); | ||
71 | Assert.That(addedItem.OwnerID, Is.EqualTo(user1.PrincipalID)); | ||
72 | Assert.That(addedItem.ParentID, Is.EqualTo(sop1.UUID)); | ||
73 | Assert.That(addedItem.InvType, Is.EqualTo((int)InventoryType.Object)); | ||
74 | Assert.That(addedItem.Type, Is.EqualTo((int)AssetType.Object)); | ||
75 | } | ||
76 | |||
77 | [Test] | ||
78 | public void TestRezObjectFromInventoryItem() | ||
79 | { | ||
80 | TestHelpers.InMethod(); | ||
81 | // log4net.Config.XmlConfigurator.Configure(); | ||
82 | |||
83 | Scene scene = new SceneHelpers().SetupScene(); | ||
84 | UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene); | ||
85 | SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, user1.PrincipalID); | ||
86 | SceneObjectPart sop1 = sog1.RootPart; | ||
87 | |||
88 | // Create an object embedded inside the first | ||
89 | UUID taskSceneObjectItemId = UUID.Parse("00000000-0000-0000-0000-100000000000"); | ||
90 | TaskInventoryItem taskSceneObjectItem | ||
91 | = TaskInventoryHelpers.AddSceneObject(scene.AssetService, sop1, "tso", taskSceneObjectItemId, user1.PrincipalID); | ||
92 | |||
93 | scene.AddSceneObject(sog1); | ||
94 | |||
95 | Vector3 rezPos = new Vector3(10, 10, 10); | ||
96 | Quaternion rezRot = new Quaternion(0.5f, 0.5f, 0.5f, 0.5f); | ||
97 | Vector3 rezVel = new Vector3(2, 2, 2); | ||
98 | |||
99 | scene.RezObject(sop1, taskSceneObjectItem, rezPos, rezRot, rezVel, 0); | ||
100 | |||
101 | SceneObjectGroup rezzedObject = scene.GetSceneObjectGroup("tso"); | ||
102 | |||
103 | Assert.That(rezzedObject, Is.Not.Null); | ||
104 | Assert.That(rezzedObject.AbsolutePosition, Is.EqualTo(rezPos)); | ||
105 | |||
106 | // Velocity doesn't get applied, probably because there is no physics in tests (yet) | ||
107 | // Assert.That(rezzedObject.Velocity, Is.EqualTo(rezVel)); | ||
108 | Assert.That(rezzedObject.Velocity, Is.EqualTo(Vector3.Zero)); | ||
109 | |||
110 | // Confusingly, this isn't the rezzedObject.Rotation | ||
111 | Assert.That(rezzedObject.RootPart.RotationOffset, Is.EqualTo(rezRot)); | ||
112 | } | ||
113 | |||
114 | /// <summary> | ||
115 | /// Test MoveTaskInventoryItem from a part inventory to a user inventory where the item has no parent folder assigned. | ||
116 | /// </summary> | ||
117 | /// <remarks> | ||
118 | /// This should place it in the most suitable user folder. | ||
119 | /// </remarks> | ||
120 | [Test] | ||
121 | public void TestMoveTaskInventoryItem() | ||
122 | { | ||
123 | TestHelpers.InMethod(); | ||
124 | // log4net.Config.XmlConfigurator.Configure(); | ||
125 | |||
126 | Scene scene = new SceneHelpers().SetupScene(); | ||
127 | UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene); | ||
128 | SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, user1.PrincipalID); | ||
129 | SceneObjectPart sop1 = sog1.RootPart; | ||
130 | TaskInventoryItem sopItem1 | ||
131 | = TaskInventoryHelpers.AddNotecard( | ||
132 | scene.AssetService, sop1, "ncItem", TestHelpers.ParseTail(0x800), TestHelpers.ParseTail(0x900), "Hello World!"); | ||
133 | |||
134 | InventoryFolderBase folder | ||
135 | = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, user1.PrincipalID, "Objects")[0]; | ||
136 | |||
137 | // Perform test | ||
138 | string message; | ||
139 | scene.MoveTaskInventoryItem(user1.PrincipalID, folder.ID, sop1, sopItem1.ItemID, out message); | ||
140 | |||
141 | InventoryItemBase ncUserItem | ||
142 | = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, user1.PrincipalID, "Objects/ncItem"); | ||
143 | Assert.That(ncUserItem, Is.Not.Null, "Objects/ncItem was not found"); | ||
144 | } | ||
145 | |||
146 | /// <summary> | ||
147 | /// Test MoveTaskInventoryItem from a part inventory to a user inventory where the item has no parent folder assigned. | ||
148 | /// </summary> | ||
149 | /// <remarks> | ||
150 | /// This should place it in the most suitable user folder. | ||
151 | /// </remarks> | ||
152 | [Test] | ||
153 | public void TestMoveTaskInventoryItemNoParent() | ||
154 | { | ||
155 | TestHelpers.InMethod(); | ||
156 | // log4net.Config.XmlConfigurator.Configure(); | ||
157 | |||
158 | Scene scene = new SceneHelpers().SetupScene(); | ||
159 | UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene); | ||
160 | SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, user1.PrincipalID); | ||
161 | |||
162 | SceneObjectPart sop1 = sog1.RootPart; | ||
163 | TaskInventoryItem sopItem1 | ||
164 | = TaskInventoryHelpers.AddNotecard( | ||
165 | scene.AssetService, sop1, "ncItem", TestHelpers.ParseTail(0x800), TestHelpers.ParseTail(0x900), "Hello World!"); | ||
166 | |||
167 | // Perform test | ||
168 | string message; | ||
169 | scene.MoveTaskInventoryItem(user1.PrincipalID, UUID.Zero, sop1, sopItem1.ItemID, out message); | ||
170 | |||
171 | InventoryItemBase ncUserItem | ||
172 | = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, user1.PrincipalID, "Notecards/ncItem"); | ||
173 | Assert.That(ncUserItem, Is.Not.Null, "Notecards/ncItem was not found"); | ||
174 | } | ||
175 | } | ||
176 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/UserInventoryTests.cs b/OpenSim/Region/Framework/Scenes/Tests/UserInventoryTests.cs new file mode 100644 index 0000000..edc0a52 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/UserInventoryTests.cs | |||
@@ -0,0 +1,143 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using System.Threading; | ||
33 | using System.Timers; | ||
34 | using Timer=System.Timers.Timer; | ||
35 | using Nini.Config; | ||
36 | using NUnit.Framework; | ||
37 | using OpenMetaverse; | ||
38 | using OpenMetaverse.Assets; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Framework.Communications; | ||
41 | using OpenSim.Region.Framework.Scenes; | ||
42 | using OpenSim.Region.Framework.Interfaces; | ||
43 | using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver; | ||
44 | using OpenSim.Region.CoreModules.World.Serialiser; | ||
45 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; | ||
46 | using OpenSim.Services.Interfaces; | ||
47 | using OpenSim.Tests.Common; | ||
48 | |||
49 | namespace OpenSim.Region.Framework.Tests | ||
50 | { | ||
51 | [TestFixture] | ||
52 | public class UserInventoryTests : OpenSimTestCase | ||
53 | { | ||
54 | [Test] | ||
55 | public void TestCreateInventoryFolders() | ||
56 | { | ||
57 | TestHelpers.InMethod(); | ||
58 | // TestHelpers.EnableLogging(); | ||
59 | |||
60 | // For this test both folders will have the same name which is legal in SL user inventories. | ||
61 | string foldersName = "f1"; | ||
62 | |||
63 | Scene scene = new SceneHelpers().SetupScene(); | ||
64 | UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1001)); | ||
65 | |||
66 | UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, user1.PrincipalID, foldersName, false); | ||
67 | |||
68 | List<InventoryFolderBase> oneFolder | ||
69 | = UserInventoryHelpers.GetInventoryFolders(scene.InventoryService, user1.PrincipalID, foldersName); | ||
70 | |||
71 | Assert.That(oneFolder.Count, Is.EqualTo(1)); | ||
72 | InventoryFolderBase firstRetrievedFolder = oneFolder[0]; | ||
73 | Assert.That(firstRetrievedFolder.Name, Is.EqualTo(foldersName)); | ||
74 | |||
75 | UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, user1.PrincipalID, foldersName, false); | ||
76 | |||
77 | List<InventoryFolderBase> twoFolders | ||
78 | = UserInventoryHelpers.GetInventoryFolders(scene.InventoryService, user1.PrincipalID, foldersName); | ||
79 | |||
80 | Assert.That(twoFolders.Count, Is.EqualTo(2)); | ||
81 | Assert.That(twoFolders[0].Name, Is.EqualTo(foldersName)); | ||
82 | Assert.That(twoFolders[1].Name, Is.EqualTo(foldersName)); | ||
83 | Assert.That(twoFolders[0].ID, Is.Not.EqualTo(twoFolders[1].ID)); | ||
84 | } | ||
85 | |||
86 | [Test] | ||
87 | public void TestGiveInventoryItem() | ||
88 | { | ||
89 | TestHelpers.InMethod(); | ||
90 | // log4net.Config.XmlConfigurator.Configure(); | ||
91 | |||
92 | Scene scene = new SceneHelpers().SetupScene(); | ||
93 | UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1001)); | ||
94 | UserAccount user2 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1002)); | ||
95 | InventoryItemBase item1 = UserInventoryHelpers.CreateInventoryItem(scene, "item1", user1.PrincipalID); | ||
96 | |||
97 | string message; | ||
98 | |||
99 | scene.GiveInventoryItem(user2.PrincipalID, user1.PrincipalID, item1.ID, out message); | ||
100 | |||
101 | InventoryItemBase retrievedItem1 | ||
102 | = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, user2.PrincipalID, "Notecards/item1"); | ||
103 | |||
104 | Assert.That(retrievedItem1, Is.Not.Null); | ||
105 | |||
106 | // Try giving back the freshly received item | ||
107 | scene.GiveInventoryItem(user1.PrincipalID, user2.PrincipalID, retrievedItem1.ID, out message); | ||
108 | |||
109 | List<InventoryItemBase> reretrievedItems | ||
110 | = UserInventoryHelpers.GetInventoryItems(scene.InventoryService, user1.PrincipalID, "Notecards/item1"); | ||
111 | |||
112 | Assert.That(reretrievedItems.Count, Is.EqualTo(2)); | ||
113 | } | ||
114 | |||
115 | [Test] | ||
116 | public void TestGiveInventoryFolder() | ||
117 | { | ||
118 | TestHelpers.InMethod(); | ||
119 | // TestHelpers.EnableLogging(); | ||
120 | |||
121 | Scene scene = new SceneHelpers().SetupScene(); | ||
122 | UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1001)); | ||
123 | UserAccount user2 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1002)); | ||
124 | InventoryFolderBase folder1 | ||
125 | = UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, user1.PrincipalID, "folder1", false); | ||
126 | |||
127 | scene.GiveInventoryFolder(null, user2.PrincipalID, user1.PrincipalID, folder1.ID, UUID.Zero); | ||
128 | |||
129 | InventoryFolderBase retrievedFolder1 | ||
130 | = UserInventoryHelpers.GetInventoryFolder(scene.InventoryService, user2.PrincipalID, "folder1"); | ||
131 | |||
132 | Assert.That(retrievedFolder1, Is.Not.Null); | ||
133 | |||
134 | // Try giving back the freshly received folder | ||
135 | scene.GiveInventoryFolder(null, user1.PrincipalID, user2.PrincipalID, retrievedFolder1.ID, UUID.Zero); | ||
136 | |||
137 | List<InventoryFolderBase> reretrievedFolders | ||
138 | = UserInventoryHelpers.GetInventoryFolders(scene.InventoryService, user1.PrincipalID, "folder1"); | ||
139 | |||
140 | Assert.That(reretrievedFolders.Count, Is.EqualTo(2)); | ||
141 | } | ||
142 | } | ||
143 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs b/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs new file mode 100644 index 0000000..937c414 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs | |||
@@ -0,0 +1,158 @@ | |||
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 | |||
28 | using System.Collections.Generic; | ||
29 | using System.Text; | ||
30 | using NUnit.Framework; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Region.Framework.Scenes; | ||
34 | using OpenSim.Services.Interfaces; | ||
35 | using OpenSim.Tests.Common; | ||
36 | |||
37 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
38 | { | ||
39 | [TestFixture] | ||
40 | public class UuidGathererTests : OpenSimTestCase | ||
41 | { | ||
42 | protected IAssetService m_assetService; | ||
43 | protected UuidGatherer m_uuidGatherer; | ||
44 | |||
45 | [SetUp] | ||
46 | public void Init() | ||
47 | { | ||
48 | // FIXME: We don't need a full scene here - it would be enough to set up the asset service. | ||
49 | Scene scene = new SceneHelpers().SetupScene(); | ||
50 | m_assetService = scene.AssetService; | ||
51 | m_uuidGatherer = new UuidGatherer(m_assetService); | ||
52 | } | ||
53 | |||
54 | [Test] | ||
55 | public void TestCorruptAsset() | ||
56 | { | ||
57 | TestHelpers.InMethod(); | ||
58 | |||
59 | UUID corruptAssetUuid = UUID.Parse("00000000-0000-0000-0000-000000000666"); | ||
60 | AssetBase corruptAsset | ||
61 | = AssetHelpers.CreateAsset(corruptAssetUuid, AssetType.Notecard, "CORRUPT ASSET", UUID.Zero); | ||
62 | m_assetService.Store(corruptAsset); | ||
63 | |||
64 | m_uuidGatherer.AddForInspection(corruptAssetUuid); | ||
65 | m_uuidGatherer.GatherAll(); | ||
66 | |||
67 | // We count the uuid as gathered even if the asset itself is corrupt. | ||
68 | Assert.That(m_uuidGatherer.GatheredUuids.Count, Is.EqualTo(1)); | ||
69 | } | ||
70 | |||
71 | /// <summary> | ||
72 | /// Test requests made for non-existent assets while we're gathering | ||
73 | /// </summary> | ||
74 | [Test] | ||
75 | public void TestMissingAsset() | ||
76 | { | ||
77 | TestHelpers.InMethod(); | ||
78 | |||
79 | UUID missingAssetUuid = UUID.Parse("00000000-0000-0000-0000-000000000666"); | ||
80 | |||
81 | m_uuidGatherer.AddForInspection(missingAssetUuid); | ||
82 | m_uuidGatherer.GatherAll(); | ||
83 | |||
84 | Assert.That(m_uuidGatherer.GatheredUuids.Count, Is.EqualTo(0)); | ||
85 | } | ||
86 | |||
87 | [Test] | ||
88 | public void TestNotecardAsset() | ||
89 | { | ||
90 | TestHelpers.InMethod(); | ||
91 | // TestHelpers.EnableLogging(); | ||
92 | |||
93 | UUID ownerId = TestHelpers.ParseTail(0x10); | ||
94 | UUID embeddedId = TestHelpers.ParseTail(0x20); | ||
95 | UUID secondLevelEmbeddedId = TestHelpers.ParseTail(0x21); | ||
96 | UUID missingEmbeddedId = TestHelpers.ParseTail(0x22); | ||
97 | UUID ncAssetId = TestHelpers.ParseTail(0x30); | ||
98 | |||
99 | AssetBase ncAsset | ||
100 | = AssetHelpers.CreateNotecardAsset( | ||
101 | ncAssetId, string.Format("Hello{0}World{1}", embeddedId, missingEmbeddedId)); | ||
102 | m_assetService.Store(ncAsset); | ||
103 | |||
104 | AssetBase embeddedAsset | ||
105 | = AssetHelpers.CreateNotecardAsset(embeddedId, string.Format("{0} We'll meet again.", secondLevelEmbeddedId)); | ||
106 | m_assetService.Store(embeddedAsset); | ||
107 | |||
108 | AssetBase secondLevelEmbeddedAsset | ||
109 | = AssetHelpers.CreateNotecardAsset(secondLevelEmbeddedId, "Don't know where, don't know when."); | ||
110 | m_assetService.Store(secondLevelEmbeddedAsset); | ||
111 | |||
112 | m_uuidGatherer.AddForInspection(ncAssetId); | ||
113 | m_uuidGatherer.GatherAll(); | ||
114 | |||
115 | // foreach (UUID key in m_uuidGatherer.GatheredUuids.Keys) | ||
116 | // System.Console.WriteLine("key : {0}", key); | ||
117 | |||
118 | Assert.That(m_uuidGatherer.GatheredUuids.Count, Is.EqualTo(3)); | ||
119 | Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(ncAssetId)); | ||
120 | Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(embeddedId)); | ||
121 | Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(secondLevelEmbeddedId)); | ||
122 | } | ||
123 | |||
124 | [Test] | ||
125 | public void TestTaskItems() | ||
126 | { | ||
127 | TestHelpers.InMethod(); | ||
128 | // TestHelpers.EnableLogging(); | ||
129 | |||
130 | UUID ownerId = TestHelpers.ParseTail(0x10); | ||
131 | |||
132 | SceneObjectGroup soL0 = SceneHelpers.CreateSceneObject(1, ownerId, "l0", 0x20); | ||
133 | SceneObjectGroup soL1 = SceneHelpers.CreateSceneObject(1, ownerId, "l1", 0x21); | ||
134 | SceneObjectGroup soL2 = SceneHelpers.CreateSceneObject(1, ownerId, "l2", 0x22); | ||
135 | |||
136 | TaskInventoryHelpers.AddScript( | ||
137 | m_assetService, soL2.RootPart, TestHelpers.ParseTail(0x33), TestHelpers.ParseTail(0x43), "l3-script", "gibberish"); | ||
138 | |||
139 | TaskInventoryHelpers.AddSceneObject( | ||
140 | m_assetService, soL1.RootPart, "l2-item", TestHelpers.ParseTail(0x32), soL2, TestHelpers.ParseTail(0x42)); | ||
141 | TaskInventoryHelpers.AddSceneObject( | ||
142 | m_assetService, soL0.RootPart, "l1-item", TestHelpers.ParseTail(0x31), soL1, TestHelpers.ParseTail(0x41)); | ||
143 | |||
144 | m_uuidGatherer.AddForInspection(soL0); | ||
145 | m_uuidGatherer.GatherAll(); | ||
146 | |||
147 | // foreach (UUID key in m_uuidGatherer.GatheredUuids.Keys) | ||
148 | // System.Console.WriteLine("key : {0}", key); | ||
149 | |||
150 | // We expect to see the default prim texture and the assets of the contained task items | ||
151 | Assert.That(m_uuidGatherer.GatheredUuids.Count, Is.EqualTo(4)); | ||
152 | Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(new UUID(Constants.DefaultTexture))); | ||
153 | Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(TestHelpers.ParseTail(0x41))); | ||
154 | Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(TestHelpers.ParseTail(0x42))); | ||
155 | Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(TestHelpers.ParseTail(0x43))); | ||
156 | } | ||
157 | } | ||
158 | } \ No newline at end of file | ||