mirror of
https://github.com/SabreTools/MPF.git
synced 2026-07-02 17:24:48 +00:00
Add tests around PS3 CFW helpers
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -102,10 +102,10 @@ namespace MPF.Processors
|
||||
/// </summary>
|
||||
/// <param name="iso">Path to ISO file</param>
|
||||
/// <returns></returns>
|
||||
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
|
||||
/// </summary>
|
||||
/// <param name="iso">Path to ISO file</param>
|
||||
/// <returns>Base filename, null if not found</returns>
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user