mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:33:30 +08:00
Refactor beatmap encoder test to be a bit easier to understand
This commit is contained in:
parent
7072207c7c
commit
93440874db
@ -28,14 +28,15 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
||||
private static IEnumerable<string> allBeatmaps => TestResources.GetStore().GetAvailableResources().Where(res => res.EndsWith(".osu"));
|
||||
|
||||
[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(encoded);
|
||||
sort(decodedAfterEncode);
|
||||
|
||||
Assert.That(encoded.Serialize(), Is.EqualTo(decoded.Serialize()));
|
||||
Assert.That(decodedAfterEncode.Serialize(), Is.EqualTo(decoded.Serialize()));
|
||||
}
|
||||
|
||||
private void sort(IBeatmap beatmap)
|
||||
@ -48,27 +49,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 sr = new LineBufferedReader(stream))
|
||||
{
|
||||
var legacyDecoded = convert(new LegacyBeatmapDecoder { ApplyOffsets = false }.Decode(sr));
|
||||
using (var reader = new LineBufferedReader(stream))
|
||||
return convert(new LegacyBeatmapDecoder { ApplyOffsets = false }.Decode(reader));
|
||||
}
|
||||
|
||||
using (var ms = new MemoryStream())
|
||||
using (var sw = new StreamWriter(ms))
|
||||
using (var sr2 = new LineBufferedReader(ms, true))
|
||||
{
|
||||
new LegacyBeatmapEncoder(legacyDecoded).Encode(sw);
|
||||
private Stream encodeToLegacy(IBeatmap beatmap)
|
||||
{
|
||||
var stream = new MemoryStream();
|
||||
|
||||
sw.Flush();
|
||||
ms.Position = 0;
|
||||
using (var writer = new StreamWriter(stream, leaveOpen: true))
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user