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,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.QEMU
{
[TestFixture]
public class QCOW3
public class QCOW3 : BlockMediaImageTest
{
readonly string[] _testFiles =
public override string[] _testFiles => new[]
{
"qcow3.qc2.lz", "qcow3_compressed.qc2.lz"
};
readonly ulong[] _sectors =
public override ulong[] _sectors => new ulong[]
{
// qcow3.qc2.lz
251904,
@@ -54,7 +51,7 @@ namespace Aaru.Tests.Images.QEMU
251904
};
readonly uint[] _sectorSize =
public override uint[] _sectorSize => new uint[]
{
// qcow3.qc2.lz
512,
@@ -63,7 +60,7 @@ namespace Aaru.Tests.Images.QEMU
512
};
readonly MediaType[] _mediaTypes =
public override MediaType[] _mediaTypes => new[]
{
// qcow3.qc2.lz
MediaType.GENERIC_HDD,
@@ -72,7 +69,7 @@ namespace Aaru.Tests.Images.QEMU
MediaType.GENERIC_HDD
};
readonly string[] _md5S =
public override string[] _md5S => new[]
{
// qcow3.qc2.lz
"4bfc9e9e2dd86aa52ef709e77d2617ed",
@@ -81,89 +78,8 @@ namespace Aaru.Tests.Images.QEMU
"4bfc9e9e2dd86aa52ef709e77d2617ed"
};
readonly string _dataFolder =
public override string _dataFolder =>
Path.Combine(Consts.TEST_FILES_ROOT, "Media image formats", "QEMU", "QEMU Copy On Write 3");
[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 Qcow2();
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 Qcow2();
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 Qcow2();
}
}