diff options
author | lbsa71 | 2009-06-07 08:50:43 +0000 |
---|---|---|
committer | lbsa71 | 2009-06-07 08:50:43 +0000 |
commit | 6267f939c5898e9aa66c3dc048412c74ee39836b (patch) | |
tree | 77cb72118854e8eb7dc02e69b977a609528fd25a /OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs | |
parent | Rename private TestllAngleBetween method (diff) | |
download | opensim-SC-6267f939c5898e9aa66c3dc048412c74ee39836b.zip opensim-SC-6267f939c5898e9aa66c3dc048412c74ee39836b.tar.gz opensim-SC-6267f939c5898e9aa66c3dc048412c74ee39836b.tar.bz2 opensim-SC-6267f939c5898e9aa66c3dc048412c74ee39836b.tar.xz |
* Reverting the test restructuring as, on second thought, this is not at all how the tests are structured.
(pt1)
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs b/OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs new file mode 100644 index 0000000..dae095f --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs | |||
@@ -0,0 +1,184 @@ | |||
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.Reflection; | ||
30 | using System.Threading; | ||
31 | using System.Text; | ||
32 | using System.Collections.Generic; | ||
33 | using Nini.Config; | ||
34 | using NUnit.Framework; | ||
35 | using NUnit.Framework.SyntaxHelpers; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Communications; | ||
39 | using OpenSim.Region.Framework.Scenes; | ||
40 | using OpenSim.Tests.Common; | ||
41 | using OpenSim.Tests.Common.Setup; | ||
42 | |||
43 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
44 | { | ||
45 | [TestFixture, LongRunning] | ||
46 | public class EntityManagerTests | ||
47 | { | ||
48 | static public Random random; | ||
49 | SceneObjectGroup found; | ||
50 | Scene scene = SceneSetupHelpers.SetupScene(); | ||
51 | |||
52 | [Test] | ||
53 | public void T010_AddObjects() | ||
54 | { | ||
55 | TestHelper.InMethod(); | ||
56 | // Console.WriteLine("Beginning test {0}", MethodBase.GetCurrentMethod()); | ||
57 | |||
58 | random = new Random(); | ||
59 | SceneObjectGroup found; | ||
60 | EntityManager entman = new EntityManager(); | ||
61 | SceneObjectGroup sog = NewSOG(); | ||
62 | UUID obj1 = sog.UUID; | ||
63 | uint li1 = sog.LocalId; | ||
64 | entman.Add(sog); | ||
65 | sog = NewSOG(); | ||
66 | UUID obj2 = sog.UUID; | ||
67 | uint li2 = sog.LocalId; | ||
68 | entman.Add(sog); | ||
69 | |||
70 | found = (SceneObjectGroup)entman[obj1]; | ||
71 | Assert.That(found.UUID ,Is.EqualTo(obj1) ); | ||
72 | found = (SceneObjectGroup)entman[li1]; | ||
73 | Assert.That(found.UUID ,Is.EqualTo(obj1) ); | ||
74 | found = (SceneObjectGroup)entman[obj2]; | ||
75 | Assert.That(found.UUID ,Is.EqualTo(obj2) ); | ||
76 | found = (SceneObjectGroup)entman[li2]; | ||
77 | Assert.That(found.UUID ,Is.EqualTo(obj2) ); | ||
78 | |||
79 | entman.Remove(obj1); | ||
80 | entman.Remove(li2); | ||
81 | |||
82 | Assert.That(entman.ContainsKey(obj1), Is.False); | ||
83 | Assert.That(entman.ContainsKey(li1), Is.False); | ||
84 | Assert.That(entman.ContainsKey(obj2), Is.False); | ||
85 | Assert.That(entman.ContainsKey(li2), Is.False); | ||
86 | } | ||
87 | |||
88 | [Test] | ||
89 | public void T011_ThreadAddRemoveTest() | ||
90 | { | ||
91 | TestHelper.InMethod(); | ||
92 | // Console.WriteLine("Beginning test {0}", MethodBase.GetCurrentMethod()); | ||
93 | |||
94 | // This test adds and removes with mutiple threads, attempting to break the | ||
95 | // uuid and localid dictionary coherence. | ||
96 | EntityManager entman = new EntityManager(); | ||
97 | SceneObjectGroup sog = NewSOG(); | ||
98 | for (int j=0; j<20; j++) | ||
99 | { | ||
100 | List<Thread> trdlist = new List<Thread>(); | ||
101 | |||
102 | for (int i=0; i<4; i++) | ||
103 | { | ||
104 | // Adds scene object | ||
105 | NewTestThreads test = new NewTestThreads(entman,sog); | ||
106 | Thread start = new Thread(new ThreadStart(test.TestAddSceneObject)); | ||
107 | start.Start(); | ||
108 | trdlist.Add(start); | ||
109 | |||
110 | // Removes it | ||
111 | test = new NewTestThreads(entman,sog); | ||
112 | start = new Thread(new ThreadStart(test.TestRemoveSceneObject)); | ||
113 | start.Start(); | ||
114 | trdlist.Add(start); | ||
115 | } | ||
116 | foreach (Thread thread in trdlist) | ||
117 | { | ||
118 | thread.Join(); | ||
119 | } | ||
120 | if (entman.ContainsKey(sog.UUID) || entman.ContainsKey(sog.LocalId)) { | ||
121 | found = (SceneObjectGroup)entman[sog.UUID]; | ||
122 | Assert.That(found.UUID,Is.EqualTo(sog.UUID)); | ||
123 | found = (SceneObjectGroup)entman[sog.LocalId]; | ||
124 | Assert.That(found.UUID,Is.EqualTo(sog.UUID)); | ||
125 | } | ||
126 | } | ||
127 | } | ||
128 | |||
129 | private SceneObjectGroup NewSOG() | ||
130 | { | ||
131 | SceneObjectGroup sog = new SceneObjectGroup(); | ||
132 | SceneObjectPart sop = new SceneObjectPart(UUID.Random(), PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero); | ||
133 | sop.Name = RandomName(); | ||
134 | sop.Description = sop.Name; | ||
135 | sop.Text = RandomName(); | ||
136 | sop.SitName = RandomName(); | ||
137 | sop.TouchName = RandomName(); | ||
138 | sop.ObjectFlags |= (uint)PrimFlags.Phantom; | ||
139 | |||
140 | sog.SetRootPart(sop); | ||
141 | |||
142 | scene.AddNewSceneObject(sog, false); | ||
143 | |||
144 | return sog; | ||
145 | } | ||
146 | |||
147 | private static string RandomName() | ||
148 | { | ||
149 | StringBuilder name = new StringBuilder(); | ||
150 | int size = random.Next(40,80); | ||
151 | char ch ; | ||
152 | for (int i=0; i<size; i++) | ||
153 | { | ||
154 | ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ; | ||
155 | name.Append(ch); | ||
156 | } | ||
157 | return name.ToString(); | ||
158 | } | ||
159 | } | ||
160 | |||
161 | public class NewTestThreads | ||
162 | { | ||
163 | private EntityManager entman; | ||
164 | private SceneObjectGroup sog; | ||
165 | private Random random; | ||
166 | |||
167 | public NewTestThreads(EntityManager entman, SceneObjectGroup sog) | ||
168 | { | ||
169 | this.entman = entman; | ||
170 | this.sog = sog; | ||
171 | this.random = new Random(); | ||
172 | } | ||
173 | public void TestAddSceneObject() | ||
174 | { | ||
175 | Thread.Sleep(random.Next(0,50)); | ||
176 | entman.Add(sog); | ||
177 | } | ||
178 | public void TestRemoveSceneObject() | ||
179 | { | ||
180 | Thread.Sleep(random.Next(0,50)); | ||
181 | entman.Remove(sog.UUID); | ||
182 | } | ||
183 | } | ||
184 | } \ No newline at end of file | ||