BasicRegionTest.cs 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  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();
  296. sog.SetScene(scene); // Reguired by nhibernate database module.
  297. sog.SetRootPart(sop);
  298. // Inserts group in DB
  299. db.StoreObject(sog,region3);
  300. List<SceneObjectGroup> sogs = db.LoadObjects(region3);
  301. Assert.That(sogs.Count, Is.EqualTo(1), "Assert.That(sogs.Count, Is.EqualTo(1))");
  302. // Makes sure there are no double insertions:
  303. db.StoreObject(sog,region3);
  304. sogs = db.LoadObjects(region3);
  305. Assert.That(sogs.Count, Is.EqualTo(1), "Assert.That(sogs.Count, Is.EqualTo(1))");
  306. // Tests if the parameters were inserted correctly
  307. SceneObjectPart p = sogs[0].RootPart;
  308. Assert.That(regionh,Is.EqualTo(p.RegionHandle), "Assert.That(regionh,Is.EqualTo(p.RegionHandle))");
  309. //Assert.That(localid,Is.EqualTo(p.LocalId), "Assert.That(localid,Is.EqualTo(p.LocalId))");
  310. Assert.That(groupos,Is.EqualTo(p.GroupPosition), "Assert.That(groupos,Is.EqualTo(p.GroupPosition))");
  311. Assert.That(name,Is.EqualTo(p.Name), "Assert.That(name,Is.EqualTo(p.Name))");
  312. Assert.That(rotoff,Is.EqualTo(p.RotationOffset), "Assert.That(rotoff,Is.EqualTo(p.RotationOffset))");
  313. Assert.That(uuid,Is.EqualTo(p.UUID), "Assert.That(uuid,Is.EqualTo(p.UUID))");
  314. Assert.That(creator,Is.EqualTo(p.CreatorID), "Assert.That(creator,Is.EqualTo(p.CreatorID))");
  315. //Assert.That(iserial,Is.EqualTo(p.InventorySerial), "Assert.That(iserial,Is.EqualTo(p.InventorySerial))");
  316. Assert.That(dic,Is.EqualTo(p.TaskInventory), "Assert.That(dic,Is.EqualTo(p.TaskInventory))");
  317. //Assert.That(objf,Is.EqualTo(p.ObjectFlags), "Assert.That(objf,Is.EqualTo(p.ObjectFlags))");
  318. Assert.That(name,Is.EqualTo(p.Name), "Assert.That(name,Is.EqualTo(p.Name))");
  319. Assert.That(material,Is.EqualTo(p.Material), "Assert.That(material,Is.EqualTo(p.Material))");
  320. Assert.That(pin,Is.EqualTo(p.ScriptAccessPin), "Assert.That(pin,Is.EqualTo(p.ScriptAccessPin))");
  321. Assert.That(textani,Is.EqualTo(p.TextureAnimation), "Assert.That(textani,Is.EqualTo(p.TextureAnimation))");
  322. Assert.That(partsys,Is.EqualTo(p.ParticleSystem), "Assert.That(partsys,Is.EqualTo(p.ParticleSystem))");
  323. //Assert.That(expires,Is.EqualTo(p.Expires), "Assert.That(expires,Is.EqualTo(p.Expires))");
  324. //Assert.That(rezzed,Is.EqualTo(p.Rezzed), "Assert.That(rezzed,Is.EqualTo(p.Rezzed))");
  325. Assert.That(offset,Is.EqualTo(p.OffsetPosition), "Assert.That(offset,Is.EqualTo(p.OffsetPosition))");
  326. Assert.That(velocity,Is.EqualTo(p.Velocity), "Assert.That(velocity,Is.EqualTo(p.Velocity))");
  327. Assert.That(angvelo,Is.EqualTo(p.AngularVelocity), "Assert.That(angvelo,Is.EqualTo(p.AngularVelocity))");
  328. Assert.That(accel,Is.EqualTo(p.Acceleration), "Assert.That(accel,Is.EqualTo(p.Acceleration))");
  329. Assert.That(description,Is.EqualTo(p.Description), "Assert.That(description,Is.EqualTo(p.Description))");
  330. Assert.That(color,Is.EqualTo(p.Color), "Assert.That(color,Is.EqualTo(p.Color))");
  331. Assert.That(text,Is.EqualTo(p.Text), "Assert.That(text,Is.EqualTo(p.Text))");
  332. Assert.That(sitname,Is.EqualTo(p.SitName), "Assert.That(sitname,Is.EqualTo(p.SitName))");
  333. Assert.That(touchname,Is.EqualTo(p.TouchName), "Assert.That(touchname,Is.EqualTo(p.TouchName))");
  334. //Assert.That(linknum,Is.EqualTo(p.LinkNum), "Assert.That(linknum,Is.EqualTo(p.LinkNum))");
  335. Assert.That(clickaction,Is.EqualTo(p.ClickAction), "Assert.That(clickaction,Is.EqualTo(p.ClickAction))");
  336. Assert.That(scale,Is.EqualTo(p.Scale), "Assert.That(scale,Is.EqualTo(p.Scale))");
  337. //Assert.That(updatef,Is.EqualTo(p.UpdateFlag), "Assert.That(updatef,Is.EqualTo(p.UpdateFlag))");
  338. Assert.That(pbshap.PathBegin, Is.EqualTo(p.Shape.PathBegin), "Assert.That(pbshap.PathBegin, Is.EqualTo(p.Shape.PathBegin))");
  339. Assert.That(pbshap.PathEnd, Is.EqualTo(p.Shape.PathEnd), "Assert.That(pbshap.PathEnd, Is.EqualTo(p.Shape.PathEnd))");
  340. Assert.That(pbshap.ProfileBegin, Is.EqualTo(p.Shape.ProfileBegin), "Assert.That(pbshap.ProfileBegin, Is.EqualTo(p.Shape.ProfileBegin))");
  341. Assert.That(pbshap.ProfileEnd, Is.EqualTo(p.Shape.ProfileEnd), "Assert.That(pbshap.ProfileEnd, Is.EqualTo(p.Shape.ProfileEnd))");
  342. Assert.That(pbshap.ProfileHollow, Is.EqualTo(p.Shape.ProfileHollow), "Assert.That(pbshap.ProfileHollow, Is.EqualTo(p.Shape.ProfileHollow))");
  343. }
  344. [Test]
  345. public void T014_UpdateObject()
  346. {
  347. string text1 = "object1 text";
  348. SceneObjectGroup sog = FindSOG("object1", region1);
  349. sog.RootPart.Text = text1;
  350. db.StoreObject(sog, region1);
  351. sog = FindSOG("object1", region1);
  352. Assert.That(text1, Is.EqualTo(sog.RootPart.Text), "Assert.That(text1, Is.EqualTo(sog.RootPart.Text))");
  353. // Creates random values
  354. UUID creator = new UUID();
  355. creator = UUID.Random();
  356. TaskInventoryDictionary dic = new TaskInventoryDictionary();
  357. localID = localID + 1;
  358. string name = "West Adam";
  359. byte material = (byte) random.Next(127);
  360. ulong regionh = (ulong)random.NextDouble() * (ulong)random.Next();
  361. int pin = random.Next();
  362. Byte[] partsys = new byte[8];
  363. Byte[] textani = new byte[8];
  364. random.NextBytes(textani);
  365. random.NextBytes(partsys);
  366. DateTime expires = new DateTime(2010, 12, 20);
  367. DateTime rezzed = new DateTime(2005, 07, 15);
  368. Vector3 groupos = new Vector3(random.Next(),random.Next(),random.Next());
  369. Vector3 offset = new Vector3(random.Next(),random.Next(),random.Next());
  370. Quaternion rotoff = new Quaternion(random.Next(),random.Next(),random.Next(),random.Next());
  371. Vector3 velocity = new Vector3(random.Next(),random.Next(),random.Next());
  372. Vector3 angvelo = new Vector3(random.Next(),random.Next(),random.Next());
  373. Vector3 accel = new Vector3(random.Next(),random.Next(),random.Next());
  374. string description = name;
  375. Color color = Color.FromArgb(255, 255, 255, 0);
  376. string text = "What You Say?{]\vz~";
  377. string sitname = RandomName();
  378. string touchname = RandomName();
  379. int linknum = random.Next();
  380. byte clickaction = (byte) random.Next(127);
  381. PrimitiveBaseShape pbshap = new PrimitiveBaseShape();
  382. pbshap = PrimitiveBaseShape.Default;
  383. Vector3 scale = new Vector3(random.Next(),random.Next(),random.Next());
  384. byte updatef = (byte) random.Next(127);
  385. // Updates the region with new values
  386. SceneObjectGroup sog2 = FindSOG("Adam West", region3);
  387. Assert.That(sog2,Is.Not.Null);
  388. sog2.RootPart.RegionHandle = regionh;
  389. sog2.RootPart.Shape = pbshap;
  390. sog2.RootPart.GroupPosition = groupos;
  391. sog2.RootPart.RotationOffset = rotoff;
  392. sog2.RootPart.CreatorID = creator;
  393. sog2.RootPart.TaskInventory = dic;
  394. sog2.RootPart.Name = name;
  395. sog2.RootPart.Material = material;
  396. sog2.RootPart.ScriptAccessPin = pin;
  397. sog2.RootPart.TextureAnimation = textani;
  398. sog2.RootPart.ParticleSystem = partsys;
  399. sog2.RootPart.Expires = expires;
  400. sog2.RootPart.Rezzed = rezzed;
  401. sog2.RootPart.OffsetPosition = offset;
  402. sog2.RootPart.Velocity = velocity;
  403. sog2.RootPart.AngularVelocity = angvelo;
  404. sog2.RootPart.Acceleration = accel;
  405. sog2.RootPart.Description = description;
  406. sog2.RootPart.Color = color;
  407. sog2.RootPart.Text = text;
  408. sog2.RootPart.SitName = sitname;
  409. sog2.RootPart.TouchName = touchname;
  410. sog2.RootPart.LinkNum = linknum;
  411. sog2.RootPart.ClickAction = clickaction;
  412. sog2.RootPart.Scale = scale;
  413. sog2.RootPart.UpdateFlag = updatef;
  414. db.StoreObject(sog2, region3);
  415. List<SceneObjectGroup> sogs = db.LoadObjects(region3);
  416. Assert.That(sogs.Count, Is.EqualTo(1), "Assert.That(sogs.Count, Is.EqualTo(1))");
  417. SceneObjectGroup retsog = FindSOG("West Adam", region3);
  418. Assert.That(retsog,Is.Not.Null);
  419. SceneObjectPart p = retsog.RootPart;
  420. Assert.That(regionh,Is.EqualTo(p.RegionHandle), "Assert.That(regionh,Is.EqualTo(p.RegionHandle))");
  421. Assert.That(groupos,Is.EqualTo(p.GroupPosition), "Assert.That(groupos,Is.EqualTo(p.GroupPosition))");
  422. Assert.That(name,Is.EqualTo(p.Name), "Assert.That(name,Is.EqualTo(p.Name))");
  423. Assert.That(rotoff,Is.EqualTo(p.RotationOffset), "Assert.That(rotoff,Is.EqualTo(p.RotationOffset))");
  424. Assert.That(creator,Is.EqualTo(p.CreatorID), "Assert.That(creator,Is.EqualTo(p.CreatorID))");
  425. Assert.That(dic,Is.EqualTo(p.TaskInventory), "Assert.That(dic,Is.EqualTo(p.TaskInventory))");
  426. Assert.That(name,Is.EqualTo(p.Name), "Assert.That(name,Is.EqualTo(p.Name))");
  427. Assert.That(material,Is.EqualTo(p.Material), "Assert.That(material,Is.EqualTo(p.Material))");
  428. Assert.That(pin,Is.EqualTo(p.ScriptAccessPin), "Assert.That(pin,Is.EqualTo(p.ScriptAccessPin))");
  429. Assert.That(textani,Is.EqualTo(p.TextureAnimation), "Assert.That(textani,Is.EqualTo(p.TextureAnimation))");
  430. Assert.That(partsys,Is.EqualTo(p.ParticleSystem), "Assert.That(partsys,Is.EqualTo(p.ParticleSystem))");
  431. Assert.That(offset,Is.EqualTo(p.OffsetPosition), "Assert.That(offset,Is.EqualTo(p.OffsetPosition))");
  432. Assert.That(velocity,Is.EqualTo(p.Velocity), "Assert.That(velocity,Is.EqualTo(p.Velocity))");
  433. Assert.That(angvelo,Is.EqualTo(p.AngularVelocity), "Assert.That(angvelo,Is.EqualTo(p.AngularVelocity))");
  434. Assert.That(accel,Is.EqualTo(p.Acceleration), "Assert.That(accel,Is.EqualTo(p.Acceleration))");
  435. Assert.That(description,Is.EqualTo(p.Description), "Assert.That(description,Is.EqualTo(p.Description))");
  436. Assert.That(color,Is.EqualTo(p.Color), "Assert.That(color,Is.EqualTo(p.Color))");
  437. Assert.That(text,Is.EqualTo(p.Text), "Assert.That(text,Is.EqualTo(p.Text))");
  438. Assert.That(sitname,Is.EqualTo(p.SitName), "Assert.That(sitname,Is.EqualTo(p.SitName))");
  439. Assert.That(touchname,Is.EqualTo(p.TouchName), "Assert.That(touchname,Is.EqualTo(p.TouchName))");
  440. Assert.That(clickaction,Is.EqualTo(p.ClickAction), "Assert.That(clickaction,Is.EqualTo(p.ClickAction))");
  441. Assert.That(scale,Is.EqualTo(p.Scale), "Assert.That(scale,Is.EqualTo(p.Scale))");
  442. }
  443. [Test]
  444. public void T015_LargeSceneObjects()
  445. {
  446. UUID id = UUID.Random();
  447. Dictionary<UUID, SceneObjectPart> mydic = new Dictionary<UUID, SceneObjectPart>();
  448. SceneObjectGroup sog = NewSOG("Test SOG", id, region4);
  449. mydic.Add(sog.RootPart.UUID,sog.RootPart);
  450. for (int i=0;i<30;i++)
  451. {
  452. UUID tmp = UUID.Random();
  453. SceneObjectPart sop = NewSOP(("Test SOP " + i.ToString()),tmp);
  454. Vector3 groupos = new Vector3(random.Next(),random.Next(),random.Next());
  455. Vector3 offset = new Vector3(random.Next(),random.Next(),random.Next());
  456. Quaternion rotoff = new Quaternion(random.Next(),random.Next(),random.Next(),random.Next());
  457. Vector3 velocity = new Vector3(random.Next(),random.Next(),random.Next());
  458. Vector3 angvelo = new Vector3(random.Next(),random.Next(),random.Next());
  459. Vector3 accel = new Vector3(random.Next(),random.Next(),random.Next());
  460. sop.GroupPosition = groupos;
  461. sop.RotationOffset = rotoff;
  462. sop.OffsetPosition = offset;
  463. sop.Velocity = velocity;
  464. sop.AngularVelocity = angvelo;
  465. sop.Acceleration = accel;
  466. mydic.Add(tmp,sop);
  467. sog.AddPart(sop);
  468. db.StoreObject(sog, region4);
  469. }
  470. SceneObjectGroup retsog = FindSOG("Test SOG", region4);
  471. SceneObjectPart[] parts = retsog.GetParts();
  472. for (int i=0;i<30;i++)
  473. {
  474. SceneObjectPart cursop = mydic[parts[i].UUID];
  475. Assert.That(cursop.GroupPosition,Is.EqualTo(parts[i].GroupPosition), "Assert.That(cursop.GroupPosition,Is.EqualTo(parts[i].GroupPosition))");
  476. Assert.That(cursop.RotationOffset,Is.EqualTo(parts[i].RotationOffset), "Assert.That(cursop.RotationOffset,Is.EqualTo(parts[i].RotationOffset))");
  477. Assert.That(cursop.OffsetPosition,Is.EqualTo(parts[i].OffsetPosition), "Assert.That(cursop.OffsetPosition,Is.EqualTo(parts[i].OffsetPosition))");
  478. Assert.That(cursop.Velocity,Is.EqualTo(parts[i].Velocity), "Assert.That(cursop.Velocity,Is.EqualTo(parts[i].Velocity))");
  479. Assert.That(cursop.AngularVelocity,Is.EqualTo(parts[i].AngularVelocity), "Assert.That(cursop.AngularVelocity,Is.EqualTo(parts[i].AngularVelocity))");
  480. Assert.That(cursop.Acceleration,Is.EqualTo(parts[i].Acceleration), "Assert.That(cursop.Acceleration,Is.EqualTo(parts[i].Acceleration))");
  481. }
  482. }
  483. [Test]
  484. public void T016_RandomSogWithSceneParts()
  485. {
  486. PropertyScrambler<SceneObjectPart> scrambler =
  487. new PropertyScrambler<SceneObjectPart>()
  488. .DontScramble(x => x.UUID);
  489. UUID tmpSog = UUID.Random();
  490. UUID tmp1 = UUID.Random();
  491. UUID tmp2 = UUID.Random();
  492. UUID tmp3 = UUID.Random();
  493. UUID newregion = UUID.Random();
  494. SceneObjectPart p1 = new SceneObjectPart();
  495. SceneObjectPart p2 = new SceneObjectPart();
  496. SceneObjectPart p3 = new SceneObjectPart();
  497. p1.Shape = PrimitiveBaseShape.Default;
  498. p2.Shape = PrimitiveBaseShape.Default;
  499. p3.Shape = PrimitiveBaseShape.Default;
  500. p1.UUID = tmp1;
  501. p2.UUID = tmp2;
  502. p3.UUID = tmp3;
  503. scrambler.Scramble(p1);
  504. scrambler.Scramble(p2);
  505. scrambler.Scramble(p3);
  506. SceneObjectGroup sog = NewSOG("Sop 0", tmpSog, newregion);
  507. PropertyScrambler<SceneObjectGroup> sogScrambler =
  508. new PropertyScrambler<SceneObjectGroup>()
  509. .DontScramble(x => x.UUID);
  510. sogScrambler.Scramble(sog);
  511. sog.UUID = tmpSog;
  512. sog.AddPart(p1);
  513. sog.AddPart(p2);
  514. sog.AddPart(p3);
  515. SceneObjectPart[] parts = sog.GetParts();
  516. Assert.That(parts.Length, Is.EqualTo(4), "Assert.That(parts.Length,Is.EqualTo(4))");
  517. db.StoreObject(sog, newregion);
  518. List<SceneObjectGroup> sogs = db.LoadObjects(newregion);
  519. Assert.That(sogs.Count, Is.EqualTo(1), "Assert.That(sogs.Count,Is.EqualTo(1))");
  520. SceneObjectGroup newsog = sogs[0];
  521. SceneObjectPart[] newparts = newsog.GetParts();
  522. Assert.That(newparts.Length, Is.EqualTo(4), "Assert.That(newparts.Length,Is.EqualTo(4))");
  523. Assert.That(newsog, Constraints.PropertyCompareConstraint(sog)
  524. .IgnoreProperty(x=>x.LocalId)
  525. .IgnoreProperty(x=>x.HasGroupChanged)
  526. .IgnoreProperty(x=>x.IsSelected)
  527. .IgnoreProperty(x=>x.RegionHandle)
  528. .IgnoreProperty(x=>x.RegionUUID)
  529. .IgnoreProperty(x=>x.Scene)
  530. .IgnoreProperty(x=>x.Children)
  531. .IgnoreProperty(x=>x.RootPart));
  532. }
  533. [Test]
  534. public void T020_PrimInventoryEmpty()
  535. {
  536. SceneObjectGroup sog = FindSOG("object1", region1);
  537. TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
  538. Assert.That(t, Is.Null);
  539. }
  540. [Test]
  541. public void T021_PrimInventoryStore()
  542. {
  543. SceneObjectGroup sog = FindSOG("object1", region1);
  544. InventoryItemBase i = NewItem(item1, zero, zero, itemname1, zero);
  545. Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True);
  546. TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
  547. Assert.That(t.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))");
  548. // TODO: seriously??? this is the way we need to loop to get this?
  549. List<TaskInventoryItem> list = new List<TaskInventoryItem>();
  550. foreach (UUID uuid in sog.RootPart.Inventory.GetInventoryList())
  551. {
  552. list.Add(sog.GetInventoryItem(sog.RootPart.LocalId, uuid));
  553. }
  554. db.StorePrimInventory(prim1, list);
  555. }
  556. [Test]
  557. public void T022_PrimInventoryRetrieve()
  558. {
  559. SceneObjectGroup sog = FindSOG("object1", region1);
  560. TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
  561. Assert.That(t.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))");
  562. }
  563. [Test]
  564. public void T023_PrimInventoryUpdate()
  565. {
  566. SceneObjectGroup sog = FindSOG("object1", region1);
  567. TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
  568. t.Name = "My New Name";
  569. sog.UpdateInventoryItem(t);
  570. Assert.That(t.Name, Is.EqualTo("My New Name"), "Assert.That(t.Name, Is.EqualTo(\"My New Name\"))");
  571. }
  572. [Test]
  573. public void T024_PrimInventoryRemove()
  574. {
  575. List<TaskInventoryItem> list = new List<TaskInventoryItem>();
  576. db.StorePrimInventory(prim1, list);
  577. SceneObjectGroup sog = FindSOG("object1", region1);
  578. TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
  579. Assert.That(t, Is.Null);
  580. }
  581. [Test]
  582. public void T025_PrimInventoryPersistency()
  583. {
  584. InventoryItemBase i = new InventoryItemBase();
  585. UUID id = UUID.Random();
  586. i.ID = id;
  587. UUID folder = UUID.Random();
  588. i.Folder = folder;
  589. UUID owner = UUID.Random();
  590. i.Owner = owner;
  591. UUID creator = UUID.Random();
  592. i.CreatorId = creator.ToString();
  593. string name = RandomName();
  594. i.Name = name;
  595. i.Description = name;
  596. UUID assetid = UUID.Random();
  597. i.AssetID = assetid;
  598. int invtype = random.Next();
  599. i.InvType = invtype;
  600. uint nextperm = (uint) random.Next();
  601. i.NextPermissions = nextperm;
  602. uint curperm = (uint) random.Next();
  603. i.CurrentPermissions = curperm;
  604. uint baseperm = (uint) random.Next();
  605. i.BasePermissions = baseperm;
  606. uint eoperm = (uint) random.Next();
  607. i.EveryOnePermissions = eoperm;
  608. int assettype = random.Next();
  609. i.AssetType = assettype;
  610. UUID groupid = UUID.Random();
  611. i.GroupID = groupid;
  612. bool groupown = true;
  613. i.GroupOwned = groupown;
  614. int saleprice = random.Next();
  615. i.SalePrice = saleprice;
  616. byte saletype = (byte) random.Next(127);
  617. i.SaleType = saletype;
  618. uint flags = (uint) random.Next();
  619. i.Flags = flags;
  620. int creationd = random.Next();
  621. i.CreationDate = creationd;
  622. SceneObjectGroup sog = FindSOG("object1", region1);
  623. Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True);
  624. TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, id);
  625. Assert.That(t.Name, Is.EqualTo(name), "Assert.That(t.Name, Is.EqualTo(name))");
  626. Assert.That(t.AssetID,Is.EqualTo(assetid), "Assert.That(t.AssetID,Is.EqualTo(assetid))");
  627. Assert.That(t.BasePermissions,Is.EqualTo(baseperm), "Assert.That(t.BasePermissions,Is.EqualTo(baseperm))");
  628. Assert.That(t.CreationDate,Is.EqualTo(creationd), "Assert.That(t.CreationDate,Is.EqualTo(creationd))");
  629. Assert.That(t.CreatorID,Is.EqualTo(creator), "Assert.That(t.CreatorID,Is.EqualTo(creator))");
  630. Assert.That(t.Description,Is.EqualTo(name), "Assert.That(t.Description,Is.EqualTo(name))");
  631. Assert.That(t.EveryonePermissions,Is.EqualTo(eoperm), "Assert.That(t.EveryonePermissions,Is.EqualTo(eoperm))");
  632. Assert.That(t.Flags,Is.EqualTo(flags), "Assert.That(t.Flags,Is.EqualTo(flags))");
  633. Assert.That(t.GroupID,Is.EqualTo(sog.RootPart.GroupID), "Assert.That(t.GroupID,Is.EqualTo(sog.RootPart.GroupID))");
  634. // Where is this group permissions??
  635. // Assert.That(t.GroupPermissions,Is.EqualTo(), "Assert.That(t.GroupPermissions,Is.EqualTo())");
  636. Assert.That(t.Type,Is.EqualTo(assettype), "Assert.That(t.Type,Is.EqualTo(assettype))");
  637. Assert.That(t.InvType, Is.EqualTo(invtype), "Assert.That(t.InvType, Is.EqualTo(invtype))");
  638. Assert.That(t.ItemID, Is.EqualTo(id), "Assert.That(t.ItemID, Is.EqualTo(id))");
  639. Assert.That(t.LastOwnerID, Is.EqualTo(sog.RootPart.LastOwnerID), "Assert.That(t.LastOwnerID, Is.EqualTo(sog.RootPart.LastOwnerID))");
  640. Assert.That(t.NextPermissions, Is.EqualTo(nextperm), "Assert.That(t.NextPermissions, Is.EqualTo(nextperm))");
  641. // Ownership changes when you drop an object into an object
  642. // owned by someone else
  643. Assert.That(t.OwnerID,Is.EqualTo(sog.RootPart.OwnerID), "Assert.That(t.OwnerID,Is.EqualTo(sog.RootPart.OwnerID))");
  644. Assert.That(t.CurrentPermissions, Is.EqualTo(curperm | 8), "Assert.That(t.CurrentPermissions, Is.EqualTo(curperm | 8))");
  645. Assert.That(t.ParentID,Is.EqualTo(sog.RootPart.FolderID), "Assert.That(t.ParentID,Is.EqualTo(sog.RootPart.FolderID))");
  646. Assert.That(t.ParentPartID,Is.EqualTo(sog.RootPart.UUID), "Assert.That(t.ParentPartID,Is.EqualTo(sog.RootPart.UUID))");
  647. }
  648. [Test]
  649. [ExpectedException(typeof(ArgumentException))]
  650. public void T026_PrimInventoryMany()
  651. {
  652. UUID i1,i2,i3,i4;
  653. i1 = UUID.Random();
  654. i2 = UUID.Random();
  655. i3 = UUID.Random();
  656. i4 = i3;
  657. InventoryItemBase ib1 = NewItem(i1, zero, zero, RandomName(), zero);
  658. InventoryItemBase ib2 = NewItem(i2, zero, zero, RandomName(), zero);
  659. InventoryItemBase ib3 = NewItem(i3, zero, zero, RandomName(), zero);
  660. InventoryItemBase ib4 = NewItem(i4, zero, zero, RandomName(), zero);
  661. SceneObjectGroup sog = FindSOG("object1", region1);
  662. Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, ib1, zero), Is.True);
  663. Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, ib2, zero), Is.True);
  664. Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, ib3, zero), Is.True);
  665. Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, ib4, zero), Is.True);
  666. TaskInventoryItem t1 = sog.GetInventoryItem(sog.RootPart.LocalId, i1);
  667. Assert.That(t1.Name, Is.EqualTo(ib1.Name), "Assert.That(t1.Name, Is.EqualTo(ib1.Name))");
  668. TaskInventoryItem t2 = sog.GetInventoryItem(sog.RootPart.LocalId, i2);
  669. Assert.That(t2.Name, Is.EqualTo(ib2.Name), "Assert.That(t2.Name, Is.EqualTo(ib2.Name))");
  670. TaskInventoryItem t3 = sog.GetInventoryItem(sog.RootPart.LocalId, i3);
  671. Assert.That(t3.Name, Is.EqualTo(ib3.Name), "Assert.That(t3.Name, Is.EqualTo(ib3.Name))");
  672. TaskInventoryItem t4 = sog.GetInventoryItem(sog.RootPart.LocalId, i4);
  673. Assert.That(t4, Is.Null);
  674. }
  675. [Test]
  676. public void T052_RemoveObject()
  677. {
  678. db.RemoveObject(prim1, region1);
  679. SceneObjectGroup sog = FindSOG("object1", region1);
  680. Assert.That(sog, Is.Null);
  681. }
  682. [Test]
  683. public void T100_DefaultRegionInfo()
  684. {
  685. RegionSettings r1 = db.LoadRegionSettings(region1);
  686. Assert.That(r1.RegionUUID, Is.EqualTo(region1), "Assert.That(r1.RegionUUID, Is.EqualTo(region1))");
  687. RegionSettings r2 = db.LoadRegionSettings(region2);
  688. Assert.That(r2.RegionUUID, Is.EqualTo(region2), "Assert.That(r2.RegionUUID, Is.EqualTo(region2))");
  689. }
  690. [Test]
  691. public void T101_UpdateRegionInfo()
  692. {
  693. int agentlimit = random.Next();
  694. double objectbonus = random.Next();
  695. int maturity = random.Next();
  696. UUID tertex1 = UUID.Random();
  697. UUID tertex2 = UUID.Random();
  698. UUID tertex3 = UUID.Random();
  699. UUID tertex4 = UUID.Random();
  700. double elev1nw = random.Next();
  701. double elev2nw = random.Next();
  702. double elev1ne = random.Next();
  703. double elev2ne = random.Next();
  704. double elev1se = random.Next();
  705. double elev2se = random.Next();
  706. double elev1sw = random.Next();
  707. double elev2sw = random.Next();
  708. double waterh = random.Next();
  709. double terrainraise = random.Next();
  710. double terrainlower = random.Next();
  711. Vector3 sunvector = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5));
  712. UUID terimgid = UUID.Random();
  713. double sunpos = random.Next();
  714. UUID cov = UUID.Random();
  715. RegionSettings r1 = db.LoadRegionSettings(region1);
  716. r1.BlockTerraform = true;
  717. r1.BlockFly = true;
  718. r1.AllowDamage = true;
  719. r1.RestrictPushing = true;
  720. r1.AllowLandResell = false;
  721. r1.AllowLandJoinDivide = false;
  722. r1.BlockShowInSearch = true;
  723. r1.AgentLimit = agentlimit;
  724. r1.ObjectBonus = objectbonus;
  725. r1.Maturity = maturity;
  726. r1.DisableScripts = true;
  727. r1.DisableCollisions = true;
  728. r1.DisablePhysics = true;
  729. r1.TerrainTexture1 = tertex1;
  730. r1.TerrainTexture2 = tertex2;
  731. r1.TerrainTexture3 = tertex3;
  732. r1.TerrainTexture4 = tertex4;
  733. r1.Elevation1NW = elev1nw;
  734. r1.Elevation2NW = elev2nw;
  735. r1.Elevation1NE = elev1ne;
  736. r1.Elevation2NE = elev2ne;
  737. r1.Elevation1SE = elev1se;
  738. r1.Elevation2SE = elev2se;
  739. r1.Elevation1SW = elev1sw;
  740. r1.Elevation2SW = elev2sw;
  741. r1.WaterHeight = waterh;
  742. r1.TerrainRaiseLimit = terrainraise;
  743. r1.TerrainLowerLimit = terrainlower;
  744. r1.UseEstateSun = false;
  745. r1.Sandbox = true;
  746. r1.SunVector = sunvector;
  747. r1.TerrainImageID = terimgid;
  748. r1.FixedSun = true;
  749. r1.SunPosition = sunpos;
  750. r1.Covenant = cov;
  751. db.StoreRegionSettings(r1);
  752. RegionSettings r1a = db.LoadRegionSettings(region1);
  753. Assert.That(r1a.RegionUUID, Is.EqualTo(region1), "Assert.That(r1a.RegionUUID, Is.EqualTo(region1))");
  754. Assert.That(r1a.BlockTerraform,Is.True);
  755. Assert.That(r1a.BlockFly,Is.True);
  756. Assert.That(r1a.AllowDamage,Is.True);
  757. Assert.That(r1a.RestrictPushing,Is.True);
  758. Assert.That(r1a.AllowLandResell,Is.False);
  759. Assert.That(r1a.AllowLandJoinDivide,Is.False);
  760. Assert.That(r1a.BlockShowInSearch,Is.True);
  761. Assert.That(r1a.AgentLimit,Is.EqualTo(agentlimit), "Assert.That(r1a.AgentLimit,Is.EqualTo(agentlimit))");
  762. Assert.That(r1a.ObjectBonus,Is.EqualTo(objectbonus), "Assert.That(r1a.ObjectBonus,Is.EqualTo(objectbonus))");
  763. Assert.That(r1a.Maturity,Is.EqualTo(maturity), "Assert.That(r1a.Maturity,Is.EqualTo(maturity))");
  764. Assert.That(r1a.DisableScripts,Is.True);
  765. Assert.That(r1a.DisableCollisions,Is.True);
  766. Assert.That(r1a.DisablePhysics,Is.True);
  767. Assert.That(r1a.TerrainTexture1,Is.EqualTo(tertex1), "Assert.That(r1a.TerrainTexture1,Is.EqualTo(tertex1))");
  768. Assert.That(r1a.TerrainTexture2,Is.EqualTo(tertex2), "Assert.That(r1a.TerrainTexture2,Is.EqualTo(tertex2))");
  769. Assert.That(r1a.TerrainTexture3,Is.EqualTo(tertex3), "Assert.That(r1a.TerrainTexture3,Is.EqualTo(tertex3))");
  770. Assert.That(r1a.TerrainTexture4,Is.EqualTo(tertex4), "Assert.That(r1a.TerrainTexture4,Is.EqualTo(tertex4))");
  771. Assert.That(r1a.Elevation1NW,Is.EqualTo(elev1nw), "Assert.That(r1a.Elevation1NW,Is.EqualTo(elev1nw))");
  772. Assert.That(r1a.Elevation2NW,Is.EqualTo(elev2nw), "Assert.That(r1a.Elevation2NW,Is.EqualTo(elev2nw))");
  773. Assert.That(r1a.Elevation1NE,Is.EqualTo(elev1ne), "Assert.That(r1a.Elevation1NE,Is.EqualTo(elev1ne))");
  774. Assert.That(r1a.Elevation2NE,Is.EqualTo(elev2ne), "Assert.That(r1a.Elevation2NE,Is.EqualTo(elev2ne))");
  775. Assert.That(r1a.Elevation1SE,Is.EqualTo(elev1se), "Assert.That(r1a.Elevation1SE,Is.EqualTo(elev1se))");
  776. Assert.That(r1a.Elevation2SE,Is.EqualTo(elev2se), "Assert.That(r1a.Elevation2SE,Is.EqualTo(elev2se))");
  777. Assert.That(r1a.Elevation1SW,Is.EqualTo(elev1sw), "Assert.That(r1a.Elevation1SW,Is.EqualTo(elev1sw))");
  778. Assert.That(r1a.Elevation2SW,Is.EqualTo(elev2sw), "Assert.That(r1a.Elevation2SW,Is.EqualTo(elev2sw))");
  779. Assert.That(r1a.WaterHeight,Is.EqualTo(waterh), "Assert.That(r1a.WaterHeight,Is.EqualTo(waterh))");
  780. Assert.That(r1a.TerrainRaiseLimit,Is.EqualTo(terrainraise), "Assert.That(r1a.TerrainRaiseLimit,Is.EqualTo(terrainraise))");
  781. Assert.That(r1a.TerrainLowerLimit,Is.EqualTo(terrainlower), "Assert.That(r1a.TerrainLowerLimit,Is.EqualTo(terrainlower))");
  782. Assert.That(r1a.UseEstateSun,Is.False);
  783. Assert.That(r1a.Sandbox,Is.True);
  784. Assert.That(r1a.SunVector,Is.EqualTo(sunvector), "Assert.That(r1a.SunVector,Is.EqualTo(sunvector))");
  785. //Assert.That(r1a.TerrainImageID,Is.EqualTo(terimgid), "Assert.That(r1a.TerrainImageID,Is.EqualTo(terimgid))");
  786. Assert.That(r1a.FixedSun,Is.True);
  787. Assert.That(r1a.SunPosition, Is.EqualTo(sunpos), "Assert.That(r1a.SunPosition, Is.EqualTo(sunpos))");
  788. Assert.That(r1a.Covenant, Is.EqualTo(cov), "Assert.That(r1a.Covenant, Is.EqualTo(cov))");
  789. }
  790. [Test]
  791. public void T300_NoTerrain()
  792. {
  793. Assert.That(db.LoadTerrain(zero), Is.Null);
  794. Assert.That(db.LoadTerrain(region1), Is.Null);
  795. Assert.That(db.LoadTerrain(region2), Is.Null);
  796. Assert.That(db.LoadTerrain(UUID.Random()), Is.Null);
  797. }
  798. [Test]
  799. public void T301_CreateTerrain()
  800. {
  801. double[,] t1 = GenTerrain(height1);
  802. db.StoreTerrain(t1, region1);
  803. Assert.That(db.LoadTerrain(zero), Is.Null);
  804. Assert.That(db.LoadTerrain(region1), Is.Not.Null);
  805. Assert.That(db.LoadTerrain(region2), Is.Null);
  806. Assert.That(db.LoadTerrain(UUID.Random()), Is.Null);
  807. }
  808. [Test]
  809. public void T302_FetchTerrain()
  810. {
  811. double[,] baseterrain1 = GenTerrain(height1);
  812. double[,] baseterrain2 = GenTerrain(height2);
  813. double[,] t1 = db.LoadTerrain(region1);
  814. Assert.That(CompareTerrain(t1, baseterrain1), Is.True);
  815. Assert.That(CompareTerrain(t1, baseterrain2), Is.False);
  816. }
  817. [Test]
  818. public void T303_UpdateTerrain()
  819. {
  820. double[,] baseterrain1 = GenTerrain(height1);
  821. double[,] baseterrain2 = GenTerrain(height2);
  822. db.StoreTerrain(baseterrain2, region1);
  823. double[,] t1 = db.LoadTerrain(region1);
  824. Assert.That(CompareTerrain(t1, baseterrain1), Is.False);
  825. Assert.That(CompareTerrain(t1, baseterrain2), Is.True);
  826. }
  827. [Test]
  828. public void T400_EmptyLand()
  829. {
  830. Assert.That(db.LoadLandObjects(zero).Count, Is.EqualTo(0), "Assert.That(db.LoadLandObjects(zero).Count, Is.EqualTo(0))");
  831. Assert.That(db.LoadLandObjects(region1).Count, Is.EqualTo(0), "Assert.That(db.LoadLandObjects(region1).Count, Is.EqualTo(0))");
  832. Assert.That(db.LoadLandObjects(region2).Count, Is.EqualTo(0), "Assert.That(db.LoadLandObjects(region2).Count, Is.EqualTo(0))");
  833. Assert.That(db.LoadLandObjects(UUID.Random()).Count, Is.EqualTo(0), "Assert.That(db.LoadLandObjects(UUID.Random()).Count, Is.EqualTo(0))");
  834. }
  835. // TODO: we should have real land tests, but Land is so
  836. // intermingled with scene that you can't test it without a
  837. // valid scene. That requires some disagregation.
  838. //************************************************************************************//
  839. // Extra private methods
  840. private double[,] GenTerrain(double value)
  841. {
  842. double[,] terret = new double[Constants.RegionSize, Constants.RegionSize];
  843. terret.Initialize();
  844. for (int x = 0; x < Constants.RegionSize; x++)
  845. for (int y = 0; y < Constants.RegionSize; y++)
  846. terret[x,y] = value;
  847. return terret;
  848. }
  849. private bool CompareTerrain(double[,] one, double[,] two)
  850. {
  851. for (int x = 0; x < Constants.RegionSize; x++)
  852. for (int y = 0; y < Constants.RegionSize; y++)
  853. if (one[x,y] != two[x,y])
  854. return false;
  855. return true;
  856. }
  857. private SceneObjectGroup FindSOG(string name, UUID r)
  858. {
  859. List<SceneObjectGroup> objs = db.LoadObjects(r);
  860. foreach (SceneObjectGroup sog in objs)
  861. {
  862. SceneObjectPart p = sog.RootPart;
  863. if (p.Name == name) {
  864. RegionInfo regionInfo = new RegionInfo();
  865. regionInfo.RegionID = r;
  866. regionInfo.RegionLocX = 0;
  867. regionInfo.RegionLocY = 0;
  868. Scene scene = new Scene(regionInfo);
  869. sog.SetScene(scene);
  870. return sog;
  871. }
  872. }
  873. return null;
  874. }
  875. // This builds a minimalistic Prim, 1 SOG with 1 root SOP. A
  876. // common failure case is people adding new fields that aren't
  877. // initialized, but have non-null db constraints. We should
  878. // honestly be passing more and more null things in here.
  879. //
  880. // Please note that in Sqlite.BuildPrim there is a commented out inline version
  881. // of this so you can debug and step through the build process and check the fields
  882. //
  883. // Real World Value: Tests for situation where extending a SceneObjectGroup/SceneObjectPart
  884. // causes the application to crash at the database layer because of null values
  885. // in NOT NULL fields
  886. //
  887. private SceneObjectGroup NewSOG(string name, UUID uuid, UUID regionId)
  888. {
  889. RegionInfo regionInfo = new RegionInfo();
  890. regionInfo.RegionID = regionId;
  891. regionInfo.RegionLocX = 0;
  892. regionInfo.RegionLocY = 0;
  893. Scene scene = new Scene(regionInfo);
  894. SceneObjectPart sop = new SceneObjectPart();
  895. sop.Name = name;
  896. sop.Description = name;
  897. sop.Text = RandomName();
  898. sop.SitName = RandomName();
  899. sop.TouchName = RandomName();
  900. sop.UUID = uuid;
  901. sop.Shape = PrimitiveBaseShape.Default;
  902. SceneObjectGroup sog = new SceneObjectGroup();
  903. sog.SetScene(scene);
  904. sog.SetRootPart(sop);
  905. return sog;
  906. }
  907. private SceneObjectPart NewSOP(string name, UUID uuid)
  908. {
  909. SceneObjectPart sop = new SceneObjectPart();
  910. sop.Name = name;
  911. sop.Description = name;
  912. sop.Text = RandomName();
  913. sop.SitName = RandomName();
  914. sop.TouchName = RandomName();
  915. sop.UUID = uuid;
  916. sop.Shape = PrimitiveBaseShape.Default;
  917. return sop;
  918. }
  919. // These are copied from the Inventory Item tests
  920. private InventoryItemBase NewItem(UUID id, UUID parent, UUID owner, string name, UUID asset)
  921. {
  922. InventoryItemBase i = new InventoryItemBase();
  923. i.ID = id;
  924. i.Folder = parent;
  925. i.Owner = owner;
  926. i.CreatorId = owner.ToString();
  927. i.Name = name;
  928. i.Description = name;
  929. i.AssetID = asset;
  930. return i;
  931. }
  932. private static string RandomName()
  933. {
  934. StringBuilder name = new StringBuilder();
  935. int size = random.Next(5,12);
  936. char ch ;
  937. for (int i=0; i<size; i++)
  938. {
  939. ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ;
  940. name.Append(ch);
  941. }
  942. return name.ToString();
  943. }
  944. // private InventoryFolderBase NewFolder(UUID id, UUID parent, UUID owner, string name)
  945. // {
  946. // InventoryFolderBase f = new InventoryFolderBase();
  947. // f.ID = id;
  948. // f.ParentID = parent;
  949. // f.Owner = owner;
  950. // f.Name = name;
  951. // return f;
  952. // }
  953. }
  954. }