2021-03-01 19:34:30 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-03-05 16:36:51 +00:00
|
|
|
using System.IO;
|
2021-03-01 19:34:30 +00:00
|
|
|
using Aaru.CommonTypes;
|
2021-09-19 21:16:47 +01:00
|
|
|
using Aaru.CommonTypes.Enums;
|
2021-03-01 19:34:30 +00:00
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
using Aaru.Core;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
namespace Aaru.Tests.Filesystems;
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
public abstract class FilesystemTest
|
2021-03-01 19:34:30 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
readonly string _fileSystemType;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-15 01:35:06 +00:00
|
|
|
protected FilesystemTest() => _fileSystemType = null;
|
2021-03-01 21:33:58 +00:00
|
|
|
|
2022-11-15 01:35:06 +00:00
|
|
|
protected FilesystemTest(string fileSystemType) => _fileSystemType = fileSystemType;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
public abstract string DataFolder { get; }
|
|
|
|
|
public abstract IFilesystem Plugin { get; }
|
|
|
|
|
public abstract bool Partitions { get; }
|
2021-03-01 21:18:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
public abstract FileSystemTest[] Tests { get; }
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
[Test]
|
|
|
|
|
public void Detect()
|
|
|
|
|
{
|
|
|
|
|
Environment.CurrentDirectory = DataFolder;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
foreach(FileSystemTest test in Tests)
|
2021-03-01 19:34:30 +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);
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.True(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)
|
|
|
|
|
continue;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var filtersList = new FiltersList();
|
|
|
|
|
IFilter inputFilter = filtersList.GetFilter(testFile);
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.IsNotNull(inputFilter, string.Format(Localization.Filter_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
var image = ImageFormat.Detect(inputFilter) as IMediaImage;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.IsNotNull(image, string.Format(Localization.Image_format_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.AreEqual(ErrorNumber.NoError, image.Open(inputFilter),
|
|
|
|
|
string.Format(Localization.Cannot_open_image_for_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
List<string> idPlugins;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(Partitions)
|
|
|
|
|
{
|
|
|
|
|
List<Partition> partitionsList = Core.Partitions.GetAll(image);
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.Greater(partitionsList.Count, 0,
|
|
|
|
|
string.Format(Localization.No_partitions_found_for_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
bool found = false;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
foreach(Partition p in partitionsList)
|
|
|
|
|
{
|
2022-11-15 15:58:43 +00:00
|
|
|
Core.Filesystems.Identify(image, out idPlugins, p, true);
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(idPlugins.Count == 0)
|
|
|
|
|
continue;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(!idPlugins.Contains(Plugin.Id.ToString()))
|
|
|
|
|
continue;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
found = true;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
2021-03-01 19:34:30 +00:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.True(found, string.Format(Localization.Filesystem_not_identified_for_0, testFile));
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var wholePart = new Partition
|
2021-03-01 19:34:30 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
Name = "Whole device",
|
|
|
|
|
Length = image.Info.Sectors,
|
|
|
|
|
Size = image.Info.Sectors * image.Info.SectorSize
|
|
|
|
|
};
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
Core.Filesystems.Identify(image, out idPlugins, wholePart, true);
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.Greater(idPlugins.Count, 0,
|
|
|
|
|
string.Format(Localization.No_filesystems_found_for_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.True(idPlugins.Contains(Plugin.Id.ToString()),
|
|
|
|
|
string.Format(Localization.Not_identified_for_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
[Test]
|
|
|
|
|
public void ImageInfo()
|
|
|
|
|
{
|
|
|
|
|
Environment.CurrentDirectory = DataFolder;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
foreach(FileSystemTest test in Tests)
|
2021-03-01 19:34:30 +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);
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.True(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)
|
|
|
|
|
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-01 19:34:30 +00:00
|
|
|
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.IsNotNull(inputFilter, string.Format(Localization.Filter_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
var image = ImageFormat.Detect(inputFilter) as IMediaImage;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.IsNotNull(image, string.Format(Localization.Image_format_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.AreEqual(ErrorNumber.NoError, image.Open(inputFilter),
|
|
|
|
|
string.Format(Localization.Cannot_open_image_for_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.AreEqual(test.MediaType, image.Info.MediaType, testFile);
|
|
|
|
|
Assert.AreEqual(test.Sectors, image.Info.Sectors, testFile);
|
|
|
|
|
Assert.AreEqual(test.SectorSize, image.Info.SectorSize, testFile);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
[Test]
|
|
|
|
|
public void Info()
|
|
|
|
|
{
|
|
|
|
|
Environment.CurrentDirectory = DataFolder;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
foreach(FileSystemTest test in Tests)
|
2021-03-01 19:34:30 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
string testFile = test.TestFile;
|
2022-11-15 15:58:43 +00:00
|
|
|
bool found = false;
|
2022-03-06 13:29:38 +00:00
|
|
|
var partition = new Partition();
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
bool exists = File.Exists(testFile);
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.True(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)
|
|
|
|
|
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-01 19:34:30 +00:00
|
|
|
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.IsNotNull(inputFilter, string.Format(Localization.Filter_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
var image = ImageFormat.Detect(inputFilter) as IMediaImage;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.IsNotNull(image, string.Format(Localization.Image_format_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.AreEqual(ErrorNumber.NoError, image.Open(inputFilter),
|
|
|
|
|
string.Format(Localization.Cannot_open_image_for_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
List<string> idPlugins;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(Partitions)
|
|
|
|
|
{
|
|
|
|
|
List<Partition> partitionsList = Core.Partitions.GetAll(image);
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.Greater(partitionsList.Count, 0,
|
|
|
|
|
string.Format(Localization.No_partitions_found_for_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// In reverse to skip boot partitions we're not interested in
|
|
|
|
|
for(int index = partitionsList.Count - 1; index >= 0; index--)
|
|
|
|
|
{
|
2022-11-15 15:58:43 +00:00
|
|
|
Core.Filesystems.Identify(image, out idPlugins, partitionsList[index], true);
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(idPlugins.Count == 0)
|
|
|
|
|
continue;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(!idPlugins.Contains(Plugin.Id.ToString()))
|
|
|
|
|
continue;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
found = true;
|
|
|
|
|
partition = partitionsList[index];
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
2021-03-01 19:34:30 +00:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
partition = new Partition
|
2021-03-01 19:34:30 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
Name = "Whole device",
|
|
|
|
|
Length = image.Info.Sectors,
|
|
|
|
|
Size = image.Info.Sectors * image.Info.SectorSize
|
|
|
|
|
};
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
Core.Filesystems.Identify(image, out idPlugins, partition, true);
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.Greater(idPlugins.Count, 0,
|
|
|
|
|
string.Format(Localization.No_filesystems_found_for_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
found = idPlugins.Contains(Plugin.Id.ToString());
|
|
|
|
|
}
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.True(found, string.Format(Localization.Filesystem_not_identified_for_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
|
|
|
|
// It is not the case, it changes
|
|
|
|
|
if(!found)
|
|
|
|
|
continue;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var fs = Activator.CreateInstance(Plugin.GetType()) as IFilesystem;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.NotNull(fs, string.Format(Localization.Could_not_instantiate_filesystem_for_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
fs.GetInformation(image, partition, out _, null);
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(test.ApplicationId != null)
|
|
|
|
|
Assert.AreEqual(test.ApplicationId, fs.XmlFsType.ApplicationIdentifier,
|
2022-11-29 10:33:40 +00:00
|
|
|
string.Format(Localization.Application_ID_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.AreEqual(test.Bootable, fs.XmlFsType.Bootable, string.Format(Localization.Bootable_0, testFile));
|
|
|
|
|
Assert.AreEqual(test.Clusters, fs.XmlFsType.Clusters, string.Format(Localization.Clusters_0, testFile));
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(test.ClusterSize, fs.XmlFsType.ClusterSize,
|
|
|
|
|
string.Format(Localization.Cluster_size_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(test.SystemId != null)
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.AreEqual(test.SystemId, fs.XmlFsType.SystemIdentifier,
|
|
|
|
|
string.Format(Localization.System_ID_0, testFile));
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(_fileSystemType ?? test.Type, fs.XmlFsType.Type,
|
|
|
|
|
string.Format(Localization.Filesystem_type_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.AreEqual(test.VolumeName, fs.XmlFsType.VolumeName,
|
|
|
|
|
string.Format(Localization.Volume_name_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-29 10:33:40 +00:00
|
|
|
Assert.AreEqual(test.VolumeSerial, fs.XmlFsType.VolumeSerial,
|
|
|
|
|
string.Format(Localization.Volume_serial_0, testFile));
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
|
|
|
|
});
|
2021-03-01 19:34:30 +00:00
|
|
|
}
|
|
|
|
|
}
|