2021-03-02 00:35:16 +00:00
|
|
|
using System;
|
2021-03-05 16:36:51 +00:00
|
|
|
using System.IO;
|
2021-03-02 00:35:16 +00:00
|
|
|
using Aaru.Checksums;
|
|
|
|
|
using Aaru.CommonTypes;
|
2021-09-16 19:10:39 +01:00
|
|
|
using Aaru.CommonTypes.Enums;
|
2021-03-02 00:35:16 +00:00
|
|
|
using Aaru.CommonTypes.Interfaces;
|
2023-10-05 16:00:38 +01:00
|
|
|
using Aaru.Core;
|
2021-03-02 00:35:16 +00:00
|
|
|
using FluentAssertions;
|
|
|
|
|
using FluentAssertions.Execution;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
namespace Aaru.Tests.Images;
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
public abstract class TapeMediaImageTest : BaseMediaImageTest
|
2021-03-02 00:35:16 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
// How many sectors to read at once
|
|
|
|
|
const uint SECTORS_TO_READ = 256;
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
public abstract TapeImageTestExpected[] Tests { get; }
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2023-10-05 16:00:38 +01:00
|
|
|
[OneTimeSetUp]
|
|
|
|
|
public void InitTest() => PluginBase.Init();
|
|
|
|
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
[Test]
|
|
|
|
|
public void Tape()
|
|
|
|
|
{
|
|
|
|
|
Environment.CurrentDirectory = DataFolder;
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
foreach(TapeImageTestExpected 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);
|
2024-05-02 03:40:35 +01:00
|
|
|
Assert.That(exists, string.Format(Localization._0_not_found, testFile));
|
2021-03-05 16:36:51 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
|
|
|
|
// It arrives here...
|
2024-05-01 04:05:22 +01:00
|
|
|
if(!exists) continue;
|
2021-03-05 16:36:51 +00:00
|
|
|
|
2023-10-05 16:00:38 +01:00
|
|
|
IFilter filter = PluginRegister.Singleton.GetFilter(testFile);
|
2022-03-06 13:29:38 +00:00
|
|
|
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 ITapeImage;
|
2024-05-02 03:40:35 +01:00
|
|
|
|
|
|
|
|
Assert.That(image,
|
|
|
|
|
Is.Not.Null,
|
|
|
|
|
string.Format(Localization.Could_not_instantiate_filesystem_for_0, testFile));
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ErrorNumber opened = image.Open(filter);
|
2024-05-02 03:40:35 +01:00
|
|
|
Assert.That(opened, Is.EqualTo(ErrorNumber.NoError), string.Format(Localization.Open_0, testFile));
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(opened != ErrorNumber.NoError) continue;
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2024-05-02 03:40:35 +01:00
|
|
|
Assert.That(image.IsTape, Is.True, string.Format(Localization.Is_tape_0, testFile));
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
using(new AssertionScope())
|
2023-10-03 23:44:33 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.Multiple(() =>
|
2021-03-02 00:35:16 +00:00
|
|
|
{
|
2024-05-01 04:05:22 +01:00
|
|
|
image.Files.Should()
|
|
|
|
|
.BeEquivalentTo(test.Files, string.Format(Localization.Tape_files_0, testFile));
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
image.TapePartitions.Should()
|
|
|
|
|
.BeEquivalentTo(test.Partitions, string.Format(Localization.Tape_partitions_0, testFile));
|
2022-03-06 13:29:38 +00:00
|
|
|
});
|
2023-10-03 23:44:33 +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 Info()
|
|
|
|
|
{
|
|
|
|
|
Environment.CurrentDirectory = DataFolder;
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
foreach(TapeImageTestExpected 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);
|
2024-05-02 03:40:35 +01:00
|
|
|
Assert.That(exists, string.Format(Localization._0_not_found, testFile));
|
2021-03-05 16:36:51 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
|
|
|
|
// It arrives here...
|
2024-05-01 04:05:22 +01:00
|
|
|
if(!exists) continue;
|
2021-03-05 16:36:51 +00:00
|
|
|
|
2023-10-05 16:00:38 +01:00
|
|
|
IFilter filter = PluginRegister.Singleton.GetFilter(testFile);
|
2022-03-06 13:29:38 +00:00
|
|
|
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 IMediaImage;
|
2024-05-02 03:40:35 +01:00
|
|
|
|
|
|
|
|
Assert.That(image,
|
|
|
|
|
Is.Not.Null,
|
|
|
|
|
string.Format(Localization.Could_not_instantiate_filesystem_for_0, testFile));
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ErrorNumber opened = image.Open(filter);
|
2024-05-02 03:40:35 +01:00
|
|
|
Assert.That(opened, Is.EqualTo(ErrorNumber.NoError), string.Format(Localization.Open_0, testFile));
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2024-05-01 04:05:22 +01: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())
|
2023-10-03 23:44:33 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.Multiple(() =>
|
2021-03-02 00:35:16 +00:00
|
|
|
{
|
2024-05-02 03:40:35 +01:00
|
|
|
Assert.That(image.Info.Sectors,
|
|
|
|
|
Is.EqualTo(test.Sectors),
|
|
|
|
|
string.Format(Localization.Sectors_0, testFile));
|
2022-11-29 10:33:40 +00:00
|
|
|
|
2024-05-02 03:40:35 +01:00
|
|
|
Assert.That(image.Info.SectorSize,
|
|
|
|
|
Is.EqualTo(test.SectorSize),
|
|
|
|
|
string.Format(Localization.Sector_size_0, testFile));
|
2022-11-29 10:33:40 +00:00
|
|
|
|
2024-05-02 03:40:35 +01:00
|
|
|
Assert.That(image.Info.MediaType,
|
|
|
|
|
Is.EqualTo(test.MediaType),
|
|
|
|
|
string.Format(Localization.Media_type_0, testFile));
|
2022-03-06 13:29:38 +00:00
|
|
|
});
|
2023-10-03 23:44:33 +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 = DataFolder;
|
|
|
|
|
ErrorNumber errno;
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
foreach(TapeImageTestExpected 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);
|
2024-05-02 03:40:35 +01:00
|
|
|
Assert.That(exists, string.Format(Localization._0_not_found, testFile));
|
2021-03-05 16:36:51 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
|
|
|
|
// It arrives here...
|
2024-05-01 04:05:22 +01:00
|
|
|
if(!exists) continue;
|
2021-03-05 16:36:51 +00:00
|
|
|
|
2023-10-05 16:00:38 +01:00
|
|
|
IFilter filter = PluginRegister.Singleton.GetFilter(testFile);
|
2022-03-06 13:29:38 +00:00
|
|
|
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 IMediaImage;
|
2024-05-02 03:40:35 +01:00
|
|
|
|
|
|
|
|
Assert.That(image,
|
|
|
|
|
Is.Not.Null,
|
|
|
|
|
string.Format(Localization.Could_not_instantiate_filesystem_for_0, testFile));
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ErrorNumber opened = image.Open(filter);
|
2024-05-02 03:40:35 +01:00
|
|
|
Assert.That(opened, Is.EqualTo(ErrorNumber.NoError), string.Format(Localization.Open_0, testFile));
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(opened != ErrorNumber.NoError) continue;
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ulong doneSectors = 0;
|
|
|
|
|
var ctx = new Md5Context();
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
while(doneSectors < image.Info.Sectors)
|
|
|
|
|
{
|
|
|
|
|
byte[] sector;
|
|
|
|
|
|
|
|
|
|
if(image.Info.Sectors - doneSectors >= SECTORS_TO_READ)
|
|
|
|
|
{
|
2025-10-23 03:07:43 +01:00
|
|
|
errno = image.ReadSectors(doneSectors, false, SECTORS_TO_READ, out sector, out _);
|
2022-03-06 13:29:38 +00:00
|
|
|
doneSectors += SECTORS_TO_READ;
|
|
|
|
|
}
|
|
|
|
|
else
|
2021-03-02 00:35:16 +00:00
|
|
|
{
|
2025-10-22 14:28:58 +01:00
|
|
|
errno = image.ReadSectors(doneSectors,
|
2025-10-23 03:07:43 +01:00
|
|
|
false,
|
2025-10-22 14:28:58 +01:00
|
|
|
(uint)(image.Info.Sectors - doneSectors),
|
|
|
|
|
out sector,
|
|
|
|
|
out _);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
doneSectors += image.Info.Sectors - doneSectors;
|
2021-03-02 00:35:16 +00:00
|
|
|
}
|
|
|
|
|
|
2024-05-02 03:40:35 +01:00
|
|
|
Assert.That(errno, Is.EqualTo(ErrorNumber.NoError));
|
2022-03-06 13:29:38 +00:00
|
|
|
ctx.Update(sector);
|
2021-03-02 00:35:16 +00:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
2024-05-02 03:40:35 +01:00
|
|
|
Assert.That(ctx.End(), Is.EqualTo(test.Md5), string.Format(Localization.Hash_0, testFile));
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
|
|
|
|
});
|
2021-03-02 00:35:16 +00:00
|
|
|
}
|
|
|
|
|
}
|