2020-12-19 22:08:42 -08:00
|
|
|
using SabreTools.DatFiles;
|
2025-01-29 13:25:36 -05:00
|
|
|
using SabreTools.DatTools;
|
2020-12-19 22:08:42 -08:00
|
|
|
using Xunit;
|
|
|
|
|
|
2025-02-19 13:34:16 -05:00
|
|
|
namespace SabreTools.Test
|
2020-12-19 22:08:42 -08:00
|
|
|
{
|
2025-01-29 20:38:09 -05:00
|
|
|
public class WriterTests
|
2020-12-19 22:08:42 -08:00
|
|
|
{
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(DatFormat.CSV, "csv")]
|
|
|
|
|
[InlineData(DatFormat.ClrMamePro, "dat")]
|
2025-04-14 11:02:20 -04:00
|
|
|
[InlineData(DatFormat.RomCenter, "dat")]
|
|
|
|
|
[InlineData(DatFormat.DOSCenter, "dat")]
|
2020-12-19 22:08:42 -08:00
|
|
|
[InlineData(DatFormat.SabreJSON, "json")]
|
2025-04-14 11:02:20 -04:00
|
|
|
[InlineData(DatFormat.RedumpMD2, "md2")]
|
|
|
|
|
[InlineData(DatFormat.RedumpMD4, "md4")]
|
|
|
|
|
[InlineData(DatFormat.RedumpMD5, "md5")]
|
|
|
|
|
[InlineData(DatFormat.RedumpSFV, "sfv")]
|
|
|
|
|
[InlineData(DatFormat.RedumpSHA1, "sha1")]
|
|
|
|
|
[InlineData(DatFormat.RedumpSHA256, "sha256")]
|
|
|
|
|
[InlineData(DatFormat.RedumpSHA384, "sha384")]
|
|
|
|
|
[InlineData(DatFormat.RedumpSHA512, "sha512")]
|
|
|
|
|
[InlineData(DatFormat.RedumpSpamSum, "spamsum")]
|
|
|
|
|
[InlineData(DatFormat.SSV, "ssv")]
|
|
|
|
|
[InlineData(DatFormat.TSV, "tsv")]
|
2020-12-19 22:08:42 -08:00
|
|
|
[InlineData(DatFormat.AttractMode, "txt")]
|
2025-04-14 11:02:20 -04:00
|
|
|
[InlineData(DatFormat.Listrom, "txt")]
|
|
|
|
|
[InlineData(DatFormat.MissFile, "txt")]
|
|
|
|
|
[InlineData(DatFormat.EverdriveSMDB, "txt")]
|
2020-12-19 22:08:42 -08:00
|
|
|
[InlineData(DatFormat.Logiqx, "xml")]
|
2025-04-14 11:02:20 -04:00
|
|
|
[InlineData(DatFormat.LogiqxDeprecated, "xml")]
|
|
|
|
|
[InlineData(DatFormat.SabreXML, "xml")]
|
|
|
|
|
[InlineData(DatFormat.SoftwareList, "xml")]
|
|
|
|
|
[InlineData(DatFormat.Listxml, "xml")]
|
|
|
|
|
[InlineData(DatFormat.OfflineList, "xml")]
|
|
|
|
|
[InlineData(DatFormat.OpenMSX, "xml")]
|
|
|
|
|
[InlineData(DatFormat.ArchiveDotOrg, "xml")]
|
|
|
|
|
public void CreateOutFileNames_SingleFormat(DatFormat datFormat, string extension)
|
2020-12-19 22:08:42 -08:00
|
|
|
{
|
|
|
|
|
// Create the empty DatHeader
|
2024-03-10 21:54:07 -04:00
|
|
|
var datHeader = new DatHeader();
|
2024-03-10 21:41:49 -04:00
|
|
|
datHeader.SetFieldValue<string?>(DatHeader.FileNameKey, "test.dat");
|
2024-03-10 21:54:07 -04:00
|
|
|
datHeader.SetFieldValue<DatFormat>(DatHeader.DatFormatKey, datFormat);
|
2020-12-19 22:08:42 -08:00
|
|
|
|
|
|
|
|
// Invoke the method
|
|
|
|
|
string outDir = "C:\\Test";
|
2025-01-29 13:25:36 -05:00
|
|
|
var actual = Writer.CreateOutFileNames(datHeader, outDir, overwrite: true);
|
2020-12-19 22:08:42 -08:00
|
|
|
|
|
|
|
|
// Check the result
|
2024-07-16 00:27:12 -04:00
|
|
|
string expected = $"{outDir}{System.IO.Path.DirectorySeparatorChar}test.{extension}";
|
2020-12-19 22:08:42 -08:00
|
|
|
Assert.Single(actual);
|
|
|
|
|
Assert.Equal(expected, actual[datFormat]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2025-04-14 11:02:20 -04:00
|
|
|
public void CreateOutFileNames_AllFormats()
|
2020-12-19 22:08:42 -08:00
|
|
|
{
|
|
|
|
|
// Create the empty DatHeader
|
2024-03-10 21:54:07 -04:00
|
|
|
var datHeader = new DatHeader();
|
2024-03-10 21:41:49 -04:00
|
|
|
datHeader.SetFieldValue<string?>(DatHeader.FileNameKey, "test.dat");
|
2024-03-10 21:54:07 -04:00
|
|
|
datHeader.SetFieldValue<DatFormat>(DatHeader.DatFormatKey, DatFormat.ALL);
|
2020-12-19 22:08:42 -08:00
|
|
|
|
|
|
|
|
// Invoke the method
|
|
|
|
|
string outDir = "C:\\Test";
|
2025-01-29 13:25:36 -05:00
|
|
|
var actual = Writer.CreateOutFileNames(datHeader, outDir, overwrite: true);
|
2020-12-19 22:08:42 -08:00
|
|
|
|
2025-04-14 11:02:20 -04:00
|
|
|
// Check the normalized results
|
2025-01-09 03:29:22 -05:00
|
|
|
Assert.Equal(28, actual.Count);
|
2025-04-14 11:02:20 -04:00
|
|
|
Assert.Equal("C:\\Test\\test.csv", actual[DatFormat.CSV].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.dat", actual[DatFormat.ClrMamePro].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.rc.dat", actual[DatFormat.RomCenter].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.dc.dat", actual[DatFormat.DOSCenter].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.json", actual[DatFormat.SabreJSON].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.md2", actual[DatFormat.RedumpMD2].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.md4", actual[DatFormat.RedumpMD4].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.md5", actual[DatFormat.RedumpMD5].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.sfv", actual[DatFormat.RedumpSFV].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.sha1", actual[DatFormat.RedumpSHA1].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.sha256", actual[DatFormat.RedumpSHA256].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.sha384", actual[DatFormat.RedumpSHA384].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.sha512", actual[DatFormat.RedumpSHA512].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.spamsum", actual[DatFormat.RedumpSpamSum].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.ssv", actual[DatFormat.SSV].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.tsv", actual[DatFormat.TSV].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.txt", actual[DatFormat.AttractMode].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.lr.txt", actual[DatFormat.Listrom].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.miss.txt", actual[DatFormat.MissFile].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.smdb.txt", actual[DatFormat.EverdriveSMDB].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.xml", actual[DatFormat.Logiqx].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.xml", actual[DatFormat.LogiqxDeprecated].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.sd.xml", actual[DatFormat.SabreXML].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.sl.xml", actual[DatFormat.SoftwareList].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.mame.xml", actual[DatFormat.Listxml].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.ol.xml", actual[DatFormat.OfflineList].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.msx.xml", actual[DatFormat.OpenMSX].Replace('/', '\\'));
|
|
|
|
|
Assert.Equal("C:\\Test\\test.ado.xml", actual[DatFormat.ArchiveDotOrg].Replace('/', '\\'));
|
2020-12-19 22:08:42 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|