mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 07:32:55 +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"));
|
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 +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 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, leaveOpen: 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