1
0

RegionTests.cs 55 KB

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