aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2013-04-29 22:14:13 +0100
committerJustin Clark-Casey (justincc)2013-04-29 22:14:13 +0100
commit67789201c3ae40bd4697f3479eb183599baa3658 (patch)
tree27da4d5f9ef3910eb2dbc793c4ebedc259aa2c9d /OpenSim
parentAdd regression test for inventory item give, reject and subsequent trash fold... (diff)
downloadopensim-SC-67789201c3ae40bd4697f3479eb183599baa3658.zip
opensim-SC-67789201c3ae40bd4697f3479eb183599baa3658.tar.gz
opensim-SC-67789201c3ae40bd4697f3479eb183599baa3658.tar.bz2
opensim-SC-67789201c3ae40bd4697f3479eb183599baa3658.tar.xz
Add TestRejectGivenFolder() and TestAcceptGivenFolder() regression tests
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs10
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/Tests/InventoryTransferModuleTests.cs193
-rw-r--r--OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs41
-rw-r--r--OpenSim/Tests/Common/Mock/TestXInventoryDataPlugin.cs28
4 files changed, 262 insertions, 10 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs
index c292700..1417a19 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs
@@ -175,9 +175,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
175 { 175 {
176 UUID folderID = new UUID(im.binaryBucket, 1); 176 UUID folderID = new UUID(im.binaryBucket, 1);
177 177
178 m_log.DebugFormat("[INVENTORY TRANSFER]: Inserting original folder {0} "+ 178 m_log.DebugFormat(
179 "into agent {1}'s inventory", 179 "[INVENTORY TRANSFER]: Inserting original folder {0} into agent {1}'s inventory",
180 folderID, new UUID(im.toAgentID)); 180 folderID, new UUID(im.toAgentID));
181 181
182 InventoryFolderBase folderCopy 182 InventoryFolderBase folderCopy
183 = scene.GiveInventoryFolder(receipientID, client.AgentId, folderID, UUID.Zero); 183 = scene.GiveInventoryFolder(receipientID, client.AgentId, folderID, UUID.Zero);
@@ -200,7 +200,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
200 user.ControllingClient.SendBulkUpdateInventory(folderCopy); 200 user.ControllingClient.SendBulkUpdateInventory(folderCopy);
201 201
202 // HACK!! 202 // HACK!!
203 // Insert the ID of the copied item into the IM so that we know which item to move to trash if it 203 // Insert the ID of the copied folder into the IM so that we know which item to move to trash if it
204 // is rejected. 204 // is rejected.
205 // XXX: This is probably a misuse of the session ID slot. 205 // XXX: This is probably a misuse of the session ID slot.
206 im.imSessionID = copyID.Guid; 206 im.imSessionID = copyID.Guid;
@@ -396,7 +396,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
396 { 396 {
397 folder = new InventoryFolderBase(inventoryID, client.AgentId); 397 folder = new InventoryFolderBase(inventoryID, client.AgentId);
398 folder = invService.GetFolder(folder); 398 folder = invService.GetFolder(folder);
399 399
400 if (folder != null & trashFolder != null) 400 if (folder != null & trashFolder != null)
401 { 401 {
402 previousParentFolderID = folder.ParentID; 402 previousParentFolderID = folder.ParentID;
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/Tests/InventoryTransferModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/Tests/InventoryTransferModuleTests.cs
index b07d38c..162a0c3 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/Tests/InventoryTransferModuleTests.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/Tests/InventoryTransferModuleTests.cs
@@ -252,5 +252,198 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer.Tests
252 252
253 Assert.That(originalItemAfterDelete, Is.Not.Null); 253 Assert.That(originalItemAfterDelete, Is.Not.Null);
254 } 254 }
255
256 [Test]
257 public void TestAcceptGivenFolder()
258 {
259 TestHelpers.InMethod();
260// TestHelpers.EnableLogging();
261
262 UUID initialSessionId = TestHelpers.ParseTail(0x10);
263 UUID folderId = TestHelpers.ParseTail(0x100);
264
265 UserAccount ua1
266 = UserAccountHelpers.CreateUserWithInventory(m_scene, "User", "One", TestHelpers.ParseTail(0x1), "pw");
267 UserAccount ua2
268 = UserAccountHelpers.CreateUserWithInventory(m_scene, "User", "Two", TestHelpers.ParseTail(0x2), "pw");
269
270 ScenePresence giverSp = SceneHelpers.AddScenePresence(m_scene, ua1);
271 TestClient giverClient = (TestClient)giverSp.ControllingClient;
272
273 ScenePresence receiverSp = SceneHelpers.AddScenePresence(m_scene, ua2);
274 TestClient receiverClient = (TestClient)receiverSp.ControllingClient;
275
276 InventoryFolderBase originalFolder
277 = UserInventoryHelpers.CreateInventoryFolder(
278 m_scene.InventoryService, giverSp.UUID, folderId, "f1", true);
279
280 byte[] giveImBinaryBucket = new byte[17];
281 giveImBinaryBucket[0] = (byte)AssetType.Folder;
282 byte[] itemIdBytes = folderId.GetBytes();
283 Array.Copy(itemIdBytes, 0, giveImBinaryBucket, 1, itemIdBytes.Length);
284
285 GridInstantMessage giveIm
286 = new GridInstantMessage(
287 m_scene,
288 giverSp.UUID,
289 giverSp.Name,
290 receiverSp.UUID,
291 (byte)InstantMessageDialog.InventoryOffered,
292 false,
293 "inventory offered msg",
294 initialSessionId,
295 false,
296 Vector3.Zero,
297 giveImBinaryBucket,
298 true);
299
300 giverClient.HandleImprovedInstantMessage(giveIm);
301
302 // These details might not all be correct.
303 GridInstantMessage acceptIm
304 = new GridInstantMessage(
305 m_scene,
306 receiverSp.UUID,
307 receiverSp.Name,
308 giverSp.UUID,
309 (byte)InstantMessageDialog.InventoryAccepted,
310 false,
311 "inventory accepted msg",
312 initialSessionId,
313 false,
314 Vector3.Zero,
315 null,
316 true);
317
318 receiverClient.HandleImprovedInstantMessage(acceptIm);
319
320 // Test for item remaining in the giver's inventory (here we assume a copy item)
321 // TODO: Test no-copy items.
322 InventoryFolderBase originalFolderAfterGive
323 = UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, giverSp.UUID, "f1");
324
325 Assert.That(originalFolderAfterGive, Is.Not.Null);
326 Assert.That(originalFolderAfterGive.ID, Is.EqualTo(originalFolder.ID));
327
328 // Test for item successfully making it into the receiver's inventory
329 InventoryFolderBase receivedFolder
330 = UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, receiverSp.UUID, "f1");
331
332 Assert.That(receivedFolder, Is.Not.Null);
333 Assert.That(receivedFolder.ID, Is.Not.EqualTo(originalFolder.ID));
334
335 // Test that on a delete, item still exists and is accessible for the giver.
336 m_scene.InventoryService.DeleteFolders(receiverSp.UUID, new List<UUID>() { receivedFolder.ID });
337
338 InventoryFolderBase originalFolderAfterDelete
339 = UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, giverSp.UUID, "f1");
340
341 Assert.That(originalFolderAfterDelete, Is.Not.Null);
342
343 // TODO: Test scenario where giver deletes their item first.
344 }
345
346 /// <summary>
347 /// Test user rejection of a given item.
348 /// </summary>
349 /// <remarks>
350 /// A rejected item still ends up in the user's trash folder.
351 /// </remarks>
352 [Test]
353 public void TestRejectGivenFolder()
354 {
355 TestHelpers.InMethod();
356// TestHelpers.EnableLogging();
357
358 UUID initialSessionId = TestHelpers.ParseTail(0x10);
359 UUID folderId = TestHelpers.ParseTail(0x100);
360
361 UserAccount ua1
362 = UserAccountHelpers.CreateUserWithInventory(m_scene, "User", "One", TestHelpers.ParseTail(0x1), "pw");
363 UserAccount ua2
364 = UserAccountHelpers.CreateUserWithInventory(m_scene, "User", "Two", TestHelpers.ParseTail(0x2), "pw");
365
366 ScenePresence giverSp = SceneHelpers.AddScenePresence(m_scene, ua1);
367 TestClient giverClient = (TestClient)giverSp.ControllingClient;
368
369 ScenePresence receiverSp = SceneHelpers.AddScenePresence(m_scene, ua2);
370 TestClient receiverClient = (TestClient)receiverSp.ControllingClient;
371
372 // Create the folder to test give
373 InventoryFolderBase originalFolder
374 = UserInventoryHelpers.CreateInventoryFolder(
375 m_scene.InventoryService, giverSp.UUID, folderId, "f1", true);
376
377 GridInstantMessage receivedIm = null;
378 receiverClient.OnReceivedInstantMessage += im => receivedIm = im;
379
380 byte[] giveImBinaryBucket = new byte[17];
381 giveImBinaryBucket[0] = (byte)AssetType.Folder;
382 byte[] itemIdBytes = folderId.GetBytes();
383 Array.Copy(itemIdBytes, 0, giveImBinaryBucket, 1, itemIdBytes.Length);
384
385 GridInstantMessage giveIm
386 = new GridInstantMessage(
387 m_scene,
388 giverSp.UUID,
389 giverSp.Name,
390 receiverSp.UUID,
391 (byte)InstantMessageDialog.InventoryOffered,
392 false,
393 "inventory offered msg",
394 initialSessionId,
395 false,
396 Vector3.Zero,
397 giveImBinaryBucket,
398 true);
399
400 giverClient.HandleImprovedInstantMessage(giveIm);
401
402 // These details might not all be correct.
403 // Session ID is now the created item ID (!)
404 GridInstantMessage rejectIm
405 = new GridInstantMessage(
406 m_scene,
407 receiverSp.UUID,
408 receiverSp.Name,
409 giverSp.UUID,
410 (byte)InstantMessageDialog.InventoryDeclined,
411 false,
412 "inventory declined msg",
413 new UUID(receivedIm.imSessionID),
414 false,
415 Vector3.Zero,
416 null,
417 true);
418
419 receiverClient.HandleImprovedInstantMessage(rejectIm);
420
421 // Test for item remaining in the giver's inventory (here we assume a copy item)
422 // TODO: Test no-copy items.
423 InventoryFolderBase originalFolderAfterGive
424 = UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, giverSp.UUID, "f1");
425
426 Assert.That(originalFolderAfterGive, Is.Not.Null);
427 Assert.That(originalFolderAfterGive.ID, Is.EqualTo(originalFolder.ID));
428
429 // Test for folder successfully making it into the receiver's inventory
430 InventoryFolderBase receivedFolder
431 = UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, receiverSp.UUID, "Trash/f1");
432
433 InventoryFolderBase trashFolder
434 = m_scene.InventoryService.GetFolderForType(receiverSp.UUID, AssetType.TrashFolder);
435
436 Assert.That(receivedFolder, Is.Not.Null);
437 Assert.That(receivedFolder.ID, Is.Not.EqualTo(originalFolder.ID));
438 Assert.That(receivedFolder.ParentID, Is.EqualTo(trashFolder.ID));
439
440 // Test that on a delete, item still exists and is accessible for the giver.
441 m_scene.InventoryService.PurgeFolder(trashFolder);
442
443 InventoryFolderBase originalFolderAfterDelete
444 = UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, giverSp.UUID, "f1");
445
446 Assert.That(originalFolderAfterDelete, Is.Not.Null);
447 }
255 } 448 }
256} \ No newline at end of file 449} \ No newline at end of file
diff --git a/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs b/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs
index a1794c9..b3b75af 100644
--- a/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs
+++ b/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs
@@ -218,12 +218,37 @@ namespace OpenSim.Tests.Common
218 public static InventoryFolderBase CreateInventoryFolder( 218 public static InventoryFolderBase CreateInventoryFolder(
219 IInventoryService inventoryService, UUID userId, string path, bool useExistingFolders) 219 IInventoryService inventoryService, UUID userId, string path, bool useExistingFolders)
220 { 220 {
221 return CreateInventoryFolder(inventoryService, userId, UUID.Random(), path, useExistingFolders);
222 }
223
224 /// <summary>
225 /// Create inventory folders starting from the user's root folder.
226 /// </summary>
227 /// <param name="inventoryService"></param>
228 /// <param name="userId"></param>
229 /// <param name="folderId"></param>
230 /// <param name="path">
231 /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER
232 /// </param>
233 /// <param name="useExistingFolders">
234 /// If true, then folders in the path which already the same name are
235 /// used. This applies to the terminal folder as well.
236 /// If false, then all folders in the path are created, even if there is already a folder at a particular
237 /// level with the same name.
238 /// </param>
239 /// <returns>
240 /// The folder created. If the path contains multiple folders then the last one created is returned.
241 /// Will return null if the root folder could not be found.
242 /// </returns>
243 public static InventoryFolderBase CreateInventoryFolder(
244 IInventoryService inventoryService, UUID userId, UUID folderId, string path, bool useExistingFolders)
245 {
221 InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId); 246 InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId);
222 247
223 if (null == rootFolder) 248 if (null == rootFolder)
224 return null; 249 return null;
225 250
226 return CreateInventoryFolder(inventoryService, rootFolder, path, useExistingFolders); 251 return CreateInventoryFolder(inventoryService, folderId, rootFolder, path, useExistingFolders);
227 } 252 }
228 253
229 /// <summary> 254 /// <summary>
@@ -235,6 +260,7 @@ namespace OpenSim.Tests.Common
235 /// TODO: May need to make it an option to create duplicate folders. 260 /// TODO: May need to make it an option to create duplicate folders.
236 /// </remarks> 261 /// </remarks>
237 /// <param name="inventoryService"></param> 262 /// <param name="inventoryService"></param>
263 /// <param name="folderId">ID of the folder to create</param>
238 /// <param name="parentFolder"></param> 264 /// <param name="parentFolder"></param>
239 /// <param name="path"> 265 /// <param name="path">
240 /// The folder to create. 266 /// The folder to create.
@@ -249,7 +275,7 @@ namespace OpenSim.Tests.Common
249 /// The folder created. If the path contains multiple folders then the last one created is returned. 275 /// The folder created. If the path contains multiple folders then the last one created is returned.
250 /// </returns> 276 /// </returns>
251 public static InventoryFolderBase CreateInventoryFolder( 277 public static InventoryFolderBase CreateInventoryFolder(
252 IInventoryService inventoryService, InventoryFolderBase parentFolder, string path, bool useExistingFolders) 278 IInventoryService inventoryService, UUID folderId, InventoryFolderBase parentFolder, string path, bool useExistingFolders)
253 { 279 {
254 string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None); 280 string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None);
255 281
@@ -262,9 +288,16 @@ namespace OpenSim.Tests.Common
262 { 288 {
263// Console.WriteLine("Creating folder {0} at {1}", components[0], parentFolder.Name); 289// Console.WriteLine("Creating folder {0} at {1}", components[0], parentFolder.Name);
264 290
291 UUID folderIdForCreate;
292
293 if (components.Length > 1)
294 folderIdForCreate = UUID.Random();
295 else
296 folderIdForCreate = folderId;
297
265 folder 298 folder
266 = new InventoryFolderBase( 299 = new InventoryFolderBase(
267 UUID.Random(), components[0], parentFolder.Owner, (short)AssetType.Unknown, parentFolder.ID, 0); 300 folderIdForCreate, components[0], parentFolder.Owner, (short)AssetType.Unknown, parentFolder.ID, 0);
268 301
269 inventoryService.AddFolder(folder); 302 inventoryService.AddFolder(folder);
270 } 303 }
@@ -274,7 +307,7 @@ namespace OpenSim.Tests.Common
274// } 307// }
275 308
276 if (components.Length > 1) 309 if (components.Length > 1)
277 return CreateInventoryFolder(inventoryService, folder, components[1], useExistingFolders); 310 return CreateInventoryFolder(inventoryService, folderId, folder, components[1], useExistingFolders);
278 else 311 else
279 return folder; 312 return folder;
280 } 313 }
diff --git a/OpenSim/Tests/Common/Mock/TestXInventoryDataPlugin.cs b/OpenSim/Tests/Common/Mock/TestXInventoryDataPlugin.cs
index ccbdf81..30b1f38 100644
--- a/OpenSim/Tests/Common/Mock/TestXInventoryDataPlugin.cs
+++ b/OpenSim/Tests/Common/Mock/TestXInventoryDataPlugin.cs
@@ -53,6 +53,9 @@ namespace OpenSim.Tests.Common.Mock
53 53
54 public XInventoryFolder[] GetFolders(string[] fields, string[] vals) 54 public XInventoryFolder[] GetFolders(string[] fields, string[] vals)
55 { 55 {
56// Console.WriteLine(
57// "Requesting folders, fields {0}, vals {1}", string.Join(",", fields), string.Join(",", vals));
58
56 List<XInventoryFolder> origFolders 59 List<XInventoryFolder> origFolders
57 = Get<XInventoryFolder>(fields, vals, m_allFolders.Values.ToList()); 60 = Get<XInventoryFolder>(fields, vals, m_allFolders.Values.ToList());
58 61
@@ -104,7 +107,30 @@ namespace OpenSim.Tests.Common.Mock
104 } 107 }
105 108
106 public bool MoveItem(string id, string newParent) { throw new NotImplementedException(); } 109 public bool MoveItem(string id, string newParent) { throw new NotImplementedException(); }
107 public bool MoveFolder(string id, string newParent) { throw new NotImplementedException(); } 110
111 public bool MoveFolder(string id, string newParent)
112 {
113 // Don't use GetFolders() here - it takes a clone!
114 XInventoryFolder folder = m_allFolders[new UUID(id)];
115
116 if (folder == null)
117 return false;
118
119 folder.parentFolderID = new UUID(newParent);
120
121 XInventoryFolder[] newParentFolders
122 = GetFolders(new string[] { "folderID" }, new string[] { folder.parentFolderID.ToString() });
123
124// Console.WriteLine(
125// "Moved folder {0} {1}, to {2} {3}",
126// folder.folderName, folder.folderID, newParentFolders[0].folderName, folder.parentFolderID);
127
128 // TODO: Really need to implement folder version incrementing, though this should be common code anyway,
129 // not reimplemented in each db plugin.
130
131 return true;
132 }
133
108 public XInventoryItem[] GetActiveGestures(UUID principalID) { throw new NotImplementedException(); } 134 public XInventoryItem[] GetActiveGestures(UUID principalID) { throw new NotImplementedException(); }
109 public int GetAssetPermissions(UUID principalID, UUID assetID) { throw new NotImplementedException(); } 135 public int GetAssetPermissions(UUID principalID, UUID assetID) { throw new NotImplementedException(); }
110 } 136 }