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.cs249
1 files changed, 249 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..30b0987
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.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 OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using NUnit.Framework;
30using NUnit.Framework.SyntaxHelpers;
31using OpenMetaverse;
32using OpenSim.Framework;
33using OpenSim.Framework.Communications;
34using OpenSim.Framework.Communications.Cache;
35using OpenSim.Region.Communications.Local;
36using OpenSim.Region.Environment.Scenes;
37using OpenSim.Tests.Common.Mock;
38using OpenSim.Tests.Common.Setup;
39
40namespace OpenSim.Region.Environment.Scenes.Tests
41{
42 /// <summary>
43 /// Linking tests
44 /// </summary>
45 [TestFixture]
46 public class SceneObjectLinkingTests
47 {
48 [Test]
49 public void TestLinkDelink2SceneObjects()
50 {
51 bool debugtest = false;
52
53 Scene scene = SceneSetupHelpers.SetupScene();
54 SceneObjectPart part1 = SceneSetupHelpers.AddSceneObject(scene);
55 SceneObjectGroup grp1 = part1.ParentGroup;
56 SceneObjectPart part2 = SceneSetupHelpers.AddSceneObject(scene);
57 SceneObjectGroup grp2 = part2.ParentGroup;
58
59 grp1.AbsolutePosition = new Vector3(10, 10, 10);
60 grp2.AbsolutePosition = Vector3.Zero;
61
62 // <90,0,0>
63 grp1.Rotation = (Quaternion.CreateFromEulers(90 * Utils.DEG_TO_RAD, 0, 0));
64
65 // <180,0,0>
66 grp2.UpdateGroupRotation(Quaternion.CreateFromEulers(180 * Utils.DEG_TO_RAD, 0, 0));
67
68 // Required for linking
69 grp1.RootPart.UpdateFlag = 0;
70 grp2.RootPart.UpdateFlag = 0;
71
72 // Link grp2 to grp1. part2 becomes child prim to grp1. grp2 is eliminated.
73 grp1.LinkToGroup(grp2);
74
75 // FIXME: Can't do this test yet since group 2 still has its root part! We can't yet null this since
76 // it might cause SOG.ProcessBackup() to fail due to the race condition. This really needs to be fixed.
77 Assert.That(grp2.IsDeleted, "SOG 2 was not registered as deleted after link.");
78 Assert.That(grp2.Children.Count, Is.EqualTo(0), "Group 2 still contained children after delink.");
79 Assert.That(grp1.Children.Count == 2);
80
81 if (debugtest)
82 {
83 System.Console.WriteLine("parts: {0}", grp1.Children.Count);
84 System.Console.WriteLine("Group1: Pos:{0}, Rot:{1}", grp1.AbsolutePosition, grp1.Rotation);
85 System.Console.WriteLine("Group1: Prim1: OffsetPosition:{0}, OffsetRotation:{1}", part1.OffsetPosition, part1.RotationOffset);
86 System.Console.WriteLine("Group1: Prim2: OffsetPosition:{0}, OffsetRotation:{1}", part2.OffsetPosition, part2.RotationOffset);
87 }
88
89 // root part should have no offset position or rotation
90 Assert.That(part1.OffsetPosition == Vector3.Zero && part1.RotationOffset == Quaternion.Identity);
91
92 // offset position should be root part position - part2.absolute position.
93 Assert.That(part2.OffsetPosition == new Vector3(-10, -10, -10));
94
95 float roll = 0;
96 float pitch = 0;
97 float yaw = 0;
98
99 // There's a euler anomoly at 180, 0, 0 so expect 180 to turn into -180.
100 part1.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw);
101 Vector3 rotEuler1 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG);
102
103 if (debugtest)
104 System.Console.WriteLine(rotEuler1);
105
106 part2.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw);
107 Vector3 rotEuler2 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG);
108
109 if (debugtest)
110 System.Console.WriteLine(rotEuler2);
111
112 Assert.That(rotEuler2.ApproxEquals(new Vector3(-180, 0, 0), 0.001f) || rotEuler2.ApproxEquals(new Vector3(180, 0, 0), 0.001f));
113
114 // Delink part 2
115 grp1.DelinkFromGroup(part2.LocalId);
116
117 if (debugtest)
118 System.Console.WriteLine("Group2: Prim2: OffsetPosition:{0}, OffsetRotation:{1}", part2.AbsolutePosition, part2.RotationOffset);
119
120 Assert.That(grp1.Children.Count, Is.EqualTo(1), "Group 1 still contained part2 after delink.");
121 Assert.That(part2.AbsolutePosition == Vector3.Zero);
122 }
123
124 [Test]
125 public void TestLinkDelink2groups4SceneObjects()
126 {
127 bool debugtest = false;
128
129 Scene scene = SceneSetupHelpers.SetupScene();
130 SceneObjectPart part1 = SceneSetupHelpers.AddSceneObject(scene);
131 SceneObjectGroup grp1 = part1.ParentGroup;
132 SceneObjectPart part2 = SceneSetupHelpers.AddSceneObject(scene);
133 SceneObjectGroup grp2 = part2.ParentGroup;
134 SceneObjectPart part3 = SceneSetupHelpers.AddSceneObject(scene);
135 SceneObjectGroup grp3 = part3.ParentGroup;
136 SceneObjectPart part4 = SceneSetupHelpers.AddSceneObject(scene);
137 SceneObjectGroup grp4 = part4.ParentGroup;
138
139 grp1.AbsolutePosition = new Vector3(10, 10, 10);
140 grp2.AbsolutePosition = Vector3.Zero;
141 grp3.AbsolutePosition = new Vector3(20, 20, 20);
142 grp4.AbsolutePosition = new Vector3(40, 40, 40);
143
144 // <90,0,0>
145 grp1.Rotation = (Quaternion.CreateFromEulers(90 * Utils.DEG_TO_RAD, 0, 0));
146
147 // <180,0,0>
148 grp2.UpdateGroupRotation(Quaternion.CreateFromEulers(180 * Utils.DEG_TO_RAD, 0, 0));
149
150 // <270,0,0>
151 grp3.Rotation = (Quaternion.CreateFromEulers(270 * Utils.DEG_TO_RAD, 0, 0));
152
153 // <0,90,0>
154 grp4.UpdateGroupRotation(Quaternion.CreateFromEulers(0, 90 * Utils.DEG_TO_RAD, 0));
155
156 // Required for linking
157 grp1.RootPart.UpdateFlag = 0;
158 grp2.RootPart.UpdateFlag = 0;
159 grp3.RootPart.UpdateFlag = 0;
160 grp4.RootPart.UpdateFlag = 0;
161
162 // Link grp2 to grp1. part2 becomes child prim to grp1. grp2 is eliminated.
163 grp1.LinkToGroup(grp2);
164
165 // Link grp4 to grp3.
166 grp3.LinkToGroup(grp4);
167
168 // At this point we should have 4 parts total in two groups.
169 Assert.That(grp1.Children.Count == 2);
170 Assert.That(grp2.IsDeleted, "Group 2 was not registered as deleted after link.");
171 Assert.That(grp2.Children.Count, Is.EqualTo(0), "Group 2 still contained parts after delink.");
172 Assert.That(grp3.Children.Count == 2);
173 Assert.That(grp4.IsDeleted, "Group 4 was not registered as deleted after link.");
174 Assert.That(grp4.Children.Count, Is.EqualTo(0), "Group 4 still contained parts after delink.");
175
176 if (debugtest)
177 {
178 System.Console.WriteLine("--------After Link-------");
179 System.Console.WriteLine("Group1: parts: {0}", grp1.Children.Count);
180 System.Console.WriteLine("Group1: Pos:{0}, Rot:{1}", grp1.AbsolutePosition, grp1.Rotation);
181 System.Console.WriteLine("Group1: Prim1: OffsetPosition:{0}, OffsetRotation:{1}", part1.OffsetPosition, part1.RotationOffset);
182 System.Console.WriteLine("Group1: Prim2: OffsetPosition:{0}, OffsetRotation:{1}", part2.OffsetPosition, part2.RotationOffset);
183
184 System.Console.WriteLine("Group3: parts: {0}", grp3.Children.Count);
185 System.Console.WriteLine("Group3: Pos:{0}, Rot:{1}", grp3.AbsolutePosition, grp3.Rotation);
186 System.Console.WriteLine("Group3: Prim1: OffsetPosition:{0}, OffsetRotation:{1}", part3.OffsetPosition, part3.RotationOffset);
187 System.Console.WriteLine("Group3: Prim2: OffsetPosition:{0}, OffsetRotation:{1}", part4.OffsetPosition, part4.RotationOffset);
188 }
189
190 // Required for linking
191 grp1.RootPart.UpdateFlag = 0;
192 grp3.RootPart.UpdateFlag = 0;
193
194 // root part should have no offset position or rotation
195 Assert.That(part1.OffsetPosition == Vector3.Zero && part1.RotationOffset == Quaternion.Identity);
196
197 // offset position should be root part position - part2.absolute position.
198 Assert.That(part2.OffsetPosition == new Vector3(-10, -10, -10));
199
200 float roll = 0;
201 float pitch = 0;
202 float yaw = 0;
203
204 // There's a euler anomoly at 180, 0, 0 so expect 180 to turn into -180.
205 part1.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw);
206 Vector3 rotEuler1 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG);
207
208 if (debugtest)
209 System.Console.WriteLine(rotEuler1);
210
211 part2.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw);
212 Vector3 rotEuler2 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG);
213
214 if (debugtest)
215 System.Console.WriteLine(rotEuler2);
216
217 Assert.That(rotEuler2.ApproxEquals(new Vector3(-180, 0, 0), 0.001f) || rotEuler2.ApproxEquals(new Vector3(180, 0, 0), 0.001f));
218
219 // Now we're linking the first group to the third group. This will make the first group child parts of the third one.
220 grp3.LinkToGroup(grp1);
221
222 // Delink parts 2 and 3
223 grp3.DelinkFromGroup(part2.LocalId);
224 grp3.DelinkFromGroup(part3.LocalId);
225
226 if (debugtest)
227 {
228 System.Console.WriteLine("--------After De-Link-------");
229 System.Console.WriteLine("Group1: parts: {0}", grp1.Children.Count);
230 System.Console.WriteLine("Group1: Pos:{0}, Rot:{1}", grp1.AbsolutePosition, grp1.Rotation);
231 System.Console.WriteLine("Group1: Prim1: OffsetPosition:{0}, OffsetRotation:{1}", part1.OffsetPosition, part1.RotationOffset);
232 System.Console.WriteLine("NoGroup: Prim2: AbsolutePosition:{0}, OffsetRotation:{1}", part2.AbsolutePosition, part2.RotationOffset);
233
234 System.Console.WriteLine("Group3: parts: {0}", grp3.Children.Count);
235 System.Console.WriteLine("Group3: Pos:{0}, Rot:{1}", grp3.AbsolutePosition, grp3.Rotation);
236 System.Console.WriteLine("Group3: Prim1: OffsetPosition:{0}, OffsetRotation:{1}", part3.OffsetPosition, part3.RotationOffset);
237 System.Console.WriteLine("Group3: Prim2: OffsetPosition:{0}, OffsetRotation:{1}", part4.OffsetPosition, part4.RotationOffset);
238 }
239
240 Assert.That(part2.AbsolutePosition == Vector3.Zero);
241 Assert.That(part4.OffsetPosition == new Vector3(20, 20, 20));
242 Quaternion compareQuaternion = new Quaternion(0, 0.7071068f, 0, 0.7071068f);
243 Assert.That((part4.RotationOffset.X - compareQuaternion.X < 0.00003)
244 && (part4.RotationOffset.Y - compareQuaternion.Y < 0.00003)
245 && (part4.RotationOffset.Z - compareQuaternion.Z < 0.00003)
246 && (part4.RotationOffset.W - compareQuaternion.W < 0.00003));
247 }
248 }
249}