2021-03-03 14:52:05 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-03-05 16:36:51 +00:00
|
|
|
using System.IO;
|
2021-03-03 14:52:05 +00:00
|
|
|
using Aaru.CommonTypes;
|
2021-09-19 21:16:47 +01:00
|
|
|
using Aaru.CommonTypes.Enums;
|
2021-03-03 14:52:05 +00:00
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
using Aaru.Core;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
namespace Aaru.Tests.Partitions;
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
public abstract class PartitionSchemeTest
|
2021-03-03 14:52:05 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
public abstract string DataFolder { get; }
|
|
|
|
|
public abstract PartitionTest[] Tests { get; }
|
2021-03-03 14:52:05 +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 Test()
|
|
|
|
|
{
|
|
|
|
|
foreach(PartitionTest test in Tests)
|
2021-03-03 14:52:05 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
string testFile = test.TestFile;
|
|
|
|
|
Environment.CurrentDirectory = DataFolder;
|
2021-03-03 14:52:05 +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...
|
|
|
|
|
if(!exists)
|
2022-11-15 00:17:12 +00:00
|
|
|
|
|
|
|
|
// ReSharper disable once HeuristicUnreachableCode
|
2022-03-06 13:29:38 +00:00
|
|
|
continue;
|
2021-03-05 16:36:51 +00:00
|
|
|
|
2023-10-05 16:00:38 +01:00
|
|
|
IFilter inputFilter = PluginRegister.Singleton.GetFilter(testFile);
|
2021-03-03 14:52:05 +00:00
|
|
|
|
2024-05-02 03:40:35 +01:00
|
|
|
Assert.That(inputFilter, Is.Not.Null, string.Format(Localization.Filter_0, testFile));
|
2021-03-03 14:52:05 +00:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
var image = ImageFormat.Detect(inputFilter) as IMediaImage;
|
2021-03-03 14:52:05 +00:00
|
|
|
|
2024-05-02 03:40:35 +01:00
|
|
|
Assert.That(image, Is.Not.Null, string.Format(Localization.Image_format_0, testFile));
|
2021-03-03 14:52:05 +00:00
|
|
|
|
2024-05-02 03:40:35 +01:00
|
|
|
Assert.That(image.Open(inputFilter),
|
|
|
|
|
Is.EqualTo(ErrorNumber.NoError),
|
|
|
|
|
string.Format(Localization.Cannot_open_image_for_0, testFile));
|
2021-03-03 14:52:05 +00:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
List<Partition> partitions = Core.Partitions.GetAll(image);
|
2021-03-03 14:52:05 +00:00
|
|
|
|
2022-11-29 10:33:40 +00:00
|
|
|
partitions.Should().BeEquivalentTo(test.Partitions, string.Format(Localization.Partitions_0, testFile));
|
2021-03-03 14:52:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|