1
0

BasicRegionTest.cs 41 KB

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