From 3a6e378a08ce5fde5b23ee302f48ba4afdf4f113 Mon Sep 17 00:00:00 2001 From: Craftplacer Date: Sat, 15 Aug 2020 23:41:53 +0200 Subject: [PATCH] Change skin testing --- .../Formats/LegacyBeatmapEncoderTest.cs | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapEncoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapEncoderTest.cs index 63fdf2a8ae..6ede30d7d8 100644 --- a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapEncoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapEncoderTest.cs @@ -32,25 +32,28 @@ namespace osu.Game.Tests.Beatmaps.Formats private static IEnumerable allBeatmaps = resource_store.GetAvailableResources().Where(res => res.EndsWith(".osu")); - private static readonly Stream beatmap_skin_stream = resource_store.GetStream("skin.ini"); - private ISkin skin; - - [SetUp] - public void Init() - { - skin = decodeSkinFromLegacy(beatmap_skin_stream); - } - [TestCaseSource(nameof(allBeatmaps))] public void TestEncodeDecodeStability(string name) { - var decoded = decodeBeatmapFromLegacy(TestResources.GetStore().GetStream(name)); - var decodedAfterEncode = decodeBeatmapFromLegacy(encodeToLegacy(decoded, skin)); + var decoded = decodeFromLegacy(TestResources.GetStore().GetStream(name)); + var decodedAfterEncode = decodeFromLegacy(encodeToLegacy(decoded)); - sort(decoded); - sort(decodedAfterEncode); + sort(decoded.beatmap); + sort(decodedAfterEncode.beatmap); - Assert.That(decodedAfterEncode.Serialize(), Is.EqualTo(decoded.Serialize())); + Assert.That(decodedAfterEncode.beatmap.Serialize(), Is.EqualTo(decoded.beatmap.Serialize())); + + areSkinsEqual(decoded.beatmapSkin, decodedAfterEncode.beatmapSkin); + } + + private void areSkinsEqual(LegacySkin expected, LegacySkin actual) + { + var expectedColours = expected.Configuration.ComboColours; + var actualColours = actual.Configuration.ComboColours; + + Assert.AreEqual(expectedColours.Count, actualColours.Count); + for (int i = 0; i < expectedColours.Count; i++) + Assert.AreEqual(expectedColours[i], actualColours[i]); } private void sort(IBeatmap beatmap) @@ -63,20 +66,19 @@ namespace osu.Game.Tests.Beatmaps.Formats } } - private IBeatmap decodeBeatmapFromLegacy(Stream stream) + private (IBeatmap beatmap, LegacyBeatmapSkin beatmapSkin) decodeFromLegacy(Stream stream) { using (var reader = new LineBufferedReader(stream)) - return convert(new LegacyBeatmapDecoder { ApplyOffsets = false }.Decode(reader)); + { + var beatmap = new LegacyBeatmapDecoder { ApplyOffsets = false }.Decode(reader); + var beatmapSkin = new LegacyBeatmapSkin(beatmap.BeatmapInfo, resource_store, null); + return (convert(beatmap), beatmapSkin); + } } - private ISkin decodeSkinFromLegacy(Stream stream) - { - using (var reader = new LineBufferedReader(stream)) - return new LegacySkin(SkinInfo.Default, resource_store, null); - } - - private Stream encodeToLegacy(IBeatmap beatmap, ISkin beatmapSkin) + private Stream encodeToLegacy((IBeatmap beatmap, LegacyBeatmapSkin beatmapSkin) fullBeatmap) { + var (beatmap, beatmapSkin) = fullBeatmap; var stream = new MemoryStream(); using (var writer = new StreamWriter(stream, Encoding.UTF8, 1024, true))