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,30 +26,23 @@
// Copyright © 2011-2021 Natalia Portillo
// ****************************************************************************/
using System;
using System.IO;
using System.Linq;
using Aaru.Checksums;
using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Structs;
using Aaru.Filters;
using FluentAssertions;
using FluentAssertions.Execution;
using Aaru.CommonTypes.Interfaces;
using NUnit.Framework;
namespace Aaru.Tests.Images
{
[TestFixture]
public class CDRWin10
public class CDRWin10 : OpticalMediaImageTest
{
readonly string[] _testFiles =
public override string[] _testFiles => new[]
{
"report_audiocd.xmd", "report_cdrom.xmd", "report_cdrw_2x.xmd", "report_cdr.xmd", "report_enhancedcd.xmd",
"test_karaoke_multi_sampler.xmd"
};
readonly ulong[] _sectors =
public override ulong[] _sectors => new ulong[]
{
// report_audiocd.xmd
0,
@@ -69,8 +62,9 @@ namespace Aaru.Tests.Images
// test_karaoke_multi_sampler.xmd
0
};
public override uint[] _sectorSize => null;
readonly MediaType[] _mediaTypes =
public override MediaType[] _mediaTypes => new[]
{
// report_audiocd.xmd
MediaType.CDDA,
@@ -91,7 +85,7 @@ namespace Aaru.Tests.Images
MediaType.CD
};
readonly string[] _md5S =
public override string[] _md5S => new[]
{
// report_audiocd.xmd
"UNKNOWN",
@@ -112,7 +106,7 @@ namespace Aaru.Tests.Images
"UNKNOWN"
};
readonly string[] _longMd5S =
public override string[] _longMd5S => new[]
{
// report_audiocd.xmd
"UNKNOWN",
@@ -133,7 +127,7 @@ namespace Aaru.Tests.Images
"UNKNOWN"
};
readonly string[] _subchannelMd5S =
public override string[] _subchannelMd5S => new[]
{
// report_audiocd.xmd
"UNKNOWN",
@@ -154,7 +148,7 @@ namespace Aaru.Tests.Images
"UNKNOWN"
};
readonly int[] _tracks =
public override int[] _tracks => new[]
{
// report_audiocd.xmd
1,
@@ -175,7 +169,7 @@ namespace Aaru.Tests.Images
1
};
readonly int[][] _trackSessions =
public override int[][] _trackSessions => new[]
{
// report_audiocd.xmd
new[]
@@ -214,7 +208,7 @@ namespace Aaru.Tests.Images
}
};
readonly ulong[][] _trackStarts =
public override ulong[][] _trackStarts => new[]
{
// report_audiocd.xmd
new ulong[]
@@ -253,7 +247,7 @@ namespace Aaru.Tests.Images
}
};
readonly ulong[][] _trackEnds =
public override ulong[][] _trackEnds => new[]
{
// report_audiocd.xmd
new ulong[]
@@ -292,7 +286,7 @@ namespace Aaru.Tests.Images
}
};
readonly ulong[][] _trackPregaps =
public override ulong[][] _trackPregaps => new[]
{
// report_audiocd.xmd
new ulong[]
@@ -331,7 +325,7 @@ namespace Aaru.Tests.Images
}
};
readonly byte[][] _trackFlags =
public override byte[][] _trackFlags => new[]
{
// report_audiocd.xmd
new byte[]
@@ -370,166 +364,7 @@ namespace Aaru.Tests.Images
}
};
readonly string _dataFolder = Path.Combine(Consts.TEST_FILES_ROOT, "Media image formats", "CDRWin 10");
[Test]
public void Info()
{
Environment.CurrentDirectory = _dataFolder;
for(int i = 0; i < _testFiles.Length; i++)
{
var filter = new ZZZNoFilter();
filter.Open(_testFiles[i]);
var image = new DiscImages.Alcohol120();
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(_mediaTypes[i], image.Info.MediaType, $"Media type: {_testFiles[i]}");
Assert.AreEqual(_tracks[i], image.Tracks.Count, $"Tracks: {_testFiles[i]}");
image.Tracks.Select(t => t.TrackSession).Should().
BeEquivalentTo(_trackSessions[i], $"Track session: {_testFiles[i]}");
image.Tracks.Select(t => t.TrackStartSector).Should().
BeEquivalentTo(_trackStarts[i], $"Track start: {_testFiles[i]}");
image.Tracks.Select(t => t.TrackEndSector).Should().
BeEquivalentTo(_trackEnds[i], $"Track end: {_testFiles[i]}");
image.Tracks.Select(t => t.TrackPregap).Should().
BeEquivalentTo(_trackPregaps[i], $"Track pregap: {_testFiles[i]}");
int trackNo = 0;
byte[] flags = new byte[image.Tracks.Count];
foreach(Track currentTrack in image.Tracks)
{
if(image.Info.ReadableSectorTags.Contains(SectorTagType.CdTrackFlags))
flags[trackNo] = image.ReadSectorTag(currentTrack.TrackSequence,
SectorTagType.CdTrackFlags)[0];
trackNo++;
}
flags.Should().BeEquivalentTo(_trackFlags[i], $"Track flags: {_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 ZZZNoFilter();
filter.Open(_testFiles[i]);
var image = new DiscImages.Alcohol120();
bool opened = image.Open(filter);
Assert.AreEqual(true, opened, $"Open: {_testFiles[i]}");
Md5Context ctx;
foreach(bool @long in new[]
{
false, true
})
{
ctx = new Md5Context();
foreach(Track currentTrack in image.Tracks)
{
ulong sectors = currentTrack.TrackEndSector - currentTrack.TrackStartSector + 1;
ulong doneSectors = 0;
while(doneSectors < sectors)
{
byte[] sector;
if(sectors - doneSectors >= SECTORS_TO_READ)
{
sector =
@long ? image.ReadSectorsLong(doneSectors, SECTORS_TO_READ,
currentTrack.TrackSequence)
: image.ReadSectors(doneSectors, SECTORS_TO_READ,
currentTrack.TrackSequence);
doneSectors += SECTORS_TO_READ;
}
else
{
sector =
@long ? image.ReadSectorsLong(doneSectors, (uint)(sectors - doneSectors),
currentTrack.TrackSequence)
: image.ReadSectors(doneSectors, (uint)(sectors - doneSectors),
currentTrack.TrackSequence);
doneSectors += sectors - doneSectors;
}
ctx.Update(sector);
}
}
Assert.AreEqual(@long ? _longMd5S[i] : _md5S[i], ctx.End(),
$"{(@long ? "Long hash" : "Hash")}: {_testFiles[i]}");
}
if(!image.Info.ReadableSectorTags.Contains(SectorTagType.CdSectorSubchannel))
continue;
ctx = new Md5Context();
foreach(Track currentTrack in image.Tracks)
{
ulong sectors = currentTrack.TrackEndSector - currentTrack.TrackStartSector + 1;
ulong doneSectors = 0;
while(doneSectors < sectors)
{
byte[] sector;
if(sectors - doneSectors >= SECTORS_TO_READ)
{
sector = image.ReadSectorsTag(doneSectors, SECTORS_TO_READ, currentTrack.TrackSequence,
SectorTagType.CdSectorSubchannel);
doneSectors += SECTORS_TO_READ;
}
else
{
sector = image.ReadSectorsTag(doneSectors, (uint)(sectors - doneSectors),
currentTrack.TrackSequence,
SectorTagType.CdSectorSubchannel);
doneSectors += sectors - doneSectors;
}
ctx.Update(sector);
}
}
Assert.AreEqual(_subchannelMd5S[i], ctx.End(), $"Subchannel hash: {_testFiles[i]}");
}
});
}
public override string _dataFolder => Path.Combine(Consts.TEST_FILES_ROOT, "Media image formats", "CDRWin 10");
public override IMediaImage _plugin => new DiscImages.Alcohol120();
}
}