2019-12-10 19:44:45 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2019-12-13 18:00:28 +08:00
|
|
|
using System.Collections.Generic;
|
2019-12-10 19:44:45 +08:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.Formats;
|
|
|
|
using osu.Game.IO;
|
2019-12-13 18:00:28 +08:00
|
|
|
using osu.Game.IO.Serialization;
|
2019-12-10 19:44:45 +08:00
|
|
|
using osu.Game.Tests.Resources;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Beatmaps.Formats
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class LegacyBeatmapEncoderTest
|
|
|
|
{
|
|
|
|
private const string normal = "Soleily - Renatus (Gamu) [Insane].osu";
|
|
|
|
|
2019-12-13 18:00:28 +08:00
|
|
|
private static IEnumerable<string> allBeatmaps => TestResources.GetStore().GetAvailableResources().Where(res => res.EndsWith(".osu"));
|
2019-12-10 19:44:45 +08:00
|
|
|
|
2019-12-13 18:00:28 +08:00
|
|
|
[TestCaseSource(nameof(allBeatmaps))]
|
|
|
|
public void TestDecodeEncodedBeatmap(string name)
|
2019-12-10 19:44:45 +08:00
|
|
|
{
|
2019-12-13 18:00:28 +08:00
|
|
|
var decoded = decode(normal, out var encoded);
|
2019-12-10 19:44:45 +08:00
|
|
|
|
2019-12-13 18:00:28 +08:00
|
|
|
Assert.That(decoded.HitObjects.Count, Is.EqualTo(encoded.HitObjects.Count));
|
|
|
|
Assert.That(encoded.Serialize(), Is.EqualTo(decoded.Serialize()));
|
2019-12-10 19:44:45 +08:00
|
|
|
}
|
|
|
|
|
2019-12-13 18:00:28 +08:00
|
|
|
private Beatmap decode(string filename, out Beatmap encoded)
|
2019-12-10 19:44:45 +08:00
|
|
|
{
|
|
|
|
using (var stream = TestResources.OpenResource(filename))
|
|
|
|
using (var sr = new LineBufferedReader(stream))
|
|
|
|
{
|
|
|
|
var legacyDecoded = new LegacyBeatmapDecoder { ApplyOffsets = false }.Decode(sr);
|
|
|
|
|
|
|
|
using (var ms = new MemoryStream())
|
|
|
|
using (var sw = new StreamWriter(ms))
|
|
|
|
using (var sr2 = new LineBufferedReader(ms))
|
|
|
|
{
|
|
|
|
new LegacyBeatmapEncoder(legacyDecoded).Encode(sw);
|
|
|
|
sw.Flush();
|
|
|
|
|
|
|
|
ms.Position = 0;
|
|
|
|
|
2019-12-13 18:00:28 +08:00
|
|
|
encoded = new LegacyBeatmapDecoder { ApplyOffsets = false }.Decode(sr2);
|
2019-12-10 19:44:45 +08:00
|
|
|
return legacyDecoded;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|