diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs | 258 |
1 files changed, 0 insertions, 258 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs deleted file mode 100644 index bf13607..0000000 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs +++ /dev/null | |||
@@ -1,258 +0,0 @@ | |||
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 NUnit.Framework.SyntaxHelpers; | ||
32 | using OpenMetaverse; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Framework.Communications; | ||
35 | using OpenSim.Framework.Communications.Cache; | ||
36 | using OpenSim.Region.Communications.Local; | ||
37 | using OpenSim.Region.Framework.Scenes; | ||
38 | using OpenSim.Tests.Common; | ||
39 | using OpenSim.Tests.Common.Mock; | ||
40 | using OpenSim.Tests.Common.Setup; | ||
41 | using log4net; | ||
42 | |||
43 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
44 | { | ||
45 | /// <summary> | ||
46 | /// Linking tests | ||
47 | /// </summary> | ||
48 | [TestFixture] | ||
49 | public class SceneObjectLinkingTests | ||
50 | { | ||
51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
52 | |||
53 | [Test] | ||
54 | public void TestLinkDelink2SceneObjects() | ||
55 | { | ||
56 | TestHelper.InMethod(); | ||
57 | |||
58 | bool debugtest = false; | ||
59 | |||
60 | Scene scene = SceneSetupHelpers.SetupScene(); | ||
61 | SceneObjectPart part1 = SceneSetupHelpers.AddSceneObject(scene); | ||
62 | SceneObjectGroup grp1 = part1.ParentGroup; | ||
63 | SceneObjectPart part2 = SceneSetupHelpers.AddSceneObject(scene); | ||
64 | SceneObjectGroup grp2 = part2.ParentGroup; | ||
65 | |||
66 | grp1.AbsolutePosition = new Vector3(10, 10, 10); | ||
67 | grp2.AbsolutePosition = Vector3.Zero; | ||
68 | |||
69 | // <90,0,0> | ||
70 | grp1.Rotation = (Quaternion.CreateFromEulers(90 * Utils.DEG_TO_RAD, 0, 0)); | ||
71 | |||
72 | // <180,0,0> | ||
73 | grp2.UpdateGroupRotation(Quaternion.CreateFromEulers(180 * Utils.DEG_TO_RAD, 0, 0)); | ||
74 | |||
75 | // Required for linking | ||
76 | grp1.RootPart.UpdateFlag = 0; | ||
77 | grp2.RootPart.UpdateFlag = 0; | ||
78 | |||
79 | // Link grp2 to grp1. part2 becomes child prim to grp1. grp2 is eliminated. | ||
80 | grp1.LinkToGroup(grp2); | ||
81 | |||
82 | // FIXME: Can't do this test yet since group 2 still has its root part! We can't yet null this since | ||
83 | // it might cause SOG.ProcessBackup() to fail due to the race condition. This really needs to be fixed. | ||
84 | Assert.That(grp2.IsDeleted, "SOG 2 was not registered as deleted after link."); | ||
85 | Assert.That(grp2.Children.Count, Is.EqualTo(0), "Group 2 still contained children after delink."); | ||
86 | Assert.That(grp1.Children.Count == 2); | ||
87 | |||
88 | if (debugtest) | ||
89 | { | ||
90 | m_log.Debug("parts: " + grp1.Children.Count); | ||
91 | m_log.Debug("Group1: Pos:"+grp1.AbsolutePosition+", Rot:"+grp1.Rotation); | ||
92 | m_log.Debug("Group1: Prim1: OffsetPosition:"+ part1.OffsetPosition+", OffsetRotation:"+part1.RotationOffset); | ||
93 | m_log.Debug("Group1: Prim2: OffsetPosition:"+part2.OffsetPosition+", OffsetRotation:"+part2.RotationOffset); | ||
94 | } | ||
95 | |||
96 | // root part should have no offset position or rotation | ||
97 | Assert.That(part1.OffsetPosition == Vector3.Zero && part1.RotationOffset == Quaternion.Identity); | ||
98 | |||
99 | // offset position should be root part position - part2.absolute position. | ||
100 | Assert.That(part2.OffsetPosition == new Vector3(-10, -10, -10)); | ||
101 | |||
102 | float roll = 0; | ||
103 | float pitch = 0; | ||
104 | float yaw = 0; | ||
105 | |||
106 | // There's a euler anomoly at 180, 0, 0 so expect 180 to turn into -180. | ||
107 | part1.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw); | ||
108 | Vector3 rotEuler1 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG); | ||
109 | |||
110 | if (debugtest) | ||
111 | m_log.Debug(rotEuler1); | ||
112 | |||
113 | part2.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw); | ||
114 | Vector3 rotEuler2 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG); | ||
115 | |||
116 | if (debugtest) | ||
117 | m_log.Debug(rotEuler2); | ||
118 | |||
119 | Assert.That(rotEuler2.ApproxEquals(new Vector3(-180, 0, 0), 0.001f) || rotEuler2.ApproxEquals(new Vector3(180, 0, 0), 0.001f)); | ||
120 | |||
121 | // Delink part 2 | ||
122 | grp1.DelinkFromGroup(part2.LocalId); | ||
123 | |||
124 | if (debugtest) | ||
125 | m_log.Debug("Group2: Prim2: OffsetPosition:" + part2.AbsolutePosition + ", OffsetRotation:" + part2.RotationOffset); | ||
126 | |||
127 | Assert.That(grp1.Children.Count, Is.EqualTo(1), "Group 1 still contained part2 after delink."); | ||
128 | Assert.That(part2.AbsolutePosition == Vector3.Zero); | ||
129 | } | ||
130 | |||
131 | [Test] | ||
132 | public void TestLinkDelink2groups4SceneObjects() | ||
133 | { | ||
134 | TestHelper.InMethod(); | ||
135 | |||
136 | bool debugtest = false; | ||
137 | |||
138 | Scene scene = SceneSetupHelpers.SetupScene(); | ||
139 | SceneObjectPart part1 = SceneSetupHelpers.AddSceneObject(scene); | ||
140 | SceneObjectGroup grp1 = part1.ParentGroup; | ||
141 | SceneObjectPart part2 = SceneSetupHelpers.AddSceneObject(scene); | ||
142 | SceneObjectGroup grp2 = part2.ParentGroup; | ||
143 | SceneObjectPart part3 = SceneSetupHelpers.AddSceneObject(scene); | ||
144 | SceneObjectGroup grp3 = part3.ParentGroup; | ||
145 | SceneObjectPart part4 = SceneSetupHelpers.AddSceneObject(scene); | ||
146 | SceneObjectGroup grp4 = part4.ParentGroup; | ||
147 | |||
148 | grp1.AbsolutePosition = new Vector3(10, 10, 10); | ||
149 | grp2.AbsolutePosition = Vector3.Zero; | ||
150 | grp3.AbsolutePosition = new Vector3(20, 20, 20); | ||
151 | grp4.AbsolutePosition = new Vector3(40, 40, 40); | ||
152 | |||
153 | // <90,0,0> | ||
154 | grp1.Rotation = (Quaternion.CreateFromEulers(90 * Utils.DEG_TO_RAD, 0, 0)); | ||
155 | |||
156 | // <180,0,0> | ||
157 | grp2.UpdateGroupRotation(Quaternion.CreateFromEulers(180 * Utils.DEG_TO_RAD, 0, 0)); | ||
158 | |||
159 | // <270,0,0> | ||
160 | grp3.Rotation = (Quaternion.CreateFromEulers(270 * Utils.DEG_TO_RAD, 0, 0)); | ||
161 | |||
162 | // <0,90,0> | ||
163 | grp4.UpdateGroupRotation(Quaternion.CreateFromEulers(0, 90 * Utils.DEG_TO_RAD, 0)); | ||
164 | |||
165 | // Required for linking | ||
166 | grp1.RootPart.UpdateFlag = 0; | ||
167 | grp2.RootPart.UpdateFlag = 0; | ||
168 | grp3.RootPart.UpdateFlag = 0; | ||
169 | grp4.RootPart.UpdateFlag = 0; | ||
170 | |||
171 | // Link grp2 to grp1. part2 becomes child prim to grp1. grp2 is eliminated. | ||
172 | grp1.LinkToGroup(grp2); | ||
173 | |||
174 | // Link grp4 to grp3. | ||
175 | grp3.LinkToGroup(grp4); | ||
176 | |||
177 | // At this point we should have 4 parts total in two groups. | ||
178 | Assert.That(grp1.Children.Count == 2); | ||
179 | Assert.That(grp2.IsDeleted, "Group 2 was not registered as deleted after link."); | ||
180 | Assert.That(grp2.Children.Count, Is.EqualTo(0), "Group 2 still contained parts after delink."); | ||
181 | Assert.That(grp3.Children.Count == 2); | ||
182 | Assert.That(grp4.IsDeleted, "Group 4 was not registered as deleted after link."); | ||
183 | Assert.That(grp4.Children.Count, Is.EqualTo(0), "Group 4 still contained parts after delink."); | ||
184 | |||
185 | if (debugtest) | ||
186 | { | ||
187 | m_log.Debug("--------After Link-------"); | ||
188 | m_log.Debug("Group1: parts:" + grp1.Children.Count); | ||
189 | m_log.Debug("Group1: Pos:"+grp1.AbsolutePosition+", Rot:"+grp1.Rotation); | ||
190 | m_log.Debug("Group1: Prim1: OffsetPosition:" + part1.OffsetPosition + ", OffsetRotation:" + part1.RotationOffset); | ||
191 | m_log.Debug("Group1: Prim2: OffsetPosition:"+part2.OffsetPosition+", OffsetRotation:"+ part2.RotationOffset); | ||
192 | |||
193 | m_log.Debug("Group3: parts:"+grp3.Children.Count); | ||
194 | m_log.Debug("Group3: Pos:"+grp3.AbsolutePosition+", Rot:"+grp3.Rotation); | ||
195 | m_log.Debug("Group3: Prim1: OffsetPosition:"+part3.OffsetPosition+", OffsetRotation:"+part3.RotationOffset); | ||
196 | m_log.Debug("Group3: Prim2: OffsetPosition:"+part4.OffsetPosition+", OffsetRotation:"+part4.RotationOffset); | ||
197 | } | ||
198 | |||
199 | // Required for linking | ||
200 | grp1.RootPart.UpdateFlag = 0; | ||
201 | grp3.RootPart.UpdateFlag = 0; | ||
202 | |||
203 | // root part should have no offset position or rotation | ||
204 | Assert.That(part1.OffsetPosition == Vector3.Zero && part1.RotationOffset == Quaternion.Identity); | ||
205 | |||
206 | // offset position should be root part position - part2.absolute position. | ||
207 | Assert.That(part2.OffsetPosition == new Vector3(-10, -10, -10)); | ||
208 | |||
209 | float roll = 0; | ||
210 | float pitch = 0; | ||
211 | float yaw = 0; | ||
212 | |||
213 | // There's a euler anomoly at 180, 0, 0 so expect 180 to turn into -180. | ||
214 | part1.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw); | ||
215 | Vector3 rotEuler1 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG); | ||
216 | |||
217 | if (debugtest) | ||
218 | m_log.Debug(rotEuler1); | ||
219 | |||
220 | part2.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw); | ||
221 | Vector3 rotEuler2 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG); | ||
222 | |||
223 | if (debugtest) | ||
224 | m_log.Debug(rotEuler2); | ||
225 | |||
226 | Assert.That(rotEuler2.ApproxEquals(new Vector3(-180, 0, 0), 0.001f) || rotEuler2.ApproxEquals(new Vector3(180, 0, 0), 0.001f)); | ||
227 | |||
228 | // Now we're linking the first group to the third group. This will make the first group child parts of the third one. | ||
229 | grp3.LinkToGroup(grp1); | ||
230 | |||
231 | // Delink parts 2 and 3 | ||
232 | grp3.DelinkFromGroup(part2.LocalId); | ||
233 | grp3.DelinkFromGroup(part3.LocalId); | ||
234 | |||
235 | if (debugtest) | ||
236 | { | ||
237 | m_log.Debug("--------After De-Link-------"); | ||
238 | m_log.Debug("Group1: parts:" + grp1.Children.Count); | ||
239 | m_log.Debug("Group1: Pos:" + grp1.AbsolutePosition + ", Rot:" + grp1.Rotation); | ||
240 | m_log.Debug("Group1: Prim1: OffsetPosition:" + part1.OffsetPosition + ", OffsetRotation:" + part1.RotationOffset); | ||
241 | m_log.Debug("Group1: Prim2: OffsetPosition:" + part2.OffsetPosition + ", OffsetRotation:" + part2.RotationOffset); | ||
242 | |||
243 | m_log.Debug("Group3: parts:" + grp3.Children.Count); | ||
244 | m_log.Debug("Group3: Pos:" + grp3.AbsolutePosition + ", Rot:" + grp3.Rotation); | ||
245 | m_log.Debug("Group3: Prim1: OffsetPosition:" + part3.OffsetPosition + ", OffsetRotation:" + part3.RotationOffset); | ||
246 | m_log.Debug("Group3: Prim2: OffsetPosition:" + part4.OffsetPosition + ", OffsetRotation:" + part4.RotationOffset); | ||
247 | } | ||
248 | |||
249 | Assert.That(part2.AbsolutePosition == Vector3.Zero); | ||
250 | Assert.That(part4.OffsetPosition == new Vector3(20, 20, 20)); | ||
251 | Quaternion compareQuaternion = new Quaternion(0, 0.7071068f, 0, 0.7071068f); | ||
252 | Assert.That((part4.RotationOffset.X - compareQuaternion.X < 0.00003) | ||
253 | && (part4.RotationOffset.Y - compareQuaternion.Y < 0.00003) | ||
254 | && (part4.RotationOffset.Z - compareQuaternion.Z < 0.00003) | ||
255 | && (part4.RotationOffset.W - compareQuaternion.W < 0.00003)); | ||
256 | } | ||
257 | } | ||
258 | } | ||