From 74ef1ed36f234d93aa3d58b1602344bcb3e00d6e Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 21 May 2010 19:36:39 +0100
Subject: add prim item and test asset save in save oar unit test
---
.../Framework/Serialization/TarArchiveWriter.cs | 7 ++++-
.../CoreModules/World/Archiver/AssetsRequest.cs | 2 +-
.../World/Archiver/Tests/ArchiverTests.cs | 32 ++++++++++++++++++++--
.../Framework/Scenes/Tests/UuidGathererTests.cs | 3 +-
OpenSim/Region/Framework/Scenes/UuidGatherer.cs | 8 ++++--
OpenSim/Tests/Common/Setup/AssetHelpers.cs | 14 ++++++++--
6 files changed, 55 insertions(+), 11 deletions(-)
(limited to 'OpenSim')
diff --git a/OpenSim/Framework/Serialization/TarArchiveWriter.cs b/OpenSim/Framework/Serialization/TarArchiveWriter.cs
index 0bd639f..fca909f 100644
--- a/OpenSim/Framework/Serialization/TarArchiveWriter.cs
+++ b/OpenSim/Framework/Serialization/TarArchiveWriter.cs
@@ -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
///
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
///
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)
diff --git a/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs
index 4215f97..a1451ce 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs
@@ -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);
}
diff --git a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs
index 624dc22..f3e5458 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs
@@ -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");
diff --git a/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs b/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs
index 8b80ebe..5e6124b 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs
@@ -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 foundAssetUuids = new Dictionary();
diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs
index 0ec3cc3..e3965ce 100644
--- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs
+++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs
@@ -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);
diff --git a/OpenSim/Tests/Common/Setup/AssetHelpers.cs b/OpenSim/Tests/Common/Setup/AssetHelpers.cs
index 1fc3cb5..1beafcf 100644
--- a/OpenSim/Tests/Common/Setup/AssetHelpers.cs
+++ b/OpenSim/Tests/Common/Setup/AssetHelpers.cs
@@ -38,12 +38,20 @@ namespace OpenSim.Tests.Common
///
/// Create an asset from the given data
///
- 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;
}
+
+ ///
+ /// Create an asset from the given data
+ ///
+ public static AssetBase CreateAsset(UUID assetUuid, AssetType assetType, string data, UUID creatorID)
+ {
+ return CreateAsset(assetUuid, assetType, Encoding.ASCII.GetBytes(data), creatorID);
+ }
///
/// Create an asset from the given scene object
--
cgit v1.1