2020-02-18 12:21:55 +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.
|
|
|
|
|
2024-04-30 01:27:45 +08:00
|
|
|
using System.IO;
|
2020-02-18 12:21:55 +08:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
2020-08-21 14:05:56 +08:00
|
|
|
using osu.Framework.Audio.Track;
|
2022-01-03 16:31:12 +08:00
|
|
|
using osu.Framework.Extensions;
|
2023-01-28 22:59:50 +08:00
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2020-02-18 12:21:55 +08:00
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Audio;
|
|
|
|
using osu.Game.Beatmaps;
|
2022-06-20 14:14:57 +08:00
|
|
|
using osu.Game.Database;
|
2020-02-18 12:21:55 +08:00
|
|
|
using osu.Game.Tests.Resources;
|
|
|
|
using osu.Game.Tests.Visual;
|
2024-04-30 01:27:45 +08:00
|
|
|
using MemoryStream = System.IO.MemoryStream;
|
2020-02-18 12:21:55 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Skins
|
|
|
|
{
|
|
|
|
[HeadlessTest]
|
|
|
|
public partial class TestSceneBeatmapSkinResources : OsuTestScene
|
|
|
|
{
|
|
|
|
[Resolved]
|
2023-01-28 22:59:50 +08:00
|
|
|
private BeatmapManager beatmaps { get; set; } = null!;
|
2020-08-21 14:05:56 +08:00
|
|
|
|
2024-04-30 01:14:58 +08:00
|
|
|
[Test]
|
2024-04-30 22:07:37 +08:00
|
|
|
public void TestRetrieveAndLegacyExportJapaneseFilename()
|
2024-04-30 01:14:58 +08:00
|
|
|
{
|
|
|
|
IWorkingBeatmap beatmap = null!;
|
2024-04-30 01:27:45 +08:00
|
|
|
MemoryStream outStream = null!;
|
2024-04-30 01:14:58 +08:00
|
|
|
|
2024-04-30 01:27:45 +08:00
|
|
|
// Ensure importer encoding is correct
|
2024-04-30 01:14:58 +08:00
|
|
|
AddStep("import beatmap", () => beatmap = importBeatmapFromArchives(@"japanese-filename.osz"));
|
|
|
|
AddAssert("sample is non-null", () => beatmap.Skin.GetSample(new SampleInfo(@"見本")) != null);
|
2024-04-30 01:27:45 +08:00
|
|
|
|
|
|
|
// Ensure exporter encoding is correct (round trip)
|
|
|
|
AddStep("export", () =>
|
|
|
|
{
|
|
|
|
outStream = new MemoryStream();
|
|
|
|
|
|
|
|
new LegacyBeatmapExporter(LocalStorage)
|
|
|
|
.ExportToStream((BeatmapSetInfo)beatmap.BeatmapInfo.BeatmapSet!, outStream, null);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("import beatmap again", () => beatmap = importBeatmapFromStream(outStream));
|
|
|
|
AddAssert("sample is non-null", () => beatmap.Skin.GetSample(new SampleInfo(@"見本")) != null);
|
2024-04-30 01:14:58 +08:00
|
|
|
}
|
|
|
|
|
2024-04-30 22:07:37 +08:00
|
|
|
[Test]
|
|
|
|
public void TestRetrieveAndNonLegacyExportJapaneseFilename()
|
|
|
|
{
|
|
|
|
IWorkingBeatmap beatmap = null!;
|
|
|
|
MemoryStream outStream = null!;
|
|
|
|
|
|
|
|
// Ensure importer encoding is correct
|
|
|
|
AddStep("import beatmap", () => beatmap = importBeatmapFromArchives(@"japanese-filename.osz"));
|
|
|
|
AddAssert("sample is non-null", () => beatmap.Skin.GetSample(new SampleInfo(@"見本")) != null);
|
|
|
|
|
|
|
|
// Ensure exporter encoding is correct (round trip)
|
|
|
|
AddStep("export", () =>
|
|
|
|
{
|
|
|
|
outStream = new MemoryStream();
|
|
|
|
|
|
|
|
new BeatmapExporter(LocalStorage)
|
|
|
|
.ExportToStream((BeatmapSetInfo)beatmap.BeatmapInfo.BeatmapSet!, outStream, null);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("import beatmap again", () => beatmap = importBeatmapFromStream(outStream));
|
|
|
|
AddAssert("sample is non-null", () => beatmap.Skin.GetSample(new SampleInfo(@"見本")) != null);
|
|
|
|
}
|
|
|
|
|
2023-01-28 22:59:50 +08:00
|
|
|
[Test]
|
|
|
|
public void TestRetrieveOggAudio()
|
2020-02-18 12:21:55 +08:00
|
|
|
{
|
2023-01-28 22:59:50 +08:00
|
|
|
IWorkingBeatmap beatmap = null!;
|
2022-01-10 11:39:49 +08:00
|
|
|
|
2023-01-28 22:59:50 +08:00
|
|
|
AddStep("import beatmap", () => beatmap = importBeatmapFromArchives(@"ogg-beatmap.osz"));
|
|
|
|
AddAssert("sample is non-null", () => beatmap.Skin.GetSample(new SampleInfo(@"sample")) != null);
|
|
|
|
AddAssert("track is non-null", () =>
|
2022-01-10 11:39:49 +08:00
|
|
|
{
|
2023-01-28 22:59:50 +08:00
|
|
|
using (var track = beatmap.LoadTrack())
|
|
|
|
return track is not TrackVirtual;
|
2022-01-10 11:39:49 +08:00
|
|
|
});
|
2020-02-18 12:21:55 +08:00
|
|
|
}
|
|
|
|
|
2023-01-28 23:02:11 +08:00
|
|
|
[Test]
|
|
|
|
public void TestRetrievalWithConflictingFilenames()
|
|
|
|
{
|
|
|
|
IWorkingBeatmap beatmap = null!;
|
|
|
|
|
|
|
|
AddStep("import beatmap", () => beatmap = importBeatmapFromArchives(@"conflicting-filenames-beatmap.osz"));
|
|
|
|
AddAssert("texture is non-null", () => beatmap.Skin.GetTexture(@"spinner-osu") != null);
|
|
|
|
AddAssert("sample is non-null", () => beatmap.Skin.GetSample(new SampleInfo(@"spinner-osu")) != null);
|
|
|
|
}
|
|
|
|
|
2024-04-30 01:27:45 +08:00
|
|
|
private IWorkingBeatmap importBeatmapFromStream(Stream stream)
|
|
|
|
{
|
|
|
|
var imported = beatmaps.Import(new ImportTask(stream, "filename.osz")).GetResultSafely();
|
|
|
|
return imported.AsNonNull().PerformRead(s => beatmaps.GetWorkingBeatmap(s.Beatmaps[0]));
|
|
|
|
}
|
|
|
|
|
2023-01-28 22:59:50 +08:00
|
|
|
private IWorkingBeatmap importBeatmapFromArchives(string filename)
|
2022-07-28 16:58:13 +08:00
|
|
|
{
|
2023-01-28 22:59:50 +08:00
|
|
|
var imported = beatmaps.Import(new ImportTask(TestResources.OpenResource($@"Archives/{filename}"), filename)).GetResultSafely();
|
|
|
|
return imported.AsNonNull().PerformRead(s => beatmaps.GetWorkingBeatmap(s.Beatmaps[0]));
|
|
|
|
}
|
2020-02-18 12:21:55 +08:00
|
|
|
}
|
|
|
|
}
|