Add tests around UIC helpers

This commit is contained in:
Matt Nadareski
2024-12-03 20:46:05 -05:00
parent 4e338d56cd
commit 0e37025150
6 changed files with 167 additions and 6 deletions

View File

@@ -1 +1,7 @@
TEST DATA
<< GetUMDAuxInfo >>
TITLE title
DISC_ID serial
DISC_VERSION version
pspUmdTypes GAME
L0 length 12345
FileSize: 12345

View File

@@ -1 +1,9 @@
TEST DATA
<< 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

View File

@@ -1 +1,3 @@
TEST DATA
<< GetVolumeLabels >>
Primary Volume Descriptor Number: 0
Volume Identifier: label

View File

@@ -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<string, List<string>> volLabels);
Assert.False(actual);
Assert.Empty(volLabels);
}
[Fact]
public void GetVolumeLabels_Invalid_Null()
{
string volDesc = "INVALID";
bool actual = UmdImageCreator.GetVolumeLabels(volDesc, out Dictionary<string, List<string>> 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<string, List<string>> volLabels);
Assert.True(actual);
KeyValuePair<string, List<string>> labelPair = Assert.Single(volLabels);
Assert.Equal("label", labelPair.Key);
string filesystem = Assert.Single(labelPair.Value);
Assert.Equal("UDF", filesystem);
}
#endregion
}
}