From dfa32302acf14ab470e0827d5efbf7bdeed09d8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 20 Nov 2024 13:16:37 +0100 Subject: [PATCH] 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. --- .../Beatmaps/IO/LegacyBeatmapExporterTest.cs | 43 ++++++++++++++++++ .../Archives/legacy-export-stability-test.olz | Bin 0 -> 946 bytes 2 files changed, 43 insertions(+) create mode 100644 osu.Game.Tests/Resources/Archives/legacy-export-stability-test.olz diff --git a/osu.Game.Tests/Beatmaps/IO/LegacyBeatmapExporterTest.cs b/osu.Game.Tests/Beatmaps/IO/LegacyBeatmapExporterTest.cs index 9947def06d..8a95d26782 100644 --- a/osu.Game.Tests/Beatmaps/IO/LegacyBeatmapExporterTest.cs +++ b/osu.Game.Tests/Beatmaps/IO/LegacyBeatmapExporterTest.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System.IO; +using System.Text; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Extensions; @@ -9,6 +10,7 @@ using osu.Framework.Testing; using osu.Game.Beatmaps; using osu.Game.Database; +using osu.Game.IO.Archives; using osu.Game.Tests.Resources; using osu.Game.Tests.Visual; 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)); } + [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) { var imported = beatmaps.Import(new ImportTask(stream, "filename.osz")).GetResultSafely(); diff --git a/osu.Game.Tests/Resources/Archives/legacy-export-stability-test.olz b/osu.Game.Tests/Resources/Archives/legacy-export-stability-test.olz new file mode 100644 index 0000000000000000000000000000000000000000..c6cf33acaf8587cbb040413f5c39d9cc7544d913 GIT binary patch literal 946 zcmWIWW@Zs#-~hsd86}YnP+-Brz+lFpz>t%go|s&zkXliYUsR%?t595$n3S25SyHJ` zl3HA%pix|qn4FrMm=~W|l9O1hsSq8jmtR~O8p6xKzUqQ)It-Uqa5FHnykKTv028T! z(RsHG1pYkNEMaJU@O$BYn=X}xyAq|hn0R}drp;*S)sYl=e5Ez-TEE=N@E4cXB`;xJ zD7tmCwe{v-e?N!Y+lYT(`1NS5e7K&d^eG;v^6C3NU);)F^6O4Z-J{szyP>R(n_rk8 z+<&KS>iRC>u5-Vi>zV%LZV)+pH|y@No&KR8?KW@Cm>2Wcz2@`TCrogcSbRoy=uEWiEqy`#@g*!aY*l22cITd(n3v$tLHi+8cY z3#uCR4o!#&|NZmU)rHk39?UF%sg!f*!tqrCFO1sK{#&1YYKwZk z^B5zt7IM6pwvab7TE%`z?YCs{S94qI4_uy+P!qc4-@&W557ozi|2U!cZ6)`-=J!)t zc@=J~kNJLe={4RLllz@tBraX>Qt8h9_Fp@FZ?o>273(6tYj0uaIp;Nrcdf03?&f^r z&+h+fS-C6j_`R$B?b9l`x%+|}4)5ZXa|_n_mzIBc_T0Rh>20ic68txuiIgw9Kc%p7 zsn*tQGYpy5*FIUQk?HB>Ba;3&=Sfro^OHS~c3XZ}?UrhAJ<6%=@Vm~Z0j(=HPU`9s zZfg~2Yc%%K&8fd5Df7@$>MwJEH#5M?w0;DB?8Hj-a0N_@bl>h($ literal 0 HcmV?d00001