diff --git a/src/test/Syroot.Worms.Armageddon.ProjectX.Test/LibraryTests.cs b/src/test/Syroot.Worms.Armageddon.ProjectX.Test/LibraryTests.cs index ff2662f..a58c06c 100644 --- a/src/test/Syroot.Worms.Armageddon.ProjectX.Test/LibraryTests.cs +++ b/src/test/Syroot.Worms.Armageddon.ProjectX.Test/LibraryTests.cs @@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.Armageddon.ProjectX /// Loads all files found in any game directories. /// [TestMethod] - public void LoadLibraries() => FileTester.Run(Game.Armageddon, "*.pxl"); + public void LoadLibraries() => Tools.TestFiles(Game.Armageddon, "*.pxl"); } } diff --git a/src/test/Syroot.Worms.Armageddon.ProjectX.Test/SchemeTests.cs b/src/test/Syroot.Worms.Armageddon.ProjectX.Test/SchemeTests.cs index c889aaa..a310074 100644 --- a/src/test/Syroot.Worms.Armageddon.ProjectX.Test/SchemeTests.cs +++ b/src/test/Syroot.Worms.Armageddon.ProjectX.Test/SchemeTests.cs @@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.Armageddon.ProjectX /// Loads all files found in any game directories. /// [TestMethod] - public void LoadSchemes() => FileTester.Run(Game.Armageddon, "*.pxs"); + public void LoadSchemes() => Tools.TestFiles(Game.Armageddon, "*.pxs"); } } diff --git a/src/test/Syroot.Worms.Armageddon.Test/GeneratedMapTests.cs b/src/test/Syroot.Worms.Armageddon.Test/GeneratedMapTests.cs index e9ca419..1b17701 100644 --- a/src/test/Syroot.Worms.Armageddon.Test/GeneratedMapTests.cs +++ b/src/test/Syroot.Worms.Armageddon.Test/GeneratedMapTests.cs @@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.Armageddon /// Loads all files found in any game directories. /// [TestMethod] - public void LoadGeneratedMaps() => FileTester.Run(Game.Armageddon | Game.WorldParty, "*.lev"); + public void LoadGeneratedMaps() => Tools.TestFiles(Game.Armageddon | Game.WorldParty, "*.lev"); } } diff --git a/src/test/Syroot.Worms.Armageddon.Test/LandDataTests.cs b/src/test/Syroot.Worms.Armageddon.Test/LandDataTests.cs index 691b436..c4f9c15 100644 --- a/src/test/Syroot.Worms.Armageddon.Test/LandDataTests.cs +++ b/src/test/Syroot.Worms.Armageddon.Test/LandDataTests.cs @@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.Armageddon /// Loads all files found in any game directories. /// [TestMethod] - public void LoadLandData() => FileTester.Run(Game.Armageddon, "land.dat"); + public void LoadLandData() => Tools.TestFiles(Game.Armageddon, "land.dat"); } } diff --git a/src/test/Syroot.Worms.Armageddon.Test/TeamContainerTests.cs b/src/test/Syroot.Worms.Armageddon.Test/TeamContainerTests.cs index b5bd9e2..8ac8249 100644 --- a/src/test/Syroot.Worms.Armageddon.Test/TeamContainerTests.cs +++ b/src/test/Syroot.Worms.Armageddon.Test/TeamContainerTests.cs @@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.Armageddon /// Tests all files found in the test directory. /// [TestMethod] - public void LoadTeamContainers() => FileTester.Run(Game.Test, "*.wgt"); + public void LoadTeamContainers() => Tools.TestFiles(Game.Test, "*.wgt"); } } diff --git a/src/test/Syroot.Worms.Test/ArchiveTests.cs b/src/test/Syroot.Worms.Test/ArchiveTests.cs index 345e5f7..3b362a4 100644 --- a/src/test/Syroot.Worms.Test/ArchiveTests.cs +++ b/src/test/Syroot.Worms.Test/ArchiveTests.cs @@ -15,6 +15,6 @@ namespace Syroot.Worms.Test /// Loads all files found in any game directories. /// [TestMethod] - public void LoadArchives() => FileTester.Run(Game.Team17, "*.dir"); + public void LoadArchives() => Tools.TestFiles(Game.Team17, "*.dir"); } } diff --git a/src/test/Syroot.Worms.Test/Core/FileTester.cs b/src/test/Syroot.Worms.Test/Core/Tools.cs similarity index 62% rename from src/test/Syroot.Worms.Test/Core/FileTester.cs rename to src/test/Syroot.Worms.Test/Core/Tools.cs index 276e22b..2d1b208 100644 --- a/src/test/Syroot.Worms.Test/Core/FileTester.cs +++ b/src/test/Syroot.Worms.Test/Core/Tools.cs @@ -11,7 +11,7 @@ namespace Syroot.Worms.Test.Core /// /// Represents methods helping in executing file-based tests. /// - public static class FileTester + public static class Tools { // ---- CONSTANTS ---------------------------------------------------------------------------------------------- @@ -27,6 +27,40 @@ namespace Syroot.Worms.Test.Core // ---- METHODS (PUBLIC) --------------------------------------------------------------------------------------- + /// + /// Loads, saves, reloads, and compares the data in the given , as long as each + /// operation is supported. + /// + /// The type of the data to load. + /// Name logged to output. + /// storing the raw data to load. + public static void TestStream(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 equatable) + { + Debug.Write($" compare"); + Assert.IsTrue(((IEquatable)newInstance).Equals(equatable)); + } + } + + Debug.WriteLine($" OK"); + } + /// /// Loads, saves, reloads, and compares the files found with the given , as long as /// each operation is supported. Excludes file names specified in the optional array @@ -36,39 +70,20 @@ namespace Syroot.Worms.Test.Core /// The games to test. /// The wildcard to match. /// Optionally, the files to exclude. - public static void Run(Game games, string wildcard, string[] excludedFiles = null) - where T : ILoadableFile, new() + public static void TestFiles(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 equatable) - { - Debug.Write($" compare"); - Assert.IsTrue(((IEquatable)newInstance).Equals(equatable)); - } + using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); + TestStream(fileName, stream); } - Debug.WriteLine($" OK"); } } diff --git a/src/test/Syroot.Worms.Test/ImageTests.cs b/src/test/Syroot.Worms.Test/ImageTests.cs index 6465656..60da5e3 100644 --- a/src/test/Syroot.Worms.Test/ImageTests.cs +++ b/src/test/Syroot.Worms.Test/ImageTests.cs @@ -15,6 +15,6 @@ namespace Syroot.Worms.Test /// Loads all files found in any game directories. /// [TestMethod] - public void LoadImages() => FileTester.Run(Game.All, "*.img"); + public void LoadImages() => Tools.TestFiles(Game.All, "*.img"); } } diff --git a/src/test/Syroot.Worms.Test/PaletteTests.cs b/src/test/Syroot.Worms.Test/PaletteTests.cs index 7602507..40a5734 100644 --- a/src/test/Syroot.Worms.Test/PaletteTests.cs +++ b/src/test/Syroot.Worms.Test/PaletteTests.cs @@ -17,7 +17,7 @@ namespace Syroot.Worms.Test [TestMethod] public void LoadPalettes() { - FileTester.Run(Game.Team17, "*.pal", new string[] + Tools.TestFiles(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. diff --git a/src/test/Syroot.Worms.WorldParty.Test/LandDataTests.cs b/src/test/Syroot.Worms.WorldParty.Test/LandDataTests.cs index 5794770..f0b3cc6 100644 --- a/src/test/Syroot.Worms.WorldParty.Test/LandDataTests.cs +++ b/src/test/Syroot.Worms.WorldParty.Test/LandDataTests.cs @@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.WorldParty /// Loads all files found in any game directories. /// [TestMethod] - public void LoadLandData() => FileTester.Run(Game.WorldParty, "land.dat"); + public void LoadLandData() => Tools.TestFiles(Game.WorldParty, "land.dat"); } } diff --git a/src/test/Syroot.Worms.WorldParty.Test/TeamContainerTests.cs b/src/test/Syroot.Worms.WorldParty.Test/TeamContainerTests.cs index 2641804..00935f2 100644 --- a/src/test/Syroot.Worms.WorldParty.Test/TeamContainerTests.cs +++ b/src/test/Syroot.Worms.WorldParty.Test/TeamContainerTests.cs @@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.WorldParty /// Loads all files found in any game directories. /// [TestMethod] - public void LoadTeamContainers() => FileTester.Run(Game.WorldParty, "*.wwp"); + public void LoadTeamContainers() => Tools.TestFiles(Game.WorldParty, "*.wwp"); } } diff --git a/src/test/Syroot.Worms.Worms2.Test/LandDataTests.cs b/src/test/Syroot.Worms.Worms2.Test/LandDataTests.cs index 1add726..3529b31 100644 --- a/src/test/Syroot.Worms.Worms2.Test/LandDataTests.cs +++ b/src/test/Syroot.Worms.Worms2.Test/LandDataTests.cs @@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.Worms2 /// Loads all files found in any game directories. /// [TestMethod] - public void LoadLandData() => FileTester.Run(Game.Worms2, "land.dat"); + public void LoadLandData() => Tools.TestFiles(Game.Worms2, "land.dat"); } } diff --git a/src/test/Syroot.Worms.Worms2.Test/SchemeOptionsTests.cs b/src/test/Syroot.Worms.Worms2.Test/SchemeOptionsTests.cs index cd0ac72..8c59f1d 100644 --- a/src/test/Syroot.Worms.Worms2.Test/SchemeOptionsTests.cs +++ b/src/test/Syroot.Worms.Worms2.Test/SchemeOptionsTests.cs @@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.Worms2 /// Loads all files found in any game directories. /// [TestMethod] - public void LoadSchemeOptions() => FileTester.Run(Game.Worms2, "*.opt"); + public void LoadSchemeOptions() => Tools.TestFiles(Game.Worms2, "*.opt"); } } diff --git a/src/test/Syroot.Worms.Worms2.Test/SchemeWeaponsTests.cs b/src/test/Syroot.Worms.Worms2.Test/SchemeWeaponsTests.cs index 5f0c4d3..0af90b4 100644 --- a/src/test/Syroot.Worms.Worms2.Test/SchemeWeaponsTests.cs +++ b/src/test/Syroot.Worms.Worms2.Test/SchemeWeaponsTests.cs @@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.Worms2 /// Loads all files found in any game directories. /// [TestMethod] - public void LoadSchemeWeapons() => FileTester.Run(Game.Worms2, "*.wep"); + public void LoadSchemeWeapons() => Tools.TestFiles(Game.Worms2, "*.wep"); } } diff --git a/src/test/Syroot.Worms.Worms2.Test/TeamContainerTests.cs b/src/test/Syroot.Worms.Worms2.Test/TeamContainerTests.cs index 9736d62..591d811 100644 --- a/src/test/Syroot.Worms.Worms2.Test/TeamContainerTests.cs +++ b/src/test/Syroot.Worms.Worms2.Test/TeamContainerTests.cs @@ -16,6 +16,6 @@ namespace Syroot.Worms.Test.Worms2 /// Loads all files found in any game directories. /// [TestMethod] - public void LoadTeamContainers() => FileTester.Run(Game.Worms2, "*.st1"); + public void LoadTeamContainers() => Tools.TestFiles(Game.Worms2, "*.st1"); } }