aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Scenes
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Scenes')
-rw-r--r--OpenSim/Region/Environment/Scenes/EntityList.cs2
-rw-r--r--OpenSim/Region/Environment/Scenes/Tests/EntityListTests.cs289
2 files changed, 290 insertions, 1 deletions
diff --git a/OpenSim/Region/Environment/Scenes/EntityList.cs b/OpenSim/Region/Environment/Scenes/EntityList.cs
index cd59f2a..2488ab3 100644
--- a/OpenSim/Region/Environment/Scenes/EntityList.cs
+++ b/OpenSim/Region/Environment/Scenes/EntityList.cs
@@ -130,7 +130,7 @@ namespace OpenSim.Region.Environment.Scenes
130 } 130 }
131 } 131 }
132 132
133 public SceneObjectGroup FindObject(int local) 133 public SceneObjectGroup FindObject(uint local)
134 { 134 {
135 try 135 try
136 { 136 {
diff --git a/OpenSim/Region/Environment/Scenes/Tests/EntityListTests.cs b/OpenSim/Region/Environment/Scenes/Tests/EntityListTests.cs
new file mode 100644
index 0000000..f4aa3d8
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/Tests/EntityListTests.cs
@@ -0,0 +1,289 @@
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 NUnit.Framework.SyntaxHelpers;
29using System;
30using System.Threading;
31using System.Text;
32using System.Collections.Generic;
33using Nini.Config;
34using NUnit.Framework;
35using OpenSim.Framework;
36using OpenSim.Framework.Communications;
37using OpenSim.Region.Environment.Scenes;
38using OpenMetaverse;
39
40namespace OpenSim.Region.Environment.Scenes.Tests
41{
42 /// <summary>
43 /// Scene oriented tests
44 /// </summary>
45 [TestFixture]
46 public class EntityListTests
47 {
48 [SetUp]
49 public void Init()
50 {
51 try
52 {
53 log4net.Config.XmlConfigurator.Configure();
54 }
55 catch
56 {
57 // I don't care, just leave log4net off
58 }
59 }
60
61 static public Random random;
62 SceneObjectGroup found;
63 Scene scene;
64
65 /// <summary>
66 /// Test adding an object to a scene. Doesn't yet do what it says on the tin.
67 /// </summary>
68 [Test]
69 public void T001_TestAddSceneObject()
70 {
71 RegionInfo regInfo = new RegionInfo(1000, 1000, null, null);
72 regInfo.RegionName = "Unit test region";
73 AgentCircuitManager acm = new AgentCircuitManager();
74 //CommunicationsManager cm = new CommunicationsManager(null, null, null, false, null);
75 CommunicationsManager cm = null;
76 //SceneCommunicationService scs = new SceneCommunicationService(cm);
77 SceneCommunicationService scs = null;
78 StorageManager sm = new OpenSim.Region.Environment.StorageManager("OpenSim.Data.Null.dll", "", "");
79 IConfigSource configSource = new IniConfigSource();
80
81 scene
82 = new Scene(regInfo, acm, cm, scs, null, sm, null, null, false, false, false, configSource, null);
83
84 SceneObjectGroup sceneObject = new SceneObjectGroup();
85 SceneObjectPart part
86 = new SceneObjectPart(UUID.Random(), PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero);
87 //part.UpdatePrimFlags(false, false, true);
88 part.ObjectFlags |= (uint)PrimFlags.Phantom;
89
90 sceneObject.RootPart = part;
91 sceneObject.AddPart(part);
92
93 scene.AddNewSceneObject(sceneObject, false);
94
95 SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
96
97 //System.Console.WriteLine("retrievedPart : {0}", retrievedPart);
98 // If the parts have the same UUID then we will consider them as one and the same
99 Assert.That(retrievedPart.UUID, Is.EqualTo(part.UUID));
100 }
101
102 [Test]
103 public void T010_AddObjects()
104 {
105 random = new Random();
106 SceneObjectGroup found;
107 EntityList entlist = new EntityList();
108 SceneObjectGroup sog = NewSOG();
109 UUID obj1 = sog.UUID;
110 uint li1 = sog.LocalId;
111 entlist.Add(sog);
112 sog = NewSOG();
113 UUID obj2 = sog.UUID;
114 uint li2 = sog.LocalId;
115 entlist.Add(sog);
116
117 found = entlist.FindObject(obj1);
118 Assert.That(found.UUID ,Is.EqualTo(obj1) );
119 found = entlist.FindObject(li1);
120 Assert.That(found.UUID ,Is.EqualTo(obj1) );
121 found = entlist.FindObject(obj2);
122 Assert.That(found.UUID ,Is.EqualTo(obj2) );
123 found = entlist.FindObject(li2);
124 Assert.That(found.UUID ,Is.EqualTo(obj2) );
125
126 entlist.RemoveObject(obj1);
127 entlist.RemoveObject(obj2);
128
129 found = entlist.FindObject(obj1);
130 Assert.That(found, Is.Null);
131 found = entlist.FindObject(obj2);
132 Assert.That(found, Is.Null);
133 }
134
135 [Test]
136 public void T011_ThreadAddRemoveTest()
137 {
138 EntityList entlist = new EntityList();
139 Dictionary<UUID, uint> dict = new Dictionary<UUID,uint>();
140 List<Thread> trdlist = new List<Thread>();
141 for (int i=0; i<80; i++)
142 {
143 SceneObjectGroup sog = NewSOG();
144 TestThreads test = new TestThreads(entlist,sog);
145 Thread start = new Thread(new ThreadStart(test.TestAddSceneObject));
146 start.Start();
147 trdlist.Add(start);
148 dict.Add(sog.UUID, sog.LocalId);
149 }
150 foreach (Thread thread in trdlist)
151 {
152 thread.Join();
153 }
154 foreach (KeyValuePair<UUID, uint> item in dict)
155 {
156 found = entlist.FindObject(item.Key);
157 Assert.That(found.UUID,Is.EqualTo(item.Key));
158 found = entlist.FindObject(item.Value);
159 Assert.That(found.UUID,Is.EqualTo(item.Key));
160
161 // Start Removing
162 TestThreads test = new TestThreads(entlist,found);
163 Thread start = new Thread(new ThreadStart(test.TestRemoveSceneObject));
164 start.Start();
165 trdlist.Add(start);
166 }
167 foreach (Thread thread in trdlist)
168 {
169 thread.Join();
170 }
171 foreach (KeyValuePair<UUID, uint> item in dict)
172 {
173 found = entlist.FindObject(item.Key);
174 Assert.That(found,Is.Null);
175 found = entlist.FindObject(item.Value);
176 Assert.That(found,Is.Null);
177 }
178 }
179
180 [Test]
181 public void T012_MultipleUUIDEntry()
182 {
183 EntityList entlist = new EntityList();
184 UUID id = UUID.Random();
185 int exceptions = 0;
186 Dictionary<UUID, uint> dict = new Dictionary<UUID,uint>();
187 List<Thread> trdlist = new List<Thread>();
188 SceneObjectGroup sog = NewSOG(id);
189 uint lid = sog.LocalId;
190 for (int i=0; i<30; i++)
191 {
192 try
193 {
194 TestThreads test = new TestThreads(entlist,sog);
195 Thread start = new Thread(new ThreadStart(test.TestAddSceneObject));
196 start.Start();
197 trdlist.Add(start);
198 }
199 catch
200 {
201 }
202 }
203 foreach (Thread thread in trdlist)
204 {
205 thread.Join();
206 }
207 found = entlist.FindObject(sog.UUID);
208 Assert.That(found.UUID,Is.EqualTo(sog.UUID));
209 found = entlist.FindObject(lid);
210 Assert.That(found.UUID,Is.EqualTo(sog.UUID));
211
212 entlist.RemoveObject(id);
213 found = entlist.FindObject(id);
214 Assert.That(found,Is.Null);
215 }
216
217 private SceneObjectGroup NewSOG()
218 {
219 SceneObjectGroup sog = new SceneObjectGroup();
220 SceneObjectPart sop = new SceneObjectPart(UUID.Random(), PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero);
221 sop.Name = RandomName();
222 sop.Description = sop.Name;
223 sop.Text = RandomName();
224 sop.SitName = RandomName();
225 sop.TouchName = RandomName();
226 sop.ObjectFlags |= (uint)PrimFlags.Phantom;
227
228 sog.AddPart(sop);
229 sog.RootPart = sop;
230
231 scene.AddNewSceneObject(sog, false);
232
233 return sog;
234 }
235
236 private SceneObjectGroup NewSOG(UUID id)
237 {
238 SceneObjectGroup sog = new SceneObjectGroup();
239 SceneObjectPart sop = new SceneObjectPart(UUID.Random(), PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero);
240 sop.UUID = id;
241 sop.Name = RandomName();
242 sop.Description = sop.Name;
243 sop.Text = RandomName();
244 sop.SitName = RandomName();
245 sop.TouchName = RandomName();
246 sop.ObjectFlags |= (uint)PrimFlags.Phantom;
247
248 sog.AddPart(sop);
249 sog.RootPart = sop;
250
251 scene.AddNewSceneObject(sog, false);
252
253 return sog;
254 }
255
256 private static string RandomName()
257 {
258 StringBuilder name = new StringBuilder();
259 int size = random.Next(40,80);
260 char ch ;
261 for (int i=0; i<size; i++)
262 {
263 ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ;
264 name.Append(ch);
265 }
266 return name.ToString();
267 }
268 }
269
270 public class TestThreads
271 {
272 private EntityList entlist;
273 private SceneObjectGroup sog;
274
275 public TestThreads(EntityList entlist, SceneObjectGroup sog)
276 {
277 this.entlist = entlist;
278 this.sog = sog;
279 }
280 public void TestAddSceneObject()
281 {
282 entlist.Add(sog);
283 }
284 public void TestRemoveSceneObject()
285 {
286 entlist.RemoveObject(sog.UUID);
287 }
288 }
289} \ No newline at end of file