Add regression TestRezScriptedAttachmentsFromInventory() though this currently only checks for the presence of script items, not for started scripts

0.7.4.1
Justin Clark-Casey (justincc) 2012-07-11 19:54:40 +01:00
parent 337ea019bd
commit 14d05dc2a9
3 changed files with 85 additions and 23 deletions

View File

@ -185,7 +185,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
}
[Test]
public void TestAddAttachmentFromInventory()
public void TestRezAttachmentFromInventory()
{
TestHelpers.InMethod();
// log4net.Config.XmlConfigurator.Configure();
@ -217,6 +217,31 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
}
/// <summary>
/// Test specific conditions associated with rezzing a scripted attachment from inventory.
/// </summary>
[Test]
public void TestRezScriptedAttachmentFromInventory()
{
TestHelpers.InMethod();
Scene scene = CreateDefaultTestScene();
UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID);
SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, sp.UUID, "att-name", 0x10);
TaskInventoryHelpers.AddScript(scene, so.RootPart);
InventoryItemBase userItem = UserInventoryHelpers.AddInventoryItem(scene, so, 0x100, 0x1000);
scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest);
// TODO: Need to have a test that checks the script is actually started but this involves a lot more
// plumbing of the script engine and either pausing for events or more infrastructure to turn off various
// script engine delays/asychronicity that isn't helpful in an automated regression testing context.
SceneObjectGroup attSo = scene.GetSceneObjectGroup(so.Name);
Assert.That(attSo.ContainsScripts(), Is.True);
}
[Test]
public void TestDetachAttachmentToGround()
{

View File

@ -69,7 +69,7 @@ namespace OpenSim.Tests.Common
}
/// <summary>
/// Add a blank script to the given part.
/// Add a simple script to the given part.
/// </summary>
/// <remarks>
/// TODO: Accept input for item and asset IDs to avoid mysterious script failures that try to use any of these
@ -81,6 +81,7 @@ namespace OpenSim.Tests.Common
public static TaskInventoryItem AddScript(Scene scene, SceneObjectPart part)
{
AssetScriptText ast = new AssetScriptText();
ast.Source = "default { state_entry() {} }";
ast.Encode();
UUID assetUuid = new UUID("00000000-0000-0000-1000-000000000000");

View File

@ -42,6 +42,57 @@ namespace OpenSim.Tests.Common
{
public static readonly string PATH_DELIMITER = "/";
/// <summary>
/// Add an existing scene object as an item in the user's inventory.
/// </summary>
/// <param name='scene'></param>
/// <param name='so'></param>
/// <param name='inventoryIdTail'></param>
/// <param name='assetIdTail'></param>
/// <returns>The inventory item created.</returns>
public static InventoryItemBase AddInventoryItem(
Scene scene, SceneObjectGroup so, int inventoryIdTail, int assetIdTail)
{
return AddInventoryItem(
scene,
so.Name,
TestHelpers.ParseTail(inventoryIdTail),
InventoryType.Object,
AssetHelpers.CreateAsset(TestHelpers.ParseTail(assetIdTail), so),
so.OwnerID);
}
/// <summary>
/// Creates a notecard in the objects folder and specify an item id.
/// </summary>
/// <param name="scene"></param>
/// <param name="itemName"></param>
/// <param name="itemId"></param>
/// <param name="itemType"></param>
/// <param name="asset">The serialized asset for this item</param>
/// <param name="userId"></param>
/// <returns></returns>
private static InventoryItemBase AddInventoryItem(
Scene scene, string itemName, UUID itemId, InventoryType itemType, AssetBase asset, UUID userId)
{
scene.AssetService.Store(asset);
InventoryItemBase item = new InventoryItemBase();
item.Name = itemName;
item.AssetID = asset.FullID;
item.ID = itemId;
item.Owner = userId;
item.AssetType = asset.Type;
item.InvType = (int)itemType;
InventoryFolderBase folder = scene.InventoryService.GetFolderForType(userId, (AssetType)asset.Type);
item.Folder = folder.ID;
scene.AddInventoryItem(item);
return item;
}
/// <summary>
/// Creates a notecard in the objects folder and specify an item id.
/// </summary>
@ -81,40 +132,25 @@ namespace OpenSim.Tests.Common
/// <param name="type">Type of item to create</param>
/// <returns></returns>
public static InventoryItemBase CreateInventoryItem(
Scene scene, string itemName, UUID itemId, UUID assetId, UUID userId, InventoryType type)
Scene scene, string itemName, UUID itemId, UUID assetId, UUID userId, InventoryType itemType)
{
AssetBase asset = null;
if (type == InventoryType.Notecard)
if (itemType == InventoryType.Notecard)
{
asset = AssetHelpers.CreateNotecardAsset();
asset.CreatorID = userId.ToString();
}
else if (type == InventoryType.Object)
else if (itemType == InventoryType.Object)
{
asset = AssetHelpers.CreateAsset(assetId, SceneHelpers.CreateSceneObject(1, userId));
}
else
{
throw new Exception(string.Format("Inventory type {0} not supported", type));
throw new Exception(string.Format("Inventory type {0} not supported", itemType));
}
scene.AssetService.Store(asset);
InventoryItemBase item = new InventoryItemBase();
item.Name = itemName;
item.AssetID = asset.FullID;
item.ID = itemId;
item.Owner = userId;
item.AssetType = asset.Type;
item.InvType = (int)type;
InventoryFolderBase folder = scene.InventoryService.GetFolderForType(userId, AssetType.Notecard);
item.Folder = folder.ID;
scene.AddInventoryItem(item);
return item;
return AddInventoryItem(scene, itemName, itemId, itemType, asset, userId);
}
/// <summary>