1
0

BasicInventoryTest.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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 NUnit.Framework;
  30. using NUnit.Framework.SyntaxHelpers;
  31. using OpenSim.Framework;
  32. using OpenSim.Data;
  33. using OpenSim.Region.Environment.Scenes;
  34. using OpenMetaverse;
  35. namespace OpenSim.Data.Tests
  36. {
  37. public class BasicInventoryTest
  38. {
  39. public IInventoryDataPlugin db;
  40. public UUID zero = UUID.Zero;
  41. public UUID folder1;
  42. public UUID folder2;
  43. public UUID folder3;
  44. public UUID owner1;
  45. public UUID owner2;
  46. public UUID owner3;
  47. public UUID item1;
  48. public UUID item2;
  49. public UUID item3;
  50. public UUID asset1;
  51. public UUID asset2;
  52. public UUID asset3;
  53. public string name1;
  54. public string name2;
  55. public string name3;
  56. public string niname1;
  57. public string iname1;
  58. public string iname2;
  59. public string iname3;
  60. public void SuperInit()
  61. {
  62. try
  63. {
  64. log4net.Config.XmlConfigurator.Configure();
  65. }
  66. catch (Exception)
  67. {
  68. // I don't care, just leave log4net off
  69. }
  70. folder1 = UUID.Random();
  71. folder2 = UUID.Random();
  72. folder3 = UUID.Random();
  73. owner1 = UUID.Random();
  74. owner2 = UUID.Random();
  75. owner3 = UUID.Random();
  76. item1 = UUID.Random();
  77. item2 = UUID.Random();
  78. item3 = UUID.Random();
  79. asset1 = UUID.Random();
  80. asset2 = UUID.Random();
  81. asset3 = UUID.Random();
  82. name1 = "Root Folder for " + owner1.ToString();
  83. name2 = "First Level folder";
  84. name3 = "First Level folder 2";
  85. niname1 = "My Shirt";
  86. iname1 = "Shirt";
  87. iname2 = "Text Board";
  88. iname3 = "No Pants Barrel";
  89. }
  90. [Test]
  91. public void T001_LoadEmpty()
  92. {
  93. Assert.That(db.getInventoryFolder(zero), Is.Null);
  94. Assert.That(db.getInventoryFolder(folder1), Is.Null);
  95. Assert.That(db.getInventoryFolder(folder2), Is.Null);
  96. Assert.That(db.getInventoryFolder(folder3), Is.Null);
  97. Assert.That(db.getInventoryItem(zero), Is.Null);
  98. Assert.That(db.getInventoryItem(item1), Is.Null);
  99. Assert.That(db.getInventoryItem(item2), Is.Null);
  100. Assert.That(db.getInventoryItem(item3), Is.Null);
  101. Assert.That(db.getUserRootFolder(zero), Is.Null);
  102. Assert.That(db.getUserRootFolder(owner1), Is.Null);
  103. }
  104. [Test]
  105. public void T999_StillNull()
  106. {
  107. // After all tests are run, these should still return no results
  108. Assert.That(db.getInventoryFolder(zero), Is.Null);
  109. Assert.That(db.getInventoryItem(zero), Is.Null);
  110. Assert.That(db.getUserRootFolder(zero), Is.Null);
  111. Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0));
  112. }
  113. // 01x - folder tests
  114. [Test]
  115. public void T010_FolderNonParent()
  116. {
  117. InventoryFolderBase f1 = NewFolder(folder2, folder1, owner1, name2);
  118. // the folder will go in
  119. db.addInventoryFolder(f1);
  120. InventoryFolderBase f1a = db.getUserRootFolder(owner1);
  121. Assert.That(f1a, Is.Null);
  122. }
  123. [Test]
  124. public void T011_FolderCreate()
  125. {
  126. InventoryFolderBase f1 = NewFolder(folder1, zero, owner1, name1);
  127. // TODO: this is probably wrong behavior, but is what we have
  128. // db.updateInventoryFolder(f1);
  129. // InventoryFolderBase f1a = db.getUserRootFolder(owner1);
  130. // Assert.That(uuid1, Is.EqualTo(f1a.ID))
  131. // Assert.That(name1, Text.Matches(f1a.Name));
  132. // Assert.That(db.getUserRootFolder(owner1), Is.Null);
  133. // succeed with true
  134. db.addInventoryFolder(f1);
  135. InventoryFolderBase f1a = db.getUserRootFolder(owner1);
  136. Assert.That(folder1, Is.EqualTo(f1a.ID));
  137. Assert.That(name1, Text.Matches(f1a.Name));
  138. }
  139. // we now have the following tree
  140. // folder1
  141. // +--- folder2
  142. // +--- folder3
  143. [Test]
  144. public void T012_FolderList()
  145. {
  146. InventoryFolderBase f2 = NewFolder(folder3, folder1, owner1, name3);
  147. db.addInventoryFolder(f2);
  148. Assert.That(db.getInventoryFolders(zero).Count, Is.EqualTo(1));
  149. Assert.That(db.getInventoryFolders(folder1).Count, Is.EqualTo(2));
  150. Assert.That(db.getInventoryFolders(folder2).Count, Is.EqualTo(0));
  151. Assert.That(db.getInventoryFolders(folder3).Count, Is.EqualTo(0));
  152. Assert.That(db.getInventoryFolders(UUID.Random()).Count, Is.EqualTo(0));
  153. }
  154. [Test]
  155. public void T013_FolderHierarchy()
  156. {
  157. Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0));
  158. Assert.That(db.getFolderHierarchy(folder1).Count, Is.EqualTo(2));
  159. Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0));
  160. Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(0));
  161. Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0));
  162. }
  163. [Test]
  164. public void T014_MoveFolder()
  165. {
  166. InventoryFolderBase f2 = db.getInventoryFolder(folder2);
  167. f2.ParentID = folder3;
  168. db.moveInventoryFolder(f2);
  169. Assert.That(db.getInventoryFolders(zero).Count, Is.EqualTo(1));
  170. Assert.That(db.getInventoryFolders(folder1).Count, Is.EqualTo(1));
  171. Assert.That(db.getInventoryFolders(folder2).Count, Is.EqualTo(0));
  172. Assert.That(db.getInventoryFolders(folder3).Count, Is.EqualTo(1));
  173. Assert.That(db.getInventoryFolders(UUID.Random()).Count, Is.EqualTo(0));
  174. }
  175. [Test]
  176. public void T015_FolderHierarchy()
  177. {
  178. Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0));
  179. Assert.That(db.getFolderHierarchy(folder1).Count, Is.EqualTo(2));
  180. Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0));
  181. Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(1));
  182. Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0));
  183. }
  184. // Item tests
  185. [Test]
  186. public void T100_NoItems()
  187. {
  188. Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0));
  189. Assert.That(db.getInventoryInFolder(folder1).Count, Is.EqualTo(0));
  190. Assert.That(db.getInventoryInFolder(folder2).Count, Is.EqualTo(0));
  191. Assert.That(db.getInventoryInFolder(folder3).Count, Is.EqualTo(0));
  192. }
  193. // TODO: Feeding a bad inventory item down the data path will
  194. // crash the system. This is largely due to the builder
  195. // routines. That should be fixed and tested for.
  196. [Test]
  197. public void T101_CreatItems()
  198. {
  199. db.addInventoryItem(NewItem(item1, folder3, owner1, iname1, asset1));
  200. db.addInventoryItem(NewItem(item2, folder3, owner1, iname2, asset2));
  201. db.addInventoryItem(NewItem(item3, folder3, owner1, iname3, asset3));
  202. Assert.That(db.getInventoryInFolder(folder3).Count, Is.EqualTo(3));
  203. }
  204. [Test]
  205. public void T102_CompareItems()
  206. {
  207. InventoryItemBase i1 = db.getInventoryItem(item1);
  208. InventoryItemBase i2 = db.getInventoryItem(item2);
  209. InventoryItemBase i3 = db.getInventoryItem(item3);
  210. Assert.That(i1.Name, Is.EqualTo(iname1));
  211. Assert.That(i2.Name, Is.EqualTo(iname2));
  212. Assert.That(i3.Name, Is.EqualTo(iname3));
  213. Assert.That(i1.Owner, Is.EqualTo(owner1));
  214. Assert.That(i2.Owner, Is.EqualTo(owner1));
  215. Assert.That(i3.Owner, Is.EqualTo(owner1));
  216. Assert.That(i1.AssetID, Is.EqualTo(asset1));
  217. Assert.That(i2.AssetID, Is.EqualTo(asset2));
  218. Assert.That(i3.AssetID, Is.EqualTo(asset3));
  219. }
  220. [Test]
  221. public void T103UpdateItem()
  222. {
  223. // TODO: probably shouldn't have the ability to have an
  224. // owner of an item in a folder not owned by the user
  225. InventoryItemBase i1 = db.getInventoryItem(item1);
  226. i1.Name = niname1;
  227. i1.Description = niname1;
  228. i1.Owner = owner2;
  229. db.updateInventoryItem(i1);
  230. i1 = db.getInventoryItem(item1);
  231. Assert.That(i1.Name, Is.EqualTo(niname1));
  232. Assert.That(i1.Description, Is.EqualTo(niname1));
  233. Assert.That(i1.Owner, Is.EqualTo(owner2));
  234. }
  235. private InventoryItemBase NewItem(UUID id, UUID parent, UUID owner, string name, UUID asset)
  236. {
  237. InventoryItemBase i = new InventoryItemBase();
  238. i.ID = id;
  239. i.Folder = parent;
  240. i.Owner = owner;
  241. i.Creator = owner;
  242. i.Name = name;
  243. i.Description = name;
  244. i.AssetID = asset;
  245. return i;
  246. }
  247. private InventoryFolderBase NewFolder(UUID id, UUID parent, UUID owner, string name)
  248. {
  249. InventoryFolderBase f = new InventoryFolderBase();
  250. f.ID = id;
  251. f.ParentID = parent;
  252. f.Owner = owner;
  253. f.Name = name;
  254. return f;
  255. }
  256. }
  257. }