BasicRegionTest.cs 53 KB

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