OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
RegionTests.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.Drawing;
31 using System.Text;
32 using log4net.Config;
33 using NUnit.Framework;
34 using OpenMetaverse;
35 using OpenSim.Framework;
36 using OpenSim.Region.Framework.Interfaces;
37 using OpenSim.Region.Framework.Scenes;
38 using OpenSim.Tests.Common;
39 using log4net;
40 using System.Reflection;
41 using System.Data.Common;
42 using System.Threading;
43 
44 // DBMS-specific:
45 using MySql.Data.MySqlClient;
46 using OpenSim.Data.MySQL;
47 
48 using Mono.Data.Sqlite;
49 using OpenSim.Data.SQLite;
50 
51 namespace OpenSim.Data.Tests
52 {
53  [TestFixture(Description = "Region store tests (SQLite)")]
54  public class SQLiteRegionTests : RegionTests<SqliteConnection, SQLiteSimulationData>
55  {
56  }
57 
58  [TestFixture(Description = "Region store tests (MySQL)")]
59  public class MySqlRegionTests : RegionTests<MySqlConnection, MySQLSimulationData>
60  {
61  }
62 
63  public class RegionTests<TConn, TRegStore> : BasicDataServiceTest<TConn, TRegStore>
64  where TConn : DbConnection, new()
65  where TRegStore : class, ISimulationDataStore, new()
66  {
67  bool m_rebuildDB;
68 
70  public UUID zero = UUID.Zero;
71  public UUID region1 = UUID.Random();
72  public UUID region2 = UUID.Random();
73  public UUID region3 = UUID.Random();
74  public UUID region4 = UUID.Random();
75  public UUID prim1 = UUID.Random();
76  public UUID prim2 = UUID.Random();
77  public UUID prim3 = UUID.Random();
78  public UUID prim4 = UUID.Random();
79  public UUID prim5 = UUID.Random();
80  public UUID prim6 = UUID.Random();
81  public UUID item1 = UUID.Random();
82  public UUID item2 = UUID.Random();
83  public UUID item3 = UUID.Random();
84 
85  public static Random random = new Random();
86 
87  public string itemname1 = "item1";
88 
89  public uint localID = 1;
90 
91  public double height1 = 20;
92  public double height2 = 100;
93 
94  public RegionTests(string conn, bool rebuild)
95  : base(conn)
96  {
97  m_rebuildDB = rebuild;
98  }
99 
100  public RegionTests() : this("", true) { }
101  public RegionTests(string conn) : this(conn, true) {}
102  public RegionTests(bool rebuild): this("", rebuild) {}
103 
104 
105  protected override void InitService(object service)
106  {
107  ClearDB();
108  db = (ISimulationDataStore)service;
109  db.Initialise(m_connStr);
110  }
111 
112  private void ClearDB()
113  {
114  string[] reg_tables = new string[] {
115  "prims", "primshapes", "primitems", "terrain", "land", "landaccesslist", "regionban", "regionsettings"
116  };
117 
118  if (m_rebuildDB)
119  {
120  DropTables(reg_tables);
121  ResetMigrations("RegionStore");
122  }
123  else
124  {
125  ClearTables(reg_tables);
126  }
127  }
128 
129  // Test Plan
130  // Prims
131  // - empty test - 001
132  // - store / retrieve basic prims (most minimal we can make) - 010, 011
133  // - store / retrieve parts in a scenegroup 012
134  // - store a prim with complete information for consistency check 013
135  // - update existing prims, make sure it sticks - 014
136  // - tests empty inventory - 020
137  // - add inventory items to prims make - 021
138  // - retrieves the added item - 022
139  // - update inventory items to prims - 023
140  // - remove inventory items make sure it sticks - 024
141  // - checks if all parameters are persistent - 025
142  // - adds many items and see if it is handled correctly - 026
143 
144  [Test]
145  public void T001_LoadEmpty()
146  {
147  TestHelpers.InMethod();
148 
149  List<SceneObjectGroup> objs = db.LoadObjects(region1);
150  List<SceneObjectGroup> objs3 = db.LoadObjects(region3);
151  List<LandData> land = db.LoadLandObjects(region1);
152 
153  Assert.That(objs.Count, Is.EqualTo(0), "Assert.That(objs.Count, Is.EqualTo(0))");
154  Assert.That(objs3.Count, Is.EqualTo(0), "Assert.That(objs3.Count, Is.EqualTo(0))");
155  Assert.That(land.Count, Is.EqualTo(0), "Assert.That(land.Count, Is.EqualTo(0))");
156  }
157 
158  // SOG round trips
159  // * store objects, make sure they save
160  // * update
161 
162  [Test]
164  {
165  TestHelpers.InMethod();
166 
167  SceneObjectGroup sog = NewSOG("object1", prim1, region1);
168  SceneObjectGroup sog2 = NewSOG("object2", prim2, region1);
169 
170  // in case the objects don't store
171  try
172  {
173  db.StoreObject(sog, region1);
174  }
175  catch (Exception e)
176  {
177  m_log.Error(e.ToString());
178  Assert.Fail();
179  }
180 
181  try
182  {
183  db.StoreObject(sog2, region1);
184  }
185  catch (Exception e)
186  {
187  m_log.Error(e.ToString());
188  Assert.Fail();
189  }
190 
191  // This tests the ADO.NET driver
192  List<SceneObjectGroup> objs = db.LoadObjects(region1);
193 
194  Assert.That(objs.Count, Is.EqualTo(2), "Assert.That(objs.Count, Is.EqualTo(2))");
195  }
196 
197  [Test]
198  public void T011_ObjectNames()
199  {
200  TestHelpers.InMethod();
201 
202  List<SceneObjectGroup> objs = db.LoadObjects(region1);
203  foreach (SceneObjectGroup sog in objs)
204  {
205  SceneObjectPart p = sog.RootPart;
206  Assert.That("", Is.Not.EqualTo(p.Name), "Assert.That(\"\", Is.Not.EqualTo(p.Name))");
207  Assert.That(p.Name, Is.EqualTo(p.Description), "Assert.That(p.Name, Is.EqualTo(p.Description))");
208  }
209  }
210 
211  [Test]
212  public void T012_SceneParts()
213  {
214  TestHelpers.InMethod();
215 
216  UUID tmp0 = UUID.Random();
217  UUID tmp1 = UUID.Random();
218  UUID tmp2 = UUID.Random();
219  UUID tmp3 = UUID.Random();
220  UUID newregion = UUID.Random();
221  SceneObjectPart p1 = NewSOP("SoP 1",tmp1);
222  SceneObjectPart p2 = NewSOP("SoP 2",tmp2);
223  SceneObjectPart p3 = NewSOP("SoP 3",tmp3);
224  SceneObjectGroup sog = NewSOG("Sop 0", tmp0, newregion);
225  sog.AddPart(p1);
226  sog.AddPart(p2);
227  sog.AddPart(p3);
228 
229  SceneObjectPart[] parts = sog.Parts;
230  Assert.That(parts.Length,Is.EqualTo(4), "Assert.That(parts.Length,Is.EqualTo(4))");
231 
232  db.StoreObject(sog, newregion);
233  List<SceneObjectGroup> sogs = db.LoadObjects(newregion);
234  Assert.That(sogs.Count,Is.EqualTo(1), "Assert.That(sogs.Count,Is.EqualTo(1))");
235  SceneObjectGroup newsog = sogs[0];
236 
237  SceneObjectPart[] newparts = newsog.Parts;
238  Assert.That(newparts.Length,Is.EqualTo(4), "Assert.That(newparts.Length,Is.EqualTo(4))");
239 
240  Assert.That(newsog.ContainsPart(tmp0), "Assert.That(newsog.ContainsPart(tmp0))");
241  Assert.That(newsog.ContainsPart(tmp1), "Assert.That(newsog.ContainsPart(tmp1))");
242  Assert.That(newsog.ContainsPart(tmp2), "Assert.That(newsog.ContainsPart(tmp2))");
243  Assert.That(newsog.ContainsPart(tmp3), "Assert.That(newsog.ContainsPart(tmp3))");
244  }
245 
246  [Test]
248  {
249  TestHelpers.InMethod();
250 
251  // Sets all ScenePart parameters, stores and retrieves them, then check for consistency with initial data
252  // The commented Asserts are the ones that are unchangeable (when storing on the database, their "Set" values are ignored
253  // The ObjectFlags is an exception, if it is entered incorrectly, the object IS REJECTED on the database silently.
254  UUID creator,uuid = new UUID();
255  creator = UUID.Random();
256  uint iserial = (uint)random.Next();
258  uint objf = (uint) random.Next();
259  uuid = prim4;
260  uint localid = localID+1;
261  localID = localID + 1;
262  string name = "Adam West";
263  byte material = (byte) random.Next((int)SOPMaterialData.MaxMaterial);
264  ulong regionh = (ulong)random.NextDouble() * (ulong)random.Next();
265  int pin = random.Next();
266  Byte[] partsys = new byte[8];
267  Byte[] textani = new byte[8];
268  random.NextBytes(textani);
269  random.NextBytes(partsys);
270  DateTime expires = new DateTime(2008, 12, 20);
271  DateTime rezzed = new DateTime(2009, 07, 15);
272  Vector3 groupos = new Vector3(random.Next(),random.Next(),random.Next());
273  Vector3 offset = new Vector3(random.Next(),random.Next(),random.Next());
274  Quaternion rotoff = new Quaternion(random.Next(),random.Next(),random.Next(),random.Next());
275  Vector3 velocity = new Vector3(random.Next(),random.Next(),random.Next());
276  Vector3 angvelo = new Vector3(random.Next(),random.Next(),random.Next());
277  Vector3 accel = new Vector3(random.Next(),random.Next(),random.Next());
278  string description = name;
279  Color color = Color.FromArgb(255, 165, 50, 100);
280  string text = "All Your Base Are Belong to Us";
281  string sitname = "SitName";
282  string touchname = "TouchName";
283  int linknum = random.Next();
284  byte clickaction = (byte) random.Next(127);
285  PrimitiveBaseShape pbshap = new PrimitiveBaseShape();
286  pbshap = PrimitiveBaseShape.Default;
287  pbshap.PathBegin = ushort.MaxValue;
288  pbshap.PathEnd = ushort.MaxValue;
289  pbshap.ProfileBegin = ushort.MaxValue;
290  pbshap.ProfileEnd = ushort.MaxValue;
291  pbshap.ProfileHollow = ushort.MaxValue;
292  Vector3 scale = new Vector3(random.Next(),random.Next(),random.Next());
293 
294  RegionInfo regionInfo = new RegionInfo();
295  regionInfo.RegionID = region3;
296  regionInfo.RegionLocX = 0;
297  regionInfo.RegionLocY = 0;
298 
299  SceneObjectPart sop = new SceneObjectPart();
300  SceneObjectGroup sog = new SceneObjectGroup(sop);
301 
302  sop.RegionHandle = regionh;
303  sop.UUID = uuid;
304  sop.LocalId = localid;
305  sop.Shape = pbshap;
306  sop.GroupPosition = groupos;
307  sop.RotationOffset = rotoff;
308  sop.CreatorID = creator;
309  sop.InventorySerial = iserial;
310  sop.TaskInventory = dic;
311  sop.Flags = (PrimFlags)objf;
312  sop.Name = name;
313  sop.Material = material;
314  sop.ScriptAccessPin = pin;
315  sop.TextureAnimation = textani;
316  sop.ParticleSystem = partsys;
317  sop.Expires = expires;
318  sop.Rezzed = rezzed;
319  sop.OffsetPosition = offset;
320  sop.Velocity = velocity;
321  sop.AngularVelocity = angvelo;
322  sop.Acceleration = accel;
323  sop.Description = description;
324  sop.Color = color;
325  sop.Text = text;
326  sop.SitName = sitname;
327  sop.TouchName = touchname;
328  sop.LinkNum = linknum;
329  sop.ClickAction = clickaction;
330  sop.Scale = scale;
331 
332  //Tests if local part accepted the parameters:
333  Assert.That(regionh,Is.EqualTo(sop.RegionHandle), "Assert.That(regionh,Is.EqualTo(sop.RegionHandle))");
334  Assert.That(localid,Is.EqualTo(sop.LocalId), "Assert.That(localid,Is.EqualTo(sop.LocalId))");
335  Assert.That(groupos,Is.EqualTo(sop.GroupPosition), "Assert.That(groupos,Is.EqualTo(sop.GroupPosition))");
336  Assert.That(name,Is.EqualTo(sop.Name), "Assert.That(name,Is.EqualTo(sop.Name))");
337  Assert.That(rotoff,Is.EqualTo(sop.RotationOffset), "Assert.That(rotoff,Is.EqualTo(sop.RotationOffset))");
338  Assert.That(uuid,Is.EqualTo(sop.UUID), "Assert.That(uuid,Is.EqualTo(sop.UUID))");
339  Assert.That(creator,Is.EqualTo(sop.CreatorID), "Assert.That(creator,Is.EqualTo(sop.CreatorID))");
340  // Modified in-class
341  // Assert.That(iserial,Is.EqualTo(sop.InventorySerial), "Assert.That(iserial,Is.EqualTo(sop.InventorySerial))");
342  Assert.That(dic,Is.EqualTo(sop.TaskInventory), "Assert.That(dic,Is.EqualTo(sop.TaskInventory))");
343  Assert.That(objf, Is.EqualTo((uint)sop.Flags), "Assert.That(objf,Is.EqualTo(sop.Flags))");
344  Assert.That(name,Is.EqualTo(sop.Name), "Assert.That(name,Is.EqualTo(sop.Name))");
345  Assert.That(material,Is.EqualTo(sop.Material), "Assert.That(material,Is.EqualTo(sop.Material))");
346  Assert.That(pin,Is.EqualTo(sop.ScriptAccessPin), "Assert.That(pin,Is.EqualTo(sop.ScriptAccessPin))");
347  Assert.That(textani,Is.EqualTo(sop.TextureAnimation), "Assert.That(textani,Is.EqualTo(sop.TextureAnimation))");
348  Assert.That(partsys,Is.EqualTo(sop.ParticleSystem), "Assert.That(partsys,Is.EqualTo(sop.ParticleSystem))");
349  Assert.That(expires,Is.EqualTo(sop.Expires), "Assert.That(expires,Is.EqualTo(sop.Expires))");
350  Assert.That(rezzed,Is.EqualTo(sop.Rezzed), "Assert.That(rezzed,Is.EqualTo(sop.Rezzed))");
351  Assert.That(offset,Is.EqualTo(sop.OffsetPosition), "Assert.That(offset,Is.EqualTo(sop.OffsetPosition))");
352  Assert.That(velocity,Is.EqualTo(sop.Velocity), "Assert.That(velocity,Is.EqualTo(sop.Velocity))");
353  Assert.That(angvelo,Is.EqualTo(sop.AngularVelocity), "Assert.That(angvelo,Is.EqualTo(sop.AngularVelocity))");
354  Assert.That(accel,Is.EqualTo(sop.Acceleration), "Assert.That(accel,Is.EqualTo(sop.Acceleration))");
355  Assert.That(description,Is.EqualTo(sop.Description), "Assert.That(description,Is.EqualTo(sop.Description))");
356  Assert.That(color,Is.EqualTo(sop.Color), "Assert.That(color,Is.EqualTo(sop.Color))");
357  Assert.That(text,Is.EqualTo(sop.Text), "Assert.That(text,Is.EqualTo(sop.Text))");
358  Assert.That(sitname,Is.EqualTo(sop.SitName), "Assert.That(sitname,Is.EqualTo(sop.SitName))");
359  Assert.That(touchname,Is.EqualTo(sop.TouchName), "Assert.That(touchname,Is.EqualTo(sop.TouchName))");
360  Assert.That(linknum,Is.EqualTo(sop.LinkNum), "Assert.That(linknum,Is.EqualTo(sop.LinkNum))");
361  Assert.That(clickaction,Is.EqualTo(sop.ClickAction), "Assert.That(clickaction,Is.EqualTo(sop.ClickAction))");
362  Assert.That(scale,Is.EqualTo(sop.Scale), "Assert.That(scale,Is.EqualTo(sop.Scale))");
363 
364  // This is necessary or object will not be inserted in DB
365  sop.Flags = PrimFlags.None;
366 
367  // Inserts group in DB
368  db.StoreObject(sog,region3);
369  List<SceneObjectGroup> sogs = db.LoadObjects(region3);
370  Assert.That(sogs.Count, Is.EqualTo(1), "Assert.That(sogs.Count, Is.EqualTo(1))");
371  // Makes sure there are no double insertions:
372  db.StoreObject(sog,region3);
373  sogs = db.LoadObjects(region3);
374  Assert.That(sogs.Count, Is.EqualTo(1), "Assert.That(sogs.Count, Is.EqualTo(1))");
375 
376 
377  // Tests if the parameters were inserted correctly
378  SceneObjectPart p = sogs[0].RootPart;
379  Assert.That(regionh,Is.EqualTo(p.RegionHandle), "Assert.That(regionh,Is.EqualTo(p.RegionHandle))");
380  //Assert.That(localid,Is.EqualTo(p.LocalId), "Assert.That(localid,Is.EqualTo(p.LocalId))");
381  Assert.That(groupos,Is.EqualTo(p.GroupPosition), "Assert.That(groupos,Is.EqualTo(p.GroupPosition))");
382  Assert.That(name,Is.EqualTo(p.Name), "Assert.That(name,Is.EqualTo(p.Name))");
383  Assert.That(rotoff,Is.EqualTo(p.RotationOffset), "Assert.That(rotoff,Is.EqualTo(p.RotationOffset))");
384  Assert.That(uuid,Is.EqualTo(p.UUID), "Assert.That(uuid,Is.EqualTo(p.UUID))");
385  Assert.That(creator,Is.EqualTo(p.CreatorID), "Assert.That(creator,Is.EqualTo(p.CreatorID))");
386  //Assert.That(iserial,Is.EqualTo(p.InventorySerial), "Assert.That(iserial,Is.EqualTo(p.InventorySerial))");
387  Assert.That(dic,Is.EqualTo(p.TaskInventory), "Assert.That(dic,Is.EqualTo(p.TaskInventory))");
388  //Assert.That(objf, Is.EqualTo((uint)p.Flags), "Assert.That(objf,Is.EqualTo(p.Flags))");
389  Assert.That(name,Is.EqualTo(p.Name), "Assert.That(name,Is.EqualTo(p.Name))");
390  Assert.That(material,Is.EqualTo(p.Material), "Assert.That(material,Is.EqualTo(p.Material))");
391  Assert.That(pin,Is.EqualTo(p.ScriptAccessPin), "Assert.That(pin,Is.EqualTo(p.ScriptAccessPin))");
392  Assert.That(textani,Is.EqualTo(p.TextureAnimation), "Assert.That(textani,Is.EqualTo(p.TextureAnimation))");
393  Assert.That(partsys,Is.EqualTo(p.ParticleSystem), "Assert.That(partsys,Is.EqualTo(p.ParticleSystem))");
394  //Assert.That(expires,Is.EqualTo(p.Expires), "Assert.That(expires,Is.EqualTo(p.Expires))");
395  //Assert.That(rezzed,Is.EqualTo(p.Rezzed), "Assert.That(rezzed,Is.EqualTo(p.Rezzed))");
396  Assert.That(offset,Is.EqualTo(p.OffsetPosition), "Assert.That(offset,Is.EqualTo(p.OffsetPosition))");
397  Assert.That(velocity,Is.EqualTo(p.Velocity), "Assert.That(velocity,Is.EqualTo(p.Velocity))");
398  Assert.That(angvelo,Is.EqualTo(p.AngularVelocity), "Assert.That(angvelo,Is.EqualTo(p.AngularVelocity))");
399  Assert.That(accel,Is.EqualTo(p.Acceleration), "Assert.That(accel,Is.EqualTo(p.Acceleration))");
400  Assert.That(description,Is.EqualTo(p.Description), "Assert.That(description,Is.EqualTo(p.Description))");
401  Assert.That(color,Is.EqualTo(p.Color), "Assert.That(color,Is.EqualTo(p.Color))");
402  Assert.That(text,Is.EqualTo(p.Text), "Assert.That(text,Is.EqualTo(p.Text))");
403  Assert.That(sitname,Is.EqualTo(p.SitName), "Assert.That(sitname,Is.EqualTo(p.SitName))");
404  Assert.That(touchname,Is.EqualTo(p.TouchName), "Assert.That(touchname,Is.EqualTo(p.TouchName))");
405  //Assert.That(linknum,Is.EqualTo(p.LinkNum), "Assert.That(linknum,Is.EqualTo(p.LinkNum))");
406  Assert.That(clickaction,Is.EqualTo(p.ClickAction), "Assert.That(clickaction,Is.EqualTo(p.ClickAction))");
407  Assert.That(scale,Is.EqualTo(p.Scale), "Assert.That(scale,Is.EqualTo(p.Scale))");
408 
409  //Assert.That(updatef,Is.EqualTo(p.UpdateFlag), "Assert.That(updatef,Is.EqualTo(p.UpdateFlag))");
410 
411  Assert.That(pbshap.PathBegin, Is.EqualTo(p.Shape.PathBegin), "Assert.That(pbshap.PathBegin, Is.EqualTo(p.Shape.PathBegin))");
412  Assert.That(pbshap.PathEnd, Is.EqualTo(p.Shape.PathEnd), "Assert.That(pbshap.PathEnd, Is.EqualTo(p.Shape.PathEnd))");
413  Assert.That(pbshap.ProfileBegin, Is.EqualTo(p.Shape.ProfileBegin), "Assert.That(pbshap.ProfileBegin, Is.EqualTo(p.Shape.ProfileBegin))");
414  Assert.That(pbshap.ProfileEnd, Is.EqualTo(p.Shape.ProfileEnd), "Assert.That(pbshap.ProfileEnd, Is.EqualTo(p.Shape.ProfileEnd))");
415  Assert.That(pbshap.ProfileHollow, Is.EqualTo(p.Shape.ProfileHollow), "Assert.That(pbshap.ProfileHollow, Is.EqualTo(p.Shape.ProfileHollow))");
416  }
417 
418  [Test]
419  public void T014_UpdateObject()
420  {
421  TestHelpers.InMethod();
422 
423  string text1 = "object1 text";
424  SceneObjectGroup sog = FindSOG("object1", region1);
425  sog.RootPart.Text = text1;
426  db.StoreObject(sog, region1);
427 
428  sog = FindSOG("object1", region1);
429  Assert.That(text1, Is.EqualTo(sog.RootPart.Text), "Assert.That(text1, Is.EqualTo(sog.RootPart.Text))");
430 
431  // Creates random values
432  UUID creator = new UUID();
433  creator = UUID.Random();
435  localID = localID + 1;
436  string name = "West Adam";
437  byte material = (byte) random.Next((int)SOPMaterialData.MaxMaterial);
438  ulong regionh = (ulong)random.NextDouble() * (ulong)random.Next();
439  int pin = random.Next();
440  Byte[] partsys = new byte[8];
441  Byte[] textani = new byte[8];
442  random.NextBytes(textani);
443  random.NextBytes(partsys);
444  DateTime expires = new DateTime(2010, 12, 20);
445  DateTime rezzed = new DateTime(2005, 07, 15);
446  Vector3 groupos = new Vector3(random.Next(),random.Next(),random.Next());
447  Vector3 offset = new Vector3(random.Next(),random.Next(),random.Next());
448  Quaternion rotoff = new Quaternion(random.Next(),random.Next(),random.Next(),random.Next());
449  Vector3 velocity = new Vector3(random.Next(),random.Next(),random.Next());
450  Vector3 angvelo = new Vector3(random.Next(),random.Next(),random.Next());
451  Vector3 accel = new Vector3(random.Next(),random.Next(),random.Next());
452  string description = name;
453  Color color = Color.FromArgb(255, 255, 255, 0);
454  string text = "What You Say?{]\vz~";
455  string sitname = RandomName();
456  string touchname = RandomName();
457  int linknum = random.Next();
458  byte clickaction = (byte) random.Next(127);
459  PrimitiveBaseShape pbshap = new PrimitiveBaseShape();
460  pbshap = PrimitiveBaseShape.Default;
461  Vector3 scale = new Vector3(random.Next(),random.Next(),random.Next());
462 
463  // Updates the region with new values
464  SceneObjectGroup sog2 = FindSOG("Adam West", region3);
465  Assert.That(sog2,Is.Not.Null);
466  sog2.RootPart.RegionHandle = regionh;
467  sog2.RootPart.Shape = pbshap;
468  sog2.RootPart.GroupPosition = groupos;
469  sog2.RootPart.RotationOffset = rotoff;
470  sog2.RootPart.CreatorID = creator;
471  sog2.RootPart.TaskInventory = dic;
472  sog2.RootPart.Name = name;
473  sog2.RootPart.Material = material;
474  sog2.RootPart.ScriptAccessPin = pin;
475  sog2.RootPart.TextureAnimation = textani;
476  sog2.RootPart.ParticleSystem = partsys;
477  sog2.RootPart.Expires = expires;
478  sog2.RootPart.Rezzed = rezzed;
479  sog2.RootPart.OffsetPosition = offset;
480  sog2.RootPart.Velocity = velocity;
481  sog2.RootPart.AngularVelocity = angvelo;
482  sog2.RootPart.Acceleration = accel;
483  sog2.RootPart.Description = description;
484  sog2.RootPart.Color = color;
485  sog2.RootPart.Text = text;
486  sog2.RootPart.SitName = sitname;
487  sog2.RootPart.TouchName = touchname;
488  sog2.RootPart.LinkNum = linknum;
489  sog2.RootPart.ClickAction = clickaction;
490  sog2.RootPart.Scale = scale;
491 
492  db.StoreObject(sog2, region3);
493  List<SceneObjectGroup> sogs = db.LoadObjects(region3);
494  Assert.That(sogs.Count, Is.EqualTo(1), "Assert.That(sogs.Count, Is.EqualTo(1))");
495 
496  SceneObjectGroup retsog = FindSOG("West Adam", region3);
497  Assert.That(retsog,Is.Not.Null);
498  SceneObjectPart p = retsog.RootPart;
499  Assert.That(regionh,Is.EqualTo(p.RegionHandle), "Assert.That(regionh,Is.EqualTo(p.RegionHandle))");
500  Assert.That(groupos,Is.EqualTo(p.GroupPosition), "Assert.That(groupos,Is.EqualTo(p.GroupPosition))");
501  Assert.That(name,Is.EqualTo(p.Name), "Assert.That(name,Is.EqualTo(p.Name))");
502  Assert.That(rotoff,Is.EqualTo(p.RotationOffset), "Assert.That(rotoff,Is.EqualTo(p.RotationOffset))");
503  Assert.That(creator,Is.EqualTo(p.CreatorID), "Assert.That(creator,Is.EqualTo(p.CreatorID))");
504  Assert.That(dic,Is.EqualTo(p.TaskInventory), "Assert.That(dic,Is.EqualTo(p.TaskInventory))");
505  Assert.That(name,Is.EqualTo(p.Name), "Assert.That(name,Is.EqualTo(p.Name))");
506  Assert.That(material,Is.EqualTo(p.Material), "Assert.That(material,Is.EqualTo(p.Material))");
507  Assert.That(pin,Is.EqualTo(p.ScriptAccessPin), "Assert.That(pin,Is.EqualTo(p.ScriptAccessPin))");
508  Assert.That(textani,Is.EqualTo(p.TextureAnimation), "Assert.That(textani,Is.EqualTo(p.TextureAnimation))");
509  Assert.That(partsys,Is.EqualTo(p.ParticleSystem), "Assert.That(partsys,Is.EqualTo(p.ParticleSystem))");
510  Assert.That(offset,Is.EqualTo(p.OffsetPosition), "Assert.That(offset,Is.EqualTo(p.OffsetPosition))");
511  Assert.That(velocity,Is.EqualTo(p.Velocity), "Assert.That(velocity,Is.EqualTo(p.Velocity))");
512  Assert.That(angvelo,Is.EqualTo(p.AngularVelocity), "Assert.That(angvelo,Is.EqualTo(p.AngularVelocity))");
513  Assert.That(accel,Is.EqualTo(p.Acceleration), "Assert.That(accel,Is.EqualTo(p.Acceleration))");
514  Assert.That(description,Is.EqualTo(p.Description), "Assert.That(description,Is.EqualTo(p.Description))");
515  Assert.That(color,Is.EqualTo(p.Color), "Assert.That(color,Is.EqualTo(p.Color))");
516  Assert.That(text,Is.EqualTo(p.Text), "Assert.That(text,Is.EqualTo(p.Text))");
517  Assert.That(sitname,Is.EqualTo(p.SitName), "Assert.That(sitname,Is.EqualTo(p.SitName))");
518  Assert.That(touchname,Is.EqualTo(p.TouchName), "Assert.That(touchname,Is.EqualTo(p.TouchName))");
519  Assert.That(clickaction,Is.EqualTo(p.ClickAction), "Assert.That(clickaction,Is.EqualTo(p.ClickAction))");
520  Assert.That(scale,Is.EqualTo(p.Scale), "Assert.That(scale,Is.EqualTo(p.Scale))");
521  }
522 
526  [Test]
528  {
529  TestHelpers.InMethod();
530 
531  UUID id = UUID.Random();
532  Dictionary<UUID, SceneObjectPart> mydic = new Dictionary<UUID, SceneObjectPart>();
533  SceneObjectGroup sog = NewSOG("Test SOG", id, region4);
534  mydic.Add(sog.RootPart.UUID,sog.RootPart);
535  for (int i = 0; i < 30; i++)
536  {
537  UUID tmp = UUID.Random();
538  SceneObjectPart sop = NewSOP(("Test SOP " + i.ToString()),tmp);
539  Vector3 groupos = new Vector3(random.Next(),random.Next(),random.Next());
540  Vector3 offset = new Vector3(random.Next(),random.Next(),random.Next());
541  Quaternion rotoff = new Quaternion(random.Next(),random.Next(),random.Next(),random.Next());
542  Vector3 velocity = new Vector3(random.Next(),random.Next(),random.Next());
543  Vector3 angvelo = new Vector3(random.Next(),random.Next(),random.Next());
544  Vector3 accel = new Vector3(random.Next(),random.Next(),random.Next());
545 
546  sop.GroupPosition = groupos;
547  sop.RotationOffset = rotoff;
548  sop.OffsetPosition = offset;
549  sop.Velocity = velocity;
550  sop.AngularVelocity = angvelo;
551  sop.Acceleration = accel;
552 
553  mydic.Add(tmp,sop);
554  sog.AddPart(sop);
555  }
556 
557  db.StoreObject(sog, region4);
558 
559  SceneObjectGroup retsog = FindSOG("Test SOG", region4);
560  SceneObjectPart[] parts = retsog.Parts;
561  for (int i = 0; i < 30; i++)
562  {
563  SceneObjectPart cursop = mydic[parts[i].UUID];
564  Assert.That(cursop.GroupPosition,Is.EqualTo(parts[i].GroupPosition), "Assert.That(cursop.GroupPosition,Is.EqualTo(parts[i].GroupPosition))");
565  Assert.That(cursop.RotationOffset,Is.EqualTo(parts[i].RotationOffset), "Assert.That(cursop.RotationOffset,Is.EqualTo(parts[i].RotationOffset))");
566  Assert.That(cursop.OffsetPosition,Is.EqualTo(parts[i].OffsetPosition), "Assert.That(cursop.OffsetPosition,Is.EqualTo(parts[i].OffsetPosition))");
567  Assert.That(cursop.Velocity,Is.EqualTo(parts[i].Velocity), "Assert.That(cursop.Velocity,Is.EqualTo(parts[i].Velocity))");
568  Assert.That(cursop.AngularVelocity,Is.EqualTo(parts[i].AngularVelocity), "Assert.That(cursop.AngularVelocity,Is.EqualTo(parts[i].AngularVelocity))");
569  Assert.That(cursop.Acceleration,Is.EqualTo(parts[i].Acceleration), "Assert.That(cursop.Acceleration,Is.EqualTo(parts[i].Acceleration))");
570  }
571  }
572 
573  //[Test]
575  {
576  TestHelpers.InMethod();
577 
578  PropertyScrambler<SceneObjectPart> scrambler =
579  new PropertyScrambler<SceneObjectPart>()
580  .DontScramble(x => x.UUID);
581  UUID tmpSog = UUID.Random();
582  UUID tmp1 = UUID.Random();
583  UUID tmp2 = UUID.Random();
584  UUID tmp3 = UUID.Random();
585  UUID newregion = UUID.Random();
586  SceneObjectPart p1 = new SceneObjectPart();
587  SceneObjectPart p2 = new SceneObjectPart();
588  SceneObjectPart p3 = new SceneObjectPart();
589  p1.Shape = PrimitiveBaseShape.Default;
590  p2.Shape = PrimitiveBaseShape.Default;
591  p3.Shape = PrimitiveBaseShape.Default;
592  p1.UUID = tmp1;
593  p2.UUID = tmp2;
594  p3.UUID = tmp3;
595  scrambler.Scramble(p1);
596  scrambler.Scramble(p2);
597  scrambler.Scramble(p3);
598 
599  SceneObjectGroup sog = NewSOG("Sop 0", tmpSog, newregion);
600  PropertyScrambler<SceneObjectGroup> sogScrambler =
601  new PropertyScrambler<SceneObjectGroup>()
602  .DontScramble(x => x.UUID);
603  sogScrambler.Scramble(sog);
604  sog.UUID = tmpSog;
605  sog.AddPart(p1);
606  sog.AddPart(p2);
607  sog.AddPart(p3);
608 
609  SceneObjectPart[] parts = sog.Parts;
610  Assert.That(parts.Length, Is.EqualTo(4), "Assert.That(parts.Length,Is.EqualTo(4))");
611 
612  db.StoreObject(sog, newregion);
613  List<SceneObjectGroup> sogs = db.LoadObjects(newregion);
614  Assert.That(sogs.Count, Is.EqualTo(1), "Assert.That(sogs.Count,Is.EqualTo(1))");
615  SceneObjectGroup newsog = sogs[0];
616 
617  SceneObjectPart[] newparts = newsog.Parts;
618  Assert.That(newparts.Length, Is.EqualTo(4), "Assert.That(newparts.Length,Is.EqualTo(4))");
619 
620  Assert.That(newsog, Constraints.PropertyCompareConstraint(sog)
621  .IgnoreProperty(x=>x.LocalId)
622  .IgnoreProperty(x=>x.HasGroupChanged)
623  .IgnoreProperty(x=>x.IsSelected)
624  .IgnoreProperty(x=>x.RegionHandle)
625  .IgnoreProperty(x=>x.RegionUUID)
626  .IgnoreProperty(x=>x.Scene)
627  .IgnoreProperty(x=>x.Parts)
628  .IgnoreProperty(x=>x.RootPart));
629  }
630 
631 
632  private SceneObjectGroup GetMySOG(string name)
633  {
634  SceneObjectGroup sog = FindSOG(name, region1);
635  if (sog == null)
636  {
637  sog = NewSOG(name, prim1, region1);
638  db.StoreObject(sog, region1);
639  }
640  return sog;
641  }
642 
643  // NOTE: it is a bad practice to rely on some of the previous tests having been run before.
644  // If the tests are run manually, one at a time, each starts with full class init (DB cleared).
645  // Even when all tests are run, NUnit 2.5+ no longer guarantee a specific test order.
646  // We shouldn't expect to find anything in the DB if we haven't put it there *in the same test*!
647 
648  [Test]
650  {
651  TestHelpers.InMethod();
652 
653  SceneObjectGroup sog = GetMySOG("object1");
654  TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
655  Assert.That(t, Is.Null);
656  }
657 
658  // TODO: Is there any point to call StorePrimInventory on a list, rather than on the prim itself?
659 
660  private void StoreInventory(SceneObjectGroup sog)
661  {
662  List<TaskInventoryItem> list = new List<TaskInventoryItem>();
663  // TODO: seriously??? this is the way we need to loop to get this?
664  foreach (UUID uuid in sog.RootPart.Inventory.GetInventoryList())
665  {
666  list.Add(sog.GetInventoryItem(sog.RootPart.LocalId, uuid));
667  }
668 
669  db.StorePrimInventory(sog.RootPart.UUID, list);
670  }
671 
672  [Test]
674  {
675  TestHelpers.InMethod();
676 
677  SceneObjectGroup sog = GetMySOG("object1");
678  InventoryItemBase i = NewItem(item1, zero, zero, itemname1, zero);
679 
680  Assert.That(sog.AddInventoryItem(zero, sog.RootPart.LocalId, i, zero), Is.True);
681  TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
682  Assert.That(t.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))");
683 
684  StoreInventory(sog);
685 
686  SceneObjectGroup sog1 = FindSOG("object1", region1);
687  Assert.That(sog1, Is.Not.Null);
688 
689  TaskInventoryItem t1 = sog1.GetInventoryItem(sog1.RootPart.LocalId, item1);
690  Assert.That(t1, Is.Not.Null);
691  Assert.That(t1.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))");
692 
693  // Updating inventory
694  t1.Name = "My New Name";
695  sog1.UpdateInventoryItem(t1);
696 
697  StoreInventory(sog1);
698 
699  SceneObjectGroup sog2 = FindSOG("object1", region1);
700  TaskInventoryItem t2 = sog2.GetInventoryItem(sog2.RootPart.LocalId, item1);
701  Assert.That(t2.Name, Is.EqualTo("My New Name"), "Assert.That(t.Name, Is.EqualTo(\"My New Name\"))");
702 
703  // Removing inventory
704  List<TaskInventoryItem> list = new List<TaskInventoryItem>();
705  db.StorePrimInventory(prim1, list);
706 
707  sog = FindSOG("object1", region1);
708  t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
709  Assert.That(t, Is.Null);
710  }
711 
712  [Test]
714  {
715  TestHelpers.InMethod();
716 
718  UUID id = UUID.Random();
719  i.ID = id;
720  UUID folder = UUID.Random();
721  i.Folder = folder;
722  UUID owner = UUID.Random();
723  i.Owner = owner;
724  UUID creator = UUID.Random();
725  i.CreatorId = creator.ToString();
726  string name = RandomName();
727  i.Name = name;
728  i.Description = name;
729  UUID assetid = UUID.Random();
730  i.AssetID = assetid;
731  int invtype = random.Next();
732  i.InvType = invtype;
733  uint nextperm = (uint) random.Next();
734  i.NextPermissions = nextperm;
735  uint curperm = (uint) random.Next();
736  i.CurrentPermissions = curperm;
737  uint baseperm = (uint) random.Next();
738  i.BasePermissions = baseperm;
739  uint eoperm = (uint) random.Next();
740  i.EveryOnePermissions = eoperm;
741  int assettype = random.Next();
742  i.AssetType = assettype;
743  UUID groupid = UUID.Random();
744  i.GroupID = groupid;
745  bool groupown = true;
746  i.GroupOwned = groupown;
747  int saleprice = random.Next();
748  i.SalePrice = saleprice;
749  byte saletype = (byte) random.Next(127);
750  i.SaleType = saletype;
751  uint flags = (uint) random.Next();
752  i.Flags = flags;
753  int creationd = random.Next();
754  i.CreationDate = creationd;
755 
756  SceneObjectGroup sog = GetMySOG("object1");
757  Assert.That(sog.AddInventoryItem(zero, sog.RootPart.LocalId, i, zero), Is.True);
758  TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, id);
759 
760  Assert.That(t.Name, Is.EqualTo(name), "Assert.That(t.Name, Is.EqualTo(name))");
761  Assert.That(t.AssetID,Is.EqualTo(assetid), "Assert.That(t.AssetID,Is.EqualTo(assetid))");
762  Assert.That(t.BasePermissions,Is.EqualTo(baseperm), "Assert.That(t.BasePermissions,Is.EqualTo(baseperm))");
763  Assert.That(t.CreationDate,Is.EqualTo(creationd), "Assert.That(t.CreationDate,Is.EqualTo(creationd))");
764  Assert.That(t.CreatorID,Is.EqualTo(creator), "Assert.That(t.CreatorID,Is.EqualTo(creator))");
765  Assert.That(t.Description,Is.EqualTo(name), "Assert.That(t.Description,Is.EqualTo(name))");
766  Assert.That(t.EveryonePermissions,Is.EqualTo(eoperm), "Assert.That(t.EveryonePermissions,Is.EqualTo(eoperm))");
767  Assert.That(t.Flags,Is.EqualTo(flags), "Assert.That(t.Flags,Is.EqualTo(flags))");
768  Assert.That(t.GroupID,Is.EqualTo(sog.RootPart.GroupID), "Assert.That(t.GroupID,Is.EqualTo(sog.RootPart.GroupID))");
769  // Where is this group permissions??
770  // Assert.That(t.GroupPermissions,Is.EqualTo(), "Assert.That(t.GroupPermissions,Is.EqualTo())");
771  Assert.That(t.Type,Is.EqualTo(assettype), "Assert.That(t.Type,Is.EqualTo(assettype))");
772  Assert.That(t.InvType, Is.EqualTo(invtype), "Assert.That(t.InvType, Is.EqualTo(invtype))");
773  Assert.That(t.ItemID, Is.EqualTo(id), "Assert.That(t.ItemID, Is.EqualTo(id))");
774  Assert.That(t.LastOwnerID, Is.EqualTo(sog.RootPart.LastOwnerID), "Assert.That(t.LastOwnerID, Is.EqualTo(sog.RootPart.LastOwnerID))");
775  Assert.That(t.NextPermissions, Is.EqualTo(nextperm), "Assert.That(t.NextPermissions, Is.EqualTo(nextperm))");
776  // Ownership changes when you drop an object into an object
777  // owned by someone else
778  Assert.That(t.OwnerID,Is.EqualTo(sog.RootPart.OwnerID), "Assert.That(t.OwnerID,Is.EqualTo(sog.RootPart.OwnerID))");
779 // Assert.That(t.CurrentPermissions, Is.EqualTo(curperm | 16), "Assert.That(t.CurrentPermissions, Is.EqualTo(curperm | 8))");
780  Assert.That(t.ParentID,Is.EqualTo(sog.RootPart.FolderID), "Assert.That(t.ParentID,Is.EqualTo(sog.RootPart.FolderID))");
781  Assert.That(t.ParentPartID,Is.EqualTo(sog.RootPart.UUID), "Assert.That(t.ParentPartID,Is.EqualTo(sog.RootPart.UUID))");
782  }
783 
784  [Test]
785  [ExpectedException(typeof(ArgumentException))]
787  {
788  TestHelpers.InMethod();
789 
790  UUID i1,i2,i3,i4;
791  i1 = UUID.Random();
792  i2 = UUID.Random();
793  i3 = UUID.Random();
794  i4 = i3;
795  InventoryItemBase ib1 = NewItem(i1, zero, zero, RandomName(), zero);
796  InventoryItemBase ib2 = NewItem(i2, zero, zero, RandomName(), zero);
797  InventoryItemBase ib3 = NewItem(i3, zero, zero, RandomName(), zero);
798  InventoryItemBase ib4 = NewItem(i4, zero, zero, RandomName(), zero);
799 
800  SceneObjectGroup sog = FindSOG("object1", region1);
801 
802  Assert.That(sog.AddInventoryItem(zero, sog.RootPart.LocalId, ib1, zero), Is.True);
803  Assert.That(sog.AddInventoryItem(zero, sog.RootPart.LocalId, ib2, zero), Is.True);
804  Assert.That(sog.AddInventoryItem(zero, sog.RootPart.LocalId, ib3, zero), Is.True);
805  Assert.That(sog.AddInventoryItem(zero, sog.RootPart.LocalId, ib4, zero), Is.True);
806 
807  TaskInventoryItem t1 = sog.GetInventoryItem(sog.RootPart.LocalId, i1);
808  Assert.That(t1.Name, Is.EqualTo(ib1.Name), "Assert.That(t1.Name, Is.EqualTo(ib1.Name))");
809  TaskInventoryItem t2 = sog.GetInventoryItem(sog.RootPart.LocalId, i2);
810  Assert.That(t2.Name, Is.EqualTo(ib2.Name), "Assert.That(t2.Name, Is.EqualTo(ib2.Name))");
811  TaskInventoryItem t3 = sog.GetInventoryItem(sog.RootPart.LocalId, i3);
812  Assert.That(t3.Name, Is.EqualTo(ib3.Name), "Assert.That(t3.Name, Is.EqualTo(ib3.Name))");
813  TaskInventoryItem t4 = sog.GetInventoryItem(sog.RootPart.LocalId, i4);
814  Assert.That(t4, Is.Null);
815  }
816 
817  [Test]
818  public void T052_RemoveObject()
819  {
820  TestHelpers.InMethod();
821 
822  db.RemoveObject(prim1, region1);
823  SceneObjectGroup sog = FindSOG("object1", region1);
824  Assert.That(sog, Is.Null);
825  }
826 
827  [Test]
829  {
830  TestHelpers.InMethod();
831 
832  RegionSettings r1 = db.LoadRegionSettings(region1);
833  Assert.That(r1.RegionUUID, Is.EqualTo(region1), "Assert.That(r1.RegionUUID, Is.EqualTo(region1))");
834 
835  RegionSettings r2 = db.LoadRegionSettings(region2);
836  Assert.That(r2.RegionUUID, Is.EqualTo(region2), "Assert.That(r2.RegionUUID, Is.EqualTo(region2))");
837  }
838 
839  [Test]
840  public void T101_UpdateRegionInfo()
841  {
842  TestHelpers.InMethod();
843 
844  int agentlimit = random.Next();
845  double objectbonus = random.Next();
846  int maturity = random.Next();
847  UUID tertex1 = UUID.Random();
848  UUID tertex2 = UUID.Random();
849  UUID tertex3 = UUID.Random();
850  UUID tertex4 = UUID.Random();
851  double elev1nw = random.Next();
852  double elev2nw = random.Next();
853  double elev1ne = random.Next();
854  double elev2ne = random.Next();
855  double elev1se = random.Next();
856  double elev2se = random.Next();
857  double elev1sw = random.Next();
858  double elev2sw = random.Next();
859  double waterh = random.Next();
860  double terrainraise = random.Next();
861  double terrainlower = random.Next();
862  Vector3 sunvector = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5));
863  UUID terimgid = UUID.Random();
864  double sunpos = random.Next();
865  UUID cov = UUID.Random();
866 
867  RegionSettings r1 = db.LoadRegionSettings(region1);
868  r1.BlockTerraform = true;
869  r1.BlockFly = true;
870  r1.AllowDamage = true;
871  r1.RestrictPushing = true;
872  r1.AllowLandResell = false;
873  r1.AllowLandJoinDivide = false;
874  r1.BlockShowInSearch = true;
875  r1.AgentLimit = agentlimit;
876  r1.ObjectBonus = objectbonus;
877  r1.Maturity = maturity;
878  r1.DisableScripts = true;
879  r1.DisableCollisions = true;
880  r1.DisablePhysics = true;
881  r1.TerrainTexture1 = tertex1;
882  r1.TerrainTexture2 = tertex2;
883  r1.TerrainTexture3 = tertex3;
884  r1.TerrainTexture4 = tertex4;
885  r1.Elevation1NW = elev1nw;
886  r1.Elevation2NW = elev2nw;
887  r1.Elevation1NE = elev1ne;
888  r1.Elevation2NE = elev2ne;
889  r1.Elevation1SE = elev1se;
890  r1.Elevation2SE = elev2se;
891  r1.Elevation1SW = elev1sw;
892  r1.Elevation2SW = elev2sw;
893  r1.WaterHeight = waterh;
894  r1.TerrainRaiseLimit = terrainraise;
895  r1.TerrainLowerLimit = terrainlower;
896  r1.UseEstateSun = false;
897  r1.Sandbox = true;
898  r1.SunVector = sunvector;
899  r1.TerrainImageID = terimgid;
900  r1.FixedSun = true;
901  r1.SunPosition = sunpos;
902  r1.Covenant = cov;
903 
904  db.StoreRegionSettings(r1);
905 
906  RegionSettings r1a = db.LoadRegionSettings(region1);
907  Assert.That(r1a.RegionUUID, Is.EqualTo(region1), "Assert.That(r1a.RegionUUID, Is.EqualTo(region1))");
908  Assert.That(r1a.BlockTerraform,Is.True);
909  Assert.That(r1a.BlockFly,Is.True);
910  Assert.That(r1a.AllowDamage,Is.True);
911  Assert.That(r1a.RestrictPushing,Is.True);
912  Assert.That(r1a.AllowLandResell,Is.False);
913  Assert.That(r1a.AllowLandJoinDivide,Is.False);
914  Assert.That(r1a.BlockShowInSearch,Is.True);
915  Assert.That(r1a.AgentLimit,Is.EqualTo(agentlimit), "Assert.That(r1a.AgentLimit,Is.EqualTo(agentlimit))");
916  Assert.That(r1a.ObjectBonus,Is.EqualTo(objectbonus), "Assert.That(r1a.ObjectBonus,Is.EqualTo(objectbonus))");
917  Assert.That(r1a.Maturity,Is.EqualTo(maturity), "Assert.That(r1a.Maturity,Is.EqualTo(maturity))");
918  Assert.That(r1a.DisableScripts,Is.True);
919  Assert.That(r1a.DisableCollisions,Is.True);
920  Assert.That(r1a.DisablePhysics,Is.True);
921  Assert.That(r1a.TerrainTexture1,Is.EqualTo(tertex1), "Assert.That(r1a.TerrainTexture1,Is.EqualTo(tertex1))");
922  Assert.That(r1a.TerrainTexture2,Is.EqualTo(tertex2), "Assert.That(r1a.TerrainTexture2,Is.EqualTo(tertex2))");
923  Assert.That(r1a.TerrainTexture3,Is.EqualTo(tertex3), "Assert.That(r1a.TerrainTexture3,Is.EqualTo(tertex3))");
924  Assert.That(r1a.TerrainTexture4,Is.EqualTo(tertex4), "Assert.That(r1a.TerrainTexture4,Is.EqualTo(tertex4))");
925  Assert.That(r1a.Elevation1NW,Is.EqualTo(elev1nw), "Assert.That(r1a.Elevation1NW,Is.EqualTo(elev1nw))");
926  Assert.That(r1a.Elevation2NW,Is.EqualTo(elev2nw), "Assert.That(r1a.Elevation2NW,Is.EqualTo(elev2nw))");
927  Assert.That(r1a.Elevation1NE,Is.EqualTo(elev1ne), "Assert.That(r1a.Elevation1NE,Is.EqualTo(elev1ne))");
928  Assert.That(r1a.Elevation2NE,Is.EqualTo(elev2ne), "Assert.That(r1a.Elevation2NE,Is.EqualTo(elev2ne))");
929  Assert.That(r1a.Elevation1SE,Is.EqualTo(elev1se), "Assert.That(r1a.Elevation1SE,Is.EqualTo(elev1se))");
930  Assert.That(r1a.Elevation2SE,Is.EqualTo(elev2se), "Assert.That(r1a.Elevation2SE,Is.EqualTo(elev2se))");
931  Assert.That(r1a.Elevation1SW,Is.EqualTo(elev1sw), "Assert.That(r1a.Elevation1SW,Is.EqualTo(elev1sw))");
932  Assert.That(r1a.Elevation2SW,Is.EqualTo(elev2sw), "Assert.That(r1a.Elevation2SW,Is.EqualTo(elev2sw))");
933  Assert.That(r1a.WaterHeight,Is.EqualTo(waterh), "Assert.That(r1a.WaterHeight,Is.EqualTo(waterh))");
934  Assert.That(r1a.TerrainRaiseLimit,Is.EqualTo(terrainraise), "Assert.That(r1a.TerrainRaiseLimit,Is.EqualTo(terrainraise))");
935  Assert.That(r1a.TerrainLowerLimit,Is.EqualTo(terrainlower), "Assert.That(r1a.TerrainLowerLimit,Is.EqualTo(terrainlower))");
936  Assert.That(r1a.UseEstateSun,Is.False);
937  Assert.That(r1a.Sandbox,Is.True);
938  Assert.That(r1a.SunVector,Is.EqualTo(sunvector), "Assert.That(r1a.SunVector,Is.EqualTo(sunvector))");
939  //Assert.That(r1a.TerrainImageID,Is.EqualTo(terimgid), "Assert.That(r1a.TerrainImageID,Is.EqualTo(terimgid))");
940  Assert.That(r1a.FixedSun,Is.True);
941  Assert.That(r1a.SunPosition, Is.EqualTo(sunpos), "Assert.That(r1a.SunPosition, Is.EqualTo(sunpos))");
942  Assert.That(r1a.Covenant, Is.EqualTo(cov), "Assert.That(r1a.Covenant, Is.EqualTo(cov))");
943  }
944 
945  [Test]
946  public void T300_NoTerrain()
947  {
948  TestHelpers.InMethod();
949 
950  Assert.That(db.LoadTerrain(zero), Is.Null);
951  Assert.That(db.LoadTerrain(region1), Is.Null);
952  Assert.That(db.LoadTerrain(region2), Is.Null);
953  Assert.That(db.LoadTerrain(UUID.Random()), Is.Null);
954  }
955 
956  [Test]
957  public void T301_CreateTerrain()
958  {
959  TestHelpers.InMethod();
960 
961  double[,] t1 = GenTerrain(height1);
962  db.StoreTerrain(t1, region1);
963 
964  // store terrain is async
965  Thread.Sleep(1000);
966 
967  Assert.That(db.LoadTerrain(zero), Is.Null);
968  Assert.That(db.LoadTerrain(region1), Is.Not.Null);
969  Assert.That(db.LoadTerrain(region2), Is.Null);
970  Assert.That(db.LoadTerrain(UUID.Random()), Is.Null);
971  }
972 
973  [Test]
974  public void T302_FetchTerrain()
975  {
976  TestHelpers.InMethod();
977 
978  double[,] baseterrain1 = GenTerrain(height1);
979  double[,] baseterrain2 = GenTerrain(height2);
980  double[,] t1 = db.LoadTerrain(region1);
981  Assert.That(CompareTerrain(t1, baseterrain1), Is.True);
982  Assert.That(CompareTerrain(t1, baseterrain2), Is.False);
983  }
984 
985  [Test]
986  public void T303_UpdateTerrain()
987  {
988  TestHelpers.InMethod();
989 
990  double[,] baseterrain1 = GenTerrain(height1);
991  double[,] baseterrain2 = GenTerrain(height2);
992  db.StoreTerrain(baseterrain2, region1);
993 
994  // store terrain is async
995  Thread.Sleep(1000);
996 
997  double[,] t1 = db.LoadTerrain(region1);
998  Assert.That(CompareTerrain(t1, baseterrain1), Is.False);
999  Assert.That(CompareTerrain(t1, baseterrain2), Is.True);
1000  }
1001 
1002  [Test]
1003  public void T400_EmptyLand()
1004  {
1005  TestHelpers.InMethod();
1006 
1007  Assert.That(db.LoadLandObjects(zero).Count, Is.EqualTo(0), "Assert.That(db.LoadLandObjects(zero).Count, Is.EqualTo(0))");
1008  Assert.That(db.LoadLandObjects(region1).Count, Is.EqualTo(0), "Assert.That(db.LoadLandObjects(region1).Count, Is.EqualTo(0))");
1009  Assert.That(db.LoadLandObjects(region2).Count, Is.EqualTo(0), "Assert.That(db.LoadLandObjects(region2).Count, Is.EqualTo(0))");
1010  Assert.That(db.LoadLandObjects(UUID.Random()).Count, Is.EqualTo(0), "Assert.That(db.LoadLandObjects(UUID.Random()).Count, Is.EqualTo(0))");
1011  }
1012 
1013  // TODO: we should have real land tests, but Land is so
1014  // intermingled with scene that you can't test it without a
1015  // valid scene. That requires some disagregation.
1016 
1017 
1018  //************************************************************************************//
1019  // Extra private methods
1020 
1021  private double[,] GenTerrain(double value)
1022  {
1023  double[,] terret = new double[Constants.RegionSize, Constants.RegionSize];
1024  terret.Initialize();
1025  for (int x = 0; x < Constants.RegionSize; x++)
1026  for (int y = 0; y < Constants.RegionSize; y++)
1027  terret[x,y] = value;
1028 
1029  return terret;
1030  }
1031 
1032  private bool CompareTerrain(double[,] one, double[,] two)
1033  {
1034  for (int x = 0; x < Constants.RegionSize; x++)
1035  for (int y = 0; y < Constants.RegionSize; y++)
1036  if (one[x,y] != two[x,y])
1037  return false;
1038 
1039  return true;
1040  }
1041 
1042  private SceneObjectGroup FindSOG(string name, UUID r)
1043  {
1044  List<SceneObjectGroup> objs = db.LoadObjects(r);
1045  foreach (SceneObjectGroup sog in objs)
1046  if (sog.Name == name)
1047  return sog;
1048 
1049  return null;
1050  }
1051 
1052  // This builds a minimalistic Prim, 1 SOG with 1 root SOP. A
1053  // common failure case is people adding new fields that aren't
1054  // initialized, but have non-null db constraints. We should
1055  // honestly be passing more and more null things in here.
1056  //
1057  // Please note that in Sqlite.BuildPrim there is a commented out inline version
1058  // of this so you can debug and step through the build process and check the fields
1059  //
1060  // Real World Value: Tests for situation where extending a SceneObjectGroup/SceneObjectPart
1061  // causes the application to crash at the database layer because of null values
1062  // in NOT NULL fields
1063  //
1064  private SceneObjectGroup NewSOG(string name, UUID uuid, UUID regionId)
1065  {
1066  RegionInfo regionInfo = new RegionInfo();
1067  regionInfo.RegionID = regionId;
1068  regionInfo.RegionLocX = 0;
1069  regionInfo.RegionLocY = 0;
1070 
1071  SceneObjectPart sop = new SceneObjectPart();
1072  sop.Name = name;
1073  sop.Description = name;
1074  sop.Text = RandomName();
1075  sop.SitName = RandomName();
1076  sop.TouchName = RandomName();
1077  sop.UUID = uuid;
1078  sop.Shape = PrimitiveBaseShape.Default;
1079 
1080  SceneObjectGroup sog = new SceneObjectGroup(sop);
1081 // sog.SetScene(scene);
1082 
1083  return sog;
1084  }
1085 
1086  private SceneObjectPart NewSOP(string name, UUID uuid)
1087  {
1088  SceneObjectPart sop = new SceneObjectPart();
1089  sop.Name = name;
1090  sop.Description = name;
1091  sop.Text = RandomName();
1092  sop.SitName = RandomName();
1093  sop.TouchName = RandomName();
1094  sop.UUID = uuid;
1095  sop.Shape = PrimitiveBaseShape.Default;
1096  return sop;
1097  }
1098 
1099  // These are copied from the Inventory Item tests
1100 
1101  private InventoryItemBase NewItem(UUID id, UUID parent, UUID owner, string name, UUID asset)
1102  {
1104  i.ID = id;
1105  i.Folder = parent;
1106  i.Owner = owner;
1107  i.CreatorId = owner.ToString();
1108  i.Name = name;
1109  i.Description = name;
1110  i.AssetID = asset;
1111  return i;
1112  }
1113 
1114  private static string RandomName()
1115  {
1116  StringBuilder name = new StringBuilder();
1117  int size = random.Next(5,12);
1118  char ch ;
1119  for (int i=0; i<size; i++)
1120  {
1121  ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ;
1122  name.Append(ch);
1123  }
1124  return name.ToString();
1125  }
1126 // private InventoryFolderBase NewFolder(UUID id, UUID parent, UUID owner, string name)
1127 // {
1128 // InventoryFolderBase f = new InventoryFolderBase();
1129 // f.ID = id;
1130 // f.ParentID = parent;
1131 // f.Owner = owner;
1132 // f.Name = name;
1133 // return f;
1134 // }
1135  }
1136 }
void T015_LargeSceneObjects()
Test storage and retrieval of a scene object with a large number of parts.
Definition: RegionTests.cs:527
IEntityInventory Inventory
This part's inventory
OpenSim.Framework.RegionInfo RegionInfo
A dictionary containing task inventory items. Indexed by item UUID.
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
PrimFlags Flags
Property flags. See OpenMetaverse.PrimFlags
Represents an item in a task inventory
Inventory Item - contains all the properties associated with an individual inventory piece...
override void InitService(object service)
To be overridden in derived classes. Do whatever init with the m_service, like setting the conn strin...
Definition: RegionTests.cs:105
List< UUID > GetInventoryList()
Get the uuids of all items in this inventory
Material
Material type for a primitive
Definition: OdeScene.cs:79
override string Name
The name of an object grouping is always the same as its root part