aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs372
1 files changed, 372 insertions, 0 deletions
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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using NUnit.Framework;
32using OpenMetaverse;
33using OpenSim.Framework;
34using OpenSim.Framework.Communications;
35using OpenSim.Region.Framework.Scenes;
36using OpenSim.Tests.Common;
37using log4net;
38
39namespace 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}