mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Make image format tests inherit a single class.
This commit is contained in:
@@ -26,26 +26,23 @@
|
||||
// Copyright © 2011-2021 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using Aaru.Checksums;
|
||||
using Aaru.CommonTypes;
|
||||
using Aaru.CommonTypes.Interfaces;
|
||||
using Aaru.DiscImages;
|
||||
using Aaru.Filters;
|
||||
using FluentAssertions.Execution;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Aaru.Tests.Images.DiskUtilities
|
||||
{
|
||||
[TestFixture]
|
||||
public class ImageDisk
|
||||
public class ImageDisk : BlockMediaImageTest
|
||||
{
|
||||
readonly string[] _testFiles =
|
||||
public override string[] _testFiles => new[]
|
||||
{
|
||||
"mf2dd_acorn.imd.lz", "mf2dd_fdformat_820.imd.lz", "mf2hd_2m.imd.lz", "mf2hd_fdformat_172.imd.lz"
|
||||
};
|
||||
|
||||
readonly ulong[] _sectors =
|
||||
public override ulong[] _sectors => new ulong[]
|
||||
{
|
||||
// mf2dd_acorn.imd.lz
|
||||
800,
|
||||
@@ -60,7 +57,7 @@ namespace Aaru.Tests.Images.DiskUtilities
|
||||
3444
|
||||
};
|
||||
|
||||
readonly uint[] _sectorSize =
|
||||
public override uint[] _sectorSize => new uint[]
|
||||
{
|
||||
// mf2dd_acorn.imd.lz
|
||||
1024,
|
||||
@@ -75,7 +72,7 @@ namespace Aaru.Tests.Images.DiskUtilities
|
||||
512
|
||||
};
|
||||
|
||||
readonly MediaType[] _mediaTypes =
|
||||
public override MediaType[] _mediaTypes => new[]
|
||||
{
|
||||
// mf2dd_acorn.imd.lz
|
||||
MediaType.ACORN_35_DS_DD,
|
||||
@@ -90,7 +87,7 @@ namespace Aaru.Tests.Images.DiskUtilities
|
||||
MediaType.FDFORMAT_35_HD
|
||||
};
|
||||
|
||||
readonly string[] _md5S =
|
||||
public override string[] _md5S => new[]
|
||||
{
|
||||
// mf2dd_acorn.imd.lz
|
||||
"2626f65b49ec085253c41fa2e2a9e788",
|
||||
@@ -105,89 +102,8 @@ namespace Aaru.Tests.Images.DiskUtilities
|
||||
"9dea1e119a73a21a38d134f36b2e5564"
|
||||
};
|
||||
|
||||
readonly string _dataFolder =
|
||||
public override string _dataFolder =>
|
||||
Path.Combine(Consts.TEST_FILES_ROOT, "Media image formats", "disk-analyse", "ImageDisk");
|
||||
|
||||
[Test]
|
||||
public void Info()
|
||||
{
|
||||
Environment.CurrentDirectory = _dataFolder;
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
for(int i = 0; i < _testFiles.Length; i++)
|
||||
{
|
||||
var filter = new LZip();
|
||||
filter.Open(_testFiles[i]);
|
||||
|
||||
var image = new Imd();
|
||||
bool opened = image.Open(filter);
|
||||
|
||||
Assert.AreEqual(true, opened, $"Open: {_testFiles[i]}");
|
||||
|
||||
if(!opened)
|
||||
continue;
|
||||
|
||||
using(new AssertionScope())
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(_sectors[i], image.Info.Sectors, $"Sectors: {_testFiles[i]}");
|
||||
Assert.AreEqual(_sectorSize[i], image.Info.SectorSize, $"Sector size: {_testFiles[i]}");
|
||||
Assert.AreEqual(_mediaTypes[i], image.Info.MediaType, $"Media type: {_testFiles[i]}");
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// How many sectors to read at once
|
||||
const uint SECTORS_TO_READ = 256;
|
||||
|
||||
[Test]
|
||||
public void Hashes()
|
||||
{
|
||||
Environment.CurrentDirectory = _dataFolder;
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
for(int i = 0; i < _testFiles.Length; i++)
|
||||
{
|
||||
var filter = new LZip();
|
||||
filter.Open(_testFiles[i]);
|
||||
|
||||
var image = new Imd();
|
||||
bool opened = image.Open(filter);
|
||||
ulong doneSectors = 0;
|
||||
|
||||
Assert.AreEqual(true, opened, $"Open: {_testFiles[i]}");
|
||||
|
||||
if(!opened)
|
||||
continue;
|
||||
|
||||
var ctx = new Md5Context();
|
||||
|
||||
while(doneSectors < image.Info.Sectors)
|
||||
{
|
||||
byte[] sector;
|
||||
|
||||
if(image.Info.Sectors - doneSectors >= SECTORS_TO_READ)
|
||||
{
|
||||
sector = image.ReadSectors(doneSectors, SECTORS_TO_READ);
|
||||
doneSectors += SECTORS_TO_READ;
|
||||
}
|
||||
else
|
||||
{
|
||||
sector = image.ReadSectors(doneSectors, (uint)(image.Info.Sectors - doneSectors));
|
||||
doneSectors += image.Info.Sectors - doneSectors;
|
||||
}
|
||||
|
||||
ctx.Update(sector);
|
||||
}
|
||||
|
||||
Assert.AreEqual(_md5S[i], ctx.End(), $"Hash: {_testFiles[i]}");
|
||||
}
|
||||
});
|
||||
}
|
||||
public override IMediaImage _plugin => new Imd();
|
||||
}
|
||||
}
|
||||
@@ -26,26 +26,23 @@
|
||||
// Copyright © 2011-2021 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using Aaru.Checksums;
|
||||
using Aaru.CommonTypes;
|
||||
using Aaru.CommonTypes.Interfaces;
|
||||
using Aaru.DiscImages;
|
||||
using Aaru.Filters;
|
||||
using FluentAssertions.Execution;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Aaru.Tests.Images.DiskUtilities
|
||||
{
|
||||
[TestFixture]
|
||||
public class Raw
|
||||
public class Raw : BlockMediaImageTest
|
||||
{
|
||||
readonly string[] _testFiles =
|
||||
public override string[] _testFiles => new[]
|
||||
{
|
||||
"mf2dd_acorn.img.lz", "mf2dd_amiga.adf.lz", "mf2dd_fdformat_820.img.lz", "mf2hd_2m.img.lz",
|
||||
"mf2hd_2m_max.img.lz", "mf2hd_fdformat_172.img.lz", "mf2hd_xdf.img.lz"
|
||||
};
|
||||
readonly ulong[] _sectors =
|
||||
public override ulong[] _sectors => new ulong[]
|
||||
{
|
||||
// mf2dd_acorn.img.lz
|
||||
1600,
|
||||
@@ -68,7 +65,7 @@ namespace Aaru.Tests.Images.DiskUtilities
|
||||
// mf2hd_xdf.img.lz
|
||||
670
|
||||
};
|
||||
readonly uint[] _sectorSize =
|
||||
public override uint[] _sectorSize => new uint[]
|
||||
{
|
||||
// mf2dd_acorn.img.lz
|
||||
512,
|
||||
@@ -91,7 +88,7 @@ namespace Aaru.Tests.Images.DiskUtilities
|
||||
// mf2hd_xdf.img.lz
|
||||
8192
|
||||
};
|
||||
readonly MediaType[] _mediaTypes =
|
||||
public override MediaType[] _mediaTypes => new[]
|
||||
{
|
||||
// mf2dd_acorn.img.lz
|
||||
MediaType.AppleSonyDS,
|
||||
@@ -114,7 +111,7 @@ namespace Aaru.Tests.Images.DiskUtilities
|
||||
// mf2hd_xdf.img.lz
|
||||
MediaType.XDF_35
|
||||
};
|
||||
readonly string[] _md5S =
|
||||
public override string[] _md5S => new[]
|
||||
{
|
||||
// mf2dd_acorn.img.lz
|
||||
"2626f65b49ec085253c41fa2e2a9e788",
|
||||
@@ -138,89 +135,8 @@ namespace Aaru.Tests.Images.DiskUtilities
|
||||
"UNKNOWN"
|
||||
};
|
||||
|
||||
readonly string _dataFolder =
|
||||
public override string _dataFolder =>
|
||||
Path.Combine(Consts.TEST_FILES_ROOT, "Media image formats", "disk-analyse", "raw");
|
||||
|
||||
[Test]
|
||||
public void Info()
|
||||
{
|
||||
Environment.CurrentDirectory = _dataFolder;
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
for(int i = 0; i < _testFiles.Length; i++)
|
||||
{
|
||||
var filter = new LZip();
|
||||
filter.Open(_testFiles[i]);
|
||||
|
||||
var image = new ZZZRawImage();
|
||||
bool opened = image.Open(filter);
|
||||
|
||||
Assert.AreEqual(true, opened, $"Open: {_testFiles[i]}");
|
||||
|
||||
if(!opened)
|
||||
continue;
|
||||
|
||||
using(new AssertionScope())
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(_sectors[i], image.Info.Sectors, $"Sectors: {_testFiles[i]}");
|
||||
Assert.AreEqual(_sectorSize[i], image.Info.SectorSize, $"Sector size: {_testFiles[i]}");
|
||||
Assert.AreEqual(_mediaTypes[i], image.Info.MediaType, $"Media type: {_testFiles[i]}");
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// How many sectors to read at once
|
||||
const uint SECTORS_TO_READ = 256;
|
||||
|
||||
[Test]
|
||||
public void Hashes()
|
||||
{
|
||||
Environment.CurrentDirectory = _dataFolder;
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
for(int i = 0; i < _testFiles.Length; i++)
|
||||
{
|
||||
var filter = new LZip();
|
||||
filter.Open(_testFiles[i]);
|
||||
|
||||
var image = new ZZZRawImage();
|
||||
bool opened = image.Open(filter);
|
||||
ulong doneSectors = 0;
|
||||
|
||||
Assert.AreEqual(true, opened, $"Open: {_testFiles[i]}");
|
||||
|
||||
if(!opened)
|
||||
continue;
|
||||
|
||||
var ctx = new Md5Context();
|
||||
|
||||
while(doneSectors < image.Info.Sectors)
|
||||
{
|
||||
byte[] sector;
|
||||
|
||||
if(image.Info.Sectors - doneSectors >= SECTORS_TO_READ)
|
||||
{
|
||||
sector = image.ReadSectors(doneSectors, SECTORS_TO_READ);
|
||||
doneSectors += SECTORS_TO_READ;
|
||||
}
|
||||
else
|
||||
{
|
||||
sector = image.ReadSectors(doneSectors, (uint)(image.Info.Sectors - doneSectors));
|
||||
doneSectors += image.Info.Sectors - doneSectors;
|
||||
}
|
||||
|
||||
ctx.Update(sector);
|
||||
}
|
||||
|
||||
Assert.AreEqual(_md5S[i], ctx.End(), $"Hash: {_testFiles[i]}");
|
||||
}
|
||||
});
|
||||
}
|
||||
public override IMediaImage _plugin => new ZZZRawImage();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user