Condense some facts into one theory, change windows test zip to be more logical

mac
Miepee 3 years ago
parent 5e91237be5
commit 3ea261fc0a

@ -108,7 +108,7 @@ public abstract class RawMods : ModsBase
if (currentOS == ModOS.Windows) if (currentOS == ModOS.Windows)
{ {
outputDelegate.SendOutput("Zip is already a raw Windows zip. Copying to output directory..."); outputDelegate.SendOutput("Zip is already a raw Windows zip. Copying to output directory...");
File.Copy(inputRawZipPath, outputRawZipPath, true); File.Copy(inputRawZipPath, outputRawZipPath);
return; return;
} }

Binary file not shown.

@ -28,100 +28,61 @@ public class RawModsTests : IDisposable
#region GetModOSOfRawZipTests #region GetModOSOfRawZipTests
[Fact] [Theory]
public void WindowsZipWithDifferentRunnerShouldBeWindows() [InlineData("./GameWin.zip", Core.ModOS.Windows)]
{ [InlineData("./GameLin.zip", Core.ModOS.Linux)]
var result = RawMods.GetModOSOfRawZip("./GameWin.zip"); [InlineData("./GameMac.zip", Core.ModOS.Mac)]
Assert.True(result == Core.ModOS.Windows); public void OSZipWithGoodRunnerShouldSucceed(string input, Core.ModOS os)
}
[Fact]
public void WindowsZipWithSameRunnerShouldBeWindows()
{ {
var destinationZip = Path.GetTempPath() + Guid.NewGuid() + ".zip"; var result = RawMods.GetModOSOfRawZip(input);
ZipFile.ExtractToDirectory("./GameWin.zip", testTempDir); Assert.True(result == os);
File.Move(testTempDir + "/AM2R Server.exe", testTempDir + "/AM2R.exe");
ZipFile.CreateFromDirectory(testTempDir, destinationZip);
var result = RawMods.GetModOSOfRawZip(destinationZip);
Assert.True(result == Core.ModOS.Windows);
File.Delete(destinationZip);
} }
[Fact] [Theory]
public void WindowsZipWithTwoRunnersShouldThrow() [InlineData("./GameLin.zip", "/runner")]
[InlineData("./GameMac.zip", "/AM2R.app/Contents/MacOS/Mac_Runner")]
public void UnixWithWrongRunnerShouldThrow(string input, string runnerSuffix)
{ {
var destinationZip = Path.GetTempPath() + Guid.NewGuid(); var destinationZip = Path.GetTempPath() + Guid.NewGuid();
ZipFile.ExtractToDirectory("./GameWin.zip", testTempDir); ZipFile.ExtractToDirectory(input, testTempDir);
File.Copy(testTempDir + "/AM2R Server.exe", testTempDir + "/AM2R.exe"); File.Move(testTempDir + runnerSuffix, testTempDir + runnerSuffix + "_");
ZipFile.CreateFromDirectory(testTempDir, destinationZip); ZipFile.CreateFromDirectory(testTempDir, destinationZip);
Assert.Throws<NotSupportedException>(() => RawMods.GetModOSOfRawZip(destinationZip)); Assert.Throws<NotSupportedException>(() => RawMods.GetModOSOfRawZip(destinationZip));
File.Delete(destinationZip); File.Delete(destinationZip);
} }
[Fact] [Fact]
public void LinuxZipWithGoodRunnerShouldBeLinux() public void WindowsZipWithDifferentRunnerShouldSucceed()
{
var result = RawMods.GetModOSOfRawZip("./GameLin.zip");
Assert.True(result == Core.ModOS.Linux);
}
[Fact]
public void LinuxZipWithWrongRunnerShouldThrow()
{ {
var destinationZip = Path.GetTempPath() + Guid.NewGuid(); var destinationZip = Path.GetTempPath() + Guid.NewGuid() + ".zip";
ZipFile.ExtractToDirectory("./GameLin.zip", testTempDir); ZipFile.ExtractToDirectory("./GameWin.zip", testTempDir);
File.Move(testTempDir + "/runner", testTempDir + "/AM2R"); File.Move(testTempDir + "/AM2R.exe", testTempDir + "/Game.exe");
ZipFile.CreateFromDirectory(testTempDir, destinationZip); ZipFile.CreateFromDirectory(testTempDir, destinationZip);
Assert.Throws<NotSupportedException>(() => RawMods.GetModOSOfRawZip(destinationZip)); var result = RawMods.GetModOSOfRawZip(destinationZip);
Assert.True(result == Core.ModOS.Windows);
File.Delete(destinationZip); File.Delete(destinationZip);
} }
[Fact] [Fact]
public void MacZipWithGoodRunnerShouldBeMac() public void WindowsZipWithTwoRunnersShouldThrow()
{
var result = RawMods.GetModOSOfRawZip("./GameMac.zip");
Assert.True(result == Core.ModOS.Mac);
}
[Fact]
public void MacZipWithWrongRunnerShouldThrow()
{ {
var destinationZip = Path.GetTempPath() + Guid.NewGuid(); var destinationZip = Path.GetTempPath() + Guid.NewGuid();
ZipFile.ExtractToDirectory("./GameMac.zip", testTempDir);
File.Move(testTempDir + "/AM2R.app/Contents/MacOS/Mac_Runner", testTempDir + "/AM2R.app/Contents/MacOS/Binary");
ZipFile.CreateFromDirectory(testTempDir, destinationZip);
Assert.Throws<NotSupportedException>(() => RawMods.GetModOSOfRawZip(destinationZip));
File.Delete(destinationZip);
}
[Fact]
public void WindowsZipWithInvalidDataFileShouldThrow()
{
var destinationZip = Path.GetTempPath() + Guid.NewGuid() + ".zip";
ZipFile.ExtractToDirectory("./GameWin.zip", testTempDir); ZipFile.ExtractToDirectory("./GameWin.zip", testTempDir);
File.Move(testTempDir + "/data.win", testTempDir + "/data.win_"); File.Copy(testTempDir + "/AM2R.exe", testTempDir + "/Game.exe");
ZipFile.CreateFromDirectory(testTempDir, destinationZip); ZipFile.CreateFromDirectory(testTempDir, destinationZip);
Assert.Throws<NotSupportedException>(() => RawMods.GetModOSOfRawZip(destinationZip)); Assert.Throws<NotSupportedException>(() => RawMods.GetModOSOfRawZip(destinationZip));
File.Delete(destinationZip); File.Delete(destinationZip);
} }
[Fact] [Theory]
public void LinuxZipWithInvalidDataFileShouldThrow() [InlineData("./GameWin.zip", "/data.win")]
[InlineData("./GameLin.zip", "/assets/game.unx")]
[InlineData("./GameMac.zip", "/AM2R.app/Contents/Resources/game.ios")]
public void OSZipWithInvalidDataFileShouldThrow(string input, string dataSuffix)
{ {
var destinationZip = Path.GetTempPath() + Guid.NewGuid() + ".zip"; var destinationZip = Path.GetTempPath() + Guid.NewGuid() + ".zip";
ZipFile.ExtractToDirectory("./GameLin.zip", testTempDir); ZipFile.ExtractToDirectory(input, testTempDir);
File.Move(testTempDir + "/assets/game.unx", testTempDir + "/assets/game.unx_"); File.Move(testTempDir + dataSuffix, testTempDir + dataSuffix + "_");
ZipFile.CreateFromDirectory(testTempDir, destinationZip);
Assert.Throws<NotSupportedException>(() => RawMods.GetModOSOfRawZip(destinationZip));
File.Delete(destinationZip);
}
[Fact]
public void MacZipWithInvalidDataFileShouldThrow()
{
var destinationZip = Path.GetTempPath() + Guid.NewGuid();
ZipFile.ExtractToDirectory("./GameMac.zip", testTempDir);
File.Move(testTempDir + "/AM2R.app/Contents/Resources/game.ios", testTempDir + "//AM2R.app/Contents/Resources/game.ios_");
ZipFile.CreateFromDirectory(testTempDir, destinationZip); ZipFile.CreateFromDirectory(testTempDir, destinationZip);
Assert.Throws<NotSupportedException>(() => RawMods.GetModOSOfRawZip(destinationZip)); Assert.Throws<NotSupportedException>(() => RawMods.GetModOSOfRawZip(destinationZip));
File.Delete(destinationZip); File.Delete(destinationZip);
@ -303,7 +264,7 @@ public class RawModsTests : IDisposable
// File contents should be same between the zips except for old runner+d3d.dll, new splash+icon, // File contents should be same between the zips except for old runner+d3d.dll, new splash+icon,
// files being lowered and data file being different // files being lowered and data file being different
var origFiles = new DirectoryInfo(origExtract).GetFiles().Select(f => f.Name.ToLower()).ToList(); var origFiles = new DirectoryInfo(origExtract).GetFiles().Select(f => f.Name.ToLower()).ToList();
origFiles.Remove("am2r server.exe"); origFiles.Remove("am2r.exe");
origFiles.Remove("d3dx9_43.dll"); origFiles.Remove("d3dx9_43.dll");
origFiles.Add("splash.png"); origFiles.Add("splash.png");
origFiles.Add("icon.png"); origFiles.Add("icon.png");
@ -458,7 +419,7 @@ public class RawModsTests : IDisposable
// File contents should be same between the zips except for old runner+d3d.dll, new splash+icon, // File contents should be same between the zips except for old runner+d3d.dll, new splash+icon,
// files being lowercase, data file being different a new gamecontrollerdb and a new yoyorunner.config // files being lowercase, data file being different a new gamecontrollerdb and a new yoyorunner.config
var origFiles = new DirectoryInfo(origExtract).GetFiles().Select(f => f.Name.ToLower()).ToList(); var origFiles = new DirectoryInfo(origExtract).GetFiles().Select(f => f.Name.ToLower()).ToList();
origFiles.Remove("am2r server.exe"); origFiles.Remove("am2r.exe");
origFiles.Remove("d3dx9_43.dll"); origFiles.Remove("d3dx9_43.dll");
origFiles.Add("splash.png"); origFiles.Add("splash.png");
origFiles.Add("icon.png"); origFiles.Add("icon.png");
@ -551,72 +512,57 @@ public class RawModsTests : IDisposable
#region PortInvalidZips #region PortInvalidZips
[Fact] [Theory]
public void PortInvalidZipToWindows() [InlineData(Core.ModOS.Windows)]
{ [InlineData(Core.ModOS.Linux)]
Assert.Throws<ArgumentNullException>(() => RawMods.PortToWindows(null, "/foo")); [InlineData(Core.ModOS.Mac)]
Assert.Throws<FileNotFoundException>(() => RawMods.PortToWindows("/foo", "/foo")); public void PortInvalidZipsToOS(Core.ModOS os)
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")); Action<string?, string?> function = os switch
Assert.Throws<FileNotFoundException>(() => RawMods.PortToMac("/foo", "/foo")); {
Assert.Throws<ArgumentOutOfRangeException>(() => RawMods.PortToMac("./GameLin.zip", null)); Core.ModOS.Windows => (input, outputFile) => RawMods.PortToWindows(input, outputFile),
Core.ModOS.Linux => (input, outputFile) => RawMods.PortToLinux(input, outputFile),
Core.ModOS.Mac => (input, outputFile) => RawMods.PortToMac(input, outputFile),
_ => throw new Exception("This should not have happened! new unhandled data!")
};
Assert.Throws<ArgumentNullException>(() => function.Invoke(null, "/foo"));
Assert.Throws<FileNotFoundException>(() => function.Invoke("/foo", "/foo"));
Assert.Throws<ArgumentOutOfRangeException>(() => function.Invoke("./GameLin.zip", null));
} }
#endregion #endregion
#region Make sure porting methods work when called in succession #region Make sure porting methods work when called in succession
[Fact]
public void TestPortToWindowsMultipleTimes()
{
const string input = "./GameLin.zip";
string outputZip = testTempDir + "/foobar.zip";
RawMods.PortToWindows(input, outputZip);
Assert.Throws<IOException>(() => RawMods.PortToWindows(input, outputZip));
File.Delete(outputZip);
RawMods.PortToWindows(input, outputZip);
Assert.True(File.Exists(outputZip));
}
[Fact]
public void TestPortToLinuxMultipleTimes()
{
const string input = "./GameLin.zip";
string outputZip = testTempDir + "/foobar.zip";
RawMods.PortToLinux(input, outputZip);
Assert.Throws<IOException>(() => RawMods.PortToLinux(input, outputZip));
File.Delete(outputZip);
RawMods.PortToLinux(input, outputZip);
Assert.True(File.Exists(outputZip));
}
[Theory] [Theory]
[InlineData("./GameWin.zip")] [InlineData("./GameWin.zip", Core.ModOS.Windows)]
[InlineData("./GameLin.zip")] [InlineData("./GameWin.zip", Core.ModOS.Linux)]
[InlineData("./GameMac.zip")] [InlineData("./GameWin.zip", Core.ModOS.Mac)]
public void TestPortToMacMultipleTimes(string input) [InlineData("./GameLin.zip", Core.ModOS.Windows)]
[InlineData("./GameLin.zip", Core.ModOS.Linux)]
[InlineData("./GameLin.zip", Core.ModOS.Mac)]
[InlineData("./GameMac.zip", Core.ModOS.Windows)]
[InlineData("./GameMac.zip", Core.ModOS.Linux)]
[InlineData("./GameMac.zip", Core.ModOS.Mac)]
public void TestPortToOSMultipleTimes(string input, Core.ModOS os)
{ {
Action<string?, string?> function = os switch
{
Core.ModOS.Windows => (inputFile, outputFile) => RawMods.PortToWindows(inputFile, outputFile),
Core.ModOS.Linux => (inputFile, outputFile) => RawMods.PortToLinux(inputFile, outputFile),
Core.ModOS.Mac => (inputFile, outputFile) => RawMods.PortToMac(inputFile, outputFile),
_ => throw new Exception("This should not have happened! new unhandled data!")
};
string outputZip = testTempDir + "/foobar.zip"; string outputZip = testTempDir + "/foobar.zip";
RawMods.PortToMac(input, outputZip); function.Invoke(input, outputZip);
Assert.Throws<IOException>(() => RawMods.PortToMac(input, outputZip)); Assert.Throws<IOException>(() => function.Invoke(input, outputZip));
File.Delete(outputZip); File.Delete(outputZip);
RawMods.PortToMac(input, outputZip); function.Invoke(input, outputZip);
Assert.True(File.Exists(outputZip)); Assert.True(File.Exists(outputZip));
} }
#endregion #endregion
// TODO: write tests for porttoandroid // TODO: write tests for porttoandroid

Loading…
Cancel
Save