Add TestRejectGivenFolder() and TestAcceptGivenFolder() regression tests
parent
0beccf23c0
commit
67789201c3
|
@ -175,8 +175,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
|
|||
{
|
||||
UUID folderID = new UUID(im.binaryBucket, 1);
|
||||
|
||||
m_log.DebugFormat("[INVENTORY TRANSFER]: Inserting original folder {0} "+
|
||||
"into agent {1}'s inventory",
|
||||
m_log.DebugFormat(
|
||||
"[INVENTORY TRANSFER]: Inserting original folder {0} into agent {1}'s inventory",
|
||||
folderID, new UUID(im.toAgentID));
|
||||
|
||||
InventoryFolderBase folderCopy
|
||||
|
@ -200,7 +200,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
|
|||
user.ControllingClient.SendBulkUpdateInventory(folderCopy);
|
||||
|
||||
// HACK!!
|
||||
// Insert the ID of the copied item into the IM so that we know which item to move to trash if it
|
||||
// Insert the ID of the copied folder into the IM so that we know which item to move to trash if it
|
||||
// is rejected.
|
||||
// XXX: This is probably a misuse of the session ID slot.
|
||||
im.imSessionID = copyID.Guid;
|
||||
|
|
|
@ -252,5 +252,198 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer.Tests
|
|||
|
||||
Assert.That(originalItemAfterDelete, Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAcceptGivenFolder()
|
||||
{
|
||||
TestHelpers.InMethod();
|
||||
// TestHelpers.EnableLogging();
|
||||
|
||||
UUID initialSessionId = TestHelpers.ParseTail(0x10);
|
||||
UUID folderId = TestHelpers.ParseTail(0x100);
|
||||
|
||||
UserAccount ua1
|
||||
= UserAccountHelpers.CreateUserWithInventory(m_scene, "User", "One", TestHelpers.ParseTail(0x1), "pw");
|
||||
UserAccount ua2
|
||||
= UserAccountHelpers.CreateUserWithInventory(m_scene, "User", "Two", TestHelpers.ParseTail(0x2), "pw");
|
||||
|
||||
ScenePresence giverSp = SceneHelpers.AddScenePresence(m_scene, ua1);
|
||||
TestClient giverClient = (TestClient)giverSp.ControllingClient;
|
||||
|
||||
ScenePresence receiverSp = SceneHelpers.AddScenePresence(m_scene, ua2);
|
||||
TestClient receiverClient = (TestClient)receiverSp.ControllingClient;
|
||||
|
||||
InventoryFolderBase originalFolder
|
||||
= UserInventoryHelpers.CreateInventoryFolder(
|
||||
m_scene.InventoryService, giverSp.UUID, folderId, "f1", true);
|
||||
|
||||
byte[] giveImBinaryBucket = new byte[17];
|
||||
giveImBinaryBucket[0] = (byte)AssetType.Folder;
|
||||
byte[] itemIdBytes = folderId.GetBytes();
|
||||
Array.Copy(itemIdBytes, 0, giveImBinaryBucket, 1, itemIdBytes.Length);
|
||||
|
||||
GridInstantMessage giveIm
|
||||
= new GridInstantMessage(
|
||||
m_scene,
|
||||
giverSp.UUID,
|
||||
giverSp.Name,
|
||||
receiverSp.UUID,
|
||||
(byte)InstantMessageDialog.InventoryOffered,
|
||||
false,
|
||||
"inventory offered msg",
|
||||
initialSessionId,
|
||||
false,
|
||||
Vector3.Zero,
|
||||
giveImBinaryBucket,
|
||||
true);
|
||||
|
||||
giverClient.HandleImprovedInstantMessage(giveIm);
|
||||
|
||||
// These details might not all be correct.
|
||||
GridInstantMessage acceptIm
|
||||
= new GridInstantMessage(
|
||||
m_scene,
|
||||
receiverSp.UUID,
|
||||
receiverSp.Name,
|
||||
giverSp.UUID,
|
||||
(byte)InstantMessageDialog.InventoryAccepted,
|
||||
false,
|
||||
"inventory accepted msg",
|
||||
initialSessionId,
|
||||
false,
|
||||
Vector3.Zero,
|
||||
null,
|
||||
true);
|
||||
|
||||
receiverClient.HandleImprovedInstantMessage(acceptIm);
|
||||
|
||||
// Test for item remaining in the giver's inventory (here we assume a copy item)
|
||||
// TODO: Test no-copy items.
|
||||
InventoryFolderBase originalFolderAfterGive
|
||||
= UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, giverSp.UUID, "f1");
|
||||
|
||||
Assert.That(originalFolderAfterGive, Is.Not.Null);
|
||||
Assert.That(originalFolderAfterGive.ID, Is.EqualTo(originalFolder.ID));
|
||||
|
||||
// Test for item successfully making it into the receiver's inventory
|
||||
InventoryFolderBase receivedFolder
|
||||
= UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, receiverSp.UUID, "f1");
|
||||
|
||||
Assert.That(receivedFolder, Is.Not.Null);
|
||||
Assert.That(receivedFolder.ID, Is.Not.EqualTo(originalFolder.ID));
|
||||
|
||||
// Test that on a delete, item still exists and is accessible for the giver.
|
||||
m_scene.InventoryService.DeleteFolders(receiverSp.UUID, new List<UUID>() { receivedFolder.ID });
|
||||
|
||||
InventoryFolderBase originalFolderAfterDelete
|
||||
= UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, giverSp.UUID, "f1");
|
||||
|
||||
Assert.That(originalFolderAfterDelete, Is.Not.Null);
|
||||
|
||||
// TODO: Test scenario where giver deletes their item first.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test user rejection of a given item.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A rejected item still ends up in the user's trash folder.
|
||||
/// </remarks>
|
||||
[Test]
|
||||
public void TestRejectGivenFolder()
|
||||
{
|
||||
TestHelpers.InMethod();
|
||||
// TestHelpers.EnableLogging();
|
||||
|
||||
UUID initialSessionId = TestHelpers.ParseTail(0x10);
|
||||
UUID folderId = TestHelpers.ParseTail(0x100);
|
||||
|
||||
UserAccount ua1
|
||||
= UserAccountHelpers.CreateUserWithInventory(m_scene, "User", "One", TestHelpers.ParseTail(0x1), "pw");
|
||||
UserAccount ua2
|
||||
= UserAccountHelpers.CreateUserWithInventory(m_scene, "User", "Two", TestHelpers.ParseTail(0x2), "pw");
|
||||
|
||||
ScenePresence giverSp = SceneHelpers.AddScenePresence(m_scene, ua1);
|
||||
TestClient giverClient = (TestClient)giverSp.ControllingClient;
|
||||
|
||||
ScenePresence receiverSp = SceneHelpers.AddScenePresence(m_scene, ua2);
|
||||
TestClient receiverClient = (TestClient)receiverSp.ControllingClient;
|
||||
|
||||
// Create the folder to test give
|
||||
InventoryFolderBase originalFolder
|
||||
= UserInventoryHelpers.CreateInventoryFolder(
|
||||
m_scene.InventoryService, giverSp.UUID, folderId, "f1", true);
|
||||
|
||||
GridInstantMessage receivedIm = null;
|
||||
receiverClient.OnReceivedInstantMessage += im => receivedIm = im;
|
||||
|
||||
byte[] giveImBinaryBucket = new byte[17];
|
||||
giveImBinaryBucket[0] = (byte)AssetType.Folder;
|
||||
byte[] itemIdBytes = folderId.GetBytes();
|
||||
Array.Copy(itemIdBytes, 0, giveImBinaryBucket, 1, itemIdBytes.Length);
|
||||
|
||||
GridInstantMessage giveIm
|
||||
= new GridInstantMessage(
|
||||
m_scene,
|
||||
giverSp.UUID,
|
||||
giverSp.Name,
|
||||
receiverSp.UUID,
|
||||
(byte)InstantMessageDialog.InventoryOffered,
|
||||
false,
|
||||
"inventory offered msg",
|
||||
initialSessionId,
|
||||
false,
|
||||
Vector3.Zero,
|
||||
giveImBinaryBucket,
|
||||
true);
|
||||
|
||||
giverClient.HandleImprovedInstantMessage(giveIm);
|
||||
|
||||
// These details might not all be correct.
|
||||
// Session ID is now the created item ID (!)
|
||||
GridInstantMessage rejectIm
|
||||
= new GridInstantMessage(
|
||||
m_scene,
|
||||
receiverSp.UUID,
|
||||
receiverSp.Name,
|
||||
giverSp.UUID,
|
||||
(byte)InstantMessageDialog.InventoryDeclined,
|
||||
false,
|
||||
"inventory declined msg",
|
||||
new UUID(receivedIm.imSessionID),
|
||||
false,
|
||||
Vector3.Zero,
|
||||
null,
|
||||
true);
|
||||
|
||||
receiverClient.HandleImprovedInstantMessage(rejectIm);
|
||||
|
||||
// Test for item remaining in the giver's inventory (here we assume a copy item)
|
||||
// TODO: Test no-copy items.
|
||||
InventoryFolderBase originalFolderAfterGive
|
||||
= UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, giverSp.UUID, "f1");
|
||||
|
||||
Assert.That(originalFolderAfterGive, Is.Not.Null);
|
||||
Assert.That(originalFolderAfterGive.ID, Is.EqualTo(originalFolder.ID));
|
||||
|
||||
// Test for folder successfully making it into the receiver's inventory
|
||||
InventoryFolderBase receivedFolder
|
||||
= UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, receiverSp.UUID, "Trash/f1");
|
||||
|
||||
InventoryFolderBase trashFolder
|
||||
= m_scene.InventoryService.GetFolderForType(receiverSp.UUID, AssetType.TrashFolder);
|
||||
|
||||
Assert.That(receivedFolder, Is.Not.Null);
|
||||
Assert.That(receivedFolder.ID, Is.Not.EqualTo(originalFolder.ID));
|
||||
Assert.That(receivedFolder.ParentID, Is.EqualTo(trashFolder.ID));
|
||||
|
||||
// Test that on a delete, item still exists and is accessible for the giver.
|
||||
m_scene.InventoryService.PurgeFolder(trashFolder);
|
||||
|
||||
InventoryFolderBase originalFolderAfterDelete
|
||||
= UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, giverSp.UUID, "f1");
|
||||
|
||||
Assert.That(originalFolderAfterDelete, Is.Not.Null);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -217,13 +217,38 @@ namespace OpenSim.Tests.Common
|
|||
/// </returns>
|
||||
public static InventoryFolderBase CreateInventoryFolder(
|
||||
IInventoryService inventoryService, UUID userId, string path, bool useExistingFolders)
|
||||
{
|
||||
return CreateInventoryFolder(inventoryService, userId, UUID.Random(), path, useExistingFolders);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create inventory folders starting from the user's root folder.
|
||||
/// </summary>
|
||||
/// <param name="inventoryService"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="folderId"></param>
|
||||
/// <param name="path">
|
||||
/// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER
|
||||
/// </param>
|
||||
/// <param name="useExistingFolders">
|
||||
/// If true, then folders in the path which already the same name are
|
||||
/// used. This applies to the terminal folder as well.
|
||||
/// If false, then all folders in the path are created, even if there is already a folder at a particular
|
||||
/// level with the same name.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The folder created. If the path contains multiple folders then the last one created is returned.
|
||||
/// Will return null if the root folder could not be found.
|
||||
/// </returns>
|
||||
public static InventoryFolderBase CreateInventoryFolder(
|
||||
IInventoryService inventoryService, UUID userId, UUID folderId, string path, bool useExistingFolders)
|
||||
{
|
||||
InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId);
|
||||
|
||||
if (null == rootFolder)
|
||||
return null;
|
||||
|
||||
return CreateInventoryFolder(inventoryService, rootFolder, path, useExistingFolders);
|
||||
return CreateInventoryFolder(inventoryService, folderId, rootFolder, path, useExistingFolders);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -235,6 +260,7 @@ namespace OpenSim.Tests.Common
|
|||
/// TODO: May need to make it an option to create duplicate folders.
|
||||
/// </remarks>
|
||||
/// <param name="inventoryService"></param>
|
||||
/// <param name="folderId">ID of the folder to create</param>
|
||||
/// <param name="parentFolder"></param>
|
||||
/// <param name="path">
|
||||
/// The folder to create.
|
||||
|
@ -249,7 +275,7 @@ namespace OpenSim.Tests.Common
|
|||
/// The folder created. If the path contains multiple folders then the last one created is returned.
|
||||
/// </returns>
|
||||
public static InventoryFolderBase CreateInventoryFolder(
|
||||
IInventoryService inventoryService, InventoryFolderBase parentFolder, string path, bool useExistingFolders)
|
||||
IInventoryService inventoryService, UUID folderId, InventoryFolderBase parentFolder, string path, bool useExistingFolders)
|
||||
{
|
||||
string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None);
|
||||
|
||||
|
@ -262,9 +288,16 @@ namespace OpenSim.Tests.Common
|
|||
{
|
||||
// Console.WriteLine("Creating folder {0} at {1}", components[0], parentFolder.Name);
|
||||
|
||||
UUID folderIdForCreate;
|
||||
|
||||
if (components.Length > 1)
|
||||
folderIdForCreate = UUID.Random();
|
||||
else
|
||||
folderIdForCreate = folderId;
|
||||
|
||||
folder
|
||||
= new InventoryFolderBase(
|
||||
UUID.Random(), components[0], parentFolder.Owner, (short)AssetType.Unknown, parentFolder.ID, 0);
|
||||
folderIdForCreate, components[0], parentFolder.Owner, (short)AssetType.Unknown, parentFolder.ID, 0);
|
||||
|
||||
inventoryService.AddFolder(folder);
|
||||
}
|
||||
|
@ -274,7 +307,7 @@ namespace OpenSim.Tests.Common
|
|||
// }
|
||||
|
||||
if (components.Length > 1)
|
||||
return CreateInventoryFolder(inventoryService, folder, components[1], useExistingFolders);
|
||||
return CreateInventoryFolder(inventoryService, folderId, folder, components[1], useExistingFolders);
|
||||
else
|
||||
return folder;
|
||||
}
|
||||
|
|
|
@ -53,6 +53,9 @@ namespace OpenSim.Tests.Common.Mock
|
|||
|
||||
public XInventoryFolder[] GetFolders(string[] fields, string[] vals)
|
||||
{
|
||||
// Console.WriteLine(
|
||||
// "Requesting folders, fields {0}, vals {1}", string.Join(",", fields), string.Join(",", vals));
|
||||
|
||||
List<XInventoryFolder> origFolders
|
||||
= Get<XInventoryFolder>(fields, vals, m_allFolders.Values.ToList());
|
||||
|
||||
|
@ -104,7 +107,30 @@ namespace OpenSim.Tests.Common.Mock
|
|||
}
|
||||
|
||||
public bool MoveItem(string id, string newParent) { throw new NotImplementedException(); }
|
||||
public bool MoveFolder(string id, string newParent) { throw new NotImplementedException(); }
|
||||
|
||||
public bool MoveFolder(string id, string newParent)
|
||||
{
|
||||
// Don't use GetFolders() here - it takes a clone!
|
||||
XInventoryFolder folder = m_allFolders[new UUID(id)];
|
||||
|
||||
if (folder == null)
|
||||
return false;
|
||||
|
||||
folder.parentFolderID = new UUID(newParent);
|
||||
|
||||
XInventoryFolder[] newParentFolders
|
||||
= GetFolders(new string[] { "folderID" }, new string[] { folder.parentFolderID.ToString() });
|
||||
|
||||
// Console.WriteLine(
|
||||
// "Moved folder {0} {1}, to {2} {3}",
|
||||
// folder.folderName, folder.folderID, newParentFolders[0].folderName, folder.parentFolderID);
|
||||
|
||||
// TODO: Really need to implement folder version incrementing, though this should be common code anyway,
|
||||
// not reimplemented in each db plugin.
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public XInventoryItem[] GetActiveGestures(UUID principalID) { throw new NotImplementedException(); }
|
||||
public int GetAssetPermissions(UUID principalID, UUID assetID) { throw new NotImplementedException(); }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue