RegionTests.cs 54 KB

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