RegionTests.cs 55 KB

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