mirror of
https://github.com/SabreTools/MPF.git
synced 2026-02-04 05:35:52 +00:00
Add tests around XBC helpers
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
- Add tests around some Aaru helpers
|
||||
- Add tests around CleanRip helpers
|
||||
- Fix CleanRip test access
|
||||
- Add tests around XBC helpers
|
||||
|
||||
### 3.2.4 (2024-11-24)
|
||||
|
||||
|
||||
@@ -1 +1,34 @@
|
||||
TEST DATA
|
||||
====================================================================
|
||||
Xbox Backup Creator v0.0 Build:0000 By Redline99
|
||||
====================================================================
|
||||
|
||||
<< IsSuccessfulLog >>
|
||||
Read completed in 00:00:00
|
||||
|
||||
<< GetDrive >>
|
||||
========================================
|
||||
< --Security Sector Details -->
|
||||
Source Drive: SH-D162D
|
||||
----------------------------------------
|
||||
|
||||
<< GetLayerbreak >>
|
||||
LayerBreak=1913776
|
||||
track.iso
|
||||
|
||||
<< GetReadErrors >>
|
||||
Creating SplitVid backup image [E]
|
||||
...
|
||||
Reading Game Partition
|
||||
Setting read speed to 1x
|
||||
Unrecovered read error at Partition LBA: 0
|
||||
|
||||
Creating Layer Break File
|
||||
LayerBreak file saved as: "track.dvd"
|
||||
A total of 65,536 sectors were zeroed out.
|
||||
A total of 31 sectors with read errors were recovered.
|
||||
|
||||
<< GetMediaID >>
|
||||
----------------------------------------
|
||||
Media ID
|
||||
A76B9983D170EFF8749A892BC-8B62A812
|
||||
---------------------------------------
|
||||
@@ -5,6 +5,7 @@ using Xunit;
|
||||
|
||||
namespace MPF.Processors.Test
|
||||
{
|
||||
// TODO: Add tests for RecreateSS
|
||||
public class XboxBackupCreatorTests
|
||||
{
|
||||
#region GetOutputFiles
|
||||
@@ -131,5 +132,256 @@ namespace MPF.Processors.Test
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetLogName
|
||||
|
||||
[Fact]
|
||||
public void GetLogName_EmptyDir_Null()
|
||||
{
|
||||
string baseDir = string.Empty;
|
||||
string? actual = XboxBackupCreator.GetLogName(baseDir);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetLogName_InvalidDir_Null()
|
||||
{
|
||||
string baseDir = "INVALID";
|
||||
string? actual = XboxBackupCreator.GetLogName(baseDir);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetLogName_ValidDirNoLog_Null()
|
||||
{
|
||||
string? baseDir = Path.Combine(Environment.CurrentDirectory, "TestData", "XboxBackupCreator");
|
||||
string? actual = XboxBackupCreator.GetLogName(baseDir);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetLogName_ValidDirLog_Path()
|
||||
{
|
||||
string? baseDir = Path.Combine(Environment.CurrentDirectory, "TestData", "XboxBackupCreator", "DVD");
|
||||
string? actual = XboxBackupCreator.GetLogName(baseDir);
|
||||
Assert.NotNull(actual);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetVersion
|
||||
|
||||
[Fact]
|
||||
public void GetVersion_Null_Null()
|
||||
{
|
||||
string? log = null;
|
||||
string? actual = XboxBackupCreator.GetVersion(log);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetVersion_Empty_Null()
|
||||
{
|
||||
string? log = string.Empty;
|
||||
string? actual = XboxBackupCreator.GetVersion(log);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetVersion_Invalid_Null()
|
||||
{
|
||||
string? log = "INVALID";
|
||||
string? actual = XboxBackupCreator.GetVersion(log);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetVersion_Valid_Filled()
|
||||
{
|
||||
string? expected = "v0.0 Build:0000 By Redline99";
|
||||
string? log = Path.Combine(Environment.CurrentDirectory, "TestData", "XboxBackupCreator", "DVD", "log.txt");
|
||||
string? actual = XboxBackupCreator.GetVersion(log);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetDrive
|
||||
|
||||
[Fact]
|
||||
public void GetDrive_Null_Null()
|
||||
{
|
||||
string? log = null;
|
||||
string? actual = XboxBackupCreator.GetDrive(log);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDrive_Empty_Null()
|
||||
{
|
||||
string? log = string.Empty;
|
||||
string? actual = XboxBackupCreator.GetDrive(log);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDrive_Invalid_Null()
|
||||
{
|
||||
string? log = "INVALID";
|
||||
string? actual = XboxBackupCreator.GetDrive(log);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDrive_Valid_Filled()
|
||||
{
|
||||
string? expected = "SH-D162D";
|
||||
string? log = Path.Combine(Environment.CurrentDirectory, "TestData", "XboxBackupCreator", "DVD", "log.txt");
|
||||
string? actual = XboxBackupCreator.GetDrive(log);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetLayerbreak
|
||||
|
||||
[Fact]
|
||||
public void GetLayerbreak_Null_Null()
|
||||
{
|
||||
long expected = -1;
|
||||
string? log = null;
|
||||
bool actual = XboxBackupCreator.GetLayerbreak(log, out long layerbreak);
|
||||
|
||||
Assert.False(actual);
|
||||
Assert.Equal(expected, layerbreak);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetLayerbreak_Empty_Null()
|
||||
{
|
||||
long expected = -1;
|
||||
string? log = string.Empty;
|
||||
bool actual = XboxBackupCreator.GetLayerbreak(log, out long layerbreak);
|
||||
|
||||
Assert.False(actual);
|
||||
Assert.Equal(expected, layerbreak);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetLayerbreak_Invalid_Null()
|
||||
{
|
||||
long expected = -1;
|
||||
string? log = "INVALID";
|
||||
bool actual = XboxBackupCreator.GetLayerbreak(log, out long layerbreak);
|
||||
|
||||
Assert.False(actual);
|
||||
Assert.Equal(expected, layerbreak);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetLayerbreak_Valid_Filled()
|
||||
{
|
||||
long expected = 1913776;
|
||||
string? log = Path.Combine(Environment.CurrentDirectory, "TestData", "XboxBackupCreator", "DVD", "log.txt");
|
||||
bool actual = XboxBackupCreator.GetLayerbreak(log, out long layerbreak);
|
||||
|
||||
Assert.True(actual);
|
||||
Assert.Equal(expected, layerbreak);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetReadErrors
|
||||
|
||||
[Fact]
|
||||
public void GetReadErrors_Null_Null()
|
||||
{
|
||||
long expected = -1;
|
||||
string? log = null;
|
||||
var processor = new XboxBackupCreator(RedumpSystem.MicrosoftXbox, MediaType.DVD);
|
||||
bool actual = processor.GetReadErrors(log, out long readErrors);
|
||||
|
||||
Assert.False(actual);
|
||||
Assert.Equal(expected, readErrors);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetReadErrors_Empty_Null()
|
||||
{
|
||||
long expected = -1;
|
||||
string? log = string.Empty;
|
||||
var processor = new XboxBackupCreator(RedumpSystem.MicrosoftXbox, MediaType.DVD);
|
||||
bool actual = processor.GetReadErrors(log, out long readErrors);
|
||||
|
||||
Assert.False(actual);
|
||||
Assert.Equal(expected, readErrors);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetReadErrors_Invalid_Null()
|
||||
{
|
||||
long expected = -1;
|
||||
string? log = "INVALID";
|
||||
var processor = new XboxBackupCreator(RedumpSystem.MicrosoftXbox, MediaType.DVD);
|
||||
bool actual = processor.GetReadErrors(log, out long readErrors);
|
||||
|
||||
Assert.False(actual);
|
||||
Assert.Equal(expected, readErrors);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetReadErrors_Valid_Filled()
|
||||
{
|
||||
long expected = 0;
|
||||
string? log = Path.Combine(Environment.CurrentDirectory, "TestData", "XboxBackupCreator", "DVD", "log.txt");
|
||||
var processor = new XboxBackupCreator(RedumpSystem.MicrosoftXbox, MediaType.DVD);
|
||||
bool actual = processor.GetReadErrors(log, out long readErrors);
|
||||
|
||||
Assert.True(actual);
|
||||
Assert.Equal(expected, readErrors);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetMediaID
|
||||
|
||||
[Fact]
|
||||
public void GetMediaID_Null_Null()
|
||||
{
|
||||
string? log = null;
|
||||
var processor = new XboxBackupCreator(RedumpSystem.MicrosoftXbox360, MediaType.DVD);
|
||||
string? actual = processor.GetMediaID(log);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetMediaID_Empty_Null()
|
||||
{
|
||||
string? log = string.Empty;
|
||||
var processor = new XboxBackupCreator(RedumpSystem.MicrosoftXbox360, MediaType.DVD);
|
||||
string? actual = processor.GetMediaID(log);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetMediaID_Invalid_Null()
|
||||
{
|
||||
string? log = "INVALID";
|
||||
var processor = new XboxBackupCreator(RedumpSystem.MicrosoftXbox360, MediaType.DVD);
|
||||
string? actual = processor.GetMediaID(log);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetMediaID_Valid_Filled()
|
||||
{
|
||||
string? expected = "A76B9983D170EFF8749A892BC-8B62A812";
|
||||
string? log = Path.Combine(Environment.CurrentDirectory, "TestData", "XboxBackupCreator", "DVD", "log.txt");
|
||||
var processor = new XboxBackupCreator(RedumpSystem.MicrosoftXbox360, MediaType.DVD);
|
||||
string? actual = processor.GetMediaID(log);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -190,10 +190,21 @@ namespace MPF.Processors
|
||||
/// </summary>
|
||||
/// <param name="baseDir">Base directory to search in</param>
|
||||
/// <returns>Log path if found, null otherwise</returns>
|
||||
private static string? GetLogName(string baseDir)
|
||||
internal static string? GetLogName(string baseDir)
|
||||
{
|
||||
// If the directory name is invalid
|
||||
if (baseDir.Length == 0)
|
||||
return null;
|
||||
|
||||
// If the directory doesn't exist
|
||||
if (!Directory.Exists(baseDir))
|
||||
return null;
|
||||
|
||||
// Check the known paths first
|
||||
if (IsSuccessfulLog(Path.Combine(baseDir, "Log.txt")))
|
||||
return Path.Combine(baseDir, "Log.txt");
|
||||
else if (IsSuccessfulLog(Path.Combine(baseDir, "log.txt")))
|
||||
return Path.Combine(baseDir, "log.txt");
|
||||
|
||||
// Search for a renamed log file (assume there is only one)
|
||||
string[] files = Directory.GetFiles(baseDir, "*.txt", SearchOption.TopDirectoryOnly);
|
||||
@@ -213,7 +224,8 @@ namespace MPF.Processors
|
||||
/// <returns>True if successful log found, false otherwise</returns>
|
||||
private static bool IsSuccessfulLog(string log)
|
||||
{
|
||||
if (!File.Exists(log))
|
||||
// If the log path is invalid
|
||||
if (string.IsNullOrEmpty(log) || !File.Exists(log))
|
||||
return false;
|
||||
|
||||
// Successful Example:
|
||||
@@ -253,8 +265,9 @@ namespace MPF.Processors
|
||||
/// </summary>
|
||||
/// <param name="log">Path to XBC log file</param>
|
||||
/// <returns>Version if possible, null on error</returns>
|
||||
private static string? GetVersion(string? log)
|
||||
internal static string? GetVersion(string? log)
|
||||
{
|
||||
// If the log path is invalid
|
||||
if (string.IsNullOrEmpty(log) || !File.Exists(log))
|
||||
return null;
|
||||
|
||||
@@ -289,8 +302,9 @@ namespace MPF.Processors
|
||||
/// </summary>
|
||||
/// <param name="log">Path to XBC log file</param>
|
||||
/// <returns>Drive model if found, null otherwise</returns>
|
||||
private static string? GetDrive(string? log)
|
||||
internal static string? GetDrive(string? log)
|
||||
{
|
||||
// If the log path is invalid
|
||||
if (string.IsNullOrEmpty(log) || !File.Exists(log))
|
||||
return null;
|
||||
|
||||
@@ -327,12 +341,12 @@ namespace MPF.Processors
|
||||
/// Get the Layerbreak value if possible
|
||||
/// </summary>
|
||||
/// <param name="dvd">Path to layerbreak file</param>
|
||||
/// <param name="layerbreak">Layerbreak value if found</param>
|
||||
/// <param name="layerbreak">Layerbreak value if found, -1 otherwise</param>
|
||||
/// <returns>True if successful, otherwise false</returns>
|
||||
/// <returns></returns>
|
||||
private static bool GetLayerbreak(string? dvd, out long layerbreak)
|
||||
internal static bool GetLayerbreak(string? dvd, out long layerbreak)
|
||||
{
|
||||
layerbreak = 0;
|
||||
layerbreak = -1;
|
||||
|
||||
if (string.IsNullOrEmpty(dvd) || !File.Exists(dvd))
|
||||
return false;
|
||||
@@ -370,7 +384,7 @@ namespace MPF.Processors
|
||||
/// <param name="log">Path to XBC log file</param>
|
||||
/// <param name="readErrors">Read error count if found, -1 otherwise</param>
|
||||
/// <returns>True if sucessful, otherwise false</returns>
|
||||
private bool GetReadErrors(string? log, out long readErrors)
|
||||
internal bool GetReadErrors(string? log, out long readErrors)
|
||||
{
|
||||
readErrors = -1;
|
||||
|
||||
@@ -441,7 +455,7 @@ namespace MPF.Processors
|
||||
/// </summary>
|
||||
/// <param name="log">Path to XBC log file</param>
|
||||
/// <returns>Media ID if Log successfully parsed, null otherwise</returns>
|
||||
private string? GetMediaID(string? log)
|
||||
internal string? GetMediaID(string? log)
|
||||
{
|
||||
if (string.IsNullOrEmpty(log) || !File.Exists(log))
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user