mirror of
https://github.com/ppy/osu
synced 2025-02-07 13:51:59 +00:00
Merge pull request #8993 from peppy/improve-encoder-test-legibility
Refactor beatmap encoder test to be a bit easier to understand
This commit is contained in:
commit
a976d84bf5
@ -6,6 +6,7 @@ using System.Collections;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Audio.Track;
|
using osu.Framework.Audio.Track;
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
@ -28,14 +29,15 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
private static IEnumerable<string> allBeatmaps => TestResources.GetStore().GetAvailableResources().Where(res => res.EndsWith(".osu"));
|
private static IEnumerable<string> allBeatmaps => TestResources.GetStore().GetAvailableResources().Where(res => res.EndsWith(".osu"));
|
||||||
|
|
||||||
[TestCaseSource(nameof(allBeatmaps))]
|
[TestCaseSource(nameof(allBeatmaps))]
|
||||||
public void TestBeatmap(string name)
|
public void TestEncodeDecodeStability(string name)
|
||||||
{
|
{
|
||||||
var decoded = decode(name, out var encoded);
|
var decoded = decodeFromLegacy(TestResources.GetStore().GetStream(name));
|
||||||
|
var decodedAfterEncode = decodeFromLegacy(encodeToLegacy(decoded));
|
||||||
|
|
||||||
sort(decoded);
|
sort(decoded);
|
||||||
sort(encoded);
|
sort(decodedAfterEncode);
|
||||||
|
|
||||||
Assert.That(encoded.Serialize(), Is.EqualTo(decoded.Serialize()));
|
Assert.That(decodedAfterEncode.Serialize(), Is.EqualTo(decoded.Serialize()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sort(IBeatmap beatmap)
|
private void sort(IBeatmap beatmap)
|
||||||
@ -48,27 +50,22 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IBeatmap decode(string filename, out IBeatmap encoded)
|
private IBeatmap decodeFromLegacy(Stream stream)
|
||||||
{
|
{
|
||||||
using (var stream = TestResources.GetStore().GetStream(filename))
|
using (var reader = new LineBufferedReader(stream))
|
||||||
using (var sr = new LineBufferedReader(stream))
|
return convert(new LegacyBeatmapDecoder { ApplyOffsets = false }.Decode(reader));
|
||||||
{
|
}
|
||||||
var legacyDecoded = convert(new LegacyBeatmapDecoder { ApplyOffsets = false }.Decode(sr));
|
|
||||||
|
|
||||||
using (var ms = new MemoryStream())
|
private Stream encodeToLegacy(IBeatmap beatmap)
|
||||||
using (var sw = new StreamWriter(ms))
|
{
|
||||||
using (var sr2 = new LineBufferedReader(ms, true))
|
var stream = new MemoryStream();
|
||||||
{
|
|
||||||
new LegacyBeatmapEncoder(legacyDecoded).Encode(sw);
|
|
||||||
|
|
||||||
sw.Flush();
|
using (var writer = new StreamWriter(stream, Encoding.UTF8, 1024, true))
|
||||||
ms.Position = 0;
|
new LegacyBeatmapEncoder(beatmap).Encode(writer);
|
||||||
|
|
||||||
encoded = convert(new LegacyBeatmapDecoder { ApplyOffsets = false }.Decode(sr2));
|
stream.Position = 0;
|
||||||
|
|
||||||
return legacyDecoded;
|
return stream;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private IBeatmap convert(IBeatmap beatmap)
|
private IBeatmap convert(IBeatmap beatmap)
|
||||||
|
Loading…
Reference in New Issue
Block a user