diff --git a/CHANGELIST.md b/CHANGELIST.md index f677b3b6..cf2aae58 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -14,6 +14,7 @@ - Fix failing XBC test - Perform better path emptiness checks - Add tests around UIC helpers +- Add tests around PS3 CFW helpers ### 3.2.4 (2024-11-24) diff --git a/MPF.Processors.Test/PS3CFWTests.cs b/MPF.Processors.Test/PS3CFWTests.cs index b0a5c6a6..dce38bd8 100644 --- a/MPF.Processors.Test/PS3CFWTests.cs +++ b/MPF.Processors.Test/PS3CFWTests.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using SabreTools.Models.Logiqx; using SabreTools.RedumpLib.Data; using Xunit; @@ -131,5 +132,71 @@ namespace MPF.Processors.Test } #endregion + + #region GeneratePS3CFWDatafile + + [Fact] + public void GeneratePS3CFWDatafile_Empty_Null() + { + string iso = string.Empty; + Datafile? actual = PS3CFW.GeneratePS3CFWDatafile(iso); + Assert.Null(actual); + } + + [Fact] + public void GeneratePS3CFWDatafile_Invalid_Null() + { + string iso = "INVALID"; + Datafile? actual = PS3CFW.GeneratePS3CFWDatafile(iso); + Assert.Null(actual); + } + + [Fact] + public void GeneratePS3CFWDatafile_Valid_Filled() + { + string iso = Path.Combine(Environment.CurrentDirectory, "TestData", "PS3CFW", "BluRay", "test.iso"); + var actual = PS3CFW.GeneratePS3CFWDatafile(iso); + + Assert.NotNull(actual); + Assert.NotNull(actual.Game); + var game = Assert.Single(actual.Game); + Assert.NotNull(game.Rom); + var rom = Assert.Single(game.Rom); + Assert.Equal("9", rom.Size); + Assert.Equal("560b9f59", rom.CRC); + Assert.Equal("edbb6676247e65c2245dd4883ed9fc24", rom.MD5); + Assert.Equal("1b33ad54d78085be5ecb1cf1b3e9da821e708075", rom.SHA1); + } + + #endregion + + #region GetCFWBasePath + + [Fact] + public void GetCFWBasePath_Empty_Null() + { + string iso = string.Empty; + string? actual = PS3CFW.GetCFWBasePath(iso); + Assert.Null(actual); + } + + [Fact] + public void GetCFWBasePath_Invalid_Null() + { + string iso = "INVALID"; + string? actual = PS3CFW.GetCFWBasePath(iso); + Assert.Null(actual); + } + + [Fact] + public void GetCFWBasePath_Valid_Filled() + { + string iso = Path.Combine(Environment.CurrentDirectory, "TestData", "PS3CFW", "BluRay", "test.iso"); + string? actual = PS3CFW.GetCFWBasePath(iso); + + Assert.NotNull(actual); + } + + #endregion } } \ No newline at end of file diff --git a/MPF.Processors/PS3CFW.cs b/MPF.Processors/PS3CFW.cs index 456fed90..55e6a8b9 100644 --- a/MPF.Processors/PS3CFW.cs +++ b/MPF.Processors/PS3CFW.cs @@ -102,10 +102,10 @@ namespace MPF.Processors /// /// Path to ISO file /// - private static Datafile? GeneratePS3CFWDatafile(string iso) + internal static Datafile? GeneratePS3CFWDatafile(string iso) { - // If the ISO file doesn't exist, we can't get info from it - if (!File.Exists(iso)) + // If the ISO file doesn't exist + if (string.IsNullOrEmpty(iso) || !File.Exists(iso)) return null; try @@ -135,17 +135,27 @@ namespace MPF.Processors /// /// Path to ISO file /// Base filename, null if not found - private string? GetCFWBasePath(string iso) + internal static string? GetCFWBasePath(string iso) { - string? dir = Path.GetDirectoryName(iso); - dir ??= "."; - - string[] files = Directory.GetFiles(dir, "*.getkey.log"); - - if (files.Length != 1) + // If the ISO file doesn't exist + if (string.IsNullOrEmpty(iso) || !File.Exists(iso)) return null; - return files[0].Substring(0, files[0].Length - 11); + try + { + string dir = Path.GetDirectoryName(iso) ?? "."; + string[] files = Directory.GetFiles(dir, "*.getkey.log"); + + if (files.Length != 1) + return null; + + return files[0].Substring(0, files[0].Length - 11); + } + catch + { + // We don't care what the exception is right now + return null; + } } #endregion