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);
@ -541,10 +555,15 @@ public abstract class RawMods : ModsBase
//zip the result //zip the result
outputDelegate.SendOutput("Creating Mac zip..."); outputDelegate.SendOutput("Creating Mac zip...");
ZipFile.CreateFromDirectory(baseTempDirectory, outputRawZipPath); ZipFile.CreateFromDirectory(baseTempDirectory, outputRawZipPath);
// Clean up // Clean up
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

@ -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)]
@ -367,7 +371,35 @@ public class RawModsTests
Assert.Equal("English.lproj", new DirectoryInfo(newExtract + "/" + appDir.Name + "/Contents/Resources").GetDirectories().First(d => d.Name == "English.lproj").Name); Assert.Equal("English.lproj", new DirectoryInfo(newExtract + "/" + appDir.Name + "/Contents/Resources").GetDirectories().First(d => d.Name == "English.lproj").Name);
Assert.True(File.Exists(newExtract + "/" + appDir.Name + "/Contents/Resources/" + deepSuffix.ToLower() + origInput.ToLower())); Assert.True(File.Exists(newExtract + "/" + appDir.Name + "/Contents/Resources/" + deepSuffix.ToLower() + origInput.ToLower()));
} }
#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 #endregion
// TODO: write tests for porttoandroid // TODO: write tests for porttoandroid

Loading…
Cancel
Save