mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Parser tests, part 4
This commit is contained in:
@@ -62,6 +62,23 @@ namespace SabreTools.Core.Tools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get a sanitized double from an input string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">String to get value from</param>
|
||||||
|
/// <returns>Value as a double?, if possible</returns>
|
||||||
|
public static double? CleanDouble(string input)
|
||||||
|
{
|
||||||
|
double? value = null;
|
||||||
|
if (input != null)
|
||||||
|
{
|
||||||
|
if (Double.TryParse(input, out double doubleValue))
|
||||||
|
value = doubleValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a sanitized size from an input string
|
/// Get a sanitized size from an input string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -537,6 +537,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
FlipX = reader.GetAttribute("flipx").AsYesNo(),
|
FlipX = reader.GetAttribute("flipx").AsYesNo(),
|
||||||
Width = Utilities.CleanLong(reader.GetAttribute("width")),
|
Width = Utilities.CleanLong(reader.GetAttribute("width")),
|
||||||
Height = Utilities.CleanLong(reader.GetAttribute("height")),
|
Height = Utilities.CleanLong(reader.GetAttribute("height")),
|
||||||
|
Refresh = Utilities.CleanDouble(reader.GetAttribute("refresh")),
|
||||||
PixClock = Utilities.CleanLong(reader.GetAttribute("pixclock")),
|
PixClock = Utilities.CleanLong(reader.GetAttribute("pixclock")),
|
||||||
HTotal = Utilities.CleanLong(reader.GetAttribute("htotal")),
|
HTotal = Utilities.CleanLong(reader.GetAttribute("htotal")),
|
||||||
HBEnd = Utilities.CleanLong(reader.GetAttribute("hbend")),
|
HBEnd = Utilities.CleanLong(reader.GetAttribute("hbend")),
|
||||||
@@ -552,13 +553,6 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Set the refresh
|
|
||||||
if (reader.GetAttribute("refresh") != null)
|
|
||||||
{
|
|
||||||
if (Double.TryParse(reader.GetAttribute("refresh"), out double refresh))
|
|
||||||
display.Refresh = refresh;
|
|
||||||
}
|
|
||||||
|
|
||||||
datItems.Add(display);
|
datItems.Add(display);
|
||||||
|
|
||||||
reader.Read();
|
reader.Read();
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
reader.ReadNextLine();
|
reader.ReadNextLine();
|
||||||
while (!reader.EndOfStream && reader.Section.ToLowerInvariant() == "credits")
|
do
|
||||||
{
|
{
|
||||||
// We don't care about whitespace, comments, or invalid
|
// We don't care about whitespace, comments, or invalid
|
||||||
if (reader.RowType != IniRowType.KeyValue)
|
if (reader.RowType != IniRowType.KeyValue)
|
||||||
@@ -163,7 +163,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
reader.ReadNextLine();
|
reader.ReadNextLine();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} while (!reader.EndOfStream && reader.Section.ToLowerInvariant() == "credits");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -177,7 +177,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
reader.ReadNextLine();
|
reader.ReadNextLine();
|
||||||
while (!reader.EndOfStream && reader.Section.ToLowerInvariant() == "dat")
|
do
|
||||||
{
|
{
|
||||||
// We don't care about whitespace, comments, or invalid
|
// We don't care about whitespace, comments, or invalid
|
||||||
if (reader.RowType != IniRowType.KeyValue)
|
if (reader.RowType != IniRowType.KeyValue)
|
||||||
@@ -227,7 +227,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
reader.ReadNextLine();
|
reader.ReadNextLine();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} while (!reader.EndOfStream && reader.Section.ToLowerInvariant() == "dat");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -241,7 +241,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
reader.ReadNextLine();
|
reader.ReadNextLine();
|
||||||
while (!reader.EndOfStream && reader.Section.ToLowerInvariant() == "emulator")
|
do
|
||||||
{
|
{
|
||||||
// We don't care about whitespace, comments, or invalid
|
// We don't care about whitespace, comments, or invalid
|
||||||
if (reader.RowType != IniRowType.KeyValue)
|
if (reader.RowType != IniRowType.KeyValue)
|
||||||
@@ -277,7 +277,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
reader.ReadNextLine();
|
reader.ReadNextLine();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} while (!reader.EndOfStream && reader.Section.ToLowerInvariant() == "emulator");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -293,7 +293,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
reader.ReadNextLine();
|
reader.ReadNextLine();
|
||||||
while (!reader.EndOfStream && reader.Section.ToLowerInvariant() == "games")
|
do
|
||||||
{
|
{
|
||||||
// We don't care about whitespace or comments
|
// We don't care about whitespace or comments
|
||||||
// We're keeping keyvalue in case a file has '=' in the row
|
// We're keeping keyvalue in case a file has '=' in the row
|
||||||
@@ -358,7 +358,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
ParseAddHelper(rom);
|
ParseAddHelper(rom);
|
||||||
|
|
||||||
reader.ReadNextLine();
|
reader.ReadNextLine();
|
||||||
}
|
} while (!reader.EndOfStream && reader.Section.ToLowerInvariant() == "games");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ namespace SabreTools.Test.DatTools
|
|||||||
[InlineData("test-logiqx.xml", DatFormat.Logiqx, 6)]
|
[InlineData("test-logiqx.xml", DatFormat.Logiqx, 6)]
|
||||||
//[InlineData(null, DatFormat.LogiqxDeprecated, 0)] // Not parsed separately
|
//[InlineData(null, DatFormat.LogiqxDeprecated, 0)] // Not parsed separately
|
||||||
//[InlineData(null, DatFormat.SoftwareList, 0)]
|
//[InlineData(null, DatFormat.SoftwareList, 0)]
|
||||||
//[InlineData(null, DatFormat.Listxml, 0)]
|
[InlineData("test-listxml.xml", DatFormat.Listxml, 20)]
|
||||||
//[InlineData(null, DatFormat.OfflineList, 0)]
|
//[InlineData(null, DatFormat.OfflineList, 0)]
|
||||||
//[InlineData(null, DatFormat.SabreXML, 0)]
|
//[InlineData(null, DatFormat.SabreXML, 0)]
|
||||||
[InlineData("test-openmsx.xml", DatFormat.OpenMSX, 3)]
|
[InlineData("test-openmsx.xml", DatFormat.OpenMSX, 3)]
|
||||||
[InlineData("test-cmp.dat", DatFormat.ClrMamePro, 6)]
|
[InlineData("test-cmp.dat", DatFormat.ClrMamePro, 6)]
|
||||||
//[InlineData(null, DatFormat.RomCenter, 0)]
|
[InlineData("test-romcenter.dat", DatFormat.RomCenter, 1)]
|
||||||
[InlineData("test-doscenter.dat", DatFormat.DOSCenter, 1)]
|
[InlineData("test-doscenter.dat", DatFormat.DOSCenter, 1)]
|
||||||
[InlineData("test-attractmode.txt", DatFormat.AttractMode, 1)]
|
[InlineData("test-attractmode.txt", DatFormat.AttractMode, 1)]
|
||||||
//[InlineData(null, DatFormat.MissFile, 0)] // Parsing is not supported
|
//[InlineData(null, DatFormat.MissFile, 0)] // Parsing is not supported
|
||||||
@@ -44,7 +44,7 @@ namespace SabreTools.Test.DatTools
|
|||||||
if (filename != null)
|
if (filename != null)
|
||||||
filename = Path.Combine(Environment.CurrentDirectory, "TestData", filename);
|
filename = Path.Combine(Environment.CurrentDirectory, "TestData", filename);
|
||||||
|
|
||||||
var datFile = Parser.CreateAndParse(filename);
|
var datFile = Parser.CreateAndParse(filename, throwOnError: true);
|
||||||
Assert.Equal(datFormat, datFile.Header.DatFormat);
|
Assert.Equal(datFormat, datFile.Header.DatFormat);
|
||||||
Assert.Equal(totalCount, datFile.Items.TotalCount);
|
Assert.Equal(totalCount, datFile.Items.TotalCount);
|
||||||
}
|
}
|
||||||
|
|||||||
49
SabreTools.Test/TestData/test-listxml.xml
Normal file
49
SabreTools.Test/TestData/test-listxml.xml
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Omitting DTD normally present here -->
|
||||||
|
|
||||||
|
<mame build="0.100" debug="yes" mameconfig="debug">
|
||||||
|
<machine name="game1" cloneof="game2" romof="game2" sampleof="genpin" sourcefile="blah.cpp" runnable="partial" isbios="no" isdevice="no" ismechanical="no">
|
||||||
|
<description>Game! (Version 1)</description>
|
||||||
|
<year>1980</year>
|
||||||
|
<manufacturer>Manufacturer</manufacturer>
|
||||||
|
<adjuster name="adjuster" default="yes">
|
||||||
|
<condition tag="tag" mask="mask" relation="eq" value="value" />
|
||||||
|
</adjuster>
|
||||||
|
<biosset name="biosset" description="description" default="yes" />
|
||||||
|
<chip name="cpu" tag="cpu" type="cpu" clock="100000" />
|
||||||
|
<condition tag="tag" mask="mask" relation="eq" value="value" />
|
||||||
|
<configuration name="configuration" tag="tag" mask="mask">
|
||||||
|
<condition tag="tag" mask="mask" relation="eq" value="value" />
|
||||||
|
<conflocation name="conflocation" number="1" inverted="no" />
|
||||||
|
<confsetting name="confsetting" value="value" default="yes" />
|
||||||
|
</configuration>
|
||||||
|
<device type="serial" tag="tag" fixed_image="abcd" mandatory="1" interface="serial">
|
||||||
|
<instance name="port_a" briefname="pa" />
|
||||||
|
<extension name=".123" />
|
||||||
|
</device>
|
||||||
|
<device_ref name="cport" />
|
||||||
|
<dipswitch name="dipswitch" tag="tag" mask="mask">
|
||||||
|
<condition tag="tag" mask="mask" relation="eq" value="value" />
|
||||||
|
<diplocation name="diplocation" number="1" inverted="no" />
|
||||||
|
<dipvalue name="dipvalue" value="value" default="yes" />
|
||||||
|
</dipswitch>
|
||||||
|
<disk name="disk" sha1="aa39a3ee5e6b4b0d3255bfef95601890afd80709" merge="disk2" region="USA" index="0" writable="no" status="good" optional="no" />
|
||||||
|
<display tag="tag" type="raster" rotate="0" flipx="no" width="1024" height="768" refresh="60.00" pixclock="10000" htotal="1092" hbend="1024" hbstart="0" vtotal="800" vbend="768" vbstart="0" />
|
||||||
|
<driver status="good" emulation="good" cocktail="good" savestate="supported" />
|
||||||
|
<feature type="camera" status="imperfect" overall="imperfect" />
|
||||||
|
<input service="yes" tilt="no" players="4" coins="2">
|
||||||
|
<control type="joy" player="1" buttons="6" reqbuttons="6" minimum="0" maximum="255" sensitivity="1" keydelta="2" reverse="no" ways="8" ways2="2" ways3="2" />
|
||||||
|
</input>
|
||||||
|
<port tag="tag">
|
||||||
|
<analog mask="mask" />
|
||||||
|
</port>
|
||||||
|
<ramoption name="ramoption" default="yes">1024KB</ramoption>
|
||||||
|
<rom name="rom.bin" bios="bios" size="1024" crc="deadbeef" sha1="ca39a3ee5e6b4b0d3255bfef95601890afd80709" merge="rom2.bin" region="USA" offset="0x0000" status="good" optional="no" />
|
||||||
|
<sample name="generic" />
|
||||||
|
<slot name="slot">
|
||||||
|
<slotoption name="slotoption" devname="devname" default="yes" />
|
||||||
|
</slot>
|
||||||
|
<softwarelist name="softwarelist" status="original" filter="filter" />
|
||||||
|
<sound channels="16" />
|
||||||
|
</machine>
|
||||||
|
</mame>
|
||||||
@@ -27,4 +27,5 @@ The softwaredb.xml file contains information about rom mapper types
|
|||||||
<dump><rom><hash>7acd00c9053fbf7f7d698485759d170a483b123d</hash><start>0x8000</start><type>ASCII8</type><remark>Comment Here</remark></rom></dump>
|
<dump><rom><hash>7acd00c9053fbf7f7d698485759d170a483b123d</hash><start>0x8000</start><type>ASCII8</type><remark>Comment Here</remark></rom></dump>
|
||||||
<dump><megarom><hash>da58f56d4b1660bc36d74bfb29776ef8ec61a831</hash><start>0x4000</start><type>ASCII16</type><remark>Comment Too</remark></megarom></dump>
|
<dump><megarom><hash>da58f56d4b1660bc36d74bfb29776ef8ec61a831</hash><start>0x4000</start><type>ASCII16</type><remark>Comment Too</remark></megarom></dump>
|
||||||
<dump><original value="true">Good</original><boot>LOAD(8)</boot><sccpluscart><type>KonamiSCC</type><hash>afb1aef44a67cf7c9232f8a1c8587c66dd820caa</hash><remark>Comment Three</remark></sccpluscart></dump>
|
<dump><original value="true">Good</original><boot>LOAD(8)</boot><sccpluscart><type>KonamiSCC</type><hash>afb1aef44a67cf7c9232f8a1c8587c66dd820caa</hash><remark>Comment Three</remark></sccpluscart></dump>
|
||||||
</software>
|
</software>
|
||||||
|
</softwaredb>
|
||||||
21
SabreTools.Test/TestData/test-romcenter.dat
Normal file
21
SabreTools.Test/TestData/test-romcenter.dat
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
[CREDITS]
|
||||||
|
author=Unknown
|
||||||
|
version=1.0
|
||||||
|
email=email@email.email
|
||||||
|
homepage=localhost
|
||||||
|
url=127.0.0.1
|
||||||
|
date=1900-01-01
|
||||||
|
comment=Not real data, sorry
|
||||||
|
|
||||||
|
[DAT]
|
||||||
|
version=2.50
|
||||||
|
plugin=Arcade
|
||||||
|
split=0
|
||||||
|
merge=0
|
||||||
|
|
||||||
|
[EMULATOR]
|
||||||
|
refname=Internal DAT Name
|
||||||
|
version=Internal DAT Name
|
||||||
|
|
||||||
|
[GAMES]
|
||||||
|
¬game2¬Game! (Version 2)¬game1¬Game! (Version 1)¬rom.bin¬deadbeef¬1024¬game2¬rom2.bin¬
|
||||||
Reference in New Issue
Block a user