RegionTests.cs 55 KB

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