aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Scenes/Tests/SceneObjectTests.cs
diff options
context:
space:
mode:
authorJustin Clarke Casey2009-02-03 20:13:34 +0000
committerJustin Clarke Casey2009-02-03 20:13:34 +0000
commit2009d1aa01ca615dbcd4b69d3cab179741d9ee1f (patch)
treef5bf449fa6194041fd2a07dbd0de243822e33fb1 /OpenSim/Region/Environment/Scenes/Tests/SceneObjectTests.cs
parent* Lock the parts for the old group while we're clearing it as well - not much... (diff)
downloadopensim-SC-2009d1aa01ca615dbcd4b69d3cab179741d9ee1f.zip
opensim-SC-2009d1aa01ca615dbcd4b69d3cab179741d9ee1f.tar.gz
opensim-SC-2009d1aa01ca615dbcd4b69d3cab179741d9ee1f.tar.bz2
opensim-SC-2009d1aa01ca615dbcd4b69d3cab179741d9ee1f.tar.xz
* Fission SceneObjectTests into basic and linking sets
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/Tests/SceneObjectTests.cs')
-rw-r--r--OpenSim/Region/Environment/Scenes/Tests/SceneObjectTests.cs340
1 files changed, 0 insertions, 340 deletions
diff --git a/OpenSim/Region/Environment/Scenes/Tests/SceneObjectTests.cs b/OpenSim/Region/Environment/Scenes/Tests/SceneObjectTests.cs
deleted file mode 100644
index 2164b0d..0000000
--- a/OpenSim/Region/Environment/Scenes/Tests/SceneObjectTests.cs
+++ /dev/null
@@ -1,340 +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 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 /// Scene object tests
44 /// </summary>
45 [TestFixture]
46 public class SceneObjectTests
47 {
48 /// <summary>
49 /// Test adding an object to a scene.
50 /// </summary>
51 [Test]
52 public void TestAddSceneObject()
53 {
54 Scene scene = SceneSetupHelpers.SetupScene();
55 SceneObjectPart part = SceneSetupHelpers.AddSceneObject(scene);
56 SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
57
58 //System.Console.WriteLine("retrievedPart : {0}", retrievedPart);
59 // If the parts have the same UUID then we will consider them as one and the same
60 Assert.That(retrievedPart.UUID, Is.EqualTo(part.UUID));
61 }
62
63 /// <summary>
64 /// Test deleting an object from a scene.
65 /// </summary>
66 [Test]
67 public void TestDeleteSceneObject()
68 {
69 TestScene scene = SceneSetupHelpers.SetupScene();
70 SceneObjectPart part = SceneSetupHelpers.AddSceneObject(scene);
71 scene.DeleteSceneObject(part.ParentGroup, false);
72
73 SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
74 Assert.That(retrievedPart, Is.Null);
75 }
76
77 /// <summary>
78 /// Test deleting an object asynchronously
79 /// </summary>
80 [Test]
81 public void TestDeleteSceneObjectAsync()
82 {
83 UUID agentId = UUID.Parse("00000000-0000-0000-0000-000000000001");
84
85 TestScene scene = SceneSetupHelpers.SetupScene();
86
87 // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
88 AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
89 sogd.Enabled = false;
90
91 SceneObjectPart part = SceneSetupHelpers.AddSceneObject(scene);
92
93 IClientAPI client = SceneSetupHelpers.AddRootAgent(scene, agentId);
94 scene.DeRezObject(client, part.LocalId, UUID.Zero, DeRezAction.Delete, UUID.Zero);
95
96 SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
97 Assert.That(retrievedPart, Is.Not.Null);
98
99 sogd.InventoryDeQueueAndDelete();
100 SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(part.LocalId);
101 Assert.That(retrievedPart2, Is.Null);
102 }
103
104 [Test]
105 public void TestLinkDelink2SceneObjects()
106 {
107 bool debugtest = false;
108
109 Scene scene = SceneSetupHelpers.SetupScene();
110 SceneObjectPart part1 = SceneSetupHelpers.AddSceneObject(scene);
111 SceneObjectGroup grp1 = part1.ParentGroup;
112 SceneObjectPart part2 = SceneSetupHelpers.AddSceneObject(scene);
113 SceneObjectGroup grp2 = part2.ParentGroup;
114
115 grp1.AbsolutePosition = new Vector3(10, 10, 10);
116 grp2.AbsolutePosition = Vector3.Zero;
117
118 // <90,0,0>
119 grp1.Rotation = (Quaternion.CreateFromEulers(90 * Utils.DEG_TO_RAD, 0, 0));
120
121 // <180,0,0>
122 grp2.UpdateGroupRotation(Quaternion.CreateFromEulers(180 * Utils.DEG_TO_RAD, 0, 0));
123
124 // Required for linking
125 grp1.RootPart.UpdateFlag = 0;
126 grp2.RootPart.UpdateFlag = 0;
127
128 // Link grp2 to grp1. part2 becomes child prim to grp1. grp2 is eliminated.
129 grp1.LinkToGroup(grp2);
130
131 // FIXME: Can't do this test yet since group 2 still has its root part! We can't yet null this since
132 // it might cause SOG.ProcessBackup() to fail due to the race condition. This really needs to be fixed.
133 Assert.That(grp2.IsDeleted, "SOG 2 was not registered as deleted after link.");
134 Assert.That(grp2.Children.Count, Is.EqualTo(0), "Group 2 still contained children after delink.");
135 Assert.That(grp1.Children.Count == 2);
136
137 if (debugtest)
138 {
139 System.Console.WriteLine("parts: {0}", grp1.Children.Count);
140 System.Console.WriteLine("Group1: Pos:{0}, Rot:{1}", grp1.AbsolutePosition, grp1.Rotation);
141 System.Console.WriteLine("Group1: Prim1: OffsetPosition:{0}, OffsetRotation:{1}", part1.OffsetPosition, part1.RotationOffset);
142 System.Console.WriteLine("Group1: Prim2: OffsetPosition:{0}, OffsetRotation:{1}", part2.OffsetPosition, part2.RotationOffset);
143 }
144
145 // root part should have no offset position or rotation
146 Assert.That(part1.OffsetPosition == Vector3.Zero && part1.RotationOffset == Quaternion.Identity);
147
148 // offset position should be root part position - part2.absolute position.
149 Assert.That(part2.OffsetPosition == new Vector3(-10, -10, -10));
150
151 float roll = 0;
152 float pitch = 0;
153 float yaw = 0;
154
155 // There's a euler anomoly at 180, 0, 0 so expect 180 to turn into -180.
156 part1.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw);
157 Vector3 rotEuler1 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG);
158
159 if (debugtest)
160 System.Console.WriteLine(rotEuler1);
161
162 part2.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw);
163 Vector3 rotEuler2 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG);
164
165 if (debugtest)
166 System.Console.WriteLine(rotEuler2);
167
168 Assert.That(rotEuler2.ApproxEquals(new Vector3(-180, 0, 0), 0.001f) || rotEuler2.ApproxEquals(new Vector3(180, 0, 0), 0.001f));
169
170 // Delink part 2
171 grp1.DelinkFromGroup(part2.LocalId);
172
173 if (debugtest)
174 System.Console.WriteLine("Group2: Prim2: OffsetPosition:{0}, OffsetRotation:{1}", part2.AbsolutePosition, part2.RotationOffset);
175
176 Assert.That(grp1.Children.Count, Is.EqualTo(1), "Group 1 still contained part2 after delink.");
177 Assert.That(part2.AbsolutePosition == Vector3.Zero);
178 }
179
180 [Test]
181 public void TestLinkDelink2groups4SceneObjects()
182 {
183 bool debugtest = false;
184
185 Scene scene = SceneSetupHelpers.SetupScene();
186 SceneObjectPart part1 = SceneSetupHelpers.AddSceneObject(scene);
187 SceneObjectGroup grp1 = part1.ParentGroup;
188 SceneObjectPart part2 = SceneSetupHelpers.AddSceneObject(scene);
189 SceneObjectGroup grp2 = part2.ParentGroup;
190 SceneObjectPart part3 = SceneSetupHelpers.AddSceneObject(scene);
191 SceneObjectGroup grp3 = part3.ParentGroup;
192 SceneObjectPart part4 = SceneSetupHelpers.AddSceneObject(scene);
193 SceneObjectGroup grp4 = part4.ParentGroup;
194
195 grp1.AbsolutePosition = new Vector3(10, 10, 10);
196 grp2.AbsolutePosition = Vector3.Zero;
197 grp3.AbsolutePosition = new Vector3(20, 20, 20);
198 grp4.AbsolutePosition = new Vector3(40, 40, 40);
199
200 // <90,0,0>
201 grp1.Rotation = (Quaternion.CreateFromEulers(90 * Utils.DEG_TO_RAD, 0, 0));
202
203 // <180,0,0>
204 grp2.UpdateGroupRotation(Quaternion.CreateFromEulers(180 * Utils.DEG_TO_RAD, 0, 0));
205
206 // <270,0,0>
207 grp3.Rotation = (Quaternion.CreateFromEulers(270 * Utils.DEG_TO_RAD, 0, 0));
208
209 // <0,90,0>
210 grp4.UpdateGroupRotation(Quaternion.CreateFromEulers(0, 90 * Utils.DEG_TO_RAD, 0));
211
212 // Required for linking
213 grp1.RootPart.UpdateFlag = 0;
214 grp2.RootPart.UpdateFlag = 0;
215 grp3.RootPart.UpdateFlag = 0;
216 grp4.RootPart.UpdateFlag = 0;
217
218 // Link grp2 to grp1. part2 becomes child prim to grp1. grp2 is eliminated.
219 grp1.LinkToGroup(grp2);
220
221 // Link grp4 to grp3.
222 grp3.LinkToGroup(grp4);
223
224 // At this point we should have 4 parts total in two groups.
225 Assert.That(grp1.Children.Count == 2);
226 Assert.That(grp2.IsDeleted, "Group 2 was not registered as deleted after link.");
227 Assert.That(grp2.Children.Count, Is.EqualTo(0), "Group 2 still contained parts after delink.");
228 Assert.That(grp3.Children.Count == 2);
229 Assert.That(grp4.IsDeleted, "Group 4 was not registered as deleted after link.");
230 Assert.That(grp4.Children.Count, Is.EqualTo(0), "Group 4 still contained parts after delink.");
231
232 if (debugtest)
233 {
234 System.Console.WriteLine("--------After Link-------");
235 System.Console.WriteLine("Group1: parts: {0}", grp1.Children.Count);
236 System.Console.WriteLine("Group1: Pos:{0}, Rot:{1}", grp1.AbsolutePosition, grp1.Rotation);
237 System.Console.WriteLine("Group1: Prim1: OffsetPosition:{0}, OffsetRotation:{1}", part1.OffsetPosition, part1.RotationOffset);
238 System.Console.WriteLine("Group1: Prim2: OffsetPosition:{0}, OffsetRotation:{1}", part2.OffsetPosition, part2.RotationOffset);
239
240 System.Console.WriteLine("Group3: parts: {0}", grp3.Children.Count);
241 System.Console.WriteLine("Group3: Pos:{0}, Rot:{1}", grp3.AbsolutePosition, grp3.Rotation);
242 System.Console.WriteLine("Group3: Prim1: OffsetPosition:{0}, OffsetRotation:{1}", part3.OffsetPosition, part3.RotationOffset);
243 System.Console.WriteLine("Group3: Prim2: OffsetPosition:{0}, OffsetRotation:{1}", part4.OffsetPosition, part4.RotationOffset);
244 }
245
246 // Required for linking
247 grp1.RootPart.UpdateFlag = 0;
248 grp3.RootPart.UpdateFlag = 0;
249
250 // root part should have no offset position or rotation
251 Assert.That(part1.OffsetPosition == Vector3.Zero && part1.RotationOffset == Quaternion.Identity);
252
253 // offset position should be root part position - part2.absolute position.
254 Assert.That(part2.OffsetPosition == new Vector3(-10, -10, -10));
255
256 float roll = 0;
257 float pitch = 0;
258 float yaw = 0;
259
260 // There's a euler anomoly at 180, 0, 0 so expect 180 to turn into -180.
261 part1.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw);
262 Vector3 rotEuler1 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG);
263
264 if (debugtest)
265 System.Console.WriteLine(rotEuler1);
266
267 part2.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw);
268 Vector3 rotEuler2 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG);
269
270 if (debugtest)
271 System.Console.WriteLine(rotEuler2);
272
273 Assert.That(rotEuler2.ApproxEquals(new Vector3(-180, 0, 0), 0.001f) || rotEuler2.ApproxEquals(new Vector3(180, 0, 0), 0.001f));
274
275 // Now we're linking the first group to the third group. This will make the first group child parts of the third one.
276 grp3.LinkToGroup(grp1);
277
278 // Delink parts 2 and 3
279 grp3.DelinkFromGroup(part2.LocalId);
280 grp3.DelinkFromGroup(part3.LocalId);
281
282 if (debugtest)
283 {
284 System.Console.WriteLine("--------After De-Link-------");
285 System.Console.WriteLine("Group1: parts: {0}", grp1.Children.Count);
286 System.Console.WriteLine("Group1: Pos:{0}, Rot:{1}", grp1.AbsolutePosition, grp1.Rotation);
287 System.Console.WriteLine("Group1: Prim1: OffsetPosition:{0}, OffsetRotation:{1}", part1.OffsetPosition, part1.RotationOffset);
288 System.Console.WriteLine("NoGroup: Prim2: AbsolutePosition:{0}, OffsetRotation:{1}", part2.AbsolutePosition, part2.RotationOffset);
289
290 System.Console.WriteLine("Group3: parts: {0}", grp3.Children.Count);
291 System.Console.WriteLine("Group3: Pos:{0}, Rot:{1}", grp3.AbsolutePosition, grp3.Rotation);
292 System.Console.WriteLine("Group3: Prim1: OffsetPosition:{0}, OffsetRotation:{1}", part3.OffsetPosition, part3.RotationOffset);
293 System.Console.WriteLine("Group3: Prim2: OffsetPosition:{0}, OffsetRotation:{1}", part4.OffsetPosition, part4.RotationOffset);
294 }
295
296 Assert.That(part2.AbsolutePosition == Vector3.Zero);
297 Assert.That(part4.OffsetPosition == new Vector3(20, 20, 20));
298 Quaternion compareQuaternion = new Quaternion(0, 0.7071068f, 0, 0.7071068f);
299 Assert.That((part4.RotationOffset.X - compareQuaternion.X < 0.00003)
300 && (part4.RotationOffset.Y - compareQuaternion.Y < 0.00003)
301 && (part4.RotationOffset.Z - compareQuaternion.Z < 0.00003)
302 && (part4.RotationOffset.W - compareQuaternion.W < 0.00003));
303 }
304
305 /// <summary>
306 /// Test deleting an object asynchronously to user inventory.
307 /// </summary>
308 [Test]
309 public void TestDeleteSceneObjectAsyncToUserInventory()
310 {
311 //log4net.Config.XmlConfigurator.Configure();
312
313 UUID agentId = UUID.Parse("00000000-0000-0000-0000-000000000001");
314 string myObjectName = "Fred";
315
316 TestScene scene = SceneSetupHelpers.SetupScene();
317 SceneObjectPart part = SceneSetupHelpers.AddSceneObject(scene, myObjectName);
318
319 Assert.That(
320 scene.CommsManager.UserAdminService.AddUser(
321 "Bob", "Hoskins", "test", "test@test.com", 1000, 1000, agentId),
322 Is.EqualTo(agentId));
323
324 IClientAPI client = SceneSetupHelpers.AddRootAgent(scene, agentId);
325
326 CachedUserInfo userInfo = scene.CommsManager.UserProfileCacheService.GetUserDetails(agentId);
327 Assert.That(userInfo, Is.Not.Null);
328 Assert.That(userInfo.RootFolder, Is.Not.Null);
329
330 SceneSetupHelpers.DeleteSceneObjectAsync(scene, part, DeRezAction.Take, userInfo.RootFolder.ID, client);
331
332 // Check that we now have the taken part in our inventory
333 Assert.That(myObjectName, Is.EqualTo(userInfo.RootFolder.FindItemByPath(myObjectName).Name));
334
335 // Check that the taken part has actually disappeared
336 SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
337 Assert.That(retrievedPart, Is.Null);
338 }
339 }
340} \ No newline at end of file