OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
SceneObjectBasicTests.cs
Go to the documentation of this file.
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 System.Threading;
32 using Nini.Config;
33 using NUnit.Framework;
34 using OpenMetaverse;
35 using OpenSim.Framework;
36 using OpenSim.Region.Framework.Scenes;
37 using OpenSim.Services.Interfaces;
38 using OpenSim.Tests.Common;
39 
40 namespace OpenSim.Region.Framework.Scenes.Tests
41 {
45  [TestFixture]
47  {
48 // [TearDown]
49 // public void TearDown()
50 // {
51 // Console.WriteLine("TearDown");
52 // GC.Collect();
53 // Thread.Sleep(3000);
54 // }
55 
56 // public class GcNotify
57 // {
58 // public static AutoResetEvent gcEvent = new AutoResetEvent(false);
59 // private static bool _initialized = false;
60 //
61 // public static void Initialize()
62 // {
63 // if (!_initialized)
64 // {
65 // _initialized = true;
66 // new GcNotify();
67 // }
68 // }
69 //
70 // private GcNotify(){}
71 //
72 // ~GcNotify()
73 // {
74 // if (!Environment.HasShutdownStarted &&
75 // !AppDomain.CurrentDomain.IsFinalizingForUnload())
76 // {
77 // Console.WriteLine("GcNotify called");
78 // gcEvent.Set();
79 // new GcNotify();
80 // }
81 // }
82 // }
83 
87  [Test]
88  public void TestAddSceneObject()
89  {
90  TestHelpers.InMethod();
91 
92  Scene scene = new SceneHelpers().SetupScene();
93  int partsToTestCount = 3;
94 
96  = SceneHelpers.CreateSceneObject(partsToTestCount, TestHelpers.ParseTail(0x1), "obj1", 0x10);
97  SceneObjectPart[] parts = so.Parts;
98 
99  Assert.That(scene.AddNewSceneObject(so, false), Is.True);
100  SceneObjectGroup retrievedSo = scene.GetSceneObjectGroup(so.UUID);
101  SceneObjectPart[] retrievedParts = retrievedSo.Parts;
102 
103  //m_log.Debug("retrievedPart : {0}", retrievedPart);
104  // If the parts have the same UUID then we will consider them as one and the same
105  Assert.That(retrievedSo.PrimCount, Is.EqualTo(partsToTestCount));
106 
107  for (int i = 0; i < partsToTestCount; i++)
108  {
109  Assert.That(retrievedParts[i].Name, Is.EqualTo(parts[i].Name));
110  Assert.That(retrievedParts[i].UUID, Is.EqualTo(parts[i].UUID));
111  }
112  }
113 
114  [Test]
119  {
120  TestHelpers.InMethod();
121 
122  Scene scene = new SceneHelpers().SetupScene();
123 
124  string obj1Name = "Alfred";
125  string obj2Name = "Betty";
126  UUID objUuid = new UUID("00000000-0000-0000-0000-000000000001");
127 
128  SceneObjectPart part1
129  = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
130  { Name = obj1Name, UUID = objUuid };
131 
132  Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part1), false), Is.True);
133 
134  SceneObjectPart part2
135  = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
136  { Name = obj2Name, UUID = objUuid };
137 
138  Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part2), false), Is.False);
139 
140  SceneObjectPart retrievedPart = scene.GetSceneObjectPart(objUuid);
141 
142  //m_log.Debug("retrievedPart : {0}", retrievedPart);
143  // If the parts have the same UUID then we will consider them as one and the same
144  Assert.That(retrievedPart.Name, Is.EqualTo(obj1Name));
145  Assert.That(retrievedPart.UUID, Is.EqualTo(objUuid));
146  }
147 
151  [Test]
153  {
154  TestHelpers.InMethod();
155 
156  Scene scene = new SceneHelpers().SetupScene();
157  int partsToTestCount = 3;
158 
160  = SceneHelpers.CreateSceneObject(partsToTestCount, TestHelpers.ParseTail(0x1), "obj1", 0x10);
161  SceneObjectPart[] parts = so.Parts;
162 
163  scene.AddNewSceneObject(so, false);
164 
165  // Test getting via the root part's local id
166  Assert.That(scene.GetGroupByPrim(so.LocalId), Is.Not.Null);
167 
168  // Test getting via a non root part's local id
169  Assert.That(scene.GetGroupByPrim(parts[partsToTestCount - 1].LocalId), Is.Not.Null);
170 
171  // Test that we don't get back an object for a local id that doesn't exist
172  Assert.That(scene.GetGroupByPrim(999), Is.Null);
173 
174  uint soid = so.LocalId;
175  uint spid = parts[partsToTestCount - 1].LocalId;
176 
177  // Now delete the scene object and check again
178  scene.DeleteSceneObject(so, false);
179 
180  Assert.That(scene.GetGroupByPrim(soid), Is.Null);
181  Assert.That(scene.GetGroupByPrim(spid), Is.Null);
182  }
183 
191  [Test]
192  public void TestDeleteSceneObject()
193  {
194  TestHelpers.InMethod();
195 
196  TestScene scene = new SceneHelpers().SetupScene();
197  SceneObjectGroup so = SceneHelpers.AddSceneObject(scene);
198 
199  Assert.That(so.IsDeleted, Is.False);
200  uint retrievedPartID = so.LocalId;
201 
202  scene.DeleteSceneObject(so, false);
203 
204  SceneObjectPart retrievedPart = scene.GetSceneObjectPart(retrievedPartID);
205 
206  Assert.That(retrievedPart, Is.Null);
207  }
208 
214  [Test]
216  {
217  string rootPartName = "rootpart";
218  UUID rootPartUuid = new UUID("00000000-0000-0000-0000-000000000001");
219  string childPartName = "childPart";
220  UUID childPartUuid = new UUID("00000000-0000-0000-0001-000000000000");
221 
222  SceneObjectPart rootPart
223  = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
224  { Name = rootPartName, UUID = rootPartUuid };
225  SceneObjectPart linkPart
226  = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
227  { Name = childPartName, UUID = childPartUuid };
228 
229  SceneObjectGroup sog = new SceneObjectGroup(rootPart);
230  sog.AddPart(linkPart);
231 
232  Assert.That(sog.UUID, Is.EqualTo(rootPartUuid));
233  Assert.That(sog.RootPart.UUID, Is.EqualTo(rootPartUuid));
234  Assert.That(sog.Parts.Length, Is.EqualTo(2));
235 
236  UUID newRootPartUuid = new UUID("00000000-0000-0000-0000-000000000002");
237  sog.UUID = newRootPartUuid;
238 
239  Assert.That(sog.UUID, Is.EqualTo(newRootPartUuid));
240  Assert.That(sog.RootPart.UUID, Is.EqualTo(newRootPartUuid));
241  Assert.That(sog.Parts.Length, Is.EqualTo(2));
242  }
243  }
244 }
void TestGetSceneObjectByPartLocalId()
Test retrieving a scene object via the local id of one of its parts.
void TestAddExistingSceneObjectUuid()
It shouldn't be possible to add a scene object if one with that uuid already exists in the scene...
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
void TestAddSceneObject()
Test adding an object to a scene.
void TestChangeSceneObjectUuid()
Changing a scene object uuid changes the root part uuid. This is a valid operation if the object is n...
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60
Basic scene object tests (create, read and delete but not update).
void TestDeleteSceneObject()
Test deleting an object from a scene.