2022-03-07 07:36:44 +00:00
|
|
|
namespace Aaru.Tests.Partitions;
|
|
|
|
|
|
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-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
|
|
|
|
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);
|
|
|
|
|
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)
|
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
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var filtersList = new FiltersList();
|
|
|
|
|
IFilter inputFilter = filtersList.GetFilter(testFile);
|
2021-03-03 14:52:05 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.IsNotNull(inputFilter, $"Filter: {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
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.IsNotNull(image, $"Image format: {testFile}");
|
2021-03-03 14:52:05 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.AreEqual(ErrorNumber.NoError, image.Open(inputFilter), $"Cannot open image for {testFile}");
|
2021-03-03 14:52:05 +00:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
List<Partition> partitions = Partitions.GetAll(image);
|
2021-03-03 14:52:05 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
partitions.Should().BeEquivalentTo(test.Partitions, $"Partitions: {testFile}");
|
2021-03-03 14:52:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|