2021-12-30 13:00:55 -08:00
|
|
|
|
using System.Collections.Generic;
|
2023-04-11 11:15:53 -04:00
|
|
|
|
using System.IO;
|
2023-10-06 20:42:34 -04:00
|
|
|
|
using MPF.Core;
|
2023-09-05 00:08:09 -04:00
|
|
|
|
using SabreTools.RedumpLib.Data;
|
2021-11-26 14:07:07 -08:00
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MPF.Test.Library
|
|
|
|
|
|
{
|
|
|
|
|
|
public class InfoToolTests
|
|
|
|
|
|
{
|
|
|
|
|
|
[Theory]
|
|
|
|
|
|
[InlineData(null, 0, 0, 0, 0, null)]
|
|
|
|
|
|
[InlineData(null, 12345, 0, 0, 0, null)]
|
|
|
|
|
|
[InlineData(null, 12345, 1, 0, 0, null)]
|
|
|
|
|
|
[InlineData(null, 12345, 1, 2, 0, null)]
|
|
|
|
|
|
[InlineData(null, 12345, 1, 2, 3, null)]
|
|
|
|
|
|
[InlineData(MediaType.CDROM, 0, 0, 0, 0, "CD-ROM")]
|
|
|
|
|
|
[InlineData(MediaType.CDROM, 12345, 0, 0, 0, "CD-ROM")]
|
|
|
|
|
|
[InlineData(MediaType.CDROM, 12345, 1, 0, 0, "CD-ROM")]
|
|
|
|
|
|
[InlineData(MediaType.CDROM, 12345, 1, 2, 0, "CD-ROM")]
|
|
|
|
|
|
[InlineData(MediaType.CDROM, 12345, 1, 2, 3, "CD-ROM")]
|
|
|
|
|
|
[InlineData(MediaType.DVD, 0, 0, 0, 0, "DVD-ROM-5")]
|
|
|
|
|
|
[InlineData(MediaType.DVD, 12345, 0, 0, 0, "DVD-ROM-5")]
|
|
|
|
|
|
[InlineData(MediaType.DVD, 12345, 1, 0, 0, "DVD-ROM-9")]
|
|
|
|
|
|
[InlineData(MediaType.DVD, 12345, 1, 2, 0, "DVD-ROM-9")]
|
|
|
|
|
|
[InlineData(MediaType.DVD, 12345, 1, 2, 3, "DVD-ROM-9")]
|
|
|
|
|
|
[InlineData(MediaType.BluRay, 0, 0, 0, 0, "BD-ROM-25")]
|
|
|
|
|
|
[InlineData(MediaType.BluRay, 12345, 0, 0, 0, "BD-ROM-25")]
|
2023-04-26 16:00:20 -04:00
|
|
|
|
[InlineData(MediaType.BluRay, 26_843_531_857, 0, 0, 0, "BD-ROM-33")]
|
2021-11-26 14:07:07 -08:00
|
|
|
|
[InlineData(MediaType.BluRay, 12345, 1, 0, 0, "BD-ROM-50")]
|
2023-04-26 16:00:20 -04:00
|
|
|
|
[InlineData(MediaType.BluRay, 53_687_063_713, 1, 0, 0, "BD-ROM-66")]
|
2021-11-26 14:07:07 -08:00
|
|
|
|
[InlineData(MediaType.BluRay, 12345, 1, 2, 0, "BD-ROM-100")]
|
|
|
|
|
|
[InlineData(MediaType.BluRay, 12345, 1, 2, 3, "BD-ROM-128")]
|
|
|
|
|
|
[InlineData(MediaType.UMD, 0, 0, 0, 0, "UMD-SL")]
|
|
|
|
|
|
[InlineData(MediaType.UMD, 12345, 0, 0, 0, "UMD-SL")]
|
|
|
|
|
|
[InlineData(MediaType.UMD, 12345, 1, 0, 0, "UMD-DL")]
|
|
|
|
|
|
[InlineData(MediaType.UMD, 12345, 1, 2, 0, "UMD-DL")]
|
|
|
|
|
|
[InlineData(MediaType.UMD, 12345, 1, 2, 3, "UMD-DL")]
|
|
|
|
|
|
public void GetFixedMediaTypeTest(
|
|
|
|
|
|
MediaType? mediaType,
|
|
|
|
|
|
long size,
|
|
|
|
|
|
long layerbreak,
|
|
|
|
|
|
long layerbreak2,
|
|
|
|
|
|
long layerbreak3,
|
2023-10-11 12:14:42 -04:00
|
|
|
|
#if NET48
|
2021-11-26 14:07:07 -08:00
|
|
|
|
string expected)
|
2023-10-11 12:14:42 -04:00
|
|
|
|
#else
|
|
|
|
|
|
string? expected)
|
|
|
|
|
|
#endif
|
2021-11-26 14:07:07 -08:00
|
|
|
|
{
|
2023-04-26 16:00:20 -04:00
|
|
|
|
// TODO: Add tests around BDU
|
2023-10-11 12:14:42 -04:00
|
|
|
|
var actual = InfoTool.GetFixedMediaType(mediaType, null, size, layerbreak, layerbreak2, layerbreak3);
|
2021-11-26 14:07:07 -08:00
|
|
|
|
Assert.Equal(expected, actual);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Theory]
|
2023-10-02 17:50:18 -04:00
|
|
|
|
[InlineData(null, "")]
|
|
|
|
|
|
[InlineData(" ", "")]
|
2022-12-13 11:48:26 -08:00
|
|
|
|
[InlineData("super\\blah.bin", "super\\blah.bin")]
|
|
|
|
|
|
[InlineData("super\\hero\\blah.bin", "super\\hero\\blah.bin")]
|
|
|
|
|
|
[InlineData("super.hero\\blah.bin", "super.hero\\blah.bin")]
|
|
|
|
|
|
[InlineData("superhero\\blah.rev.bin", "superhero\\blah.rev.bin")]
|
|
|
|
|
|
[InlineData("super&hero\\blah.bin", "super&hero\\blah.bin")]
|
|
|
|
|
|
[InlineData("superhero\\blah&foo.bin", "superhero\\blah&foo.bin")]
|
2023-10-11 12:14:42 -04:00
|
|
|
|
#if NET48
|
2022-12-13 11:48:26 -08:00
|
|
|
|
public void NormalizeOutputPathsTest(string outputPath, string expectedPath)
|
2023-10-11 12:14:42 -04:00
|
|
|
|
#else
|
|
|
|
|
|
public void NormalizeOutputPathsTest(string? outputPath, string? expectedPath)
|
|
|
|
|
|
#endif
|
2021-11-26 14:07:07 -08:00
|
|
|
|
{
|
2023-04-11 11:15:53 -04:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(expectedPath))
|
|
|
|
|
|
expectedPath = Path.GetFullPath(expectedPath);
|
|
|
|
|
|
|
2023-10-02 17:50:18 -04:00
|
|
|
|
string actualPath = InfoTool.NormalizeOutputPaths(outputPath, true);
|
2022-12-13 11:48:26 -08:00
|
|
|
|
Assert.Equal(expectedPath, actualPath);
|
2021-11-26 14:07:07 -08:00
|
|
|
|
}
|
2021-12-30 13:00:55 -08:00
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void ProcessSpecialFieldsCompleteTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Create a new SubmissionInfo object
|
2023-10-11 12:29:06 -04:00
|
|
|
|
var info = new SubmissionInfo()
|
2021-12-30 13:00:55 -08:00
|
|
|
|
{
|
|
|
|
|
|
CommonDiscInfo = new CommonDiscInfoSection()
|
|
|
|
|
|
{
|
|
|
|
|
|
Comments = "This is a comments line\n[T:ISBN] ISBN Value",
|
2023-09-05 00:08:09 -04:00
|
|
|
|
#if NET48
|
2021-12-30 13:00:55 -08:00
|
|
|
|
CommentsSpecialFields = new Dictionary<SiteCode?, string>()
|
2023-09-05 00:08:09 -04:00
|
|
|
|
#else
|
|
|
|
|
|
CommentsSpecialFields = new Dictionary<SiteCode, string>()
|
|
|
|
|
|
#endif
|
2021-12-30 13:00:55 -08:00
|
|
|
|
{
|
|
|
|
|
|
[SiteCode.VolumeLabel] = "VOLUME_LABEL",
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
Contents = "This is a contents line\n[T:GF] Game Footage",
|
2023-09-05 00:08:09 -04:00
|
|
|
|
#if NET48
|
2021-12-30 13:00:55 -08:00
|
|
|
|
ContentsSpecialFields = new Dictionary<SiteCode?, string>()
|
2023-09-05 00:08:09 -04:00
|
|
|
|
#else
|
|
|
|
|
|
ContentsSpecialFields = new Dictionary<SiteCode, string>()
|
|
|
|
|
|
#endif
|
2021-12-30 13:00:55 -08:00
|
|
|
|
{
|
|
|
|
|
|
[SiteCode.Patches] = "1.04 patch",
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Process the special fields
|
|
|
|
|
|
InfoTool.ProcessSpecialFields(info);
|
|
|
|
|
|
|
|
|
|
|
|
// Validate the basics
|
|
|
|
|
|
Assert.NotNull(info.CommonDiscInfo.Comments);
|
|
|
|
|
|
Assert.Null(info.CommonDiscInfo.CommentsSpecialFields);
|
|
|
|
|
|
Assert.NotNull(info.CommonDiscInfo.Contents);
|
|
|
|
|
|
Assert.Null(info.CommonDiscInfo.ContentsSpecialFields);
|
|
|
|
|
|
|
|
|
|
|
|
// Split the values
|
|
|
|
|
|
string[] splitComments = info.CommonDiscInfo.Comments.Split('\n');
|
|
|
|
|
|
string[] splitContents = info.CommonDiscInfo.Contents.Split('\n');
|
|
|
|
|
|
|
|
|
|
|
|
// Validate the lines
|
|
|
|
|
|
Assert.Equal(3, splitComments.Length);
|
2022-01-02 22:01:21 -08:00
|
|
|
|
Assert.Equal(5, splitContents.Length);
|
2021-12-30 13:00:55 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void ProcessSpecialFieldsNullObjectTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Create a new SubmissionInfo object
|
2023-10-11 12:29:06 -04:00
|
|
|
|
var info = new SubmissionInfo()
|
2021-12-30 13:00:55 -08:00
|
|
|
|
{
|
|
|
|
|
|
CommonDiscInfo = null,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Process the special fields
|
|
|
|
|
|
InfoTool.ProcessSpecialFields(info);
|
|
|
|
|
|
|
|
|
|
|
|
// Validate
|
|
|
|
|
|
Assert.Null(info.CommonDiscInfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void ProcessSpecialFieldsNullCommentsContentsTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Create a new SubmissionInfo object
|
2023-10-11 12:29:06 -04:00
|
|
|
|
var info = new SubmissionInfo()
|
2021-12-30 13:00:55 -08:00
|
|
|
|
{
|
|
|
|
|
|
CommonDiscInfo = new CommonDiscInfoSection()
|
|
|
|
|
|
{
|
|
|
|
|
|
Comments = null,
|
2023-09-05 00:08:09 -04:00
|
|
|
|
#if NET48
|
2021-12-30 13:00:55 -08:00
|
|
|
|
CommentsSpecialFields = new Dictionary<SiteCode?, string>()
|
2023-09-05 00:08:09 -04:00
|
|
|
|
#else
|
|
|
|
|
|
CommentsSpecialFields = new Dictionary<SiteCode, string>()
|
|
|
|
|
|
#endif
|
2021-12-30 13:00:55 -08:00
|
|
|
|
{
|
|
|
|
|
|
[SiteCode.VolumeLabel] = "VOLUME_LABEL",
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
Contents = null,
|
2023-09-05 00:08:09 -04:00
|
|
|
|
#if NET48
|
2021-12-30 13:00:55 -08:00
|
|
|
|
ContentsSpecialFields = new Dictionary<SiteCode?, string>()
|
2023-09-05 00:08:09 -04:00
|
|
|
|
#else
|
|
|
|
|
|
ContentsSpecialFields = new Dictionary<SiteCode, string>()
|
|
|
|
|
|
#endif
|
2021-12-30 13:00:55 -08:00
|
|
|
|
{
|
|
|
|
|
|
[SiteCode.Patches] = "1.04 patch",
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Process the special fields
|
|
|
|
|
|
InfoTool.ProcessSpecialFields(info);
|
|
|
|
|
|
|
|
|
|
|
|
// Validate the basics
|
|
|
|
|
|
Assert.NotNull(info.CommonDiscInfo.Comments);
|
|
|
|
|
|
Assert.Null(info.CommonDiscInfo.CommentsSpecialFields);
|
|
|
|
|
|
Assert.NotNull(info.CommonDiscInfo.Contents);
|
|
|
|
|
|
Assert.Null(info.CommonDiscInfo.ContentsSpecialFields);
|
|
|
|
|
|
|
|
|
|
|
|
// Split the values
|
|
|
|
|
|
string[] splitComments = info.CommonDiscInfo.Comments.Split('\n');
|
|
|
|
|
|
string[] splitContents = info.CommonDiscInfo.Contents.Split('\n');
|
|
|
|
|
|
|
|
|
|
|
|
// Validate the lines
|
|
|
|
|
|
Assert.Single(splitComments);
|
2022-01-02 22:01:21 -08:00
|
|
|
|
Assert.Equal(2, splitContents.Length);
|
2021-12-30 13:00:55 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void ProcessSpecialFieldsNullDictionariesTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Create a new SubmissionInfo object
|
2023-10-11 12:29:06 -04:00
|
|
|
|
var info = new SubmissionInfo()
|
2021-12-30 13:00:55 -08:00
|
|
|
|
{
|
|
|
|
|
|
CommonDiscInfo = new CommonDiscInfoSection()
|
|
|
|
|
|
{
|
|
|
|
|
|
Comments = "This is a comments line\n[T:ISBN] ISBN Value",
|
|
|
|
|
|
CommentsSpecialFields = null,
|
|
|
|
|
|
|
|
|
|
|
|
Contents = "This is a contents line\n[T:GF] Game Footage",
|
|
|
|
|
|
ContentsSpecialFields = null,
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Process the special fields
|
|
|
|
|
|
InfoTool.ProcessSpecialFields(info);
|
|
|
|
|
|
|
|
|
|
|
|
// Validate the basics
|
|
|
|
|
|
Assert.NotNull(info.CommonDiscInfo.Comments);
|
|
|
|
|
|
Assert.Null(info.CommonDiscInfo.CommentsSpecialFields);
|
|
|
|
|
|
Assert.NotNull(info.CommonDiscInfo.Contents);
|
|
|
|
|
|
Assert.Null(info.CommonDiscInfo.ContentsSpecialFields);
|
|
|
|
|
|
|
|
|
|
|
|
// Split the values
|
|
|
|
|
|
string[] splitComments = info.CommonDiscInfo.Comments.Split('\n');
|
|
|
|
|
|
string[] splitContents = info.CommonDiscInfo.Contents.Split('\n');
|
|
|
|
|
|
|
|
|
|
|
|
// Validate the lines
|
|
|
|
|
|
Assert.Equal(2, splitComments.Length);
|
|
|
|
|
|
Assert.Equal(2, splitContents.Length);
|
|
|
|
|
|
}
|
2021-11-26 14:07:07 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|