2021-11-24 22:19:57 -08:00
using System.Collections.Generic ;
using MPF.Core.Data ;
using MPF.Modules.DiscImageCreator ;
2023-09-05 00:08:09 -04:00
using SabreTools.RedumpLib.Data ;
2021-11-05 14:44:58 -07:00
using Xunit ;
namespace MPF.Test.Modules
{
public class DiscImageCreatorTests
{
2021-11-25 22:38:59 -08:00
#region Old Tests
2021-11-24 22:19:57 -08:00
[Theory]
[InlineData(RedumpSystem.MicrosoftXbox, MediaType.CDROM, CommandStrings.CompactDisc)]
[InlineData(RedumpSystem.MicrosoftXbox, MediaType.DVD, CommandStrings.XBOX)]
[InlineData(RedumpSystem.MicrosoftXbox, MediaType.LaserDisc, null)]
[InlineData(RedumpSystem.SonyPlayStation3, MediaType.BluRay, CommandStrings.BluRay)]
[InlineData(RedumpSystem.AppleMacintosh, MediaType.FloppyDisk, CommandStrings.Floppy)]
[InlineData(RedumpSystem.RawThrillsVarious, MediaType.GDROM, null)]
public void ParametersFromSystemAndTypeTest ( RedumpSystem ? knownSystem , MediaType ? mediaType , string expected )
{
2022-02-10 13:40:07 -08:00
var options = new Options ( ) ;
2021-11-24 22:19:57 -08:00
var actual = new Parameters ( knownSystem , mediaType , 'D' , "disc.bin" , 16 , options ) ;
Assert . Equal ( expected , actual . BaseCommand ) ;
}
[Theory]
2022-02-10 13:40:07 -08:00
[InlineData(RedumpSystem.AppleMacintosh, MediaType.LaserDisc, null)] // Deliberately unsupported
[InlineData(RedumpSystem.IBMPCcompatible, MediaType.CDROM, new string[] { FlagStrings . C2Opcode , FlagStrings . NoFixSubQSecuROM , FlagStrings . ScanFileProtect } ) ]
[InlineData(RedumpSystem.NintendoGameCube, MediaType.NintendoGameCubeGameDisc, new string[] { FlagStrings . Raw } ) ]
public void ParametersFromOptionsSpecialDefaultTest ( RedumpSystem ? knownSystem , MediaType ? mediaType , string [ ] expected )
2021-11-24 22:19:57 -08:00
{
2022-02-10 13:40:07 -08:00
var options = new Options ( ) ;
2021-11-24 22:19:57 -08:00
var actual = new Parameters ( knownSystem , mediaType , 'D' , "disc.bin" , 16 , options ) ;
HashSet < string > expectedSet = new HashSet < string > ( expected ? ? new string [ 0 ] ) ;
2022-02-10 13:40:07 -08:00
HashSet < string > actualSet = GenerateUsedKeys ( actual ) ;
Assert . Equal ( expectedSet , actualSet ) ;
}
[Theory]
[InlineData(RedumpSystem.SegaDreamcast, MediaType.GDROM, 1000, new string[] { FlagStrings . C2Opcode } ) ]
[InlineData(RedumpSystem.SegaDreamcast, MediaType.GDROM, -1, new string[] { FlagStrings . C2Opcode } ) ]
public void ParametersFromOptionsC2RereadTest ( RedumpSystem ? knownSystem , MediaType ? mediaType , int rereadC2 , string [ ] expected )
{
var options = new Options { DICRereadCount = rereadC2 } ;
var actual = new Parameters ( knownSystem , mediaType , 'D' , "disc.bin" , 16 , options ) ;
HashSet < string > expectedSet = new HashSet < string > ( expected ? ? new string [ 0 ] ) ;
HashSet < string > actualSet = GenerateUsedKeys ( actual ) ;
2021-11-24 22:19:57 -08:00
Assert . Equal ( expectedSet , actualSet ) ;
if ( rereadC2 = = - 1 | | ! knownSystem . MediaTypes ( ) . Contains ( mediaType ) )
Assert . Null ( actual . C2OpcodeValue [ 0 ] ) ;
else
Assert . Equal ( rereadC2 , actual . C2OpcodeValue [ 0 ] ) ;
2022-02-10 13:40:07 -08:00
}
[Theory]
2022-03-01 13:27:31 -08:00
[InlineData(RedumpSystem.IBMPCcompatible, MediaType.DVD, 1000, new string[] { FlagStrings . DVDReread } ) ]
[InlineData(RedumpSystem.IBMPCcompatible, MediaType.DVD, -1, new string[] { FlagStrings . DVDReread } ) ]
[InlineData(RedumpSystem.IBMPCcompatible, MediaType.BluRay, 1000, new string[] { FlagStrings . DVDReread } ) ]
[InlineData(RedumpSystem.IBMPCcompatible, MediaType.BluRay, -1, new string[] { FlagStrings . DVDReread } ) ]
public void ParametersFromOptionsDVDRereadTest ( RedumpSystem ? knownSystem , MediaType ? mediaType , int rereadDVDBD , string [ ] expected )
{
var options = new Options { DICDVDRereadCount = rereadDVDBD } ;
var actual = new Parameters ( knownSystem , mediaType , 'D' , "disc.bin" , 16 , options ) ;
HashSet < string > expectedSet = new HashSet < string > ( expected ? ? new string [ 0 ] ) ;
HashSet < string > actualSet = GenerateUsedKeys ( actual ) ;
Assert . Equal ( expectedSet , actualSet ) ;
if ( rereadDVDBD = = - 1 | | ! knownSystem . MediaTypes ( ) . Contains ( mediaType ) )
Assert . Null ( actual . DVDRereadValue ) ;
else
Assert . Equal ( rereadDVDBD , actual . DVDRereadValue ) ;
}
[Theory]
[InlineData(RedumpSystem.BDVideo, MediaType.BluRay, true, new string[] { FlagStrings . DVDReread } ) ]
[InlineData(RedumpSystem.BDVideo, MediaType.BluRay, false, new string[] { FlagStrings . DVDReread } ) ]
2022-02-10 13:40:07 -08:00
[InlineData(RedumpSystem.IBMPCcompatible, MediaType.CDROM, true, new string[] { FlagStrings . C2Opcode , FlagStrings . NoFixSubQSecuROM , FlagStrings . MultiSectorRead , FlagStrings . ScanFileProtect } ) ]
[InlineData(RedumpSystem.IBMPCcompatible, MediaType.CDROM, false, new string[] { FlagStrings . C2Opcode , FlagStrings . NoFixSubQSecuROM , FlagStrings . ScanFileProtect } ) ]
2022-03-01 13:27:31 -08:00
[InlineData(RedumpSystem.IBMPCcompatible, MediaType.DVD, true, new string[] { FlagStrings . DVDReread } ) ]
[InlineData(RedumpSystem.IBMPCcompatible, MediaType.DVD, false, new string[] { FlagStrings . DVDReread } ) ]
[InlineData(RedumpSystem.HDDVDVideo, MediaType.HDDVD, true, new string[] { FlagStrings . DVDReread } ) ]
[InlineData(RedumpSystem.HDDVDVideo, MediaType.HDDVD, false, new string[] { FlagStrings . DVDReread } ) ]
2022-02-10 13:40:07 -08:00
public void ParametersFromOptionsMultiSectorReadTest ( RedumpSystem ? knownSystem , MediaType ? mediaType , bool multiSectorRead , string [ ] expected )
{
var options = new Options { DICMultiSectorRead = multiSectorRead } ;
var actual = new Parameters ( knownSystem , mediaType , 'D' , "disc.bin" , 16 , options ) ;
HashSet < string > expectedSet = new HashSet < string > ( expected ? ? new string [ 0 ] ) ;
HashSet < string > actualSet = GenerateUsedKeys ( actual ) ;
Assert . Equal ( expectedSet , actualSet ) ;
2022-03-01 13:27:31 -08:00
if ( expectedSet . Count ! = 1 & & multiSectorRead )
2022-02-10 13:40:07 -08:00
Assert . Equal ( 0 , actual . MultiSectorReadValue ) ;
}
[Theory]
2022-03-01 13:27:31 -08:00
[InlineData(RedumpSystem.BDVideo, MediaType.BluRay, true, new string[] { FlagStrings . DVDReread } ) ]
[InlineData(RedumpSystem.BDVideo, MediaType.BluRay, false, new string[] { FlagStrings . DVDReread } ) ]
2022-02-10 13:40:07 -08:00
[InlineData(RedumpSystem.IBMPCcompatible, MediaType.CDROM, true, new string[] { FlagStrings . C2Opcode , FlagStrings . NoFixSubQSecuROM , FlagStrings . ScanFileProtect , FlagStrings . ScanSectorProtect , FlagStrings . SubchannelReadLevel } ) ]
[InlineData(RedumpSystem.IBMPCcompatible, MediaType.CDROM, false, new string[] { FlagStrings . C2Opcode , FlagStrings . NoFixSubQSecuROM , FlagStrings . ScanFileProtect } ) ]
2022-03-01 13:27:31 -08:00
[InlineData(RedumpSystem.IBMPCcompatible, MediaType.DVD, true, new string[] { FlagStrings . DVDReread , FlagStrings . ScanFileProtect } ) ]
[InlineData(RedumpSystem.IBMPCcompatible, MediaType.DVD, false, new string[] { FlagStrings . DVDReread } ) ]
[InlineData(RedumpSystem.HDDVDVideo, MediaType.HDDVD, true, new string[] { FlagStrings . DVDReread } ) ]
[InlineData(RedumpSystem.HDDVDVideo, MediaType.HDDVD, false, new string[] { FlagStrings . DVDReread } ) ]
2022-02-10 13:40:07 -08:00
public void ParametersFromOptionsParanoidModeTest ( RedumpSystem ? knownSystem , MediaType ? mediaType , bool paranoidMode , string [ ] expected )
{
var options = new Options { DICParanoidMode = paranoidMode } ;
var actual = new Parameters ( knownSystem , mediaType , 'D' , "disc.bin" , 16 , options ) ;
HashSet < string > expectedSet = new HashSet < string > ( expected ? ? new string [ 0 ] ) ;
HashSet < string > actualSet = GenerateUsedKeys ( actual ) ;
Assert . Equal ( expectedSet , actualSet ) ;
if ( paranoidMode )
{
if ( actualSet . Contains ( FlagStrings . ScanSectorProtect ) )
Assert . True ( actual [ FlagStrings . ScanSectorProtect ] ) ;
if ( actualSet . Contains ( FlagStrings . SubchannelReadLevel ) )
{
Assert . True ( actual [ FlagStrings . SubchannelReadLevel ] ) ;
Assert . Equal ( 2 , actual . SubchannelReadLevelValue ) ;
}
}
else
{
if ( actualSet . Contains ( FlagStrings . ScanSectorProtect ) )
Assert . False ( actual [ FlagStrings . ScanSectorProtect ] ) ;
if ( actualSet . Contains ( FlagStrings . SubchannelReadLevel ) )
Assert . False ( actual [ FlagStrings . SubchannelReadLevel ] ) ;
Assert . Null ( actual . SubchannelReadLevelValue ) ;
}
2021-11-24 22:19:57 -08:00
}
[Theory]
[InlineData(null, false)]
[InlineData("", false)]
[InlineData("cd F test.bin 8 /c2 20", true)]
[InlineData("fd A test.img", true)]
[InlineData("dvd X super\\test.iso 8 /raw", true)]
[InlineData("bd D longer\\path_test.iso 16", true)]
[InlineData("stop D", true)]
[InlineData("ls", false)]
public void ValidateParametersTest ( string parameters , bool expected )
{
var actual = new Parameters ( parameters ) ;
Assert . Equal ( expected , actual . IsValid ( ) ) ;
}
2021-11-25 22:38:59 -08:00
[Theory]
[InlineData(MediaType.CDROM, ".bin")]
[InlineData(MediaType.DVD, ".iso")]
[InlineData(MediaType.LaserDisc, ".raw")]
[InlineData(MediaType.NintendoWiiUOpticalDisc, ".wud")]
[InlineData(MediaType.FloppyDisk, ".img")]
[InlineData(MediaType.Cassette, ".wav")]
[InlineData(MediaType.NONE, null)]
public void MediaTypeToExtensionTest ( MediaType ? mediaType , string expected )
{
2022-02-10 13:40:07 -08:00
string actual = Converters . Extension ( mediaType ) ;
2021-11-25 22:38:59 -08:00
Assert . Equal ( expected , actual ) ;
}
[Theory]
[InlineData(CommandStrings.Audio, MediaType.CDROM)]
[InlineData(CommandStrings.BluRay, MediaType.BluRay)]
[InlineData(CommandStrings.Close, null)]
[InlineData(CommandStrings.CompactDisc, MediaType.CDROM)]
[InlineData(CommandStrings.Data, MediaType.CDROM)]
[InlineData(CommandStrings.DigitalVideoDisc, MediaType.DVD)]
[InlineData(CommandStrings.Eject, null)]
[InlineData(CommandStrings.Floppy, MediaType.FloppyDisk)]
[InlineData(CommandStrings.GDROM, MediaType.GDROM)]
[InlineData(CommandStrings.MDS, null)]
[InlineData(CommandStrings.Reset, null)]
[InlineData(CommandStrings.SACD, MediaType.CDROM)]
[InlineData(CommandStrings.Start, null)]
[InlineData(CommandStrings.Stop, null)]
[InlineData(CommandStrings.Sub, null)]
[InlineData(CommandStrings.Swap, MediaType.GDROM)]
[InlineData(CommandStrings.XBOX, MediaType.DVD)]
public void BaseCommandToMediaTypeTest ( string command , MediaType ? expected )
{
2022-02-10 13:40:07 -08:00
MediaType ? actual = Converters . ToMediaType ( command ) ;
2021-11-25 22:38:59 -08:00
Assert . Equal ( expected , actual ) ;
}
[Theory]
[InlineData(CommandStrings.Audio, RedumpSystem.AudioCD)]
[InlineData(CommandStrings.BluRay, RedumpSystem.SonyPlayStation3)]
[InlineData(CommandStrings.Close, null)]
[InlineData(CommandStrings.CompactDisc, RedumpSystem.IBMPCcompatible)]
[InlineData(CommandStrings.Data, RedumpSystem.IBMPCcompatible)]
[InlineData(CommandStrings.DigitalVideoDisc, RedumpSystem.IBMPCcompatible)]
[InlineData(CommandStrings.Eject, null)]
[InlineData(CommandStrings.Floppy, RedumpSystem.IBMPCcompatible)]
[InlineData(CommandStrings.GDROM, RedumpSystem.SegaDreamcast)]
[InlineData(CommandStrings.MDS, null)]
[InlineData(CommandStrings.Reset, null)]
[InlineData(CommandStrings.SACD, RedumpSystem.SuperAudioCD)]
[InlineData(CommandStrings.Start, null)]
[InlineData(CommandStrings.Stop, null)]
[InlineData(CommandStrings.Sub, null)]
[InlineData(CommandStrings.Swap, RedumpSystem.SegaDreamcast)]
[InlineData(CommandStrings.XBOX, RedumpSystem.MicrosoftXbox)]
public void BaseCommandToRedumpSystemTest ( string command , RedumpSystem ? expected )
{
2022-02-10 13:40:07 -08:00
RedumpSystem ? actual = Converters . ToRedumpSystem ( command ) ;
2021-11-25 22:38:59 -08:00
Assert . Equal ( expected , actual ) ;
}
#endregion
2021-11-05 14:44:58 -07:00
[Fact]
public void DiscImageCreatorAudioParametersTest ( )
{
string originalParameters = "audio F \"ISO\\Audio CD\\Audio CD.bin\" 72 -5 0" ;
// Validate that a common audio commandline is parsed
var parametersObject = new Parameters ( originalParameters ) ;
Assert . NotNull ( parametersObject ) ;
// Validate that the same set of parameters are generated on the output
string newParameters = parametersObject . GenerateParameters ( ) ;
Assert . NotNull ( newParameters ) ;
Assert . Equal ( originalParameters , newParameters ) ;
}
[Fact]
public void DiscImageCreatorDataParametersTest ( )
{
string originalParameters = "data F \"ISO\\Data CD\\Data CD.bin\" 72 -5 0" ;
// Validate that a common audio commandline is parsed
var parametersObject = new Parameters ( originalParameters ) ;
Assert . NotNull ( parametersObject ) ;
// Validate that the same set of parameters are generated on the output
string newParameters = parametersObject . GenerateParameters ( ) ;
Assert . NotNull ( newParameters ) ;
Assert . Equal ( originalParameters , newParameters ) ;
}
2022-02-10 13:40:07 -08:00
/// <summary>
/// Generate a HashSet of keys that are considered to be set
/// </summary>
/// <param name="parameters">Parameters object to get keys from</param>
/// <returns>HashSet representing the strings</returns>
private static HashSet < string > GenerateUsedKeys ( Parameters parameters )
{
HashSet < string > usedKeys = new HashSet < string > ( ) ;
if ( parameters ? . Keys = = null )
return usedKeys ;
foreach ( string key in parameters . Keys )
{
if ( parameters [ key ] = = true )
usedKeys . Add ( key ) ;
}
return usedKeys ;
}
2021-11-05 14:44:58 -07:00
}
}