Add tests for invalid paths

mac
Miepee 3 years ago
parent 92a3c17750
commit b2eff24918

@ -26,6 +26,12 @@ public abstract class RawMods : ModsBase
/// <exception cref="NotSupportedException">The OS for which the zip was made for could not be determined.</exception> /// <exception cref="NotSupportedException">The OS for which the zip was made for could not be determined.</exception>
public static ModOS GetModOSOfRawZip(string inputRawZipPath) public static ModOS GetModOSOfRawZip(string inputRawZipPath)
{ {
if (inputRawZipPath is null)
throw new ArgumentNullException(nameof(inputRawZipPath) + " cannot be null!");
if (!File.Exists(inputRawZipPath))
throw new FileNotFoundException(nameof(inputRawZipPath) + " does not exist!");
ZipArchive archive = ZipFile.OpenRead(inputRawZipPath); ZipArchive archive = ZipFile.OpenRead(inputRawZipPath);
// Since exe's can be differently named, we'll search for exactly one exe in no subdirectories. // Since exe's can be differently named, we'll search for exactly one exe in no subdirectories.
var exeList = archive.Entries.Where(f => f.FullName.EndsWith(".exe")).ToList(); var exeList = archive.Entries.Where(f => f.FullName.EndsWith(".exe")).ToList();
@ -94,6 +100,8 @@ public abstract class RawMods : ModsBase
/// <exception cref="NotSupportedException">The raw mod zip was made for an OS that can't be determined.</exception> /// <exception cref="NotSupportedException">The raw mod zip was made for an OS that can't be determined.</exception>
public static void PortToWindows(string inputRawZipPath, string outputRawZipPath, OutputHandlerDelegate outputDelegate = null) public static void PortToWindows(string inputRawZipPath, string outputRawZipPath, OutputHandlerDelegate outputDelegate = null)
{ {
CheckIfOutputPathIsNull(outputRawZipPath);
ModOS currentOS = GetModOSOfRawZip(inputRawZipPath); ModOS currentOS = GetModOSOfRawZip(inputRawZipPath);
outputDelegate.SendOutput("Zip Recognized as " + currentOS); outputDelegate.SendOutput("Zip Recognized as " + currentOS);
@ -160,6 +168,8 @@ public abstract class RawMods : ModsBase
public static void PortToLinux(string inputRawZipPath, string outputRawZipPath, string pathToIcon = null, string pathToSplashScreen = null, public static void PortToLinux(string inputRawZipPath, string outputRawZipPath, string pathToIcon = null, string pathToSplashScreen = null,
OutputHandlerDelegate outputDelegate = null) OutputHandlerDelegate outputDelegate = null)
{ {
CheckIfOutputPathIsNull(outputRawZipPath);
ModOS currentOS = GetModOSOfRawZip(inputRawZipPath); ModOS currentOS = GetModOSOfRawZip(inputRawZipPath);
outputDelegate.SendOutput("Zip Recognized as " + currentOS); outputDelegate.SendOutput("Zip Recognized as " + currentOS);
@ -235,6 +245,8 @@ public abstract class RawMods : ModsBase
public static void PortToAndroid(string inputRawZipPath, string outputRawApkPath, string pathToIcon = null, string pathToSplashScreen = null, public static void PortToAndroid(string inputRawZipPath, string outputRawApkPath, string pathToIcon = null, string pathToSplashScreen = null,
bool useCustomSaveDirectory = false, bool usesInternet = false, OutputHandlerDelegate outputDelegate = null) bool useCustomSaveDirectory = false, bool usesInternet = false, OutputHandlerDelegate outputDelegate = null)
{ {
CheckIfOutputPathIsNull(outputRawApkPath);
ModOS currentOS = GetModOSOfRawZip(inputRawZipPath); ModOS currentOS = GetModOSOfRawZip(inputRawZipPath);
outputDelegate.SendOutput("Zip Recognized as " + currentOS); outputDelegate.SendOutput("Zip Recognized as " + currentOS);
@ -432,6 +444,8 @@ public abstract class RawMods : ModsBase
public static void PortToMac(string inputRawZipPath, string outputRawZipPath, string pathToIcon = null, string pathToSplashScreen = null, public static void PortToMac(string inputRawZipPath, string outputRawZipPath, string pathToIcon = null, string pathToSplashScreen = null,
OutputHandlerDelegate outputDelegate = null) OutputHandlerDelegate outputDelegate = null)
{ {
CheckIfOutputPathIsNull(outputRawZipPath);
ModOS currentOS = GetModOSOfRawZip(inputRawZipPath); ModOS currentOS = GetModOSOfRawZip(inputRawZipPath);
outputDelegate.SendOutput("Zip Recognized as " + currentOS); outputDelegate.SendOutput("Zip Recognized as " + currentOS);
@ -546,6 +560,11 @@ public abstract class RawMods : ModsBase
Directory.Delete(TempDir, true); Directory.Delete(TempDir, true);
} }
private static void CheckIfOutputPathIsNull(string outputPath)
{
if (outputPath is null || String.IsNullOrWhiteSpace(outputPath)) throw new ArgumentOutOfRangeException(nameof(outputPath) + " cannot be null!");
}
/// <summary> /// <summary>
/// Converts a GameMaker data file to bytecode version 16 /// Converts a GameMaker data file to bytecode version 16
/// </summary> /// </summary>

@ -267,6 +267,10 @@ public class RawModsTests
Assert.True(File.Exists(newExtract + "/assets/" + deepSuffix.ToLower() + origInput.ToLower())); Assert.True(File.Exists(newExtract + "/assets/" + deepSuffix.ToLower() + origInput.ToLower()));
} }
#endregion
#region PortToMac
[Theory] [Theory]
[InlineData("./GameWin.zip", false, false)] [InlineData("./GameWin.zip", false, false)]
[InlineData("./GameLin.zip", false, false)] [InlineData("./GameLin.zip", false, false)]
@ -370,5 +374,33 @@ public class RawModsTests
#endregion #endregion
#region PortInvalidZips
[Fact]
public void PortInvalidZipToWindows()
{
Assert.Throws<ArgumentNullException>(() => RawMods.PortToWindows(null, "/foo"));
Assert.Throws<FileNotFoundException>(() => RawMods.PortToWindows("/foo", "/foo"));
Assert.Throws<ArgumentOutOfRangeException>(() => RawMods.PortToWindows("./GameLin.zip", null));
}
[Fact]
public void PortInvalidZipToLinux()
{
Assert.Throws<ArgumentNullException>(() => RawMods.PortToLinux(null, "/foo"));
Assert.Throws<FileNotFoundException>(() => RawMods.PortToLinux("/foo", "/foo"));
Assert.Throws<ArgumentOutOfRangeException>(() => RawMods.PortToLinux("./GameLin.zip", null));
}
[Fact]
public void PortInvalidZipToMac()
{
Assert.Throws<ArgumentNullException>(() => RawMods.PortToMac(null, "/foo"));
Assert.Throws<FileNotFoundException>(() => RawMods.PortToMac("/foo", "/foo"));
Assert.Throws<ArgumentOutOfRangeException>(() => RawMods.PortToMac("./GameLin.zip", null));
}
#endregion
// TODO: write tests for porttoandroid // TODO: write tests for porttoandroid
} }
Loading…
Cancel
Save