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