OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
PrimCountModuleTests.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 log4net.Config;
32 using NUnit.Framework;
33 using OpenMetaverse;
34 using OpenMetaverse.Assets;
35 using OpenSim.Framework;
36 using OpenSim.Region.Framework.Interfaces;
37 using OpenSim.Region.Framework.Scenes;
38 using OpenSim.Tests.Common;
39 
40 namespace OpenSim.Region.CoreModules.World.Land.Tests
41 {
42  [TestFixture]
44  {
45  protected UUID m_userId = new UUID("00000000-0000-0000-0000-100000000000");
46  protected UUID m_groupId = new UUID("00000000-0000-0000-8888-000000000000");
47  protected UUID m_otherUserId = new UUID("99999999-9999-9999-9999-999999999999");
48  protected TestScene m_scene;
50 
54  protected ILandObject m_lo;
55 
59  protected ILandObject m_lo2;
60 
61  [SetUp]
62  public override void SetUp()
63  {
64  base.SetUp();
65 
66  m_pcm = new PrimCountModule();
68  m_scene = new SceneHelpers().SetupScene();
69  SceneHelpers.SetupSceneModules(m_scene, lmm, m_pcm);
70 
71  int xParcelDivider = (int)Constants.RegionSize - 1;
72 
73  ILandObject lo = new LandObject(m_userId, false, m_scene);
74  lo.LandData.Name = "m_lo";
75  lo.SetLandBitmap(
76  lo.GetSquareLandBitmap(0, 0, xParcelDivider, (int)Constants.RegionSize));
77  m_lo = lmm.AddLandObject(lo);
78 
79  ILandObject lo2 = new LandObject(m_userId, false, m_scene);
80  lo2.SetLandBitmap(
81  lo2.GetSquareLandBitmap(xParcelDivider, 0, (int)Constants.RegionSize, (int)Constants.RegionSize));
82  lo2.LandData.Name = "m_lo2";
83  m_lo2 = lmm.AddLandObject(lo2);
84  }
85 
89  [Test]
90  public void TestInitialCounts()
91  {
92  IPrimCounts pc = m_lo.PrimCounts;
93 
94  Assert.That(pc.Owner, Is.EqualTo(0));
95  Assert.That(pc.Group, Is.EqualTo(0));
96  Assert.That(pc.Others, Is.EqualTo(0));
97  Assert.That(pc.Total, Is.EqualTo(0));
98  Assert.That(pc.Selected, Is.EqualTo(0));
99  Assert.That(pc.Users[m_userId], Is.EqualTo(0));
100  Assert.That(pc.Users[m_otherUserId], Is.EqualTo(0));
101  Assert.That(pc.Simulator, Is.EqualTo(0));
102  }
103 
107  [Test]
108  public void TestAddOwnerObject()
109  {
110  TestHelpers.InMethod();
111 // log4net.Config.XmlConfigurator.Configure();
112 
113  IPrimCounts pc = m_lo.PrimCounts;
114 
115  SceneObjectGroup sog = SceneHelpers.CreateSceneObject(3, m_userId, "a", 0x01);
116  m_scene.AddNewSceneObject(sog, false);
117 
118  Assert.That(pc.Owner, Is.EqualTo(3));
119  Assert.That(pc.Group, Is.EqualTo(0));
120  Assert.That(pc.Others, Is.EqualTo(0));
121  Assert.That(pc.Total, Is.EqualTo(3));
122  Assert.That(pc.Selected, Is.EqualTo(0));
123  Assert.That(pc.Users[m_userId], Is.EqualTo(3));
124  Assert.That(pc.Users[m_otherUserId], Is.EqualTo(0));
125  Assert.That(pc.Simulator, Is.EqualTo(3));
126 
127  // Add a second object and retest
128  SceneObjectGroup sog2 = SceneHelpers.CreateSceneObject(2, m_userId, "b", 0x10);
129  m_scene.AddNewSceneObject(sog2, false);
130 
131  Assert.That(pc.Owner, Is.EqualTo(5));
132  Assert.That(pc.Group, Is.EqualTo(0));
133  Assert.That(pc.Others, Is.EqualTo(0));
134  Assert.That(pc.Total, Is.EqualTo(5));
135  Assert.That(pc.Selected, Is.EqualTo(0));
136  Assert.That(pc.Users[m_userId], Is.EqualTo(5));
137  Assert.That(pc.Users[m_otherUserId], Is.EqualTo(0));
138  Assert.That(pc.Simulator, Is.EqualTo(5));
139  }
140 
144  [Test]
145  public void TestCopyOwnerObject()
146  {
147  TestHelpers.InMethod();
148 // log4net.Config.XmlConfigurator.Configure();
149 
150  IPrimCounts pc = m_lo.PrimCounts;
151 
152  SceneObjectGroup sog = SceneHelpers.CreateSceneObject(3, m_userId, "a", 0x01);
153  m_scene.AddNewSceneObject(sog, false);
154  m_scene.SceneGraph.DuplicateObject(sog.LocalId, Vector3.Zero, 0, m_userId, UUID.Zero, Quaternion.Identity);
155 
156  Assert.That(pc.Owner, Is.EqualTo(6));
157  Assert.That(pc.Group, Is.EqualTo(0));
158  Assert.That(pc.Others, Is.EqualTo(0));
159  Assert.That(pc.Total, Is.EqualTo(6));
160  Assert.That(pc.Selected, Is.EqualTo(0));
161  Assert.That(pc.Users[m_userId], Is.EqualTo(6));
162  Assert.That(pc.Users[m_otherUserId], Is.EqualTo(0));
163  Assert.That(pc.Simulator, Is.EqualTo(6));
164  }
165 
170  [Test]
171  public void TestMoveOwnerObject()
172  {
173  TestHelpers.InMethod();
174 // log4net.Config.XmlConfigurator.Configure();
175 
176  SceneObjectGroup sog = SceneHelpers.CreateSceneObject(3, m_userId, "a", 0x01);
177  m_scene.AddNewSceneObject(sog, false);
178  SceneObjectGroup sog2 = SceneHelpers.CreateSceneObject(2, m_userId, "b", 0x10);
179  m_scene.AddNewSceneObject(sog2, false);
180 
181  // Move the first scene object to the eastern strip parcel
182  sog.AbsolutePosition = new Vector3(254, 2, 2);
183 
184  IPrimCounts pclo1 = m_lo.PrimCounts;
185 
186  Assert.That(pclo1.Owner, Is.EqualTo(2));
187  Assert.That(pclo1.Group, Is.EqualTo(0));
188  Assert.That(pclo1.Others, Is.EqualTo(0));
189  Assert.That(pclo1.Total, Is.EqualTo(2));
190  Assert.That(pclo1.Selected, Is.EqualTo(0));
191  Assert.That(pclo1.Users[m_userId], Is.EqualTo(2));
192  Assert.That(pclo1.Users[m_otherUserId], Is.EqualTo(0));
193  Assert.That(pclo1.Simulator, Is.EqualTo(5));
194 
195  IPrimCounts pclo2 = m_lo2.PrimCounts;
196 
197  Assert.That(pclo2.Owner, Is.EqualTo(3));
198  Assert.That(pclo2.Group, Is.EqualTo(0));
199  Assert.That(pclo2.Others, Is.EqualTo(0));
200  Assert.That(pclo2.Total, Is.EqualTo(3));
201  Assert.That(pclo2.Selected, Is.EqualTo(0));
202  Assert.That(pclo2.Users[m_userId], Is.EqualTo(3));
203  Assert.That(pclo2.Users[m_otherUserId], Is.EqualTo(0));
204  Assert.That(pclo2.Simulator, Is.EqualTo(5));
205 
206  // Now move it back again
207  sog.AbsolutePosition = new Vector3(2, 2, 2);
208 
209  Assert.That(pclo1.Owner, Is.EqualTo(5));
210  Assert.That(pclo1.Group, Is.EqualTo(0));
211  Assert.That(pclo1.Others, Is.EqualTo(0));
212  Assert.That(pclo1.Total, Is.EqualTo(5));
213  Assert.That(pclo1.Selected, Is.EqualTo(0));
214  Assert.That(pclo1.Users[m_userId], Is.EqualTo(5));
215  Assert.That(pclo1.Users[m_otherUserId], Is.EqualTo(0));
216  Assert.That(pclo1.Simulator, Is.EqualTo(5));
217 
218  Assert.That(pclo2.Owner, Is.EqualTo(0));
219  Assert.That(pclo2.Group, Is.EqualTo(0));
220  Assert.That(pclo2.Others, Is.EqualTo(0));
221  Assert.That(pclo2.Total, Is.EqualTo(0));
222  Assert.That(pclo2.Selected, Is.EqualTo(0));
223  Assert.That(pclo2.Users[m_userId], Is.EqualTo(0));
224  Assert.That(pclo2.Users[m_otherUserId], Is.EqualTo(0));
225  Assert.That(pclo2.Simulator, Is.EqualTo(5));
226  }
227 
231  [Test]
232  public void TestRemoveOwnerObject()
233  {
234  TestHelpers.InMethod();
235 // log4net.Config.XmlConfigurator.Configure();
236 
237  IPrimCounts pc = m_lo.PrimCounts;
238 
239  m_scene.AddNewSceneObject(SceneHelpers.CreateSceneObject(1, m_userId, "a", 0x1), false);
240  SceneObjectGroup sogToDelete = SceneHelpers.CreateSceneObject(3, m_userId, "b", 0x10);
241  m_scene.AddNewSceneObject(sogToDelete, false);
242  m_scene.DeleteSceneObject(sogToDelete, false);
243 
244  Assert.That(pc.Owner, Is.EqualTo(1));
245  Assert.That(pc.Group, Is.EqualTo(0));
246  Assert.That(pc.Others, Is.EqualTo(0));
247  Assert.That(pc.Total, Is.EqualTo(1));
248  Assert.That(pc.Selected, Is.EqualTo(0));
249  Assert.That(pc.Users[m_userId], Is.EqualTo(1));
250  Assert.That(pc.Users[m_otherUserId], Is.EqualTo(0));
251  Assert.That(pc.Simulator, Is.EqualTo(1));
252  }
253 
254  [Test]
255  public void TestAddGroupObject()
256  {
257  TestHelpers.InMethod();
258 // log4net.Config.XmlConfigurator.Configure();
259 
260  m_lo.DeedToGroup(m_groupId);
261 
262  IPrimCounts pc = m_lo.PrimCounts;
263 
264  SceneObjectGroup sog = SceneHelpers.CreateSceneObject(3, m_otherUserId, "a", 0x01);
265  sog.GroupID = m_groupId;
266  m_scene.AddNewSceneObject(sog, false);
267 
268  Assert.That(pc.Owner, Is.EqualTo(0));
269  Assert.That(pc.Group, Is.EqualTo(3));
270  Assert.That(pc.Others, Is.EqualTo(0));
271  Assert.That(pc.Total, Is.EqualTo(3));
272  Assert.That(pc.Selected, Is.EqualTo(0));
273 
274  // Is this desired behaviour? Not totally sure.
275  Assert.That(pc.Users[m_userId], Is.EqualTo(0));
276  Assert.That(pc.Users[m_groupId], Is.EqualTo(0));
277  Assert.That(pc.Users[m_otherUserId], Is.EqualTo(3));
278 
279  Assert.That(pc.Simulator, Is.EqualTo(3));
280  }
281 
285  [Test]
286  public void TestRemoveGroupObject()
287  {
288  TestHelpers.InMethod();
289 // log4net.Config.XmlConfigurator.Configure();
290 
291  m_lo.DeedToGroup(m_groupId);
292 
293  IPrimCounts pc = m_lo.PrimCounts;
294 
295  SceneObjectGroup sogToKeep = SceneHelpers.CreateSceneObject(1, m_userId, "a", 0x1);
296  sogToKeep.GroupID = m_groupId;
297  m_scene.AddNewSceneObject(sogToKeep, false);
298 
299  SceneObjectGroup sogToDelete = SceneHelpers.CreateSceneObject(3, m_userId, "b", 0x10);
300  m_scene.AddNewSceneObject(sogToDelete, false);
301  m_scene.DeleteSceneObject(sogToDelete, false);
302 
303  Assert.That(pc.Owner, Is.EqualTo(0));
304  Assert.That(pc.Group, Is.EqualTo(1));
305  Assert.That(pc.Others, Is.EqualTo(0));
306  Assert.That(pc.Total, Is.EqualTo(1));
307  Assert.That(pc.Selected, Is.EqualTo(0));
308  Assert.That(pc.Users[m_userId], Is.EqualTo(1));
309  Assert.That(pc.Users[m_groupId], Is.EqualTo(0));
310  Assert.That(pc.Users[m_otherUserId], Is.EqualTo(0));
311  Assert.That(pc.Simulator, Is.EqualTo(1));
312  }
313 
314  [Test]
315  public void TestAddOthersObject()
316  {
317  TestHelpers.InMethod();
318 // log4net.Config.XmlConfigurator.Configure();
319 
320  IPrimCounts pc = m_lo.PrimCounts;
321 
322  SceneObjectGroup sog = SceneHelpers.CreateSceneObject(3, m_otherUserId, "a", 0x01);
323  m_scene.AddNewSceneObject(sog, false);
324 
325  Assert.That(pc.Owner, Is.EqualTo(0));
326  Assert.That(pc.Group, Is.EqualTo(0));
327  Assert.That(pc.Others, Is.EqualTo(3));
328  Assert.That(pc.Total, Is.EqualTo(3));
329  Assert.That(pc.Selected, Is.EqualTo(0));
330  Assert.That(pc.Users[m_userId], Is.EqualTo(0));
331  Assert.That(pc.Users[m_otherUserId], Is.EqualTo(3));
332  Assert.That(pc.Simulator, Is.EqualTo(3));
333  }
334 
335  [Test]
337  {
338  TestHelpers.InMethod();
339 // log4net.Config.XmlConfigurator.Configure();
340 
341  IPrimCounts pc = m_lo.PrimCounts;
342 
343  m_scene.AddNewSceneObject(SceneHelpers.CreateSceneObject(1, m_otherUserId, "a", 0x1), false);
344  SceneObjectGroup sogToDelete = SceneHelpers.CreateSceneObject(3, m_otherUserId, "b", 0x10);
345  m_scene.AddNewSceneObject(sogToDelete, false);
346  m_scene.DeleteSceneObject(sogToDelete, false);
347 
348  Assert.That(pc.Owner, Is.EqualTo(0));
349  Assert.That(pc.Group, Is.EqualTo(0));
350  Assert.That(pc.Others, Is.EqualTo(1));
351  Assert.That(pc.Total, Is.EqualTo(1));
352  Assert.That(pc.Selected, Is.EqualTo(0));
353  Assert.That(pc.Users[m_userId], Is.EqualTo(0));
354  Assert.That(pc.Users[m_otherUserId], Is.EqualTo(1));
355  Assert.That(pc.Simulator, Is.EqualTo(1));
356  }
357 
361  [Test]
362  public void TestTaint()
363  {
364  TestHelpers.InMethod();
365  IPrimCounts pc = m_lo.PrimCounts;
366 
367  SceneObjectGroup sog = SceneHelpers.CreateSceneObject(3, m_userId, "a", 0x01);
368  m_scene.AddNewSceneObject(sog, false);
369 
370  m_pcm.TaintPrimCount();
371 
372  Assert.That(pc.Owner, Is.EqualTo(3));
373  Assert.That(pc.Group, Is.EqualTo(0));
374  Assert.That(pc.Others, Is.EqualTo(0));
375  Assert.That(pc.Total, Is.EqualTo(3));
376  Assert.That(pc.Selected, Is.EqualTo(0));
377  Assert.That(pc.Users[m_userId], Is.EqualTo(3));
378  Assert.That(pc.Users[m_otherUserId], Is.EqualTo(0));
379  Assert.That(pc.Simulator, Is.EqualTo(3));
380  }
381  }
382 }
void TestRemoveGroupObject()
Test count after a parcel owner owned object is removed.
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
ILandObject m_lo
A parcel that covers the entire sim except for a 1 unit wide strip on the eastern side...
Keeps track of a specific piece of land's information
Definition: LandObject.cs:43
void TestCopyOwnerObject()
Test count after a parcel owner owned copied object is added.
void TestAddOwnerObject()
Test count after a parcel owner owned object is added.
void TestMoveOwnerObject()
Test that parcel counts update correctly when an object is moved between parcels, where that movement...
void TestTaint()
Test the count is correct after is has been tainted.
void TestRemoveOwnerObject()
Test count after a parcel owner owned object is removed.
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60
ILandObject m_lo2
A parcel that covers just the eastern strip of the sim.
void TestInitialCounts()
Test that counts before we do anything are correct.