mirror of
https://github.com/SabreTools/MPF.git
synced 2026-07-02 17:24:48 +00:00
Add tests around some Aaru helpers
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
- Add processor base implementation tests
|
||||
- Ensure SS.bin only required for DVD
|
||||
- Update tests to account for new file count
|
||||
- Add tests around some Aaru helpers
|
||||
|
||||
### 3.2.4 (2024-11-24)
|
||||
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using SabreTools.RedumpLib.Data;
|
||||
using Schemas;
|
||||
using Xunit;
|
||||
|
||||
#pragma warning disable CS0618 // Ignore "Type or member is obsolete"
|
||||
|
||||
namespace MPF.Processors.Test
|
||||
{
|
||||
// TODO: Add tests around remaining helper methods
|
||||
public class AaruTests
|
||||
{
|
||||
#region GetOutputFiles
|
||||
@@ -164,5 +168,180 @@ namespace MPF.Processors.Test
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GenerateCuesheet
|
||||
|
||||
[Fact]
|
||||
public void GenerateCuesheet_Null_Null()
|
||||
{
|
||||
CICMMetadataType? cicmSidecar = null;
|
||||
string basePath = "test";
|
||||
string? actual = Aaru.GenerateCuesheet(cicmSidecar, basePath);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenerateCuesheet_Empty_Null()
|
||||
{
|
||||
CICMMetadataType? cicmSidecar = new CICMMetadataType();
|
||||
string basePath = "test";
|
||||
string? actual = Aaru.GenerateCuesheet(cicmSidecar, basePath);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenerateCuesheet_Valid_Filled()
|
||||
{
|
||||
TrackType trackType = new TrackType
|
||||
{
|
||||
BytesPerSector = 2352,
|
||||
Flags = new TrackFlagsType { Quadraphonic = true },
|
||||
Indexes = [new TrackIndexType { index = 1, Value = 0 }],
|
||||
ISRC = "isrc",
|
||||
Sequence = new TrackSequenceType { TrackNumber = 1 },
|
||||
TrackType1 = TrackTypeTrackType.mode1,
|
||||
};
|
||||
|
||||
OpticalDiscType opticalDiscType = new OpticalDiscType
|
||||
{
|
||||
DiscType = "CD-ROM",
|
||||
MediaCatalogueNumber = "mcn",
|
||||
Track = [trackType],
|
||||
Tracks = [1],
|
||||
};
|
||||
|
||||
CICMMetadataType? cicmSidecar = new CICMMetadataType
|
||||
{
|
||||
OpticalDisc = [opticalDiscType],
|
||||
Performer = ["performer"],
|
||||
};
|
||||
|
||||
string basePath = "test";
|
||||
string? actual = Aaru.GenerateCuesheet(cicmSidecar, basePath);
|
||||
|
||||
// TODO: Unexpected outcome -- Non-null but empty cuesheet generated
|
||||
// TODO: Add structure validation
|
||||
Assert.NotNull(actual);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GenerateDatafile
|
||||
|
||||
[Fact]
|
||||
public void GenerateDatafile_Null_Null()
|
||||
{
|
||||
CICMMetadataType? cicmSidecar = null;
|
||||
string basePath = "test";
|
||||
var actual = Aaru.GenerateDatafile(cicmSidecar, basePath);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenerateDatafile_Empty_Null()
|
||||
{
|
||||
CICMMetadataType? cicmSidecar = new CICMMetadataType();
|
||||
string basePath = "test";
|
||||
var actual = Aaru.GenerateDatafile(cicmSidecar, basePath);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenerateDatafile_Valid_Filled()
|
||||
{
|
||||
TrackType trackType = new TrackType
|
||||
{
|
||||
Checksums =
|
||||
[
|
||||
new ChecksumType { type = ChecksumTypeType.crc32, Value = "00000000" },
|
||||
new ChecksumType { type = ChecksumTypeType.md5, Value = "d41d8cd98f00b204e9800998ecf8427e" },
|
||||
new ChecksumType { type = ChecksumTypeType.sha1, Value = "da39a3ee5e6b4b0d3255bfef95601890afd80709" },
|
||||
],
|
||||
Sequence = new TrackSequenceType { TrackNumber = 1 },
|
||||
Size = 12345,
|
||||
};
|
||||
|
||||
OpticalDiscType opticalDiscType = new OpticalDiscType
|
||||
{
|
||||
DiscType = "CD-ROM",
|
||||
MediaCatalogueNumber = "mcn",
|
||||
Track = [trackType],
|
||||
Tracks = [1],
|
||||
};
|
||||
|
||||
CICMMetadataType? cicmSidecar = new CICMMetadataType
|
||||
{
|
||||
OpticalDisc = [opticalDiscType],
|
||||
};
|
||||
|
||||
string basePath = "test";
|
||||
var actual = Aaru.GenerateDatafile(cicmSidecar, basePath);
|
||||
|
||||
// TODO: Add structure validation
|
||||
Assert.NotNull(actual);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GeneratePVD
|
||||
|
||||
[Fact]
|
||||
public void GeneratePVD_Null_Null()
|
||||
{
|
||||
CICMMetadataType? cicmSidecar = null;
|
||||
var actual = Aaru.GeneratePVD(cicmSidecar);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GeneratePVD_Empty_Null()
|
||||
{
|
||||
CICMMetadataType? cicmSidecar = new CICMMetadataType();
|
||||
var actual = Aaru.GeneratePVD(cicmSidecar);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GeneratePVD_Valid_Filled()
|
||||
{
|
||||
FileSystemType fileSystemType = new FileSystemType
|
||||
{
|
||||
CreationDate = DateTime.UtcNow,
|
||||
CreationDateSpecified = true,
|
||||
ModificationDate = DateTime.UtcNow,
|
||||
ModificationDateSpecified = true,
|
||||
ExpirationDate = DateTime.UtcNow,
|
||||
ExpirationDateSpecified = true,
|
||||
EffectiveDate = DateTime.UtcNow,
|
||||
EffectiveDateSpecified = true,
|
||||
};
|
||||
|
||||
PartitionType partitionType = new PartitionType
|
||||
{
|
||||
FileSystems = [fileSystemType],
|
||||
};
|
||||
|
||||
TrackType trackType = new TrackType
|
||||
{
|
||||
FileSystemInformation = [partitionType],
|
||||
};
|
||||
|
||||
OpticalDiscType opticalDiscType = new OpticalDiscType
|
||||
{
|
||||
Track = [trackType],
|
||||
};
|
||||
|
||||
CICMMetadataType? cicmSidecar = new CICMMetadataType
|
||||
{
|
||||
OpticalDisc = [opticalDiscType],
|
||||
};
|
||||
|
||||
string? actual = Aaru.GeneratePVD(cicmSidecar);
|
||||
|
||||
// TODO: Add structure validation
|
||||
Assert.NotNull(actual);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -257,63 +257,7 @@ namespace MPF.Processors
|
||||
|
||||
#endregion
|
||||
|
||||
#region Information Extraction Methods
|
||||
|
||||
/// <summary>
|
||||
/// Convert the TrackTypeTrackType value to a CueTrackDataType
|
||||
/// </summary>
|
||||
/// <param name="trackType">TrackTypeTrackType to convert</param>
|
||||
/// <param name="bytesPerSector">Sector size to help with specific subtypes</param>
|
||||
/// <returns>CueTrackDataType representing the input data</returns>
|
||||
private static CueTrackDataType ConvertToDataType(TrackTypeTrackType trackType, uint bytesPerSector)
|
||||
{
|
||||
switch (trackType)
|
||||
{
|
||||
case TrackTypeTrackType.audio:
|
||||
return CueTrackDataType.AUDIO;
|
||||
|
||||
case TrackTypeTrackType.mode1:
|
||||
if (bytesPerSector == 2048)
|
||||
return CueTrackDataType.MODE1_2048;
|
||||
else
|
||||
return CueTrackDataType.MODE1_2352;
|
||||
|
||||
case TrackTypeTrackType.mode2:
|
||||
case TrackTypeTrackType.m2f1:
|
||||
case TrackTypeTrackType.m2f2:
|
||||
if (bytesPerSector == 2336)
|
||||
return CueTrackDataType.MODE2_2336;
|
||||
else
|
||||
return CueTrackDataType.MODE2_2352;
|
||||
|
||||
default:
|
||||
return CueTrackDataType.MODE1_2352;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert the TrackFlagsType value to a CueTrackFlag
|
||||
/// </summary>
|
||||
/// <param name="trackFlagsType">TrackFlagsType containing flag data</param>
|
||||
/// <returns>CueTrackFlag representing the flags</returns>
|
||||
private static CueTrackFlag ConvertToTrackFlag(TrackFlagsType trackFlagsType)
|
||||
{
|
||||
if (trackFlagsType == null)
|
||||
return 0;
|
||||
|
||||
CueTrackFlag flag = 0;
|
||||
|
||||
if (trackFlagsType.CopyPermitted)
|
||||
flag |= CueTrackFlag.DCP;
|
||||
|
||||
if (trackFlagsType.Quadraphonic)
|
||||
flag |= CueTrackFlag.FourCH;
|
||||
|
||||
if (trackFlagsType.PreEmphasis)
|
||||
flag |= CueTrackFlag.PRE;
|
||||
|
||||
return flag;
|
||||
}
|
||||
#region Cuesheet Generation
|
||||
|
||||
/// <summary>
|
||||
/// Generate a cuesheet string based on CICM sidecar data
|
||||
@@ -321,7 +265,7 @@ namespace MPF.Processors
|
||||
/// <param name="cicmSidecar">CICM Sidecar data generated by Aaru</param>
|
||||
/// <param name="basePath">Base path for determining file names</param>
|
||||
/// <returns>String containing the cuesheet, null on error</returns>
|
||||
private static string? GenerateCuesheet(CICMMetadataType? cicmSidecar, string basePath)
|
||||
internal static string? GenerateCuesheet(CICMMetadataType? cicmSidecar, string basePath)
|
||||
{
|
||||
// If the object is null, we can't get information from it
|
||||
if (cicmSidecar == null)
|
||||
@@ -455,20 +399,79 @@ namespace MPF.Processors
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert the TrackTypeTrackType value to a CueTrackDataType
|
||||
/// </summary>
|
||||
/// <param name="trackType">TrackTypeTrackType to convert</param>
|
||||
/// <param name="bytesPerSector">Sector size to help with specific subtypes</param>
|
||||
/// <returns>CueTrackDataType representing the input data</returns>
|
||||
private static CueTrackDataType ConvertToDataType(TrackTypeTrackType trackType, uint bytesPerSector)
|
||||
{
|
||||
switch (trackType)
|
||||
{
|
||||
case TrackTypeTrackType.audio:
|
||||
return CueTrackDataType.AUDIO;
|
||||
|
||||
case TrackTypeTrackType.mode1:
|
||||
if (bytesPerSector == 2048)
|
||||
return CueTrackDataType.MODE1_2048;
|
||||
else
|
||||
return CueTrackDataType.MODE1_2352;
|
||||
|
||||
case TrackTypeTrackType.mode2:
|
||||
case TrackTypeTrackType.m2f1:
|
||||
case TrackTypeTrackType.m2f2:
|
||||
if (bytesPerSector == 2336)
|
||||
return CueTrackDataType.MODE2_2336;
|
||||
else
|
||||
return CueTrackDataType.MODE2_2352;
|
||||
|
||||
default:
|
||||
return CueTrackDataType.MODE1_2352;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert the TrackFlagsType value to a CueTrackFlag
|
||||
/// </summary>
|
||||
/// <param name="trackFlagsType">TrackFlagsType containing flag data</param>
|
||||
/// <returns>CueTrackFlag representing the flags</returns>
|
||||
private static CueTrackFlag ConvertToTrackFlag(TrackFlagsType trackFlagsType)
|
||||
{
|
||||
if (trackFlagsType == null)
|
||||
return 0;
|
||||
|
||||
CueTrackFlag flag = 0;
|
||||
|
||||
if (trackFlagsType.CopyPermitted)
|
||||
flag |= CueTrackFlag.DCP;
|
||||
|
||||
if (trackFlagsType.Quadraphonic)
|
||||
flag |= CueTrackFlag.FourCH;
|
||||
|
||||
if (trackFlagsType.PreEmphasis)
|
||||
flag |= CueTrackFlag.PRE;
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Datafile Generation
|
||||
|
||||
/// <summary>
|
||||
/// Generate a CMP XML datfile string based on CICM sidecar data
|
||||
/// </summary>
|
||||
/// <param name="cicmSidecar">CICM Sidecar data generated by Aaru</param>
|
||||
/// <param name="basePath">Base path for determining file names</param>
|
||||
/// <returns>Datafile containing the hash information, null on error</returns>
|
||||
private static Datafile? GenerateDatafile(CICMMetadataType? cicmSidecar, string basePath)
|
||||
internal static Datafile? GenerateDatafile(CICMMetadataType? cicmSidecar, string basePath)
|
||||
{
|
||||
// If the object is null, we can't get information from it
|
||||
if (cicmSidecar == null)
|
||||
return null;
|
||||
|
||||
// Required variables
|
||||
var datafile = new Datafile();
|
||||
var roms = new List<Rom>();
|
||||
|
||||
// Process OpticalDisc, if possible
|
||||
@@ -562,10 +565,16 @@ namespace MPF.Processors
|
||||
}
|
||||
|
||||
// Assign the roms to a new game
|
||||
datafile.Game = new Game[1];
|
||||
datafile.Game[0] = new Game { Rom = [.. roms] };
|
||||
if (roms.Count > 0)
|
||||
{
|
||||
var datafile = new Datafile
|
||||
{
|
||||
Game = [new Game { Rom = [.. roms] }]
|
||||
};
|
||||
return datafile;
|
||||
}
|
||||
|
||||
return datafile;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -593,12 +602,16 @@ namespace MPF.Processors
|
||||
return trackName;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region PVD Generation
|
||||
|
||||
/// <summary>
|
||||
/// Generate a Redump-compatible PVD block based on CICM sidecar file
|
||||
/// </summary>
|
||||
/// <param name="cicmSidecar">CICM Sidecar data generated by Aaru</param>
|
||||
/// <returns>String containing the PVD, null on error</returns>
|
||||
private static string? GeneratePVD(CICMMetadataType? cicmSidecar)
|
||||
internal static string? GeneratePVD(CICMMetadataType? cicmSidecar)
|
||||
{
|
||||
// If the object is null, we can't get information from it
|
||||
if (cicmSidecar == null)
|
||||
@@ -796,6 +809,10 @@ namespace MPF.Processors
|
||||
return pvdLine.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Information Extraction Methods
|
||||
|
||||
/// <summary>
|
||||
/// Read the CICM Sidecar as an object
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user