mirror of
https://gitlab.com/Syroot/Worms.git
synced 2025-01-13 15:27:59 +03:00
Rename FileTester to Tools and allow testing of single Streams.
This commit is contained in:
parent
66d4d15305
commit
10008eaf6e
@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.Armageddon.ProjectX
|
||||
/// Loads all files found in any game directories.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void LoadLibraries() => FileTester.Run<Library>(Game.Armageddon, "*.pxl");
|
||||
public void LoadLibraries() => Tools.TestFiles<Library>(Game.Armageddon, "*.pxl");
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.Armageddon.ProjectX
|
||||
/// Loads all files found in any game directories.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void LoadSchemes() => FileTester.Run<Scheme>(Game.Armageddon, "*.pxs");
|
||||
public void LoadSchemes() => Tools.TestFiles<Scheme>(Game.Armageddon, "*.pxs");
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.Armageddon
|
||||
/// Loads all files found in any game directories.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void LoadGeneratedMaps() => FileTester.Run<GeneratedMap>(Game.Armageddon | Game.WorldParty, "*.lev");
|
||||
public void LoadGeneratedMaps() => Tools.TestFiles<GeneratedMap>(Game.Armageddon | Game.WorldParty, "*.lev");
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.Armageddon
|
||||
/// Loads all files found in any game directories.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void LoadLandData() => FileTester.Run<LandData>(Game.Armageddon, "land.dat");
|
||||
public void LoadLandData() => Tools.TestFiles<LandData>(Game.Armageddon, "land.dat");
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.Armageddon
|
||||
/// Tests all files found in the test directory.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void LoadTeamContainers() => FileTester.Run<TeamContainer>(Game.Test, "*.wgt");
|
||||
public void LoadTeamContainers() => Tools.TestFiles<TeamContainer>(Game.Test, "*.wgt");
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,6 @@ namespace Syroot.Worms.Test
|
||||
/// Loads all files found in any game directories.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void LoadArchives() => FileTester.Run<Archive>(Game.Team17, "*.dir");
|
||||
public void LoadArchives() => Tools.TestFiles<Archive>(Game.Team17, "*.dir");
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace Syroot.Worms.Test.Core
|
||||
/// <summary>
|
||||
/// Represents methods helping in executing file-based tests.
|
||||
/// </summary>
|
||||
public static class FileTester
|
||||
public static class Tools
|
||||
{
|
||||
// ---- CONSTANTS ----------------------------------------------------------------------------------------------
|
||||
|
||||
@ -27,6 +27,40 @@ namespace Syroot.Worms.Test.Core
|
||||
|
||||
// ---- METHODS (PUBLIC) ---------------------------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Loads, saves, reloads, and compares the data in the given <paramref name="stream"/>, as long as each
|
||||
/// operation is supported.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the data to load.</typeparam>
|
||||
/// <param name="name">Name logged to output.</param>
|
||||
/// <param name="stream"><see cref="Stream"/> storing the raw data to load.</param>
|
||||
public static void TestStream<T>(string name, Stream stream) where T : ILoadable, new()
|
||||
{
|
||||
Debug.Write($"\"{name}\" load");
|
||||
T instance = new T();
|
||||
instance.Load(stream);
|
||||
|
||||
if (instance is ISaveable saveable)
|
||||
{
|
||||
Debug.Write($" save");
|
||||
using MemoryStream newStream = new MemoryStream();
|
||||
saveable.Save(newStream);
|
||||
|
||||
Debug.Write($" reload");
|
||||
newStream.Position = 0;
|
||||
T newInstance = new T();
|
||||
newInstance.Load(newStream);
|
||||
|
||||
if (instance is IEquatable<T> equatable)
|
||||
{
|
||||
Debug.Write($" compare");
|
||||
Assert.IsTrue(((IEquatable<T>)newInstance).Equals(equatable));
|
||||
}
|
||||
}
|
||||
|
||||
Debug.WriteLine($" OK");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads, saves, reloads, and compares the files found with the given <paramref name="wildcard"/>, as long as
|
||||
/// each operation is supported. Excludes file names specified in the optional array
|
||||
@ -36,40 +70,21 @@ namespace Syroot.Worms.Test.Core
|
||||
/// <param name="games">The games to test.</param>
|
||||
/// <param name="wildcard">The wildcard to match.</param>
|
||||
/// <param name="excludedFiles">Optionally, the files to exclude.</param>
|
||||
public static void Run<T>(Game games, string wildcard, string[] excludedFiles = null)
|
||||
where T : ILoadableFile, new()
|
||||
public static void TestFiles<T>(Game games, string wildcard, string[] excludedFiles = null)
|
||||
where T : ILoadable, new()
|
||||
{
|
||||
foreach (string fileName in FindFiles(games, wildcard))
|
||||
{
|
||||
if (excludedFiles?.Contains(Path.GetFileName(fileName), StringComparer.OrdinalIgnoreCase) == true)
|
||||
{
|
||||
Debug.WriteLine($"Skipping {fileName}");
|
||||
continue;
|
||||
Debug.WriteLine($"\"{fileName}\" skipped");
|
||||
}
|
||||
|
||||
Debug.Write($"\"{fileName}\" load");
|
||||
T instance = new T();
|
||||
instance.Load(fileName);
|
||||
|
||||
if (instance is ISaveableFile saveable)
|
||||
else
|
||||
{
|
||||
Debug.Write($" save");
|
||||
using MemoryStream stream = new MemoryStream();
|
||||
saveable.Save(stream);
|
||||
|
||||
Debug.Write($" reload");
|
||||
stream.Position = 0;
|
||||
T newInstance = new T();
|
||||
newInstance.Load(stream);
|
||||
|
||||
if (instance is IEquatable<T> equatable)
|
||||
{
|
||||
Debug.Write($" compare");
|
||||
Assert.IsTrue(((IEquatable<T>)newInstance).Equals(equatable));
|
||||
using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
TestStream<T>(fileName, stream);
|
||||
}
|
||||
}
|
||||
Debug.WriteLine($" OK");
|
||||
}
|
||||
}
|
||||
|
||||
// ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------
|
@ -15,6 +15,6 @@ namespace Syroot.Worms.Test
|
||||
/// Loads all files found in any game directories.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void LoadImages() => FileTester.Run<Img>(Game.All, "*.img");
|
||||
public void LoadImages() => Tools.TestFiles<Img>(Game.All, "*.img");
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ namespace Syroot.Worms.Test
|
||||
[TestMethod]
|
||||
public void LoadPalettes()
|
||||
{
|
||||
FileTester.Run<RiffPalette>(Game.Team17, "*.pal", new string[]
|
||||
Tools.TestFiles<RiffPalette>(Game.Team17, "*.pal", new string[]
|
||||
{
|
||||
"wwp.pal", // Contains 4 bytes of trash after the data chunk.
|
||||
"wwpmaped.pal" // Contains 4 bytes of trash after the data chunk.
|
||||
|
@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.WorldParty
|
||||
/// Loads all files found in any game directories.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void LoadLandData() => FileTester.Run<LandData>(Game.WorldParty, "land.dat");
|
||||
public void LoadLandData() => Tools.TestFiles<LandData>(Game.WorldParty, "land.dat");
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.WorldParty
|
||||
/// Loads all files found in any game directories.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void LoadTeamContainers() => FileTester.Run<TeamContainer>(Game.WorldParty, "*.wwp");
|
||||
public void LoadTeamContainers() => Tools.TestFiles<TeamContainer>(Game.WorldParty, "*.wwp");
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.Worms2
|
||||
/// Loads all files found in any game directories.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void LoadLandData() => FileTester.Run<LandData>(Game.Worms2, "land.dat");
|
||||
public void LoadLandData() => Tools.TestFiles<LandData>(Game.Worms2, "land.dat");
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.Worms2
|
||||
/// Loads all files found in any game directories.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void LoadSchemeOptions() => FileTester.Run<SchemeOptions>(Game.Worms2, "*.opt");
|
||||
public void LoadSchemeOptions() => Tools.TestFiles<SchemeOptions>(Game.Worms2, "*.opt");
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.Worms2
|
||||
/// Loads all files found in any game directories.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void LoadSchemeWeapons() => FileTester.Run<SchemeWeapons>(Game.Worms2, "*.wep");
|
||||
public void LoadSchemeWeapons() => Tools.TestFiles<SchemeWeapons>(Game.Worms2, "*.wep");
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.Worms2
|
||||
/// Loads all files found in any game directories.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void LoadTeamContainers() => FileTester.Run<TeamContainer>(Game.Worms2, "*.st1");
|
||||
public void LoadTeamContainers() => Tools.TestFiles<TeamContainer>(Game.Worms2, "*.st1");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user