Add portToMac tests, fix issues with lowercaseFunction, fix invalid linux test zip

mac
Miepee 3 years ago
parent ce74e64d9e
commit c44344a3a4

@ -28,7 +28,8 @@ public static class HelperMethods
// ReSharper disable once PossibleNullReferenceException - since this is a subdirectory, it always has a parent // ReSharper disable once PossibleNullReferenceException - since this is a subdirectory, it always has a parent
// Windows is dumb, thus we need to move in two trips // Windows is dumb, thus we need to move in two trips
subDir.MoveTo(subDir.Parent.FullName + "/" + subDir.Name.ToLower() + "_"); subDir.MoveTo(subDir.Parent.FullName + "/" + subDir.Name.ToLower() + "_");
subDir.MoveTo(subDir.FullName.Substring(0, subDir.FullName.Length-1)); // -2 because after a moving operation, DirInfo already appends a /
subDir.MoveTo(subDir.FullName.Substring(0, subDir.FullName.Length-2));
LowercaseFolder(subDir.FullName); LowercaseFolder(subDir.FullName);
} }
} }

@ -32,11 +32,14 @@ public abstract class RawMods : ModsBase
if (exeList.Count == 1 && !exeList[0].FullName.Contains('/') && archive.Entries.Any(f => f.FullName == "data.win")) if (exeList.Count == 1 && !exeList[0].FullName.Contains('/') && archive.Entries.Any(f => f.FullName == "data.win"))
return ModOS.Windows; return ModOS.Windows;
//TODO: any uppercase files should be invalid!
if (archive.Entries.Any(f => f.FullName == "runner") && archive.Entries.Any(f => f.FullName == "assets/game.unx")) if (archive.Entries.Any(f => f.FullName == "runner") && archive.Entries.Any(f => f.FullName == "assets/game.unx"))
return ModOS.Linux; return ModOS.Linux;
// I probably *should* use fullpaths for these, but the .app file could technically be different and don't want to thinka bout how to circumvent it // I probably *should* use fullpaths for these, but the .app file could technically be different and don't want to thinka bout how to circumvent it
if (archive.Entries.Any(f => f.FullName.Contains("Contents/MacOS/Mac_Runner")) && archive.Entries.Any(f => f.FullName.Contains("Contents/Resources/game.ios"))) if (archive.Entries.Any(f => f.FullName.EndsWith(".app/Contents/MacOS/Mac_Runner")) && archive.Entries.Any(f => f.FullName.EndsWith(".app/Contents/Resources/game.ios"))
&& archive.Entries.Any(f => f.FullName.EndsWith(".app/Contents/Info.plist")) && archive.Entries.Any(f => f.FullName.EndsWith(".app/Contents/PkgInfo"))
&& archive.Entries.Any(f => f.FullName.EndsWith(".app/Contents/Frameworks/libYoYoGamepad.dylib")) && archive.Entries.Any(f => f.FullName.EndsWith(".app/Contents/Frameworks/libYoYoIAP.dylib")))
return ModOS.Mac; return ModOS.Mac;
throw new NotSupportedException("The OS of the mod zip is unknown and thus not supported"); throw new NotSupportedException("The OS of the mod zip is unknown and thus not supported");

Binary file not shown.

@ -116,7 +116,7 @@ public class RawModsTests
var outputZip = testTempDir + Guid.NewGuid(); var outputZip = testTempDir + Guid.NewGuid();
var origExtract = testTempDir + Guid.NewGuid(); var origExtract = testTempDir + Guid.NewGuid();
var newExtract = testTempDir + Guid.NewGuid() + "/"; var newExtract = testTempDir + Guid.NewGuid() + "/";
var deepSuffix = "foobar/foobar/foo/blag/"; var deepSuffix = "Foobar/Foobar/Foo/Blag/";
var origInput = inputZip; var origInput = inputZip;
if (useSubdirectories) if (useSubdirectories)
@ -139,13 +139,14 @@ public class RawModsTests
RawMods.PortToWindows(inputZip, outputZip); RawMods.PortToWindows(inputZip, outputZip);
// Our function should see that its a windows zip // Our function should see that its a windows zip
Assert.True(RawMods.GetModOSOfRawZip(outputZip) == Core.ModOS.Windows); Assert.True(RawMods.GetModOSOfRawZip(outputZip) == Core.ModOS.Windows);
ZipFile.ExtractToDirectory(inputZip, origExtract);
ZipFile.ExtractToDirectory(outputZip, newExtract);
switch (origMod) switch (origMod)
{ {
case Core.ModOS.Windows: case Core.ModOS.Windows:
{ {
// File contents should be same between the zips // File contents should be same between the zips
ZipFile.ExtractToDirectory(inputZip, origExtract);
ZipFile.ExtractToDirectory(outputZip, newExtract);
var origFiles = new DirectoryInfo(origExtract).GetFiles().Select(f => f.Name).ToList(); var origFiles = new DirectoryInfo(origExtract).GetFiles().Select(f => f.Name).ToList();
origFiles.Sort(); origFiles.Sort();
var newFiles = new DirectoryInfo(newExtract).GetFiles().Select(f => f.Name).ToList(); var newFiles = new DirectoryInfo(newExtract).GetFiles().Select(f => f.Name).ToList();
@ -156,8 +157,6 @@ public class RawModsTests
case Core.ModOS.Linux: case Core.ModOS.Linux:
{ {
// File contents should be same between the zips except for runner missing in original and data file being different // File contents should be same between the zips except for runner missing in original and data file being different
ZipFile.ExtractToDirectory(inputZip, origExtract);
ZipFile.ExtractToDirectory(outputZip, newExtract);
List<string> origFiles = new DirectoryInfo(origExtract + "/assets").GetFiles().Select(f => f.Name).ToList(); List<string> origFiles = new DirectoryInfo(origExtract + "/assets").GetFiles().Select(f => f.Name).ToList();
origFiles.Remove("game.unx"); origFiles.Remove("game.unx");
origFiles.Add("data.win"); origFiles.Add("data.win");
@ -182,6 +181,7 @@ public class RawModsTests
} }
#endregion #endregion
// TODO: check that the ports here use the icons we specified
#region PortToLinux #region PortToLinux
[Theory] [Theory]
@ -195,7 +195,7 @@ public class RawModsTests
var outputZip = testTempDir + Guid.NewGuid(); var outputZip = testTempDir + Guid.NewGuid();
var origExtract = testTempDir + Guid.NewGuid(); var origExtract = testTempDir + Guid.NewGuid();
var newExtract = testTempDir + Guid.NewGuid() + "/"; var newExtract = testTempDir + Guid.NewGuid() + "/";
var deepSuffix = "foobar/foobar/foo/blag/"; var deepSuffix = "Foobar/Foobar/Foo/Blag/";
var origInput = inputZip; var origInput = inputZip;
if (useSubdirectories) if (useSubdirectories)
@ -218,22 +218,22 @@ public class RawModsTests
RawMods.PortToLinux(inputZip, outputZip); RawMods.PortToLinux(inputZip, outputZip);
// Our function should see that its a linux zip // Our function should see that its a linux zip
Assert.True(RawMods.GetModOSOfRawZip(outputZip) == Core.ModOS.Linux); Assert.True(RawMods.GetModOSOfRawZip(outputZip) == Core.ModOS.Linux);
ZipFile.ExtractToDirectory(inputZip, origExtract);
ZipFile.ExtractToDirectory(outputZip, newExtract);
switch (origMod) switch (origMod)
{ {
case Core.ModOS.Windows: case Core.ModOS.Windows:
{ {
// File contents should be same between the zips except for old runner+d3d.dll, new splash+icon, ogg being lowered and data file being different // File contents should be same between the zips except for old runner+d3d.dll, new splash+icon,
ZipFile.ExtractToDirectory(inputZip, origExtract); // files being lowered and data file being different
ZipFile.ExtractToDirectory(outputZip, newExtract); var origFiles = new DirectoryInfo(origExtract).GetFiles().Select(f => f.Name.ToLower()).ToList();
var origFiles = new DirectoryInfo(origExtract).GetFiles().Select(f => f.Name).ToList(); origFiles.Remove("am2r server.exe");
origFiles.Remove("AM2R Server.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");
origFiles.Remove("data.win"); origFiles.Remove("data.win");
origFiles.Add("game.unx"); origFiles.Add("game.unx");
origFiles.Remove("CoolSong.ogg");
origFiles.Add("coolsong.ogg");
origFiles.Sort(); origFiles.Sort();
var newFiles = new DirectoryInfo(newExtract + "/assets").GetFiles().Select(f => f.Name).ToList(); var newFiles = new DirectoryInfo(newExtract + "/assets").GetFiles().Select(f => f.Name).ToList();
newFiles.Sort(); newFiles.Sort();
@ -243,8 +243,6 @@ public class RawModsTests
case Core.ModOS.Linux: case Core.ModOS.Linux:
{ {
// File contents should be same between the zips // File contents should be same between the zips
ZipFile.ExtractToDirectory(inputZip, origExtract);
ZipFile.ExtractToDirectory(outputZip, newExtract);
List<string> origFiles = new DirectoryInfo(origExtract + "/assets").GetFiles().Select(f => f.Name).ToList(); List<string> origFiles = new DirectoryInfo(origExtract + "/assets").GetFiles().Select(f => f.Name).ToList();
origFiles.Sort(); origFiles.Sort();
List<string> newFiles = new DirectoryInfo(newExtract + "/assets").GetFiles().Select(f => f.Name).ToList(); List<string> newFiles = new DirectoryInfo(newExtract + "/assets").GetFiles().Select(f => f.Name).ToList();
@ -260,16 +258,107 @@ public class RawModsTests
// If we didn't specify any, there should no more subdirs after that at the end // If we didn't specify any, there should no more subdirs after that at the end
if (!useSubdirectories) if (!useSubdirectories)
{ {
Assert.Empty(new DirectoryInfo(newExtract + "/assets").GetDirectories()); Assert.Empty(new DirectoryInfo(newExtract + "/assets").GetDirectories());
return; return;
} }
//Otherwise there should be our stuff //Otherwise there should be our stuff
Assert.True(File.Exists(newExtract + "/assets/" + deepSuffix + origInput)); Assert.True(File.Exists(newExtract + "/assets/" + deepSuffix.ToLower() + origInput.ToLower()));
}
[Theory]
[InlineData("./GameWin.zip", false, false)]
[InlineData("./GameLin.zip", false, false)]
[InlineData("./GameWin.zip", true, true)]
[InlineData("./GameLin.zip", true, true)]
public void PortZipToMac(string inputZip, bool useSubdirectories, bool createWorkingDirectoryBeforeHand)
{
var origMod = RawMods.GetModOSOfRawZip(inputZip);
var outputZip = testTempDir + Guid.NewGuid();
var origExtract = testTempDir + Guid.NewGuid();
var newExtract = testTempDir + Guid.NewGuid() + "/";
var deepSuffix = "Foobar/Foobar/Foo/Blag/";
var origInput = inputZip;
if (useSubdirectories)
{
string archiveDeepSuffix = deepSuffix;
if (origMod == Core.ModOS.Linux)
{
archiveDeepSuffix = "assets/" + deepSuffix;
}
File.Copy(inputZip, testTempDir + inputZip + "_modified");
inputZip = testTempDir + inputZip + "_modified";
using ZipArchive archive = ZipFile.Open(inputZip, ZipArchiveMode.Update);
archive.CreateEntry(archiveDeepSuffix + origInput);
}
if (createWorkingDirectoryBeforeHand)
Directory.CreateDirectory(libTempDir + Path.GetFileNameWithoutExtension(inputZip));
RawMods.PortToMac(inputZip, outputZip);
// Our function should see that its a mac zip
Assert.True(RawMods.GetModOSOfRawZip(outputZip) == Core.ModOS.Mac);
ZipFile.ExtractToDirectory(inputZip, origExtract);
ZipFile.ExtractToDirectory(outputZip, newExtract);
var appDir = new DirectoryInfo(newExtract).GetDirectories().First(n => n.Name.EndsWith(".app"));
switch (origMod)
{
case Core.ModOS.Windows:
{
// 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
var origFiles = new DirectoryInfo(origExtract).GetFiles().Select(f => f.Name.ToLower()).ToList();
origFiles.Remove("am2r server.exe");
origFiles.Remove("d3dx9_43.dll");
origFiles.Add("splash.png");
origFiles.Add("icon.png");
origFiles.Remove("data.win");
origFiles.Add("game.ios");
origFiles.Add("gamecontrollerdb.txt");
origFiles.Add("yoyorunner.config");
origFiles.Sort();
var newFiles = new DirectoryInfo(appDir.FullName + "/Contents/Resources").GetFiles().Select(f => f.Name).ToList();
newFiles.Sort();
Assert.True(origFiles.SequenceEqual(newFiles));
break;
}
case Core.ModOS.Linux:
{
// File contents should be same between the zips except for all files being lowercase, data file being different and mac specific files
List<string> origFiles = new DirectoryInfo(origExtract + "/assets").GetFiles().Select(f => f.Name.ToLower()).ToList();
origFiles.Remove("game.unx");
origFiles.Add("game.ios");
origFiles.Add("gamecontrollerdb.txt");
origFiles.Add("yoyorunner.config");
origFiles.Sort();
List<string> newFiles = new DirectoryInfo(newExtract + "/" + appDir.Name + "/Contents/Resources").GetFiles().Select(f => f.Name).ToList();
newFiles.Sort();
Assert.True(origFiles.SequenceEqual(newFiles));
break;
}
}
// There should be exactly one subdir here and it should end with .app
Assert.Single(new DirectoryInfo(newExtract).GetDirectories());
Assert.EndsWith(".app", new DirectoryInfo(newExtract).GetDirectories().First().Name);
// If we didn't specify any, there should one more subdirs after that at the end (the English.lproj)
if (!useSubdirectories)
{
Assert.Equal("English.lproj", new DirectoryInfo(newExtract + "/" + appDir.Name + "/Contents/Resources").GetDirectories().First().Name);
return;
}
//Otherwise there should be also stuff
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()));
} }
#endregion #endregion
// TODO: write tests for porttoandroid, porttomac // TODO: write tests for porttoandroid
} }
Loading…
Cancel
Save