aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/Tests/InventoryTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/Tests/InventoryTests.cs')
-rw-r--r--OpenSim/Data/Tests/InventoryTests.cs347
1 files changed, 347 insertions, 0 deletions
diff --git a/OpenSim/Data/Tests/InventoryTests.cs b/OpenSim/Data/Tests/InventoryTests.cs
new file mode 100644
index 0000000..876dcf9
--- /dev/null
+++ b/OpenSim/Data/Tests/InventoryTests.cs
@@ -0,0 +1,347 @@
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
28using System;
29using log4net.Config;
30using NUnit.Framework;
31using NUnit.Framework.SyntaxHelpers;
32using OpenMetaverse;
33using OpenSim.Framework;
34using log4net;
35using System.Reflection;
36using System.Data.Common;
37
38// DBMS-specific:
39using MySql.Data.MySqlClient;
40using OpenSim.Data.MySQL;
41
42using System.Data.SqlClient;
43using OpenSim.Data.MSSQL;
44
45using Mono.Data.Sqlite;
46using OpenSim.Data.SQLite;
47
48namespace OpenSim.Data.Tests
49{
50 [TestFixture(typeof(MySqlConnection), typeof(MySQLInventoryData), Description = "Inventory store tests (MySQL)")]
51 [TestFixture(typeof(SqlConnection), typeof(MSSQLInventoryData), Description = "Inventory store tests (MS SQL Server)")]
52 [TestFixture(typeof(SqliteConnection), typeof(SQLiteInventoryStore), Description = "Inventory store tests (SQLite)")]
53
54 public class InventoryTests<TConn, TInvStore> : BasicDataServiceTest<TConn, TInvStore>
55 where TConn : DbConnection, new()
56 where TInvStore : class, IInventoryDataPlugin, new()
57 {
58 public IInventoryDataPlugin db;
59
60 public UUID zero = UUID.Zero;
61
62 public UUID folder1 = UUID.Random();
63 public UUID folder2 = UUID.Random();
64 public UUID folder3 = UUID.Random();
65 public UUID owner1 = UUID.Random();
66 public UUID owner2 = UUID.Random();
67 public UUID owner3 = UUID.Random();
68
69 public UUID item1 = UUID.Random();
70 public UUID item2 = UUID.Random();
71 public UUID item3 = UUID.Random();
72 public UUID asset1 = UUID.Random();
73 public UUID asset2 = UUID.Random();
74 public UUID asset3 = UUID.Random();
75
76 public string name1;
77 public string name2 = "First Level folder";
78 public string name3 = "First Level folder 2";
79 public string niname1 = "My Shirt";
80 public string iname1 = "Shirt";
81 public string iname2 = "Text Board";
82 public string iname3 = "No Pants Barrel";
83
84 public InventoryTests(string conn) : base(conn)
85 {
86 name1 = "Root Folder for " + owner1.ToString();
87 }
88
89 protected override void InitService(object service)
90 {
91 db = (IInventoryDataPlugin)service;
92 db.Initialise(m_connStr);
93 ClearDB();
94 }
95
96 private void ClearDB()
97 {
98 DropTables("inventoryitems", "inventoryfolders");
99 ExecuteSql("delete from migrations where name='Inventory'");
100 }
101
102 [Test]
103 public void T001_LoadEmpty()
104 {
105 Assert.That(db.getInventoryFolder(zero), Is.Null);
106 Assert.That(db.getInventoryFolder(folder1), Is.Null);
107 Assert.That(db.getInventoryFolder(folder2), Is.Null);
108 Assert.That(db.getInventoryFolder(folder3), Is.Null);
109
110 Assert.That(db.getInventoryItem(zero), Is.Null);
111 Assert.That(db.getInventoryItem(item1), Is.Null);
112 Assert.That(db.getInventoryItem(item2), Is.Null);
113 Assert.That(db.getInventoryItem(item3), Is.Null);
114
115 Assert.That(db.getUserRootFolder(zero), Is.Null);
116 Assert.That(db.getUserRootFolder(owner1), Is.Null);
117 }
118
119 // 01x - folder tests
120 [Test]
121 public void T010_FolderNonParent()
122 {
123 InventoryFolderBase f1 = NewFolder(folder2, folder1, owner1, name2);
124 // the folder will go in
125 db.addInventoryFolder(f1);
126 InventoryFolderBase f1a = db.getUserRootFolder(owner1);
127 Assert.That(f1a, Is.Null);
128 }
129
130 [Test]
131 public void T011_FolderCreate()
132 {
133 InventoryFolderBase f1 = NewFolder(folder1, zero, owner1, name1);
134 // TODO: this is probably wrong behavior, but is what we have
135 // db.updateInventoryFolder(f1);
136 // InventoryFolderBase f1a = db.getUserRootFolder(owner1);
137 // Assert.That(uuid1, Is.EqualTo(f1a.ID))
138 // Assert.That(name1, Text.Matches(f1a.Name), "Assert.That(name1, Text.Matches(f1a.Name))");
139 // Assert.That(db.getUserRootFolder(owner1), Is.Null);
140
141 // succeed with true
142 db.addInventoryFolder(f1);
143 InventoryFolderBase f1a = db.getUserRootFolder(owner1);
144 Assert.That(folder1, Is.EqualTo(f1a.ID), "Assert.That(folder1, Is.EqualTo(f1a.ID))");
145 Assert.That(name1, Text.Matches(f1a.Name), "Assert.That(name1, Text.Matches(f1a.Name))");
146 }
147
148 // we now have the following tree
149 // folder1
150 // +--- folder2
151 // +--- folder3
152
153 [Test]
154 public void T012_FolderList()
155 {
156 InventoryFolderBase f2 = NewFolder(folder3, folder1, owner1, name3);
157 db.addInventoryFolder(f2);
158
159 Assert.That(db.getInventoryFolders(zero).Count, Is.EqualTo(1), "Assert.That(db.getInventoryFolders(zero).Count, Is.EqualTo(1))");
160 Assert.That(db.getInventoryFolders(folder1).Count, Is.EqualTo(2), "Assert.That(db.getInventoryFolders(folder1).Count, Is.EqualTo(2))");
161 Assert.That(db.getInventoryFolders(folder2).Count, Is.EqualTo(0), "Assert.That(db.getInventoryFolders(folder2).Count, Is.EqualTo(0))");
162 Assert.That(db.getInventoryFolders(folder3).Count, Is.EqualTo(0), "Assert.That(db.getInventoryFolders(folder3).Count, Is.EqualTo(0))");
163 Assert.That(db.getInventoryFolders(UUID.Random()).Count, Is.EqualTo(0), "Assert.That(db.getInventoryFolders(UUID.Random()).Count, Is.EqualTo(0))");
164
165 }
166
167 [Test]
168 public void T013_FolderHierarchy()
169 {
170 Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0))");
171 Assert.That(db.getFolderHierarchy(folder1).Count, Is.EqualTo(2), "Assert.That(db.getFolderHierarchy(folder1).Count, Is.EqualTo(2))");
172 Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0))");
173 Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(0))");
174 Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0))");
175 }
176
177
178 [Test]
179 public void T014_MoveFolder()
180 {
181 InventoryFolderBase f2 = db.getInventoryFolder(folder2);
182 f2.ParentID = folder3;
183 db.moveInventoryFolder(f2);
184
185 Assert.That(db.getInventoryFolders(zero).Count, Is.EqualTo(1), "Assert.That(db.getInventoryFolders(zero).Count, Is.EqualTo(1))");
186 Assert.That(db.getInventoryFolders(folder1).Count, Is.EqualTo(1), "Assert.That(db.getInventoryFolders(folder1).Count, Is.EqualTo(1))");
187 Assert.That(db.getInventoryFolders(folder2).Count, Is.EqualTo(0), "Assert.That(db.getInventoryFolders(folder2).Count, Is.EqualTo(0))");
188 Assert.That(db.getInventoryFolders(folder3).Count, Is.EqualTo(1), "Assert.That(db.getInventoryFolders(folder3).Count, Is.EqualTo(1))");
189 Assert.That(db.getInventoryFolders(UUID.Random()).Count, Is.EqualTo(0), "Assert.That(db.getInventoryFolders(UUID.Random()).Count, Is.EqualTo(0))");
190 }
191
192 [Test]
193 public void T015_FolderHierarchy()
194 {
195 Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0))");
196 Assert.That(db.getFolderHierarchy(folder1).Count, Is.EqualTo(2), "Assert.That(db.getFolderHierarchy(folder1).Count, Is.EqualTo(2))");
197 Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0))");
198 Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(1), "Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(1))");
199 Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0))");
200 }
201
202 // Item tests
203 [Test]
204 public void T100_NoItems()
205 {
206 Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0), "Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0))");
207 Assert.That(db.getInventoryInFolder(folder1).Count, Is.EqualTo(0), "Assert.That(db.getInventoryInFolder(folder1).Count, Is.EqualTo(0))");
208 Assert.That(db.getInventoryInFolder(folder2).Count, Is.EqualTo(0), "Assert.That(db.getInventoryInFolder(folder2).Count, Is.EqualTo(0))");
209 Assert.That(db.getInventoryInFolder(folder3).Count, Is.EqualTo(0), "Assert.That(db.getInventoryInFolder(folder3).Count, Is.EqualTo(0))");
210 }
211
212 // TODO: Feeding a bad inventory item down the data path will
213 // crash the system. This is largely due to the builder
214 // routines. That should be fixed and tested for.
215 [Test]
216 public void T101_CreatItems()
217 {
218 db.addInventoryItem(NewItem(item1, folder3, owner1, iname1, asset1));
219 db.addInventoryItem(NewItem(item2, folder3, owner1, iname2, asset2));
220 db.addInventoryItem(NewItem(item3, folder3, owner1, iname3, asset3));
221 Assert.That(db.getInventoryInFolder(folder3).Count, Is.EqualTo(3), "Assert.That(db.getInventoryInFolder(folder3).Count, Is.EqualTo(3))");
222 }
223
224 [Test]
225 public void T102_CompareItems()
226 {
227 InventoryItemBase i1 = db.getInventoryItem(item1);
228 InventoryItemBase i2 = db.getInventoryItem(item2);
229 InventoryItemBase i3 = db.getInventoryItem(item3);
230 Assert.That(i1.Name, Is.EqualTo(iname1), "Assert.That(i1.Name, Is.EqualTo(iname1))");
231 Assert.That(i2.Name, Is.EqualTo(iname2), "Assert.That(i2.Name, Is.EqualTo(iname2))");
232 Assert.That(i3.Name, Is.EqualTo(iname3), "Assert.That(i3.Name, Is.EqualTo(iname3))");
233 Assert.That(i1.Owner, Is.EqualTo(owner1), "Assert.That(i1.Owner, Is.EqualTo(owner1))");
234 Assert.That(i2.Owner, Is.EqualTo(owner1), "Assert.That(i2.Owner, Is.EqualTo(owner1))");
235 Assert.That(i3.Owner, Is.EqualTo(owner1), "Assert.That(i3.Owner, Is.EqualTo(owner1))");
236 Assert.That(i1.AssetID, Is.EqualTo(asset1), "Assert.That(i1.AssetID, Is.EqualTo(asset1))");
237 Assert.That(i2.AssetID, Is.EqualTo(asset2), "Assert.That(i2.AssetID, Is.EqualTo(asset2))");
238 Assert.That(i3.AssetID, Is.EqualTo(asset3), "Assert.That(i3.AssetID, Is.EqualTo(asset3))");
239 }
240
241 [Test]
242 public void T103_UpdateItem()
243 {
244 // TODO: probably shouldn't have the ability to have an
245 // owner of an item in a folder not owned by the user
246
247 InventoryItemBase i1 = db.getInventoryItem(item1);
248 i1.Name = niname1;
249 i1.Description = niname1;
250 i1.Owner = owner2;
251 db.updateInventoryItem(i1);
252
253 i1 = db.getInventoryItem(item1);
254 Assert.That(i1.Name, Is.EqualTo(niname1), "Assert.That(i1.Name, Is.EqualTo(niname1))");
255 Assert.That(i1.Description, Is.EqualTo(niname1), "Assert.That(i1.Description, Is.EqualTo(niname1))");
256 Assert.That(i1.Owner, Is.EqualTo(owner2), "Assert.That(i1.Owner, Is.EqualTo(owner2))");
257 }
258
259 [Test]
260 public void T104_RandomUpdateItem()
261 {
262 PropertyScrambler<InventoryFolderBase> folderScrambler =
263 new PropertyScrambler<InventoryFolderBase>()
264 .DontScramble(x => x.Owner)
265 .DontScramble(x => x.ParentID)
266 .DontScramble(x => x.ID);
267 UUID owner = UUID.Random();
268 UUID folder = UUID.Random();
269 UUID rootId = UUID.Random();
270 UUID rootAsset = UUID.Random();
271 InventoryFolderBase f1 = NewFolder(folder, zero, owner, name1);
272 folderScrambler.Scramble(f1);
273
274 db.addInventoryFolder(f1);
275 InventoryFolderBase f1a = db.getUserRootFolder(owner);
276 Assert.That(f1a, Constraints.PropertyCompareConstraint(f1));
277
278 folderScrambler.Scramble(f1a);
279
280 db.updateInventoryFolder(f1a);
281
282 InventoryFolderBase f1b = db.getUserRootFolder(owner);
283 Assert.That(f1b, Constraints.PropertyCompareConstraint(f1a));
284
285 //Now we have a valid folder to insert into, we can insert the item.
286 PropertyScrambler<InventoryItemBase> inventoryScrambler =
287 new PropertyScrambler<InventoryItemBase>()
288 .DontScramble(x => x.ID)
289 .DontScramble(x => x.AssetID)
290 .DontScramble(x => x.Owner)
291 .DontScramble(x => x.Folder);
292 InventoryItemBase root = NewItem(rootId, folder, owner, iname1, rootAsset);
293 inventoryScrambler.Scramble(root);
294 db.addInventoryItem(root);
295
296 InventoryItemBase expected = db.getInventoryItem(rootId);
297 Assert.That(expected, Constraints.PropertyCompareConstraint(root)
298 .IgnoreProperty(x => x.InvType)
299 .IgnoreProperty(x => x.CreatorIdAsUuid)
300 .IgnoreProperty(x => x.Description)
301 .IgnoreProperty(x => x.CreatorId));
302
303 inventoryScrambler.Scramble(expected);
304 db.updateInventoryItem(expected);
305
306 InventoryItemBase actual = db.getInventoryItem(rootId);
307 Assert.That(actual, Constraints.PropertyCompareConstraint(expected)
308 .IgnoreProperty(x => x.InvType)
309 .IgnoreProperty(x => x.CreatorIdAsUuid)
310 .IgnoreProperty(x => x.Description)
311 .IgnoreProperty(x => x.CreatorId));
312 }
313
314 [Test]
315 public void T999_StillNull()
316 {
317 // After all tests are run, these should still return no results
318 Assert.That(db.getInventoryFolder(zero), Is.Null);
319 Assert.That(db.getInventoryItem(zero), Is.Null);
320 Assert.That(db.getUserRootFolder(zero), Is.Null);
321 Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0), "Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0))");
322 }
323
324 private InventoryItemBase NewItem(UUID id, UUID parent, UUID owner, string name, UUID asset)
325 {
326 InventoryItemBase i = new InventoryItemBase();
327 i.ID = id;
328 i.Folder = parent;
329 i.Owner = owner;
330 i.CreatorId = owner.ToString();
331 i.Name = name;
332 i.Description = name;
333 i.AssetID = asset;
334 return i;
335 }
336
337 private InventoryFolderBase NewFolder(UUID id, UUID parent, UUID owner, string name)
338 {
339 InventoryFolderBase f = new InventoryFolderBase();
340 f.ID = id;
341 f.ParentID = parent;
342 f.Owner = owner;
343 f.Name = name;
344 return f;
345 }
346 }
347}