RegionTests.cs 55 KB

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