diff --git a/CHANGELIST.md b/CHANGELIST.md index f187393b..a1eb0d74 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -32,6 +32,7 @@ - Update to DIC 20211101 - Add protection sanitization for StarForce - Trim filenames for DVD protection from DIC +- Fill out internal tests around Redump library ### 2.1 (2021-07-22) - Enum, no more diff --git a/MPF.Test/RedumpLib/ExtensionsTests.cs b/MPF.Test/RedumpLib/ExtensionsTests.cs index a83653e2..e6122b54 100644 --- a/MPF.Test/RedumpLib/ExtensionsTests.cs +++ b/MPF.Test/RedumpLib/ExtensionsTests.cs @@ -360,7 +360,7 @@ namespace MPF.Test.RedumpLib /// /// Check that every Region has a long name provided /// - /// Region value to check + /// Region value to check /// True to expect a null value, false otherwise [Theory] [MemberData(nameof(GenerateRegionTestData))] @@ -407,5 +407,154 @@ namespace MPF.Test.RedumpLib } #endregion + + #region System + + /// + /// RedumpSystem values that are considered markers and not real systems + /// + private static readonly RedumpSystem?[] _markerSystemTypes = new RedumpSystem?[] + { + RedumpSystem.MarkerArcadeEnd, + RedumpSystem.MarkerComputerEnd, + RedumpSystem.MarkerDiscBasedConsoleEnd, + RedumpSystem.MarkerOtherEnd, + }; + + /// + /// Check that every RedumpSystem has a long name provided + /// + /// RedumpSystem value to check + /// True to expect a null value, false otherwise + [Theory] + [MemberData(nameof(GenerateRedumpSystemTestData))] + public void RedumpSystemLongNameTest(RedumpSystem? redumpSystem, bool expectNull) + { + string actual = redumpSystem.LongName(); + + if (expectNull) + Assert.Null(actual); + else + Assert.NotNull(actual); + } + + // TODO: Re-enable the following test once non-Redump systems are accounted for + + /// + /// Check that every RedumpSystem has a short name provided + /// + /// RedumpSystem value to check + /// True to expect a null value, false otherwise + //[Theory] + //[MemberData(nameof(GenerateRedumpSystemTestData))] + //public void RedumpSystemShortNameTest(RedumpSystem? redumpSystem, bool expectNull) + //{ + // string actual = redumpSystem.ShortName(); + + // if (expectNull) + // Assert.Null(actual); + // else + // Assert.NotNull(actual); + //} + + // TODO: Test the other attributes as well + // Most are bool checks so they're not as interesting to have unit tests around + // SystemCategory always returns something as well, so is it worth testing? + + /// + /// Generate a test set of RedumpSystem values + /// + /// MemberData-compatible list of RedumpSystem values + public static List GenerateRedumpSystemTestData() + { + var testData = new List() { new object[] { null, true } }; + foreach (RedumpSystem? redumpSystem in Enum.GetValues(typeof(RedumpSystem))) + { + // We want to skip all markers for this + if (_markerSystemTypes.Contains(redumpSystem)) + continue; + + testData.Add(new object[] { redumpSystem, false }); + } + + return testData; + } + + #endregion + + #region System Category + + /// + /// Check that every SystemCategory has a long name provided + /// + /// SystemCategory value to check + /// True to expect a null value, false otherwise + [Theory] + [MemberData(nameof(GenerateSystemCategoryTestData))] + public void SystemCategoryLongNameTest(SystemCategory? systemCategory, bool expectNull) + { + string actual = systemCategory.LongName(); + + if (expectNull) + Assert.Null(actual); + else + Assert.NotNull(actual); + } + + /// + /// Generate a test set of SystemCategory values + /// + /// MemberData-compatible list of SystemCategory values + public static List GenerateSystemCategoryTestData() + { + var testData = new List() { new object[] { null, true } }; + foreach (SystemCategory? systemCategory in Enum.GetValues(typeof(SystemCategory))) + { + if (systemCategory == SystemCategory.NONE) + testData.Add(new object[] { systemCategory, true }); + else + testData.Add(new object[] { systemCategory, false }); + } + + return testData; + } + + #endregion + + #region Yes/No + + /// + /// Check that every YesNo has a long name provided + /// + /// YesNo value to check + /// True to expect a null value, false otherwise + [Theory] + [MemberData(nameof(GenerateYesNoTestData))] + public void YesNoLongNameTest(YesNo? yesNo, bool expectNull) + { + string actual = yesNo.LongName(); + + if (expectNull) + Assert.Null(actual); + else + Assert.NotNull(actual); + } + + /// + /// Generate a test set of YesNo values + /// + /// MemberData-compatible list of YesNo values + public static List GenerateYesNoTestData() + { + var testData = new List() { new object[] { null, false } }; + foreach (YesNo? yesNo in Enum.GetValues(typeof(YesNo))) + { + testData.Add(new object[] { yesNo, false }); + } + + return testData; + } + + #endregion } } diff --git a/RedumpLib/Converters/YesNoConverter.cs b/RedumpLib/Converters/YesNoConverter.cs index 001eb29c..a5ab3cbd 100644 --- a/RedumpLib/Converters/YesNoConverter.cs +++ b/RedumpLib/Converters/YesNoConverter.cs @@ -8,16 +8,16 @@ namespace RedumpLib.Converters /// /// Serialize YesNo enum values /// - public class YesNoConverter : JsonConverter + public class YesNoConverter : JsonConverter { public override bool CanRead { get { return false; } } - public override YesNo ReadJson(JsonReader reader, Type objectType, YesNo existingValue, bool hasExistingValue, JsonSerializer serializer) + public override YesNo? ReadJson(JsonReader reader, Type objectType, YesNo? existingValue, bool hasExistingValue, JsonSerializer serializer) { throw new NotImplementedException(); } - public override void WriteJson(JsonWriter writer, YesNo value, JsonSerializer serializer) + public override void WriteJson(JsonWriter writer, YesNo? value, JsonSerializer serializer) { JToken t = JToken.FromObject(value.LongName() ?? string.Empty); t.WriteTo(writer); diff --git a/RedumpLib/Data/Extensions.cs b/RedumpLib/Data/Extensions.cs index 2f2169de..3f510133 100644 --- a/RedumpLib/Data/Extensions.cs +++ b/RedumpLib/Data/Extensions.cs @@ -2138,7 +2138,7 @@ namespace RedumpLib.Data /// /// /// - public static string LongName(this YesNo yesno) => AttributeHelper.GetAttribute(yesno)?.LongName ?? "Yes/No"; + public static string LongName(this YesNo? yesno) => AttributeHelper.GetAttribute(yesno)?.LongName ?? "Yes/No"; /// /// Get the YesNo enum value for a given string diff --git a/RedumpLib/Data/SubmissionInfo.cs b/RedumpLib/Data/SubmissionInfo.cs index bac1d0e0..9fd749d2 100644 --- a/RedumpLib/Data/SubmissionInfo.cs +++ b/RedumpLib/Data/SubmissionInfo.cs @@ -296,7 +296,7 @@ namespace RedumpLib.Data { [JsonProperty(PropertyName = "d_edc", NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(YesNoConverter))] - public YesNo EDC { get; set; } + public YesNo? EDC { get; set; } public object Clone() { @@ -376,11 +376,11 @@ namespace RedumpLib.Data { [JsonProperty(PropertyName = "d_protection_a", NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(YesNoConverter))] - public YesNo AntiModchip { get; set; } + public YesNo? AntiModchip { get; set; } [JsonProperty(PropertyName = "d_protection_1", NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(YesNoConverter))] - public YesNo LibCrypt { get; set; } + public YesNo? LibCrypt { get; set; } [JsonProperty(PropertyName = "d_libcrypt", NullValueHandling = NullValueHandling.Ignore)] public string LibCryptData { get; set; }