2020-09-24 08:24:05 +00: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.
|
|
|
|
|
2020-09-24 13:25:04 +00:00
|
|
|
using System;
|
2020-09-24 13:00:13 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
2020-09-24 08:24:05 +00:00
|
|
|
using NUnit.Framework;
|
2020-10-04 14:57:35 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Screens;
|
2020-09-24 13:00:13 +00:00
|
|
|
using osu.Framework.Testing;
|
2020-09-24 08:24:05 +00:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
2020-09-24 13:00:13 +00:00
|
|
|
using osu.Game.Screens.Edit.Setup;
|
|
|
|
using osu.Game.Tests.Resources;
|
|
|
|
using SharpCompress.Archives;
|
|
|
|
using SharpCompress.Archives.Zip;
|
2020-09-24 08:24:05 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Editing
|
|
|
|
{
|
|
|
|
public class TestSceneEditorBeatmapCreation : EditorTestScene
|
|
|
|
{
|
|
|
|
protected override Ruleset CreateEditorRuleset() => new OsuRuleset();
|
|
|
|
|
2020-09-25 03:24:41 +00:00
|
|
|
protected override bool EditorComponentsReady => Editor.ChildrenOfType<SetupScreen>().SingleOrDefault()?.IsLoaded == true;
|
2020-09-24 13:00:13 +00:00
|
|
|
|
2020-10-04 14:57:35 +00:00
|
|
|
[Resolved]
|
|
|
|
private BeatmapManager beatmapManager { get; set; }
|
|
|
|
|
2020-09-24 13:25:04 +00:00
|
|
|
public override void SetUpSteps()
|
|
|
|
{
|
|
|
|
AddStep("set dummy", () => Beatmap.Value = new DummyWorkingBeatmap(Audio, null));
|
|
|
|
|
|
|
|
base.SetUpSteps();
|
2020-09-24 08:24:05 +00:00
|
|
|
|
2020-09-25 03:25:50 +00:00
|
|
|
// if we save a beatmap with a hash collision, things fall over.
|
|
|
|
// probably needs a more solid resolution in the future but this will do for now.
|
|
|
|
AddStep("make new beatmap unique", () => EditorBeatmap.Metadata.Title = Guid.NewGuid().ToString());
|
2020-09-25 09:40:20 +00:00
|
|
|
}
|
2020-09-25 03:25:50 +00:00
|
|
|
|
2020-09-25 09:40:20 +00:00
|
|
|
[Test]
|
|
|
|
public void TestCreateNewBeatmap()
|
|
|
|
{
|
2020-09-24 08:24:05 +00:00
|
|
|
AddStep("save beatmap", () => Editor.Save());
|
|
|
|
AddAssert("new beatmap persisted", () => EditorBeatmap.BeatmapInfo.ID > 0);
|
2020-10-04 14:57:35 +00:00
|
|
|
AddAssert("new beatmap in database", () => beatmapManager.QueryBeatmapSet(s => s.ID == EditorBeatmap.BeatmapInfo.BeatmapSet.ID)?.DeletePending == false);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestExitWithoutSave()
|
|
|
|
{
|
|
|
|
AddStep("exit without save", () => Editor.Exit());
|
|
|
|
AddUntilStep("wait for exit", () => !Editor.IsCurrentScreen());
|
|
|
|
AddAssert("new beatmap not persisted", () => beatmapManager.QueryBeatmapSet(s => s.ID == EditorBeatmap.BeatmapInfo.BeatmapSet.ID)?.DeletePending == true);
|
2020-09-24 08:24:05 +00:00
|
|
|
}
|
2020-09-24 13:00:13 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAddAudioTrack()
|
|
|
|
{
|
|
|
|
AddAssert("switch track to real track", () =>
|
|
|
|
{
|
|
|
|
var setup = Editor.ChildrenOfType<SetupScreen>().First();
|
|
|
|
|
|
|
|
var temp = TestResources.GetTestBeatmapForImport();
|
|
|
|
|
|
|
|
string extractedFolder = $"{temp}_extracted";
|
|
|
|
Directory.CreateDirectory(extractedFolder);
|
|
|
|
|
|
|
|
using (var zip = ZipArchive.Open(temp))
|
|
|
|
zip.WriteToDirectory(extractedFolder);
|
|
|
|
|
2020-10-06 06:17:15 +00:00
|
|
|
bool success = setup.ChildrenOfType<ResourcesSection>().First().ChangeAudioTrack(Path.Combine(extractedFolder, "03. Renatus - Soleily 192kbps.mp3"));
|
2020-09-24 13:00:13 +00:00
|
|
|
|
|
|
|
File.Delete(temp);
|
|
|
|
Directory.Delete(extractedFolder, true);
|
|
|
|
|
|
|
|
return success;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddAssert("track length changed", () => Beatmap.Value.Track.Length > 60000);
|
|
|
|
}
|
2020-09-24 08:24:05 +00:00
|
|
|
}
|
|
|
|
}
|