add test to ensure that an IAR starts with the control file

bulletsim
Justin Clark-Casey (justincc) 2011-04-18 22:24:42 +01:00
parent 61619ddefc
commit e00e518692
2 changed files with 39 additions and 11 deletions

View File

@ -77,12 +77,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
/// </value> /// </value>
private Stream m_loadStream; private Stream m_loadStream;
/// <summary> public bool ControlFileLoaded { get; private set; }
/// FIXME: Do not perform this check since older versions of OpenSim do save the control file after other things
/// (I thought they weren't). We will need to bump the version number and perform this check on all
/// subsequent IAR versions only
/// </summary>
protected bool m_controlFileLoaded = true;
protected bool m_assetsLoaded; protected bool m_assetsLoaded;
protected bool m_inventoryNodesLoaded; protected bool m_inventoryNodesLoaded;
@ -131,6 +127,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
m_userInfo = userInfo; m_userInfo = userInfo;
m_invPath = invPath; m_invPath = invPath;
m_loadStream = loadStream; m_loadStream = loadStream;
// FIXME: Do not perform this check since older versions of OpenSim do save the control file after other things
// (I thought they weren't). We will need to bump the version number and perform this check on all
// subsequent IAR versions only
ControlFileLoaded = true;
} }
/// <summary> /// <summary>
@ -522,7 +523,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
/// </summary> /// </summary>
/// <param name="path"></param> /// <param name="path"></param>
/// <param name="data"></param> /// <param name="data"></param>
protected void LoadControlFile(string path, byte[] data) public void LoadControlFile(string path, byte[] data)
{ {
XDocument doc = XDocument.Parse(Encoding.ASCII.GetString(data)); XDocument doc = XDocument.Parse(Encoding.ASCII.GetString(data));
XElement archiveElement = doc.Element("archive"); XElement archiveElement = doc.Element("archive");
@ -538,7 +539,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
majorVersion, MAX_MAJOR_VERSION)); majorVersion, MAX_MAJOR_VERSION));
} }
m_controlFileLoaded = true; ControlFileLoaded = true;
m_log.InfoFormat("[INVENTORY ARCHIVER]: Loading IAR with version {0}", version); m_log.InfoFormat("[INVENTORY ARCHIVER]: Loading IAR with version {0}", version);
} }
@ -550,7 +551,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
/// <param name="data"></param> /// <param name="data"></param>
protected void LoadInventoryFile(string path, TarArchiveReader.TarEntryType entryType, byte[] data) protected void LoadInventoryFile(string path, TarArchiveReader.TarEntryType entryType, byte[] data)
{ {
if (!m_controlFileLoaded) if (!ControlFileLoaded)
throw new Exception( throw new Exception(
string.Format( string.Format(
"The IAR you are trying to load does not list {0} before {1}. Aborting load", "The IAR you are trying to load does not list {0} before {1}. Aborting load",
@ -597,7 +598,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
/// <param name="data"></param> /// <param name="data"></param>
protected void LoadAssetFile(string path, byte[] data) protected void LoadAssetFile(string path, byte[] data)
{ {
if (!m_controlFileLoaded) if (!ControlFileLoaded)
throw new Exception( throw new Exception(
string.Format( string.Format(
"The IAR you are trying to load does not list {0} before {1}. Aborting load", "The IAR you are trying to load does not list {0} before {1}. Aborting load",

View File

@ -96,6 +96,33 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
Assert.That(coaObjects[1].AbsolutePosition, Is.EqualTo(new Vector3(25, 50, 75))); Assert.That(coaObjects[1].AbsolutePosition, Is.EqualTo(new Vector3(25, 50, 75)));
} }
/// <summary>
/// Test that the IAR has the required files in the right order.
/// </summary>
/// <remarks>
/// At the moment, the only thing that matters is that the control file is the very first one.
/// </remarks>
[Test]
public void TestOrder()
{
TestHelper.InMethod();
// log4net.Config.XmlConfigurator.Configure();
MemoryStream archiveReadStream = new MemoryStream(m_iarStreamBytes);
TarArchiveReader tar = new TarArchiveReader(archiveReadStream);
string filePath;
TarArchiveReader.TarEntryType tarEntryType;
byte[] data = tar.ReadEntry(out filePath, out tarEntryType);
Assert.That(filePath, Is.EqualTo(ArchiveConstants.CONTROL_FILE_PATH));
InventoryArchiveReadRequest iarr
= new InventoryArchiveReadRequest(null, null, null, (Stream)null, false);
iarr.LoadControlFile(filePath, data);
Assert.That(iarr.ControlFileLoaded, Is.True);
}
/// <summary> /// <summary>
/// Test saving a single inventory item to a V0.1 OpenSim Inventory Archive /// Test saving a single inventory item to a V0.1 OpenSim Inventory Archive
/// (subject to change since there is no fixed format yet). /// (subject to change since there is no fixed format yet).