Update Listxml deserialization test, fix issues

This commit is contained in:
Matt Nadareski
2023-07-14 11:09:57 -04:00
parent bda3315c7a
commit 4dc0185629
13 changed files with 283942 additions and 134 deletions

View File

@@ -16,6 +16,10 @@ namespace SabreTools.Models.Listxml
[XmlAttribute("type")]
public string Type { get; set; }
/// <remarks>Only present in older versions</remarks>
[XmlAttribute("soundonly")]
public string SoundOnly { get; set; }
[XmlAttribute("clock")]
public string? Clock { get; set; }

View File

@@ -9,6 +9,10 @@ namespace SabreTools.Models.Listxml
[XmlAttribute("name")]
public string Name { get; set; }
/// <remarks>Only present in older versions</remarks>
[XmlAttribute("md5")]
public string? MD5 { get; set; }
[XmlAttribute("sha1")]
public string? SHA1 { get; set; }

View File

@@ -6,10 +6,22 @@ namespace SabreTools.Models.Listxml
[XmlRoot("driver")]
public class Driver
{
/// <remarks>(good|imperfect|preliminary)</remarks>
/// <remarks>(good|imperfect|preliminary), (good|preliminary|test) in older versions</remarks>
[XmlAttribute("status")]
public string Status { get; set; }
/// <remarks>(good|imperfect|preliminary), Only present in older versions</remarks>
[XmlAttribute("color")]
public string Color { get; set; }
/// <remarks>(good|imperfect|preliminary), Only present in older versions</remarks>
[XmlAttribute("sound")]
public string Sound { get; set; }
/// <remarks>Only present in older versions</remarks>
[XmlAttribute("palettesize")]
public string PaletteSize { get; set; }
/// <remarks>(good|imperfect|preliminary)</remarks>
[XmlAttribute("emulation")]
public string Emulation { get; set; }

View File

@@ -0,0 +1,12 @@
using System.Xml.Serialization;
namespace SabreTools.Models.Listxml
{
[XmlRoot("game")]
public class Game : GameBase
{
/// <remarks>Appears after Manufacturer</remarks>
[XmlElement("history")]
public string? History { get; set; }
}
}

View File

@@ -0,0 +1,109 @@
using System.Xml;
using System.Xml.Serialization;
namespace SabreTools.Models.Listxml
{
/// <summary>
/// Base class to unify the various game-like types
/// </summary>
public abstract class GameBase
{
[XmlAttribute("name")]
public string Name { get; set; }
/// <remarks>(yes|no) "no"</remarks>
[XmlAttribute("runnable")]
public string? Runnable { get; set; }
[XmlAttribute("cloneof")]
public string? CloneOf { get; set; }
[XmlAttribute("romof")]
public string? RomOf { get; set; }
[XmlAttribute("sampleof")]
public string? SampleOf { get; set; }
[XmlElement("description")]
public string Description { get; set; }
[XmlElement("year")]
public string? Year { get; set; }
[XmlElement("manufacturer")]
public string? Manufacturer { get; set; }
[XmlElement("biosset")]
public BiosSet[]? BiosSet { get; set; }
[XmlElement("rom")]
public Rom[]? Rom { get; set; }
[XmlElement("disk")]
public Disk[]? Disk { get; set; }
[XmlElement("device_ref")]
public DeviceRef[]? DeviceRef { get; set; }
[XmlElement("sample")]
public Sample[]? Sample { get; set; }
[XmlElement("chip")]
public Chip[]? Chip { get; set; }
[XmlElement("display")]
public Display[]? Display { get; set; }
/// <remarks>Only present in older versions</remarks>
[XmlElement("video")]
public Video[]? Video { get; set; }
[XmlElement("sound")]
public Sound? Sound { get; set; }
[XmlElement("input")]
public Input? Input { get; set; }
[XmlElement("dipswitch")]
public DipSwitch[]? DipSwitch { get; set; }
[XmlElement("configuration")]
public Configuration[]? Configuration { get; set; }
[XmlElement("port")]
public Port[]? Port { get; set; }
[XmlElement("adjuster")]
public Adjuster[]? Adjuster { get; set; }
[XmlElement("driver")]
public Driver? Driver { get; set; }
[XmlElement("feature")]
public Feature[]? Feature { get; set; }
[XmlElement("device")]
public Device[]? Device { get; set; }
[XmlElement("slot")]
public Slot[]? Slot { get; set; }
[XmlElement("softwarelist")]
public SoftwareList[]? SoftwareList { get; set; }
[XmlElement("ramoption")]
public RamOption[]? RamOption { get; set; }
#region DO NOT USE IN PRODUCTION
/// <remarks>Should be empty</remarks>
[XmlAnyAttribute]
public XmlAttribute[]? ADDITIONAL_ATTRIBUTES { get; set; }
/// <remarks>Should be empty</remarks>
[XmlAnyElement]
public object[]? ADDITIONAL_ELEMENTS { get; set; }
#endregion
}
}

View File

@@ -18,11 +18,18 @@ namespace SabreTools.Models.Listxml
[XmlAttribute("players")]
public string Players { get; set; }
/// <remarks>Only present in older versions</remarks>
[XmlAttribute("control")]
public string? ControlAttr { get; set; }
/// <remarks>Only present in older versions, Numeric?</remarks>
[XmlAttribute("buttons")]
public string Buttons { get; set; }
/// <remarks>Numeric?</remarks>
[XmlAttribute("coins")]
public string? Coins { get; set; }
/// <remarks>Numeric?</remarks>
[XmlElement("control")]
public Control[]? Control { get; set; }

View File

@@ -1,118 +1,25 @@
using System.Xml;
using System.Xml.Serialization;
namespace SabreTools.Models.Listxml
{
[XmlRoot("machine")]
public class Machine
public class Machine : GameBase
{
[XmlAttribute("name")]
public string Name { get; set; }
/// <remarks>Appears after Name</remarks>
[XmlAttribute("sourcefile")]
public string? SourceFile { get; set; }
/// <remarks>(yes|no) "no"</remarks>
/// <remarks>(yes|no) "no", Appears after SourceFile</remarks>
[XmlAttribute("isbios")]
public string? IsBios { get; set; }
/// <remarks>(yes|no) "no"</remarks>
/// <remarks>(yes|no) "no", Appears after IsBios</remarks>
[XmlAttribute("isdevice")]
public string? IsDevice { get; set; }
/// <remarks>(yes|no) "no"</remarks>
/// <remarks>(yes|no) "no", Appears after IsDevice</remarks>
[XmlAttribute("ismechanical")]
public string? IsMechanical { get; set; }
/// <remarks>(yes|no) "no"</remarks>
[XmlAttribute("runnable")]
public string? Runnable { get; set; }
[XmlAttribute("cloneof")]
public string? CloneOf { get; set; }
[XmlAttribute("romof")]
public string? RomOf { get; set; }
[XmlAttribute("sampleof")]
public string? SampleOf { get; set; }
[XmlElement("description")]
public string Description { get; set; }
[XmlElement("year")]
public string? Year { get; set; }
[XmlElement("manufacturer")]
public string? Manufacturer { get; set; }
[XmlElement("biosset")]
public BiosSet[]? BiosSet { get; set; }
[XmlElement("rom")]
public Rom[]? Rom { get; set; }
[XmlElement("disk")]
public Disk[]? Disk { get; set; }
[XmlElement("device_ref")]
public DeviceRef[]? DeviceRef { get; set; }
[XmlElement("sample")]
public Sample[]? Sample { get; set; }
[XmlElement("chip")]
public Chip[]? Chip { get; set; }
[XmlElement("display")]
public Display[]? Display { get; set; }
[XmlElement("sound")]
public Sound? Sound { get; set; }
[XmlElement("input")]
public Input? Input { get; set; }
[XmlElement("dipswitch")]
public DipSwitch[]? DipSwitch { get; set; }
[XmlElement("configuration")]
public Configuration[]? Configuration { get; set; }
[XmlElement("port")]
public Port[]? Port { get; set; }
[XmlElement("adjuster")]
public Adjuster[]? Adjuster { get; set; }
[XmlElement("driver")]
public Driver? Driver { get; set; }
[XmlElement("feature")]
public Feature[]? Feature { get; set; }
[XmlElement("device")]
public Device[]? Device { get; set; }
[XmlElement("slot")]
public Slot[]? Slot { get; set; }
[XmlElement("softwarelist")]
public SoftwareList[]? SoftwareList { get; set; }
[XmlElement("ramoption")]
public RamOption[]? RamOption { get; set; }
#region DO NOT USE IN PRODUCTION
/// <remarks>Should be empty</remarks>
[XmlAnyAttribute]
public XmlAttribute[]? ADDITIONAL_ATTRIBUTES { get; set; }
/// <remarks>Should be empty</remarks>
[XmlAnyElement]
public object[]? ADDITIONAL_ELEMENTS { get; set; }
#endregion
}
}

View File

@@ -16,8 +16,9 @@ namespace SabreTools.Models.Listxml
[XmlAttribute("mameconfig")]
public string MameConfig { get; set; }
[XmlElement("machine")]
public Machine[] Machine { get; set; }
[XmlElement("machine", typeof(Machine))]
[XmlElement("game", typeof(Game))]
public GameBase[] Game { get; set; }
#region DO NOT USE IN PRODUCTION

View File

@@ -39,6 +39,14 @@ namespace SabreTools.Models.Listxml
[XmlAttribute("optional")]
public string? Optional { get; set; }
/// <remarks>(yes|no) "no", Only present in older versions</remarks>
[XmlAttribute("dispose")]
public string? Dispose { get; set; }
/// <remarks>(yes|no) "no", Only present in older versions</remarks>
[XmlAttribute("soundonly")]
public string? SoundOnly { get; set; }
#region DO NOT USE IN PRODUCTION
/// <remarks>Should be empty</remarks>

View File

@@ -0,0 +1,49 @@
using System.Xml;
using System.Xml.Serialization;
namespace SabreTools.Models.Listxml
{
[XmlRoot("video")]
public class Video
{
/// <remarks>(raster|vector)</remarks>
[XmlAttribute("screen")]
public string Screen { get; set; }
/// <remarks>(vertical|horizontal)</remarks>
[XmlAttribute("orientation")]
public string Orientation { get; set; }
/// <remarks>Numeric?</remarks>
[XmlAttribute("width")]
public string? Width { get; set; }
/// <remarks>Numeric?</remarks>
[XmlAttribute("height")]
public string? Height { get; set; }
/// <remarks>Numeric?</remarks>
[XmlAttribute("aspectx")]
public string? AspectX { get; set; }
/// <remarks>Numeric?</remarks>
[XmlAttribute("aspecty")]
public string? AspectY { get; set; }
/// <remarks>Numeric?</remarks>
[XmlAttribute("refresh")]
public string? Refresh { get; set; }
#region DO NOT USE IN PRODUCTION
/// <remarks>Should be empty</remarks>
[XmlAnyAttribute]
public XmlAttribute[]? ADDITIONAL_ATTRIBUTES { get; set; }
/// <remarks>Should be empty</remarks>
[XmlAnyElement]
public object[]? ADDITIONAL_ELEMENTS { get; set; }
#endregion
}
}

View File

@@ -224,7 +224,8 @@ namespace SabreTools.Test.Parser
}
[Theory]
[InlineData("test-listxml-files.xml.gz", 45861)]
[InlineData("test-listxml-files1.xml.gz", 45861)]
[InlineData("test-listxml-files2.xml", 3998)]
public void ListxmlDeserializeTest(string path, long count)
{
// Open the file for reading
@@ -234,78 +235,84 @@ namespace SabreTools.Test.Parser
var dat = Serialization.Listxml.Deserialize(filename);
// Validate the values
Assert.NotNull(dat?.Machine);
Assert.Equal(count, dat.Machine.Length);
Assert.NotNull(dat?.Game);
Assert.Equal(count, dat.Game.Length);
// Validate we're not missing any attributes or elements
Assert.Null(dat.ADDITIONAL_ATTRIBUTES);
Assert.Null(dat.ADDITIONAL_ELEMENTS);
foreach (var machine in dat.Machine)
foreach (var game in dat.Game)
{
Assert.Null(machine.ADDITIONAL_ATTRIBUTES);
Assert.Null(machine.ADDITIONAL_ELEMENTS);
Assert.Null(game.ADDITIONAL_ATTRIBUTES);
Assert.Null(game.ADDITIONAL_ELEMENTS);
foreach (var biosset in machine.BiosSet ?? Array.Empty<Models.Listxml.BiosSet>())
foreach (var biosset in game.BiosSet ?? Array.Empty<Models.Listxml.BiosSet>())
{
Assert.Null(biosset.ADDITIONAL_ATTRIBUTES);
Assert.Null(biosset.ADDITIONAL_ELEMENTS);
}
foreach (var rom in machine.Rom ?? Array.Empty<Models.Listxml.Rom>())
foreach (var rom in game.Rom ?? Array.Empty<Models.Listxml.Rom>())
{
Assert.Null(rom.ADDITIONAL_ATTRIBUTES);
Assert.Null(rom.ADDITIONAL_ELEMENTS);
}
foreach (var disk in machine.Disk ?? Array.Empty<Models.Listxml.Disk>())
foreach (var disk in game.Disk ?? Array.Empty<Models.Listxml.Disk>())
{
Assert.Null(disk.ADDITIONAL_ATTRIBUTES);
Assert.Null(disk.ADDITIONAL_ELEMENTS);
}
foreach (var deviceRef in machine.DeviceRef ?? Array.Empty<Models.Listxml.DeviceRef>())
foreach (var deviceRef in game.DeviceRef ?? Array.Empty<Models.Listxml.DeviceRef>())
{
Assert.Null(deviceRef.ADDITIONAL_ATTRIBUTES);
Assert.Null(deviceRef.ADDITIONAL_ELEMENTS);
}
foreach (var sample in machine.Sample ?? Array.Empty<Models.Listxml.Sample>())
foreach (var sample in game.Sample ?? Array.Empty<Models.Listxml.Sample>())
{
Assert.Null(sample.ADDITIONAL_ATTRIBUTES);
Assert.Null(sample.ADDITIONAL_ELEMENTS);
}
foreach (var chip in machine.Chip ?? Array.Empty<Models.Listxml.Chip>())
foreach (var chip in game.Chip ?? Array.Empty<Models.Listxml.Chip>())
{
Assert.Null(chip.ADDITIONAL_ATTRIBUTES);
Assert.Null(chip.ADDITIONAL_ELEMENTS);
}
foreach (var display in machine.Display ?? Array.Empty<Models.Listxml.Display>())
foreach (var display in game.Display ?? Array.Empty<Models.Listxml.Display>())
{
Assert.Null(display.ADDITIONAL_ATTRIBUTES);
Assert.Null(display.ADDITIONAL_ELEMENTS);
}
if (machine.Sound != null)
foreach (var video in game.Video ?? Array.Empty<Models.Listxml.Video>())
{
Assert.Null(machine.Sound.ADDITIONAL_ATTRIBUTES);
Assert.Null(machine.Sound.ADDITIONAL_ELEMENTS);
Assert.Null(video.ADDITIONAL_ATTRIBUTES);
Assert.Null(video.ADDITIONAL_ELEMENTS);
}
if (machine.Input != null)
if (game.Sound != null)
{
Assert.Null(machine.Input.ADDITIONAL_ATTRIBUTES);
Assert.Null(machine.Input.ADDITIONAL_ELEMENTS);
Assert.Null(game.Sound.ADDITIONAL_ATTRIBUTES);
Assert.Null(game.Sound.ADDITIONAL_ELEMENTS);
}
foreach (var control in machine.Input.Control ?? Array.Empty<Models.Listxml.Control>())
if (game.Input != null)
{
Assert.Null(game.Input.ADDITIONAL_ATTRIBUTES);
Assert.Null(game.Input.ADDITIONAL_ELEMENTS);
foreach (var control in game.Input.Control ?? Array.Empty<Models.Listxml.Control>())
{
Assert.Null(control.ADDITIONAL_ATTRIBUTES);
Assert.Null(control.ADDITIONAL_ELEMENTS);
}
}
foreach (var dipswitch in machine.DipSwitch ?? Array.Empty<Models.Listxml.DipSwitch>())
foreach (var dipswitch in game.DipSwitch ?? Array.Empty<Models.Listxml.DipSwitch>())
{
Assert.Null(dipswitch.ADDITIONAL_ATTRIBUTES);
Assert.Null(dipswitch.ADDITIONAL_ELEMENTS);
@@ -335,7 +342,7 @@ namespace SabreTools.Test.Parser
}
}
foreach (var configuration in machine.Configuration ?? Array.Empty<Models.Listxml.Configuration>())
foreach (var configuration in game.Configuration ?? Array.Empty<Models.Listxml.Configuration>())
{
Assert.Null(configuration.ADDITIONAL_ATTRIBUTES);
Assert.Null(configuration.ADDITIONAL_ELEMENTS);
@@ -365,7 +372,7 @@ namespace SabreTools.Test.Parser
}
}
foreach (var port in machine.Port ?? Array.Empty<Models.Listxml.Port>())
foreach (var port in game.Port ?? Array.Empty<Models.Listxml.Port>())
{
Assert.Null(port.ADDITIONAL_ATTRIBUTES);
Assert.Null(port.ADDITIONAL_ELEMENTS);
@@ -377,7 +384,7 @@ namespace SabreTools.Test.Parser
}
}
foreach (var adjuster in machine.Adjuster ?? Array.Empty<Models.Listxml.Adjuster>())
foreach (var adjuster in game.Adjuster ?? Array.Empty<Models.Listxml.Adjuster>())
{
Assert.Null(adjuster.ADDITIONAL_ATTRIBUTES);
Assert.Null(adjuster.ADDITIONAL_ELEMENTS);
@@ -389,19 +396,19 @@ namespace SabreTools.Test.Parser
}
}
if (machine.Driver != null)
if (game.Driver != null)
{
Assert.Null(machine.Driver.ADDITIONAL_ATTRIBUTES);
Assert.Null(machine.Driver.ADDITIONAL_ELEMENTS);
Assert.Null(game.Driver.ADDITIONAL_ATTRIBUTES);
Assert.Null(game.Driver.ADDITIONAL_ELEMENTS);
}
foreach (var feature in machine.Feature ?? Array.Empty<Models.Listxml.Feature>())
foreach (var feature in game.Feature ?? Array.Empty<Models.Listxml.Feature>())
{
Assert.Null(feature.ADDITIONAL_ATTRIBUTES);
Assert.Null(feature.ADDITIONAL_ELEMENTS);
}
foreach (var device in machine.Device ?? Array.Empty<Models.Listxml.Device>())
foreach (var device in game.Device ?? Array.Empty<Models.Listxml.Device>())
{
Assert.Null(device.ADDITIONAL_ATTRIBUTES);
Assert.Null(device.ADDITIONAL_ELEMENTS);
@@ -419,7 +426,7 @@ namespace SabreTools.Test.Parser
}
}
foreach (var slot in machine.Slot ?? Array.Empty<Models.Listxml.Slot>())
foreach (var slot in game.Slot ?? Array.Empty<Models.Listxml.Slot>())
{
Assert.Null(slot.ADDITIONAL_ATTRIBUTES);
Assert.Null(slot.ADDITIONAL_ELEMENTS);
@@ -431,13 +438,13 @@ namespace SabreTools.Test.Parser
}
}
foreach (var softwarelist in machine.SoftwareList ?? Array.Empty<Models.Listxml.SoftwareList>())
foreach (var softwarelist in game.SoftwareList ?? Array.Empty<Models.Listxml.SoftwareList>())
{
Assert.Null(softwarelist.ADDITIONAL_ATTRIBUTES);
Assert.Null(softwarelist.ADDITIONAL_ELEMENTS);
}
foreach (var ramoption in machine.RamOption ?? Array.Empty<Models.Listxml.RamOption>())
foreach (var ramoption in game.RamOption ?? Array.Empty<Models.Listxml.RamOption>())
{
Assert.Null(ramoption.ADDITIONAL_ATTRIBUTES);
Assert.Null(ramoption.ADDITIONAL_ELEMENTS);

File diff suppressed because it is too large Load Diff