Add test case covering stability of compatibility export operation

This is important as the format will be used more when lazer beatmap
submission comes online, and its stability is a useful property for
that.

Included archive contains an `.osu` with a few fractional-millisecond
timing points and objects, as well as a multi-segment-type slider. That
should cover the range of all possible modifications that the
compatibility exporter currently performs.
This commit is contained in:
Bartłomiej Dach 2024-11-20 13:16:37 +01:00
parent fabeb6f838
commit dfa32302ac
No known key found for this signature in database
2 changed files with 43 additions and 0 deletions

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.IO; using System.IO;
using System.Text;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions; using osu.Framework.Extensions;
@ -9,6 +10,7 @@
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.IO.Archives;
using osu.Game.Tests.Resources; using osu.Game.Tests.Resources;
using osu.Game.Tests.Visual; using osu.Game.Tests.Visual;
using MemoryStream = System.IO.MemoryStream; using MemoryStream = System.IO.MemoryStream;
@ -48,6 +50,47 @@ public void TestObjectsSnappedAfterTruncatingExport()
AddAssert("hit object is snapped", () => beatmap.Beatmap.HitObjects[0].StartTime, () => Is.EqualTo(28519).Within(0.001)); AddAssert("hit object is snapped", () => beatmap.Beatmap.HitObjects[0].StartTime, () => Is.EqualTo(28519).Within(0.001));
} }
[Test]
public void TestExportStability()
{
IWorkingBeatmap beatmap = null!;
MemoryStream firstExport = null!;
MemoryStream secondExport = null!;
// Ensure importer encoding is correct
AddStep("import beatmap", () => beatmap = importBeatmapFromArchives(@"legacy-export-stability-test.olz"));
AddStep("export once", () =>
{
firstExport = new MemoryStream();
new LegacyBeatmapExporter(LocalStorage)
.ExportToStream((BeatmapSetInfo)beatmap.BeatmapInfo.BeatmapSet!, firstExport, null);
});
AddStep("import beatmap again", () => beatmap = importBeatmapFromStream(firstExport));
AddStep("export again", () =>
{
secondExport = new MemoryStream();
new LegacyBeatmapExporter(LocalStorage)
.ExportToStream((BeatmapSetInfo)beatmap.BeatmapInfo.BeatmapSet!, secondExport, null);
});
const string osu_filename = @"legacy export - stability test (spaceman_atlas) [].osu";
AddAssert("exports are identical",
() => getStringContentsOf(osu_filename, firstExport.GetBuffer()),
() => Is.EqualTo(getStringContentsOf(osu_filename, secondExport.GetBuffer())));
string getStringContentsOf(string filename, byte[] archiveBytes)
{
using var memoryStream = new MemoryStream(archiveBytes);
using var archiveReader = new ZipArchiveReader(memoryStream);
byte[] fileContent = archiveReader.GetStream(filename).ReadAllBytesToArray();
return Encoding.UTF8.GetString(fileContent);
}
}
private IWorkingBeatmap importBeatmapFromStream(Stream stream) private IWorkingBeatmap importBeatmapFromStream(Stream stream)
{ {
var imported = beatmaps.Import(new ImportTask(stream, "filename.osz")).GetResultSafely(); var imported = beatmaps.Import(new ImportTask(stream, "filename.osz")).GetResultSafely();