2022-03-07 07:36:44 +00:00
|
|
|
namespace Aaru.Tests.Images;
|
|
|
|
|
|
2021-03-02 00:35:16 +00:00
|
|
|
using System;
|
2021-07-07 04:14:10 +01:00
|
|
|
using System.Collections.Generic;
|
2021-03-05 16:36:51 +00:00
|
|
|
using System.IO;
|
2021-03-02 00:35:16 +00:00
|
|
|
using System.Linq;
|
2021-07-07 04:14:10 +01:00
|
|
|
using System.Text;
|
2021-03-02 00:35:16 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Aaru.Checksums;
|
|
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
using Aaru.CommonTypes.Enums;
|
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
using Aaru.CommonTypes.Structs;
|
2021-07-07 04:14:10 +01:00
|
|
|
using Aaru.Core;
|
|
|
|
|
using Aaru.Tests.Filesystems;
|
2021-03-02 00:35:16 +00:00
|
|
|
using FluentAssertions;
|
|
|
|
|
using FluentAssertions.Execution;
|
2021-07-07 04:14:10 +01:00
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Converters;
|
2021-03-02 00:35:16 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
public abstract class OpticalMediaImageTest : BaseMediaImageTest
|
2021-03-02 00:35:16 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
const uint SECTORS_TO_READ = 256;
|
|
|
|
|
public abstract OpticalImageTestExpected[] Tests { get; }
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Info()
|
2021-03-02 00:35:16 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
Environment.CurrentDirectory = DataFolder;
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.Multiple(() =>
|
2021-03-02 00:35:16 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
foreach(OpticalImageTestExpected test in Tests)
|
2021-03-02 00:35:16 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
string testFile = test.TestFile;
|
2021-03-05 16:36:51 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
bool exists = File.Exists(testFile);
|
|
|
|
|
Assert.True(exists, $"{testFile} not found");
|
2021-03-05 16:36:51 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
|
|
|
|
// It arrives here...
|
|
|
|
|
if(!exists)
|
|
|
|
|
continue;
|
2021-03-05 16:36:51 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var filtersList = new FiltersList();
|
|
|
|
|
IFilter filter = filtersList.GetFilter(testFile);
|
|
|
|
|
filter.Open(testFile);
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-15 01:37:37 +00:00
|
|
|
var image = Activator.CreateInstance(Plugin.GetType()) as IOpticalMediaImage;
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.NotNull(image, $"Could not instantiate filesystem for {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ErrorNumber opened = image.Open(filter);
|
|
|
|
|
Assert.AreEqual(ErrorNumber.NoError, opened, $"Open: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(opened != ErrorNumber.NoError)
|
|
|
|
|
continue;
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
using(new AssertionScope())
|
|
|
|
|
Assert.Multiple(() =>
|
2021-03-02 00:35:16 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.AreEqual(test.Sectors, image.Info.Sectors, $"Sectors: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(test.SectorSize > 0)
|
|
|
|
|
Assert.AreEqual(test.SectorSize, image.Info.SectorSize, $"Sector size: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.AreEqual(test.MediaType, image.Info.MediaType, $"Media type: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(image.Info.XmlMediaType != XmlMediaType.OpticalDisc)
|
|
|
|
|
return;
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.AreEqual(test.Tracks.Length, image.Tracks.Count, $"Tracks: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
image.Tracks.Select(t => t.Session).Should().
|
|
|
|
|
BeEquivalentTo(test.Tracks.Select(s => s.Session), $"Track session: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
image.Tracks.Select(t => t.StartSector).Should().
|
|
|
|
|
BeEquivalentTo(test.Tracks.Select(s => s.Start), $"Track start: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
image.Tracks.Select(t => t.EndSector).Should().
|
|
|
|
|
BeEquivalentTo(test.Tracks.Select(s => s.End), $"Track end: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
image.Tracks.Select(t => t.Pregap).Should().
|
|
|
|
|
BeEquivalentTo(test.Tracks.Select(s => s.Pregap), $"Track pregap: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
var trackNo = 0;
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
var flags = new byte?[image.Tracks.Count];
|
|
|
|
|
ulong latestEndSector = 0;
|
2021-07-01 22:36:54 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
foreach(Track currentTrack in image.Tracks)
|
|
|
|
|
{
|
|
|
|
|
if(currentTrack.EndSector > latestEndSector)
|
|
|
|
|
latestEndSector = currentTrack.EndSector;
|
2021-09-20 20:52:18 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(image.Info.ReadableSectorTags.Contains(SectorTagType.CdTrackFlags))
|
|
|
|
|
{
|
|
|
|
|
ErrorNumber errno =
|
|
|
|
|
image.ReadSectorTag(currentTrack.Sequence, SectorTagType.CdTrackFlags,
|
|
|
|
|
out byte[] tmp);
|
2021-09-20 20:52:18 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
continue;
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
flags[trackNo] = tmp[0];
|
2021-03-02 00:35:16 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
trackNo++;
|
|
|
|
|
}
|
2021-07-01 22:36:54 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
flags.Should().BeEquivalentTo(test.Tracks.Select(s => s.Flags), $"Track flags: {testFile}");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(latestEndSector, image.Info.Sectors - 1,
|
|
|
|
|
$"Last sector for tracks is {latestEndSector}, but it is {image.Info.Sectors} for image");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-07-09 09:50:41 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
[Test]
|
|
|
|
|
public void Contents()
|
|
|
|
|
{
|
|
|
|
|
Environment.CurrentDirectory = DataFolder;
|
2021-07-09 09:50:41 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
foreach(OpticalImageTestExpected test in Tests)
|
2021-07-09 09:50:41 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
string testFile = test.TestFile;
|
2021-07-09 09:50:41 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
bool exists = File.Exists(testFile);
|
|
|
|
|
Assert.True(exists, $"{testFile} not found");
|
2021-07-09 09:50:41 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
|
|
|
|
// It arrives here...
|
|
|
|
|
if(!exists)
|
|
|
|
|
continue;
|
2021-07-09 09:50:41 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var filtersList = new FiltersList();
|
|
|
|
|
IFilter filter = filtersList.GetFilter(testFile);
|
|
|
|
|
filter.Open(testFile);
|
2021-07-09 09:50:41 +01:00
|
|
|
|
2022-03-15 01:37:37 +00:00
|
|
|
var image = Activator.CreateInstance(Plugin.GetType()) as IOpticalMediaImage;
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.NotNull(image, $"Could not instantiate filesystem for {testFile}");
|
2021-07-09 09:50:41 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ErrorNumber opened = image.Open(filter);
|
|
|
|
|
Assert.AreEqual(ErrorNumber.NoError, opened, $"Open: {testFile}");
|
2021-07-09 09:50:41 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(opened != ErrorNumber.NoError)
|
|
|
|
|
continue;
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
using(new AssertionScope())
|
|
|
|
|
Assert.Multiple(() =>
|
2021-07-07 04:14:10 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
foreach(TrackInfoTestExpected track in test.Tracks)
|
2021-07-07 04:14:10 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
if(track.FileSystems is null)
|
|
|
|
|
continue;
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ulong trackStart = track.Start + track.Pregap;
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(track.Number == 1 &&
|
|
|
|
|
track.Pregap >= 150)
|
|
|
|
|
trackStart -= 150;
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var partition = new Partition
|
|
|
|
|
{
|
|
|
|
|
Length = track.End - trackStart + 1,
|
|
|
|
|
Start = trackStart
|
|
|
|
|
};
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
Filesystems.Identify(image, out List<string> idPlugins, partition);
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.AreEqual(track.FileSystems.Length, idPlugins.Count,
|
|
|
|
|
$"Expected {track.FileSystems.Length} filesystems in {testFile} but found {idPlugins.Count}");
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
for(var i = 0; i < track.FileSystems.Length; i++)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
PluginBase plugins = GetPluginBase.Instance;
|
|
|
|
|
bool found = plugins.PluginsList.TryGetValue(idPlugins[i], out IFilesystem plugin);
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
|
|
|
|
// It is not the case, it changes
|
|
|
|
|
if(!found)
|
|
|
|
|
continue;
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var fs = Activator.CreateInstance(plugin.GetType()) as IFilesystem;
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.NotNull(fs, $"Could not instantiate filesystem for {testFile}");
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
fs.GetInformation(image, partition, out _, null);
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(track.FileSystems[i].ApplicationId != null)
|
|
|
|
|
Assert.AreEqual(track.FileSystems[i].ApplicationId,
|
2022-03-07 07:36:44 +00:00
|
|
|
fs.XmlFsType.ApplicationIdentifier, $"Application ID: {testFile}");
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.AreEqual(track.FileSystems[i].Bootable, fs.XmlFsType.Bootable,
|
|
|
|
|
$"Bootable: {testFile}");
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.AreEqual(track.FileSystems[i].Clusters, fs.XmlFsType.Clusters,
|
|
|
|
|
$"Clusters: {testFile}");
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.AreEqual(track.FileSystems[i].ClusterSize, fs.XmlFsType.ClusterSize,
|
|
|
|
|
$"Cluster size: {testFile}");
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(track.FileSystems[i].SystemId != null)
|
|
|
|
|
Assert.AreEqual(track.FileSystems[i].SystemId, fs.XmlFsType.SystemIdentifier,
|
|
|
|
|
$"System ID: {testFile}");
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.AreEqual(track.FileSystems[i].Type, fs.XmlFsType.Type,
|
|
|
|
|
$"Filesystem type: {testFile}");
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.AreEqual(track.FileSystems[i].VolumeName, fs.XmlFsType.VolumeName,
|
|
|
|
|
$"Volume name: {testFile}");
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.AreEqual(track.FileSystems[i].VolumeSerial, fs.XmlFsType.VolumeSerial,
|
|
|
|
|
$"Volume serial: {testFile}");
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-11-14 01:49:10 +00:00
|
|
|
if(Activator.CreateInstance(plugin.GetType()) is not IReadOnlyFilesystem rofs)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
if(track.FileSystems[i].Contents != null ||
|
|
|
|
|
track.FileSystems[i].ContentsJson != null ||
|
|
|
|
|
File.Exists($"{testFile}.track{track.Number}.filesystem{i}.contents.json"))
|
2022-03-17 23:54:41 +00:00
|
|
|
Assert.NotNull(null,
|
2022-03-06 13:29:38 +00:00
|
|
|
$"Could not instantiate filesystem for {testFile}, track {track.Number}, filesystem {i}");
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
track.FileSystems[i].Encoding ??= Encoding.ASCII;
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ErrorNumber ret = rofs.Mount(image, partition, track.FileSystems[i].Encoding, null,
|
|
|
|
|
track.FileSystems[i].Namespace);
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.AreEqual(ErrorNumber.NoError, ret, $"Unmountable: {testFile}");
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var serializer = new JsonSerializer
|
|
|
|
|
{
|
|
|
|
|
Formatting = Formatting.Indented,
|
|
|
|
|
MaxDepth = 16384,
|
|
|
|
|
NullValueHandling = NullValueHandling.Ignore
|
|
|
|
|
};
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
serializer.Converters.Add(new StringEnumConverter());
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(track.FileSystems[i].ContentsJson != null)
|
|
|
|
|
track.FileSystems[i].Contents =
|
|
|
|
|
serializer.
|
|
|
|
|
Deserialize<
|
2022-03-07 07:36:44 +00:00
|
|
|
Dictionary<string, FileData>>(new JsonTextReader(new StringReader(track.
|
|
|
|
|
FileSystems[i].
|
|
|
|
|
ContentsJson)));
|
2022-03-06 13:29:38 +00:00
|
|
|
else if(File.Exists($"{testFile}.track{track.Number}.filesystem{i}.contents.json"))
|
|
|
|
|
{
|
|
|
|
|
var sr =
|
2022-03-07 07:36:44 +00:00
|
|
|
new StreamReader($"{testFile}.track{track.Number}.filesystem{i}.contents.json");
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
track.FileSystems[i].Contents =
|
2022-03-07 07:36:44 +00:00
|
|
|
serializer.Deserialize<Dictionary<string, FileData>>(new JsonTextReader(sr));
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(track.FileSystems[i].Contents is null)
|
|
|
|
|
continue;
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
ReadOnlyFilesystemTest.TestDirectory(rofs, "/", track.FileSystems[i].Contents, testFile,
|
|
|
|
|
false);
|
2021-07-07 04:14:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// Uncomment to generate JSON file
|
|
|
|
|
/* var contents = ReadOnlyFilesystemTest.BuildDirectory(rofs, "/");
|
2021-09-14 21:18:28 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var sw = new StreamWriter($"{testFile}.track{track.Number}.filesystem{i}.contents.json");
|
|
|
|
|
serializer.Serialize(sw, contents);
|
|
|
|
|
sw.Close();*/
|
2021-07-07 04:14:10 +01:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
[Test]
|
|
|
|
|
public void Hashes()
|
|
|
|
|
{
|
|
|
|
|
Environment.CurrentDirectory = Environment.CurrentDirectory = DataFolder;
|
|
|
|
|
ErrorNumber errno;
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
2022-03-16 00:31:33 +00:00
|
|
|
Parallel.For(0L, Tests.Length, (i, _) =>
|
2021-03-02 00:35:16 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
string testFile = Tests[i].TestFile;
|
2021-03-05 16:36:51 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
bool exists = File.Exists(testFile);
|
|
|
|
|
Assert.True(exists, $"{testFile} not found");
|
2021-03-05 16:36:51 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
|
|
|
|
// It arrives here...
|
|
|
|
|
if(!exists)
|
|
|
|
|
return;
|
2021-03-05 16:36:51 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var filtersList = new FiltersList();
|
|
|
|
|
IFilter filter = filtersList.GetFilter(testFile);
|
|
|
|
|
filter.Open(testFile);
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-15 01:37:37 +00:00
|
|
|
var image = Activator.CreateInstance(Plugin.GetType()) as IOpticalMediaImage;
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.NotNull(image, $"Could not instantiate filesystem for {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ErrorNumber opened = image.Open(filter);
|
|
|
|
|
Assert.AreEqual(ErrorNumber.NoError, opened, $"Open: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(opened != ErrorNumber.NoError)
|
|
|
|
|
return;
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Md5Context ctx;
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(image.Info.XmlMediaType == XmlMediaType.OpticalDisc)
|
|
|
|
|
{
|
|
|
|
|
foreach(bool @long in new[]
|
2021-03-02 00:35:16 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
false, true
|
|
|
|
|
})
|
|
|
|
|
{
|
2021-03-02 00:35:16 +00:00
|
|
|
ctx = new Md5Context();
|
|
|
|
|
|
|
|
|
|
foreach(Track currentTrack in image.Tracks)
|
|
|
|
|
{
|
2021-09-14 21:18:28 +01:00
|
|
|
ulong sectors = currentTrack.EndSector - currentTrack.StartSector + 1;
|
2021-03-02 00:35:16 +00:00
|
|
|
ulong doneSectors = 0;
|
|
|
|
|
|
|
|
|
|
while(doneSectors < sectors)
|
|
|
|
|
{
|
|
|
|
|
byte[] sector;
|
|
|
|
|
|
|
|
|
|
if(sectors - doneSectors >= SECTORS_TO_READ)
|
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
errno = @long ? image.ReadSectorsLong(doneSectors, SECTORS_TO_READ,
|
|
|
|
|
currentTrack.Sequence, out sector)
|
2022-03-07 07:36:44 +00:00
|
|
|
: image.ReadSectors(doneSectors, SECTORS_TO_READ, currentTrack.Sequence,
|
2022-03-06 13:29:38 +00:00
|
|
|
out sector);
|
2021-03-02 00:35:16 +00:00
|
|
|
|
|
|
|
|
doneSectors += SECTORS_TO_READ;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-03-07 07:36:44 +00:00
|
|
|
errno = @long ? image.ReadSectorsLong(doneSectors, (uint)(sectors - doneSectors),
|
2022-03-06 13:29:38 +00:00
|
|
|
currentTrack.Sequence, out sector)
|
|
|
|
|
: image.ReadSectors(doneSectors, (uint)(sectors - doneSectors),
|
|
|
|
|
currentTrack.Sequence, out sector);
|
2021-03-02 00:35:16 +00:00
|
|
|
|
|
|
|
|
doneSectors += sectors - doneSectors;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-21 03:42:15 +01:00
|
|
|
Assert.AreEqual(ErrorNumber.NoError, errno);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
2021-03-02 00:35:16 +00:00
|
|
|
ctx.Update(sector);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-15 01:37:37 +00:00
|
|
|
Assert.AreEqual(@long ? Tests[i].LongMd5 : Tests[i].Md5, ctx.End(),
|
2022-03-06 13:29:38 +00:00
|
|
|
$"{(@long ? "Long hash" : "Hash")}: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
if(!image.Info.ReadableSectorTags.Contains(SectorTagType.CdSectorSubchannel))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ctx = new Md5Context();
|
|
|
|
|
|
|
|
|
|
foreach(Track currentTrack in image.Tracks)
|
2021-03-02 00:35:16 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
ulong sectors = currentTrack.EndSector - currentTrack.StartSector + 1;
|
2021-03-02 00:35:16 +00:00
|
|
|
ulong doneSectors = 0;
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
while(doneSectors < sectors)
|
2021-03-02 00:35:16 +00:00
|
|
|
{
|
|
|
|
|
byte[] sector;
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(sectors - doneSectors >= SECTORS_TO_READ)
|
2021-03-02 00:35:16 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
errno = image.ReadSectorsTag(doneSectors, SECTORS_TO_READ, currentTrack.Sequence,
|
|
|
|
|
SectorTagType.CdSectorSubchannel, out sector);
|
|
|
|
|
|
2021-03-02 00:35:16 +00:00
|
|
|
doneSectors += SECTORS_TO_READ;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
errno = image.ReadSectorsTag(doneSectors, (uint)(sectors - doneSectors),
|
2022-03-07 07:36:44 +00:00
|
|
|
currentTrack.Sequence, SectorTagType.CdSectorSubchannel,
|
|
|
|
|
out sector);
|
2021-09-19 21:16:47 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
doneSectors += sectors - doneSectors;
|
2021-03-02 00:35:16 +00:00
|
|
|
}
|
|
|
|
|
|
2021-09-19 21:16:47 +01:00
|
|
|
Assert.AreEqual(ErrorNumber.NoError, errno);
|
2021-03-02 00:35:16 +00:00
|
|
|
ctx.Update(sector);
|
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-15 01:37:37 +00:00
|
|
|
Assert.AreEqual(Tests[i].SubchannelMd5, ctx.End(), $"Subchannel hash: {testFile}");
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ctx = new Md5Context();
|
|
|
|
|
ulong doneSectors = 0;
|
|
|
|
|
|
|
|
|
|
while(doneSectors < image.Info.Sectors)
|
|
|
|
|
{
|
|
|
|
|
byte[] sector;
|
|
|
|
|
|
|
|
|
|
if(image.Info.Sectors - doneSectors >= SECTORS_TO_READ)
|
|
|
|
|
{
|
|
|
|
|
errno = image.ReadSectors(doneSectors, SECTORS_TO_READ, out sector);
|
|
|
|
|
doneSectors += SECTORS_TO_READ;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
errno = image.ReadSectors(doneSectors, (uint)(image.Info.Sectors - doneSectors),
|
|
|
|
|
out sector);
|
|
|
|
|
|
|
|
|
|
doneSectors += image.Info.Sectors - doneSectors;
|
|
|
|
|
}
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.AreEqual(ErrorNumber.NoError, errno);
|
|
|
|
|
ctx.Update(sector);
|
2021-03-02 00:35:16 +00:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
2022-03-15 01:37:37 +00:00
|
|
|
Assert.AreEqual(Tests[i].Md5, ctx.End(), $"Hash: {testFile}");
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
2021-03-02 00:35:16 +00:00
|
|
|
});
|
2022-03-06 13:29:38 +00:00
|
|
|
});
|
2021-03-02 00:35:16 +00:00
|
|
|
}
|
|
|
|
|
}
|