add prim item and test asset save in save oar unit test

soprefactor
Justin Clark-Casey (justincc) 2010-05-21 19:36:39 +01:00
parent 78a0fd5281
commit 74ef1ed36f
6 changed files with 55 additions and 11 deletions

View File

@ -28,7 +28,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using log4net;
namespace OpenSim.Framework.Serialization
{
@ -37,7 +39,7 @@ namespace OpenSim.Framework.Serialization
/// </summary>
public class TarArchiveWriter
{
//private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding();
protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding();
@ -148,6 +150,9 @@ namespace OpenSim.Framework.Serialization
/// <param name="fileType"></param>
protected void WriteEntry(string filePath, byte[] data, char fileType)
{
// m_log.DebugFormat(
// "[TAR ARCHIVE WRITER]: Data for {0} is {1} bytes", filePath, (null == data ? "null" : data.Length.ToString()));
byte[] header = new byte[512];
// file path field (100)

View File

@ -239,7 +239,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
if (asset != null)
{
// m_log.DebugFormat("[ARCHIVER]: Recording asset {0} as found", id);
// m_log.DebugFormat("[ARCHIVER]: Writing asset {0}", id);
m_foundAssetUuids.Add(asset.FullID);
m_assetsArchiver.WriteAsset(asset);
}

View File

@ -33,8 +33,8 @@ using log4net.Config;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using OpenMetaverse;
using OpenMetaverse.Assets;
using OpenSim.Framework;
using OpenSim.Framework.Serialization;
using OpenSim.Framework.Serialization.External;
using OpenSim.Region.CoreModules.World.Serialiser;
@ -44,6 +44,9 @@ using OpenSim.Region.Framework.Scenes.Serialization;
using OpenSim.Tests.Common;
using OpenSim.Tests.Common.Mock;
using OpenSim.Tests.Common.Setup;
using ArchiveConstants = OpenSim.Framework.Serialization.ArchiveConstants;
using TarArchiveReader = OpenSim.Framework.Serialization.TarArchiveReader;
using TarArchiveWriter = OpenSim.Framework.Serialization.TarArchiveWriter;
namespace OpenSim.Region.CoreModules.World.Archiver.Tests
{
@ -55,6 +58,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
protected TestScene m_scene;
protected ArchiverModule m_archiverModule;
protected TaskInventoryItem m_soundItem;
[SetUp]
public void SetUp()
@ -127,7 +132,19 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
m_scene.AddNewSceneObject(new SceneObjectGroup(part1), false);
SceneObjectPart part2 = CreateSceneObjectPart2();
m_scene.AddNewSceneObject(new SceneObjectGroup(part2), false);
AssetNotecard nc = new AssetNotecard("Hello World!");
UUID ncAssetUuid = new UUID("00000000-0000-0000-1000-000000000000");
UUID ncItemUuid = new UUID("00000000-0000-0000-1100-000000000000");
AssetBase ncAsset
= AssetHelpers.CreateAsset(ncAssetUuid, AssetType.Notecard, nc.AssetData, UUID.Zero);
m_scene.AssetService.Store(ncAsset);
SceneObjectGroup sog2 = new SceneObjectGroup(part2);
TaskInventoryItem ncItem
= new TaskInventoryItem { Name = "ncItem", AssetID = ncAssetUuid, ItemID = ncItemUuid };
part2.Inventory.AddInventoryItem(ncItem, true);
m_scene.AddNewSceneObject(sog2, false);
MemoryStream archiveWriteStream = new MemoryStream();
m_scene.EventManager.OnOarFileSaved += SaveCompleted;
@ -151,8 +168,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
TarArchiveReader tar = new TarArchiveReader(archiveReadStream);
bool gotControlFile = false;
bool gotNcAssetFile = false;
bool gotObject1File = false;
bool gotObject2File = false;
string expectedNcAssetFileName = string.Format("{0}_{1}", ncAssetUuid, "notecard.txt");
string expectedObject1FileName = string.Format(
"{0}_{1:000}-{2:000}-{3:000}__{4}.xml",
part1.Name,
@ -173,6 +193,13 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
{
gotControlFile = true;
}
else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH))
{
string fileName = filePath.Remove(0, ArchiveConstants.ASSETS_PATH.Length);
Assert.That(fileName, Is.EqualTo(expectedNcAssetFileName));
gotNcAssetFile = true;
}
else if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH))
{
string fileName = filePath.Remove(0, ArchiveConstants.OBJECTS_PATH.Length);
@ -191,6 +218,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
}
Assert.That(gotControlFile, Is.True, "No control file in archive");
Assert.That(gotNcAssetFile, Is.True, "No notecard asset file in archive");
Assert.That(gotObject1File, Is.True, "No object1 file in archive");
Assert.That(gotObject2File, Is.True, "No object2 file in archive");

View File

@ -58,7 +58,8 @@ namespace OpenSim.Region.Framework.Scenes.Tests
TestHelper.InMethod();
UUID corruptAssetUuid = UUID.Parse("00000000-0000-0000-0000-000000000666");
AssetBase corruptAsset = AssetHelpers.CreateAsset(corruptAssetUuid, "CORRUPT ASSET", UUID.Zero);
AssetBase corruptAsset
= AssetHelpers.CreateAsset(corruptAssetUuid, AssetType.Notecard, "CORRUPT ASSET", UUID.Zero);
m_assetService.Store(corruptAsset);
IDictionary<UUID, AssetType> foundAssetUuids = new Dictionary<UUID, AssetType>();

View File

@ -123,8 +123,8 @@ namespace OpenSim.Region.Framework.Scenes
foreach (SceneObjectPart part in sceneObject.GetParts())
{
//m_log.DebugFormat(
// "[ARCHIVER]: Getting part {0}, {1} for object {2}", part.Name, part.UUID, sceneObject.UUID);
// m_log.DebugFormat(
// "[ARCHIVER]: Getting part {0}, {1} for object {2}", part.Name, part.UUID, sceneObject.UUID);
try
{
@ -155,7 +155,9 @@ namespace OpenSim.Region.Framework.Scenes
// Now analyze this prim's inventory items to preserve all the uuids that they reference
foreach (TaskInventoryItem tii in taskDictionary.Values)
{
//m_log.DebugFormat("[ARCHIVER]: Analysing item asset type {0}", tii.Type);
// m_log.DebugFormat(
// "[ARCHIVER]: Analysing item {0} asset type {1} in {2} {3}",
// tii.Name, tii.Type, part.Name, part.UUID);
if (!assetUuids.ContainsKey(tii.AssetID))
GatherAssetUuids(tii.AssetID, (AssetType)tii.Type, assetUuids);

View File

@ -38,12 +38,20 @@ namespace OpenSim.Tests.Common
/// <summary>
/// Create an asset from the given data
/// </summary>
public static AssetBase CreateAsset(UUID assetUuid, string data, UUID creatorID)
public static AssetBase CreateAsset(UUID assetUuid, AssetType assetType, byte[] data, UUID creatorID)
{
AssetBase asset = new AssetBase(assetUuid, assetUuid.ToString(), (sbyte)AssetType.Object, creatorID.ToString());
asset.Data = Encoding.ASCII.GetBytes(data);
AssetBase asset = new AssetBase(assetUuid, assetUuid.ToString(), (sbyte)assetType, creatorID.ToString());
asset.Data = data;
return asset;
}
/// <summary>
/// Create an asset from the given data
/// </summary>
public static AssetBase CreateAsset(UUID assetUuid, AssetType assetType, string data, UUID creatorID)
{
return CreateAsset(assetUuid, assetType, Encoding.ASCII.GetBytes(data), creatorID);
}
/// <summary>
/// Create an asset from the given scene object