BasicRegionTest.cs 53 KB

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