opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 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 OpenSim.Tests.Common.Mock;
38 using log4net;
39  
40 namespace OpenSim.Region.Framework.Scenes.Tests
41 {
42 [TestFixture]
43 public class SceneObjectLinkingTests : OpenSimTestCase
44 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46  
47 /// <summary>
48 /// Links to self should be ignored.
49 /// </summary>
50 [Test]
51 public void TestLinkToSelf()
52 {
53 TestHelpers.InMethod();
54  
55 UUID ownerId = TestHelpers.ParseTail(0x1);
56 int nParts = 3;
57  
58 TestScene scene = new SceneHelpers().SetupScene();
59 SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(nParts, ownerId, "TestLinkToSelf_", 0x10);
60 scene.AddSceneObject(sog1);
61 scene.LinkObjects(ownerId, sog1.LocalId, new List<uint>() { sog1.Parts[1].LocalId });
62 // sog1.LinkToGroup(sog1);
63  
64 Assert.That(sog1.Parts.Length, Is.EqualTo(nParts));
65 }
66  
67 [Test]
68 public void TestLinkDelink2SceneObjects()
69 {
70 TestHelpers.InMethod();
71  
72 bool debugtest = false;
73  
74 Scene scene = new SceneHelpers().SetupScene();
75 SceneObjectGroup grp1 = SceneHelpers.AddSceneObject(scene);
76 SceneObjectPart part1 = grp1.RootPart;
77 SceneObjectGroup grp2 = SceneHelpers.AddSceneObject(scene);
78 SceneObjectPart part2 = grp2.RootPart;
79  
80 grp1.AbsolutePosition = new Vector3(10, 10, 10);
81 grp2.AbsolutePosition = Vector3.Zero;
82  
83 // <90,0,0>
84 // grp1.UpdateGroupRotationR(Quaternion.CreateFromEulers(90 * Utils.DEG_TO_RAD, 0, 0));
85  
86 // <180,0,0>
87 grp2.UpdateGroupRotationR(Quaternion.CreateFromEulers(180 * Utils.DEG_TO_RAD, 0, 0));
88  
89 // Required for linking
90 grp1.RootPart.ClearUpdateSchedule();
91 grp2.RootPart.ClearUpdateSchedule();
92  
93 // Link grp2 to grp1. part2 becomes child prim to grp1. grp2 is eliminated.
94 grp1.LinkToGroup(grp2);
95  
96 // FIXME: Can't do this test yet since group 2 still has its root part! We can't yet null this since
97 // it might cause SOG.ProcessBackup() to fail due to the race condition. This really needs to be fixed.
98 Assert.That(grp2.IsDeleted, "SOG 2 was not registered as deleted after link.");
99 Assert.That(grp2.Parts.Length, Is.EqualTo(0), "Group 2 still contained children after delink.");
100 Assert.That(grp1.Parts.Length == 2);
101  
102 if (debugtest)
103 {
104 m_log.Debug("parts: " + grp1.Parts.Length);
105 m_log.Debug("Group1: Pos:"+grp1.AbsolutePosition+", Rot:"+grp1.GroupRotation);
106 m_log.Debug("Group1: Prim1: OffsetPosition:"+ part1.OffsetPosition+", OffsetRotation:"+part1.RotationOffset);
107 m_log.Debug("Group1: Prim2: OffsetPosition:"+part2.OffsetPosition+", OffsetRotation:"+part2.RotationOffset);
108 }
109  
110 // root part should have no offset position or rotation
111 Assert.That(part1.OffsetPosition == Vector3.Zero && part1.RotationOffset == Quaternion.Identity,
112 "root part should have no offset position or rotation");
113  
114 // offset position should be root part position - part2.absolute position.
115 Assert.That(part2.OffsetPosition == new Vector3(-10, -10, -10),
116 "offset position should be root part position - part2.absolute position.");
117  
118 float roll = 0;
119 float pitch = 0;
120 float yaw = 0;
121  
122 // There's a euler anomoly at 180, 0, 0 so expect 180 to turn into -180.
123 part1.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw);
124 Vector3 rotEuler1 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG);
125  
126 if (debugtest)
127 m_log.Debug(rotEuler1);
128  
129 part2.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw);
130 Vector3 rotEuler2 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG);
131  
132 if (debugtest)
133 m_log.Debug(rotEuler2);
134  
135 Assert.That(rotEuler2.ApproxEquals(new Vector3(-180, 0, 0), 0.001f) || rotEuler2.ApproxEquals(new Vector3(180, 0, 0), 0.001f),
136 "Not exactly sure what this is asserting...");
137  
138 // Delink part 2
139 SceneObjectGroup grp3 = grp1.DelinkFromGroup(part2.LocalId);
140  
141 if (debugtest)
142 m_log.Debug("Group2: Prim2: OffsetPosition:" + part2.AbsolutePosition + ", OffsetRotation:" + part2.RotationOffset);
143  
144 Assert.That(grp1.Parts.Length, Is.EqualTo(1), "Group 1 still contained part2 after delink.");
145 Assert.That(part2.AbsolutePosition == Vector3.Zero, "The absolute position should be zero");
146 Assert.That(grp3.HasGroupChangedDueToDelink, Is.True);
147 }
148  
149 [Test]
150 public void TestLinkDelink2groups4SceneObjects()
151 {
152 TestHelpers.InMethod();
153  
154 bool debugtest = false;
155  
156 Scene scene = new SceneHelpers().SetupScene();
157 SceneObjectGroup grp1 = SceneHelpers.AddSceneObject(scene);
158 SceneObjectPart part1 = grp1.RootPart;
159 SceneObjectGroup grp2 = SceneHelpers.AddSceneObject(scene);
160 SceneObjectPart part2 = grp2.RootPart;
161 SceneObjectGroup grp3 = SceneHelpers.AddSceneObject(scene);
162 SceneObjectPart part3 = grp3.RootPart;
163 SceneObjectGroup grp4 = SceneHelpers.AddSceneObject(scene);
164 SceneObjectPart part4 = grp4.RootPart;
165  
166 grp1.AbsolutePosition = new Vector3(10, 10, 10);
167 grp2.AbsolutePosition = Vector3.Zero;
168 grp3.AbsolutePosition = new Vector3(20, 20, 20);
169 grp4.AbsolutePosition = new Vector3(40, 40, 40);
170  
171 // <90,0,0>
172 // grp1.UpdateGroupRotationR(Quaternion.CreateFromEulers(90 * Utils.DEG_TO_RAD, 0, 0));
173  
174 // <180,0,0>
175 grp2.UpdateGroupRotationR(Quaternion.CreateFromEulers(180 * Utils.DEG_TO_RAD, 0, 0));
176  
177 // <270,0,0>
178 // grp3.UpdateGroupRotationR(Quaternion.CreateFromEulers(270 * Utils.DEG_TO_RAD, 0, 0));
179  
180 // <0,90,0>
181 grp4.UpdateGroupRotationR(Quaternion.CreateFromEulers(0, 90 * Utils.DEG_TO_RAD, 0));
182  
183 // Required for linking
184 grp1.RootPart.ClearUpdateSchedule();
185 grp2.RootPart.ClearUpdateSchedule();
186 grp3.RootPart.ClearUpdateSchedule();
187 grp4.RootPart.ClearUpdateSchedule();
188  
189 // Link grp2 to grp1. part2 becomes child prim to grp1. grp2 is eliminated.
190 grp1.LinkToGroup(grp2);
191  
192 // Link grp4 to grp3.
193 grp3.LinkToGroup(grp4);
194  
195 // At this point we should have 4 parts total in two groups.
196 Assert.That(grp1.Parts.Length == 2, "Group1 children count should be 2");
197 Assert.That(grp2.IsDeleted, "Group 2 was not registered as deleted after link.");
198 Assert.That(grp2.Parts.Length, Is.EqualTo(0), "Group 2 still contained parts after delink.");
199 Assert.That(grp3.Parts.Length == 2, "Group3 children count should be 2");
200 Assert.That(grp4.IsDeleted, "Group 4 was not registered as deleted after link.");
201 Assert.That(grp4.Parts.Length, Is.EqualTo(0), "Group 4 still contained parts after delink.");
202  
203 if (debugtest)
204 {
205 m_log.Debug("--------After Link-------");
206 m_log.Debug("Group1: parts:" + grp1.Parts.Length);
207 m_log.Debug("Group1: Pos:"+grp1.AbsolutePosition+", Rot:"+grp1.GroupRotation);
208 m_log.Debug("Group1: Prim1: OffsetPosition:" + part1.OffsetPosition + ", OffsetRotation:" + part1.RotationOffset);
209 m_log.Debug("Group1: Prim2: OffsetPosition:"+part2.OffsetPosition+", OffsetRotation:"+ part2.RotationOffset);
210  
211 m_log.Debug("Group3: parts:" + grp3.Parts.Length);
212 m_log.Debug("Group3: Pos:"+grp3.AbsolutePosition+", Rot:"+grp3.GroupRotation);
213 m_log.Debug("Group3: Prim1: OffsetPosition:"+part3.OffsetPosition+", OffsetRotation:"+part3.RotationOffset);
214 m_log.Debug("Group3: Prim2: OffsetPosition:"+part4.OffsetPosition+", OffsetRotation:"+part4.RotationOffset);
215 }
216  
217 // Required for linking
218 grp1.RootPart.ClearUpdateSchedule();
219 grp3.RootPart.ClearUpdateSchedule();
220  
221 // root part should have no offset position or rotation
222 Assert.That(part1.OffsetPosition == Vector3.Zero && part1.RotationOffset == Quaternion.Identity,
223 "root part should have no offset position or rotation (again)");
224  
225 // offset position should be root part position - part2.absolute position.
226 Assert.That(part2.OffsetPosition == new Vector3(-10, -10, -10),
227 "offset position should be root part position - part2.absolute position (again)");
228  
229 float roll = 0;
230 float pitch = 0;
231 float yaw = 0;
232  
233 // There's a euler anomoly at 180, 0, 0 so expect 180 to turn into -180.
234 part1.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw);
235 Vector3 rotEuler1 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG);
236  
237 if (debugtest)
238 m_log.Debug(rotEuler1);
239  
240 part2.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw);
241 Vector3 rotEuler2 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG);
242  
243 if (debugtest)
244 m_log.Debug(rotEuler2);
245  
246 Assert.That(rotEuler2.ApproxEquals(new Vector3(-180, 0, 0), 0.001f) || rotEuler2.ApproxEquals(new Vector3(180, 0, 0), 0.001f),
247 "Not sure what this assertion is all about...");
248  
249 // Now we're linking the first group to the third group. This will make the first group child parts of the third one.
250 grp3.LinkToGroup(grp1);
251  
252 // Delink parts 2 and 3
253 grp3.DelinkFromGroup(part2.LocalId);
254 grp3.DelinkFromGroup(part3.LocalId);
255  
256 if (debugtest)
257 {
258 m_log.Debug("--------After De-Link-------");
259 m_log.Debug("Group1: parts:" + grp1.Parts.Length);
260 m_log.Debug("Group1: Pos:" + grp1.AbsolutePosition + ", Rot:" + grp1.GroupRotation);
261 m_log.Debug("Group1: Prim1: OffsetPosition:" + part1.OffsetPosition + ", OffsetRotation:" + part1.RotationOffset);
262 m_log.Debug("Group1: Prim2: OffsetPosition:" + part2.OffsetPosition + ", OffsetRotation:" + part2.RotationOffset);
263  
264 m_log.Debug("Group3: parts:" + grp3.Parts.Length);
265 m_log.Debug("Group3: Pos:" + grp3.AbsolutePosition + ", Rot:" + grp3.GroupRotation);
266 m_log.Debug("Group3: Prim1: OffsetPosition:" + part3.OffsetPosition + ", OffsetRotation:" + part3.RotationOffset);
267 m_log.Debug("Group3: Prim2: OffsetPosition:" + part4.OffsetPosition + ", OffsetRotation:" + part4.RotationOffset);
268 }
269  
270 Assert.That(part2.AbsolutePosition == Vector3.Zero, "Badness 1");
271 Assert.That(part4.OffsetPosition == new Vector3(20, 20, 20), "Badness 2");
272 Quaternion compareQuaternion = new Quaternion(0, 0.7071068f, 0, 0.7071068f);
273 Assert.That((part4.RotationOffset.X - compareQuaternion.X < 0.00003)
274 && (part4.RotationOffset.Y - compareQuaternion.Y < 0.00003)
275 && (part4.RotationOffset.Z - compareQuaternion.Z < 0.00003)
276 && (part4.RotationOffset.W - compareQuaternion.W < 0.00003),
277 "Badness 3");
278 }
279  
280 /// <summary>
281 /// Test that a new scene object which is already linked is correctly persisted to the persistence layer.
282 /// </summary>
283 [Test]
284 public void TestNewSceneObjectLinkPersistence()
285 {
286 TestHelpers.InMethod();
287 //log4net.Config.XmlConfigurator.Configure();
288  
289 TestScene scene = new SceneHelpers().SetupScene();
290  
291 string rootPartName = "rootpart";
292 UUID rootPartUuid = new UUID("00000000-0000-0000-0000-000000000001");
293 string linkPartName = "linkpart";
294 UUID linkPartUuid = new UUID("00000000-0000-0000-0001-000000000000");
295  
296 SceneObjectPart rootPart
297 = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
298 { Name = rootPartName, UUID = rootPartUuid };
299 SceneObjectPart linkPart
300 = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
301 { Name = linkPartName, UUID = linkPartUuid };
302  
303 SceneObjectGroup sog = new SceneObjectGroup(rootPart);
304 sog.AddPart(linkPart);
305 scene.AddNewSceneObject(sog, true);
306  
307 // In a test, we have to crank the backup handle manually. Normally this would be done by the timer invoked
308 // scene backup thread.
309 scene.Backup(true);
310  
311 List<SceneObjectGroup> storedObjects = scene.SimulationDataService.LoadObjects(scene.RegionInfo.RegionID);
312  
313 Assert.That(storedObjects.Count, Is.EqualTo(1));
314 Assert.That(storedObjects[0].Parts.Length, Is.EqualTo(2));
315 Assert.That(storedObjects[0].ContainsPart(rootPartUuid));
316 Assert.That(storedObjects[0].ContainsPart(linkPartUuid));
317 }
318  
319 /// <summary>
320 /// Test that a delink of a previously linked object is correctly persisted to the database
321 /// </summary>
322 [Test]
323 public void TestDelinkPersistence()
324 {
325 TestHelpers.InMethod();
326 //log4net.Config.XmlConfigurator.Configure();
327  
328 TestScene scene = new SceneHelpers().SetupScene();
329  
330 string rootPartName = "rootpart";
331 UUID rootPartUuid = new UUID("00000000-0000-0000-0000-000000000001");
332 string linkPartName = "linkpart";
333 UUID linkPartUuid = new UUID("00000000-0000-0000-0001-000000000000");
334  
335 SceneObjectPart rootPart
336 = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
337 { Name = rootPartName, UUID = rootPartUuid };
338 SceneObjectPart linkPart
339 = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
340 { Name = linkPartName, UUID = linkPartUuid };
341  
342 SceneObjectGroup sog = new SceneObjectGroup(rootPart);
343 sog.AddPart(linkPart);
344 scene.AddNewSceneObject(sog, true);
345  
346 // In a test, we have to crank the backup handle manually. Normally this would be done by the timer invoked
347 // scene backup thread.
348 scene.Backup(true);
349  
350 // These changes should occur immediately without waiting for a backup pass
351 SceneObjectGroup groupToDelete = sog.DelinkFromGroup(linkPart, false);
352  
353 Assert.That(groupToDelete.HasGroupChangedDueToDelink, Is.True);
354 scene.DeleteSceneObject(groupToDelete, false);
355 Assert.That(groupToDelete.HasGroupChangedDueToDelink, Is.False);
356  
357 List<SceneObjectGroup> storedObjects = scene.SimulationDataService.LoadObjects(scene.RegionInfo.RegionID);
358  
359 Assert.That(storedObjects.Count, Is.EqualTo(1));
360 Assert.That(storedObjects[0].Parts.Length, Is.EqualTo(1));
361 Assert.That(storedObjects[0].ContainsPart(rootPartUuid));
362 }
363 }
364 }