Make image format tests inherit a single class.

This commit is contained in:
2021-03-02 00:35:16 +00:00
parent a3e626d9fa
commit bf746bdde0
111 changed files with 2637 additions and 13189 deletions

View File

@@ -26,28 +26,25 @@
// 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.DiskCopy65
{
[TestFixture]
public class UDCo_obsolete
public class UDCo_obsolete : BlockMediaImageTest
{
readonly string[] _testFiles =
public override string[] _testFiles => new[]
{
"DC6_UDCo_DOS_1440.img.lz", "DC6_UDCo_DOS_720.img.lz", "DC6_UDCo_DOS_DMF.img.lz",
"DC6_UDCo_HFS_1440.img.lz", "DC6_UDCo_HFS_800.img.lz", "DC6_UDCo_HFS_DMF.img.lz", "DC6_UDCo_PD_1440.img.lz",
"DC6_UDCo_PD_800.img.lz", "DC6_UDCo_PD_DMF.img.lz"
};
readonly ulong[] _sectors =
public override ulong[] _sectors => new ulong[]
{
// DC6_UDCo_DOS_1440.img.lz
2880,
@@ -77,7 +74,7 @@ namespace Aaru.Tests.Images.DiskCopy65
3360
};
readonly uint[] _sectorSize =
public override uint[] _sectorSize => new uint[]
{
// DC6_UDCo_DOS_1440.img.lz
512,
@@ -107,7 +104,7 @@ namespace Aaru.Tests.Images.DiskCopy65
512
};
readonly MediaType[] _mediaTypes =
public override MediaType[] _mediaTypes => new[]
{
// DC6_UDCo_DOS_1440.img.lz
MediaType.DOS_35_HD,
@@ -137,7 +134,7 @@ namespace Aaru.Tests.Images.DiskCopy65
MediaType.DMF
};
readonly string[] _md5S =
public override string[] _md5S => new[]
{
// DC6_UDCo_DOS_1440.img.lz
"ff419213080574056ebd9adf7bab3d32",
@@ -167,82 +164,8 @@ namespace Aaru.Tests.Images.DiskCopy65
"7fbf0251a93cb36d98e68b7d19624de5"
};
readonly string _dataFolder =
public override string _dataFolder =>
Path.Combine(Consts.TEST_FILES_ROOT, "Media image formats", "DiskCopy 6.5", "UDIF", "UDCo_OBS");
[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 Udif();
bool opened = image.Open(filter);
Assert.AreEqual(true, opened, $"Open: {_testFiles[i]}");
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 Udif();
bool opened = image.Open(filter);
ulong doneSectors = 0;
Assert.AreEqual(true, opened, $"Open: {_testFiles[i]}");
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 Udif();
}
}