aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Scenes/Tests/EntityManagerTests.cs
diff options
context:
space:
mode:
authorSean Dague2008-12-12 18:33:16 +0000
committerSean Dague2008-12-12 18:33:16 +0000
commit7a4f11b94da2ba2fbe24393ce2804214e199bce7 (patch)
tree106c9d1e745156a100da8bfc352a0997a04062fe /OpenSim/Region/Environment/Scenes/Tests/EntityManagerTests.cs
parentMade the casting of stings to floats more robust and work more like SL. (diff)
downloadopensim-SC-7a4f11b94da2ba2fbe24393ce2804214e199bce7.zip
opensim-SC-7a4f11b94da2ba2fbe24393ce2804214e199bce7.tar.gz
opensim-SC-7a4f11b94da2ba2fbe24393ce2804214e199bce7.tar.bz2
opensim-SC-7a4f11b94da2ba2fbe24393ce2804214e199bce7.tar.xz
* Deleted old EntiyList tests, added new EntityManager tests
* Edited EntityManager to treat Exceptions From: Arthur Rodrigo S Valadares <arthursv@linux.vnet.ibm.com>
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/Tests/EntityManagerTests.cs')
-rw-r--r--OpenSim/Region/Environment/Scenes/Tests/EntityManagerTests.cs178
1 files changed, 178 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Scenes/Tests/EntityManagerTests.cs b/OpenSim/Region/Environment/Scenes/Tests/EntityManagerTests.cs
new file mode 100644
index 0000000..5923a2c
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/Tests/EntityManagerTests.cs
@@ -0,0 +1,178 @@
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 EntityManagerTests
47 {
48 static public Random random;
49 SceneObjectGroup found;
50 Scene scene = SceneTestUtils.SetupScene();
51
52 [Test]
53 public void T010_AddObjects()
54 {
55 random = new Random();
56 SceneObjectGroup found;
57 EntityManager entman = new EntityManager();
58 SceneObjectGroup sog = NewSOG();
59 UUID obj1 = sog.UUID;
60 uint li1 = sog.LocalId;
61 entman.Add(sog);
62 sog = NewSOG();
63 UUID obj2 = sog.UUID;
64 uint li2 = sog.LocalId;
65 entman.Add(sog);
66
67 found = (SceneObjectGroup)entman[obj1];
68 Assert.That(found.UUID ,Is.EqualTo(obj1) );
69 found = (SceneObjectGroup)entman[li1];
70 Assert.That(found.UUID ,Is.EqualTo(obj1) );
71 found = (SceneObjectGroup)entman[obj2];
72 Assert.That(found.UUID ,Is.EqualTo(obj2) );
73 found = (SceneObjectGroup)entman[li2];
74 Assert.That(found.UUID ,Is.EqualTo(obj2) );
75
76 entman.Remove(obj1);
77 entman.Remove(li2);
78
79 Assert.That(entman.ContainsKey(obj1), Is.False);
80 Assert.That(entman.ContainsKey(li1), Is.False);
81 Assert.That(entman.ContainsKey(obj2), Is.False);
82 Assert.That(entman.ContainsKey(li2), Is.False);
83 }
84
85 [Test]
86 public void T011_ThreadAddRemoveTest()
87 {
88 // This test adds and removes with mutiple threads, attempting to break the
89 // uuid and localid dictionary coherence.
90 EntityManager entman = new EntityManager();
91 SceneObjectGroup sog = NewSOG();
92 for (int j=0; j<20; j++)
93 {
94 List<Thread> trdlist = new List<Thread>();
95
96 for (int i=0; i<4; i++)
97 {
98 // Adds scene object
99 NewTestThreads test = new NewTestThreads(entman,sog);
100 Thread start = new Thread(new ThreadStart(test.TestAddSceneObject));
101 start.Start();
102 trdlist.Add(start);
103
104 // Removes it
105 test = new NewTestThreads(entman,sog);
106 start = new Thread(new ThreadStart(test.TestRemoveSceneObject));
107 start.Start();
108 trdlist.Add(start);
109 }
110 foreach (Thread thread in trdlist)
111 {
112 thread.Join();
113 }
114 if (entman.ContainsKey(sog.UUID) || entman.ContainsKey(sog.LocalId)) {
115 found = (SceneObjectGroup)entman[sog.UUID];
116 Assert.That(found.UUID,Is.EqualTo(sog.UUID));
117 found = (SceneObjectGroup)entman[sog.LocalId];
118 Assert.That(found.UUID,Is.EqualTo(sog.UUID));
119 }
120 }
121 }
122
123 private SceneObjectGroup NewSOG()
124 {
125 SceneObjectGroup sog = new SceneObjectGroup();
126 SceneObjectPart sop = new SceneObjectPart(UUID.Random(), PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero);
127 sop.Name = RandomName();
128 sop.Description = sop.Name;
129 sop.Text = RandomName();
130 sop.SitName = RandomName();
131 sop.TouchName = RandomName();
132 sop.ObjectFlags |= (uint)PrimFlags.Phantom;
133
134 sog.SetRootPart(sop);
135
136 scene.AddNewSceneObject(sog, false);
137
138 return sog;
139 }
140
141 private static string RandomName()
142 {
143 StringBuilder name = new StringBuilder();
144 int size = random.Next(40,80);
145 char ch ;
146 for (int i=0; i<size; i++)
147 {
148 ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ;
149 name.Append(ch);
150 }
151 return name.ToString();
152 }
153 }
154
155 public class NewTestThreads
156 {
157 private EntityManager entman;
158 private SceneObjectGroup sog;
159 private Random random;
160
161 public NewTestThreads(EntityManager entman, SceneObjectGroup sog)
162 {
163 this.entman = entman;
164 this.sog = sog;
165 this.random = new Random();
166 }
167 public void TestAddSceneObject()
168 {
169 Thread.Sleep(random.Next(0,50));
170 entman.Add(sog);
171 }
172 public void TestRemoveSceneObject()
173 {
174 Thread.Sleep(random.Next(0,50));
175 entman.Remove(sog.UUID);
176 }
177 }
178} \ No newline at end of file