RegionTests.cs 55 KB

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