diff --git a/CHANGELIST.md b/CHANGELIST.md index 7f41b15e..f677b3b6 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -13,6 +13,7 @@ - Add tests around XBC helpers - Fix failing XBC test - Perform better path emptiness checks +- Add tests around UIC helpers ### 3.2.4 (2024-11-24) diff --git a/MPF.Processors.Test/TestData/UmdImageCreator/UMD/test_disc.txt b/MPF.Processors.Test/TestData/UmdImageCreator/UMD/test_disc.txt index 1aa4b5d8..bcea7b94 100644 --- a/MPF.Processors.Test/TestData/UmdImageCreator/UMD/test_disc.txt +++ b/MPF.Processors.Test/TestData/UmdImageCreator/UMD/test_disc.txt @@ -1 +1,7 @@ -TEST DATA \ No newline at end of file +<< GetUMDAuxInfo >> +TITLE title +DISC_ID serial +DISC_VERSION version +pspUmdTypes GAME +L0 length 12345 +FileSize: 12345 diff --git a/MPF.Processors.Test/TestData/UmdImageCreator/UMD/test_mainInfo.txt b/MPF.Processors.Test/TestData/UmdImageCreator/UMD/test_mainInfo.txt index 1aa4b5d8..a2313efe 100644 --- a/MPF.Processors.Test/TestData/UmdImageCreator/UMD/test_mainInfo.txt +++ b/MPF.Processors.Test/TestData/UmdImageCreator/UMD/test_mainInfo.txt @@ -1 +1,9 @@ -TEST DATA \ No newline at end of file +<< GetPVD >> +========== LBA[000016, 0x0000010]: Main Channel ========== +0310 TEST DATA +0320 TEST DATA +0330 TEST DATA +0340 TEST DATA +0350 TEST DATA +0360 TEST DATA +0370 TEST DATA diff --git a/MPF.Processors.Test/TestData/UmdImageCreator/UMD/test_volDesc.txt b/MPF.Processors.Test/TestData/UmdImageCreator/UMD/test_volDesc.txt index 1aa4b5d8..16939ef8 100644 --- a/MPF.Processors.Test/TestData/UmdImageCreator/UMD/test_volDesc.txt +++ b/MPF.Processors.Test/TestData/UmdImageCreator/UMD/test_volDesc.txt @@ -1 +1,3 @@ -TEST DATA \ No newline at end of file +<< GetVolumeLabels >> +Primary Volume Descriptor Number: 0 +Volume Identifier: label \ No newline at end of file diff --git a/MPF.Processors.Test/UmdImageCreatorTests.cs b/MPF.Processors.Test/UmdImageCreatorTests.cs index 890d0908..56d4d438 100644 --- a/MPF.Processors.Test/UmdImageCreatorTests.cs +++ b/MPF.Processors.Test/UmdImageCreatorTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using SabreTools.RedumpLib.Data; using Xunit; @@ -131,5 +132,148 @@ namespace MPF.Processors.Test } #endregion + + #region GetPVD + + [Fact] + public void GetPVD_Empty_Null() + { + string mainInfo = string.Empty; + string? actual = UmdImageCreator.GetPVD(mainInfo); + Assert.Null(actual); + } + + [Fact] + public void GetPVD_Invalid_Null() + { + string mainInfo = "INVALID"; + string? actual = UmdImageCreator.GetPVD(mainInfo); + Assert.Null(actual); + } + + [Fact] + public void GetPVD_Valid_Filled() + { + string mainInfo = Path.Combine(Environment.CurrentDirectory, "TestData", "UmdImageCreator", "UMD", "test_mainInfo.txt"); + string? actual = UmdImageCreator.GetPVD(mainInfo); + Assert.NotNull(actual); + } + + #endregion + + #region GetUMDAuxInfo + + [Fact] + public void GetUMDAuxInfo_Empty_Null() + { + long expectedSize = -1; + + string disc = string.Empty; + bool actual = UmdImageCreator.GetUMDAuxInfo(disc, + out string? title, + out DiscCategory? category, + out string? serial, + out string? version, + out string? layer, + out long size); + + Assert.False(actual); + Assert.Null(title); + Assert.Null(category); + Assert.Null(serial); + Assert.Null(version); + Assert.Null(layer); + Assert.Equal(expectedSize, size); + } + + [Fact] + public void GetUMDAuxInfo_Invalid_Null() + { + long expectedSize = -1; + + string disc = "INVALID"; + bool actual = UmdImageCreator.GetUMDAuxInfo(disc, + out string? title, + out DiscCategory? category, + out string? serial, + out string? version, + out string? layer, + out long size); + + Assert.False(actual); + Assert.Null(title); + Assert.Null(category); + Assert.Null(serial); + Assert.Null(version); + Assert.Null(layer); + Assert.Equal(expectedSize, size); + } + + [Fact] + public void GetUMDAuxInfo_Valid_Filled() + { + string? expectedTitle = "title"; + DiscCategory? expectedCategory = DiscCategory.Games; + string? expectedSerial = "seri-al"; + string? expectedVersion = "version"; + string? expectedLayer = "12345"; + long expectedSize = 12345; + + string disc = Path.Combine(Environment.CurrentDirectory, "TestData", "UmdImageCreator", "UMD", "test_disc.txt"); + bool actual = UmdImageCreator.GetUMDAuxInfo(disc, + out string? title, + out DiscCategory? category, + out string? serial, + out string? version, + out string? layer, + out long size); + + Assert.True(actual); + Assert.Equal(expectedTitle, title); + Assert.Equal(expectedCategory, category); + Assert.Equal(expectedSerial, serial); + Assert.Equal(expectedVersion, version); + Assert.Equal(expectedLayer, layer); + Assert.Equal(expectedSize, size); + } + + #endregion + + #region GetVolumeLabels + + [Fact] + public void GetVolumeLabels_Empty_Null() + { + string volDesc = string.Empty; + bool actual = UmdImageCreator.GetVolumeLabels(volDesc, out Dictionary> volLabels); + + Assert.False(actual); + Assert.Empty(volLabels); + } + + [Fact] + public void GetVolumeLabels_Invalid_Null() + { + string volDesc = "INVALID"; + bool actual = UmdImageCreator.GetVolumeLabels(volDesc, out Dictionary> volLabels); + + Assert.False(actual); + Assert.Empty(volLabels); + } + + [Fact] + public void GetVolumeLabels_Valid_Filled() + { + string volDesc = Path.Combine(Environment.CurrentDirectory, "TestData", "UmdImageCreator", "UMD", "test_volDesc.txt"); + bool actual = UmdImageCreator.GetVolumeLabels(volDesc, out Dictionary> volLabels); + + Assert.True(actual); + KeyValuePair> labelPair = Assert.Single(volLabels); + Assert.Equal("label", labelPair.Key); + string filesystem = Assert.Single(labelPair.Value); + Assert.Equal("UDF", filesystem); + } + + #endregion } } \ No newline at end of file diff --git a/MPF.Processors/UmdImageCreator.cs b/MPF.Processors/UmdImageCreator.cs index 360e9b2e..a5558ad6 100644 --- a/MPF.Processors/UmdImageCreator.cs +++ b/MPF.Processors/UmdImageCreator.cs @@ -156,7 +156,7 @@ namespace MPF.Processors /// /// _disc.txt file location /// True on successful extraction of info, false otherwise - private static bool GetUMDAuxInfo(string disc, + internal static bool GetUMDAuxInfo(string disc, out string? title, out DiscCategory? category, out string? serial, @@ -218,8 +218,8 @@ namespace MPF.Processors /// /// _volDesc.txt file location /// Volume labels (by type), or null if none present - /// This is a copy of the code from DiscImageCreator and has extrandous checks - private static bool GetVolumeLabels(string volDesc, out Dictionary> volLabels) + /// This is a copy of the code from DiscImageCreator and has extraneous checks + internal static bool GetVolumeLabels(string volDesc, out Dictionary> volLabels) { // If the file doesn't exist, can't get the volume labels volLabels = [];