BasicInventoryTest.cs 11 KB

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