2021-03-01 19:34:30 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Aaru.CommonTypes;
|
2022-12-17 22:41:56 +00:00
|
|
|
using Aaru.CommonTypes.AaruMetadata;
|
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-12-17 22:41:56 +00:00
|
|
|
using File = System.IO.File;
|
|
|
|
|
using Partition = Aaru.CommonTypes.Partition;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
namespace Aaru.Tests.Filesystems;
|
|
|
|
|
|
2023-10-04 08:29:56 +01:00
|
|
|
public abstract class FilesystemTest(string fileSystemType)
|
2021-03-01 19:34:30 +00:00
|
|
|
{
|
2023-10-04 08:29:56 +01:00
|
|
|
protected FilesystemTest() : this(null) {}
|
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
|
|
|
|
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 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...
|
2024-05-01 04:05:22 +01:00
|
|
|
if(!exists) continue;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2023-10-05 16:00:38 +01:00
|
|
|
IFilter inputFilter = PluginRegister.Singleton.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
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
Assert.AreEqual(ErrorNumber.NoError,
|
|
|
|
|
image.Open(inputFilter),
|
2022-11-29 10:33:40 +00:00
|
|
|
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
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
Assert.Greater(partitionsList.Count,
|
|
|
|
|
0,
|
2022-11-29 10:33:40 +00:00
|
|
|
string.Format(Localization.No_partitions_found_for_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2023-10-03 23:44:33 +01:00
|
|
|
var 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
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(idPlugins.Count == 0) continue;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2024-05-01 04:05:22 +01: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
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
Assert.Greater(idPlugins.Count,
|
|
|
|
|
0,
|
2022-11-29 10:33:40 +00:00
|
|
|
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...
|
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 inputFilter = PluginRegister.Singleton.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
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
Assert.AreEqual(ErrorNumber.NoError,
|
|
|
|
|
image.Open(inputFilter),
|
2022-11-29 10:33:40 +00:00
|
|
|
string.Format(Localization.Cannot_open_image_for_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2023-10-03 23:44:33 +01:00
|
|
|
Assert.AreEqual(test.MediaType, image.Info.MediaType, testFile);
|
|
|
|
|
Assert.AreEqual(test.Sectors, image.Info.Sectors, testFile);
|
2022-03-06 13:29:38 +00:00
|
|
|
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;
|
2023-10-03 23:44:33 +01:00
|
|
|
var 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...
|
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 inputFilter = PluginRegister.Singleton.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
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
Assert.AreEqual(ErrorNumber.NoError,
|
|
|
|
|
image.Open(inputFilter),
|
2022-11-29 10:33:40 +00:00
|
|
|
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
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
Assert.Greater(partitionsList.Count,
|
|
|
|
|
0,
|
2022-11-29 10:33:40 +00:00
|
|
|
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
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(idPlugins.Count == 0) continue;
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2024-05-01 04:05:22 +01: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
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
Assert.Greater(idPlugins.Count,
|
|
|
|
|
0,
|
2022-11-29 10:33:40 +00:00
|
|
|
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
|
2024-05-01 04:05:22 +01:00
|
|
|
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-12-17 22:41:56 +00:00
|
|
|
fs.GetInformation(image, partition, null, out _, out FileSystem fsMetadata);
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(test.ApplicationId != null)
|
2023-10-03 23:44:33 +01:00
|
|
|
{
|
2024-05-01 04:05:22 +01:00
|
|
|
Assert.AreEqual(test.ApplicationId,
|
|
|
|
|
fsMetadata.ApplicationIdentifier,
|
2022-11-29 10:33:40 +00:00
|
|
|
string.Format(Localization.Application_ID_0, testFile));
|
2023-10-03 23:44:33 +01:00
|
|
|
}
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2022-12-17 22:41:56 +00:00
|
|
|
Assert.AreEqual(test.Bootable, fsMetadata.Bootable, string.Format(Localization.Bootable_0, testFile));
|
|
|
|
|
Assert.AreEqual(test.Clusters, fsMetadata.Clusters, string.Format(Localization.Clusters_0, testFile));
|
2022-11-29 10:33:40 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
Assert.AreEqual(test.ClusterSize,
|
|
|
|
|
fsMetadata.ClusterSize,
|
2022-11-29 10:33:40 +00:00
|
|
|
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)
|
2023-10-03 23:44:33 +01:00
|
|
|
{
|
2024-05-01 04:05:22 +01:00
|
|
|
Assert.AreEqual(test.SystemId,
|
|
|
|
|
fsMetadata.SystemIdentifier,
|
2022-11-29 10:33:40 +00:00
|
|
|
string.Format(Localization.System_ID_0, testFile));
|
2023-10-03 23:44:33 +01:00
|
|
|
}
|
2022-11-29 10:33:40 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
Assert.AreEqual(fileSystemType ?? test.Type,
|
|
|
|
|
fsMetadata.Type,
|
2022-11-29 10:33:40 +00:00
|
|
|
string.Format(Localization.Filesystem_type_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
Assert.AreEqual(test.VolumeName,
|
|
|
|
|
fsMetadata.VolumeName,
|
2022-11-29 10:33:40 +00:00
|
|
|
string.Format(Localization.Volume_name_0, testFile));
|
2021-03-01 19:34:30 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
Assert.AreEqual(test.VolumeSerial,
|
|
|
|
|
fsMetadata.VolumeSerial,
|
2022-11-29 10:33:40 +00:00
|
|
|
string.Format(Localization.Volume_serial_0, testFile));
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
|
|
|
|
});
|
2021-03-01 19:34:30 +00:00
|
|
|
}
|
|
|
|
|
}
|