diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs | 242 |
1 files changed, 242 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs new file mode 100644 index 0000000..bdf0700 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs | |||
@@ -0,0 +1,242 @@ | |||
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.Framework.Communications; | ||
37 | using OpenSim.Region.Framework.Scenes; | ||
38 | using OpenSim.Services.Interfaces; | ||
39 | using OpenSim.Tests.Common; | ||
40 | |||
41 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
42 | { | ||
43 | /// <summary> | ||
44 | /// Basic scene object tests (create, read and delete but not update). | ||
45 | /// </summary> | ||
46 | [TestFixture] | ||
47 | public class SceneObjectBasicTests : OpenSimTestCase | ||
48 | { | ||
49 | // [TearDown] | ||
50 | // public void TearDown() | ||
51 | // { | ||
52 | // Console.WriteLine("TearDown"); | ||
53 | // GC.Collect(); | ||
54 | // Thread.Sleep(3000); | ||
55 | // } | ||
56 | |||
57 | // public class GcNotify | ||
58 | // { | ||
59 | // public static AutoResetEvent gcEvent = new AutoResetEvent(false); | ||
60 | // private static bool _initialized = false; | ||
61 | // | ||
62 | // public static void Initialize() | ||
63 | // { | ||
64 | // if (!_initialized) | ||
65 | // { | ||
66 | // _initialized = true; | ||
67 | // new GcNotify(); | ||
68 | // } | ||
69 | // } | ||
70 | // | ||
71 | // private GcNotify(){} | ||
72 | // | ||
73 | // ~GcNotify() | ||
74 | // { | ||
75 | // if (!Environment.HasShutdownStarted && | ||
76 | // !AppDomain.CurrentDomain.IsFinalizingForUnload()) | ||
77 | // { | ||
78 | // Console.WriteLine("GcNotify called"); | ||
79 | // gcEvent.Set(); | ||
80 | // new GcNotify(); | ||
81 | // } | ||
82 | // } | ||
83 | // } | ||
84 | |||
85 | /// <summary> | ||
86 | /// Test adding an object to a scene. | ||
87 | /// </summary> | ||
88 | [Test] | ||
89 | public void TestAddSceneObject() | ||
90 | { | ||
91 | TestHelpers.InMethod(); | ||
92 | |||
93 | Scene scene = new SceneHelpers().SetupScene(); | ||
94 | int partsToTestCount = 3; | ||
95 | |||
96 | SceneObjectGroup so | ||
97 | = SceneHelpers.CreateSceneObject(partsToTestCount, TestHelpers.ParseTail(0x1), "obj1", 0x10); | ||
98 | SceneObjectPart[] parts = so.Parts; | ||
99 | |||
100 | Assert.That(scene.AddNewSceneObject(so, false), Is.True); | ||
101 | SceneObjectGroup retrievedSo = scene.GetSceneObjectGroup(so.UUID); | ||
102 | SceneObjectPart[] retrievedParts = retrievedSo.Parts; | ||
103 | |||
104 | //m_log.Debug("retrievedPart : {0}", retrievedPart); | ||
105 | // If the parts have the same UUID then we will consider them as one and the same | ||
106 | Assert.That(retrievedSo.PrimCount, Is.EqualTo(partsToTestCount)); | ||
107 | |||
108 | for (int i = 0; i < partsToTestCount; i++) | ||
109 | { | ||
110 | Assert.That(retrievedParts[i].Name, Is.EqualTo(parts[i].Name)); | ||
111 | Assert.That(retrievedParts[i].UUID, Is.EqualTo(parts[i].UUID)); | ||
112 | } | ||
113 | } | ||
114 | |||
115 | [Test] | ||
116 | /// <summary> | ||
117 | /// It shouldn't be possible to add a scene object if one with that uuid already exists in the scene. | ||
118 | /// </summary> | ||
119 | public void TestAddExistingSceneObjectUuid() | ||
120 | { | ||
121 | TestHelpers.InMethod(); | ||
122 | |||
123 | Scene scene = new SceneHelpers().SetupScene(); | ||
124 | |||
125 | string obj1Name = "Alfred"; | ||
126 | string obj2Name = "Betty"; | ||
127 | UUID objUuid = new UUID("00000000-0000-0000-0000-000000000001"); | ||
128 | |||
129 | SceneObjectPart part1 | ||
130 | = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) | ||
131 | { Name = obj1Name, UUID = objUuid }; | ||
132 | |||
133 | Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part1), false), Is.True); | ||
134 | |||
135 | SceneObjectPart part2 | ||
136 | = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) | ||
137 | { Name = obj2Name, UUID = objUuid }; | ||
138 | |||
139 | Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part2), false), Is.False); | ||
140 | |||
141 | SceneObjectPart retrievedPart = scene.GetSceneObjectPart(objUuid); | ||
142 | |||
143 | //m_log.Debug("retrievedPart : {0}", retrievedPart); | ||
144 | // If the parts have the same UUID then we will consider them as one and the same | ||
145 | Assert.That(retrievedPart.Name, Is.EqualTo(obj1Name)); | ||
146 | Assert.That(retrievedPart.UUID, Is.EqualTo(objUuid)); | ||
147 | } | ||
148 | |||
149 | /// <summary> | ||
150 | /// Test retrieving a scene object via the local id of one of its parts. | ||
151 | /// </summary> | ||
152 | [Test] | ||
153 | public void TestGetSceneObjectByPartLocalId() | ||
154 | { | ||
155 | TestHelpers.InMethod(); | ||
156 | |||
157 | Scene scene = new SceneHelpers().SetupScene(); | ||
158 | int partsToTestCount = 3; | ||
159 | |||
160 | SceneObjectGroup so | ||
161 | = SceneHelpers.CreateSceneObject(partsToTestCount, TestHelpers.ParseTail(0x1), "obj1", 0x10); | ||
162 | SceneObjectPart[] parts = so.Parts; | ||
163 | |||
164 | scene.AddNewSceneObject(so, false); | ||
165 | |||
166 | // Test getting via the root part's local id | ||
167 | Assert.That(scene.GetGroupByPrim(so.LocalId), Is.Not.Null); | ||
168 | |||
169 | // Test getting via a non root part's local id | ||
170 | Assert.That(scene.GetGroupByPrim(parts[partsToTestCount - 1].LocalId), Is.Not.Null); | ||
171 | |||
172 | // Test that we don't get back an object for a local id that doesn't exist | ||
173 | Assert.That(scene.GetGroupByPrim(999), Is.Null); | ||
174 | |||
175 | // Now delete the scene object and check again | ||
176 | scene.DeleteSceneObject(so, false); | ||
177 | |||
178 | Assert.That(scene.GetGroupByPrim(so.LocalId), Is.Null); | ||
179 | Assert.That(scene.GetGroupByPrim(parts[partsToTestCount - 1].LocalId), Is.Null); | ||
180 | } | ||
181 | |||
182 | /// <summary> | ||
183 | /// Test deleting an object from a scene. | ||
184 | /// </summary> | ||
185 | /// <remarks> | ||
186 | /// This is the most basic form of delete. For all more sophisticated forms of derez (done asynchrnously | ||
187 | /// and where object can be taken to user inventory, etc.), see SceneObjectDeRezTests. | ||
188 | /// </remarks> | ||
189 | [Test] | ||
190 | public void TestDeleteSceneObject() | ||
191 | { | ||
192 | TestHelpers.InMethod(); | ||
193 | |||
194 | TestScene scene = new SceneHelpers().SetupScene(); | ||
195 | SceneObjectGroup so = SceneHelpers.AddSceneObject(scene); | ||
196 | |||
197 | Assert.That(so.IsDeleted, Is.False); | ||
198 | |||
199 | scene.DeleteSceneObject(so, false); | ||
200 | |||
201 | Assert.That(so.IsDeleted, Is.True); | ||
202 | |||
203 | SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId); | ||
204 | Assert.That(retrievedPart, Is.Null); | ||
205 | } | ||
206 | |||
207 | /// <summary> | ||
208 | /// Changing a scene object uuid changes the root part uuid. This is a valid operation if the object is not | ||
209 | /// in a scene and is useful if one wants to supply a UUID directly rather than use the one generated by | ||
210 | /// OpenSim. | ||
211 | /// </summary> | ||
212 | [Test] | ||
213 | public void TestChangeSceneObjectUuid() | ||
214 | { | ||
215 | string rootPartName = "rootpart"; | ||
216 | UUID rootPartUuid = new UUID("00000000-0000-0000-0000-000000000001"); | ||
217 | string childPartName = "childPart"; | ||
218 | UUID childPartUuid = new UUID("00000000-0000-0000-0001-000000000000"); | ||
219 | |||
220 | SceneObjectPart rootPart | ||
221 | = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) | ||
222 | { Name = rootPartName, UUID = rootPartUuid }; | ||
223 | SceneObjectPart linkPart | ||
224 | = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) | ||
225 | { Name = childPartName, UUID = childPartUuid }; | ||
226 | |||
227 | SceneObjectGroup sog = new SceneObjectGroup(rootPart); | ||
228 | sog.AddPart(linkPart); | ||
229 | |||
230 | Assert.That(sog.UUID, Is.EqualTo(rootPartUuid)); | ||
231 | Assert.That(sog.RootPart.UUID, Is.EqualTo(rootPartUuid)); | ||
232 | Assert.That(sog.Parts.Length, Is.EqualTo(2)); | ||
233 | |||
234 | UUID newRootPartUuid = new UUID("00000000-0000-0000-0000-000000000002"); | ||
235 | sog.UUID = newRootPartUuid; | ||
236 | |||
237 | Assert.That(sog.UUID, Is.EqualTo(newRootPartUuid)); | ||
238 | Assert.That(sog.RootPart.UUID, Is.EqualTo(newRootPartUuid)); | ||
239 | Assert.That(sog.Parts.Length, Is.EqualTo(2)); | ||
240 | } | ||
241 | } | ||
242 | } \ No newline at end of file | ||