1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-24 04:52:56 +08:00
osu-lazer/osu.Game.Tests/Visual/Navigation/TestScenePresentScore.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

242 lines
10 KiB
C#
Raw Normal View History

2020-06-15 19:32:27 +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.
using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Online.API;
2020-06-15 19:32:27 +08:00
using osu.Game.Rulesets;
using osu.Game.Rulesets.Catch;
2020-06-15 19:32:27 +08:00
using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.Osu;
using osu.Game.Scoring;
using osu.Game.Screens;
2020-06-15 19:32:27 +08:00
using osu.Game.Screens.Menu;
using osu.Game.Screens.Play;
using osu.Game.Screens.Ranking;
using osu.Game.Screens.Select;
2020-06-15 19:32:27 +08:00
namespace osu.Game.Tests.Visual.Navigation
{
public partial class TestScenePresentScore : OsuGameTestScene
{
2024-05-20 20:46:28 +08:00
private BeatmapSetInfo beatmap = null!;
2020-06-15 19:32:27 +08:00
[SetUpSteps]
public new void SetUpSteps()
{
AddStep("import beatmap", () =>
{
beatmap = Game.BeatmapManager.Import(new BeatmapSetInfo
{
Hash = Guid.NewGuid().ToString(),
OnlineID = 1,
Beatmaps =
2020-06-15 19:32:27 +08:00
{
new BeatmapInfo
{
OnlineID = 1 * 1024,
Metadata = new BeatmapMetadata
{
Artist = "SomeArtist",
2022-01-18 22:30:40 +08:00
Author = { Username = "SomeAuthor" },
Title = "import"
},
Difficulty = new BeatmapDifficulty(),
2020-06-15 19:32:27 +08:00
Ruleset = new OsuRuleset().RulesetInfo
},
new BeatmapInfo
{
OnlineID = 1 * 2048,
Metadata = new BeatmapMetadata
{
Artist = "SomeArtist",
2022-01-18 22:30:40 +08:00
Author = { Username = "SomeAuthor" },
Title = "import"
},
Difficulty = new BeatmapDifficulty(),
2020-06-15 19:32:27 +08:00
Ruleset = new OsuRuleset().RulesetInfo
},
}
2024-05-20 20:46:28 +08:00
})!.Value;
2020-06-15 19:32:27 +08:00
});
}
[Test]
public void TestFromMainMenu([Values] ScorePresentType type)
{
var firstImport = importScore(1);
var secondImport = importScore(3);
2020-06-15 19:32:27 +08:00
presentAndConfirm(firstImport, type);
returnToMenu();
presentAndConfirm(secondImport, type);
2020-06-15 19:32:27 +08:00
returnToMenu();
returnToMenu();
}
[Test]
public void TestFromMainMenuDifferentRuleset([Values] ScorePresentType type)
{
var firstImport = importScore(1);
var secondImport = importScore(3, new ManiaRuleset().RulesetInfo);
2020-06-15 19:32:27 +08:00
presentAndConfirm(firstImport, type);
returnToMenu();
presentAndConfirm(secondImport, type);
2020-06-15 19:32:27 +08:00
returnToMenu();
returnToMenu();
}
[Test]
public void TestFromSongSelectWithFilter([Values] ScorePresentType type)
{
2023-11-24 14:06:51 +08:00
AddStep("enter song select", () => Game.ChildrenOfType<ButtonSystem>().Single().OnSolo?.Invoke());
AddUntilStep("song select is current", () => Game.ScreenStack.CurrentScreen is PlaySongSelect songSelect && songSelect.BeatmapSetsLoaded);
AddStep("filter to nothing", () => ((PlaySongSelect)Game.ScreenStack.CurrentScreen).FilterControl.CurrentTextSearch.Value = "fdsajkl;fgewq");
AddUntilStep("wait for no results", () => Beatmap.IsDefault);
var firstImport = importScore(1, new CatchRuleset().RulesetInfo);
presentAndConfirm(firstImport, type);
}
[Test]
public void TestFromSongSelectWithConvertRulesetChange([Values] ScorePresentType type)
{
2023-11-24 14:06:51 +08:00
AddStep("enter song select", () => Game.ChildrenOfType<ButtonSystem>().Single().OnSolo?.Invoke());
AddUntilStep("song select is current", () => Game.ScreenStack.CurrentScreen is PlaySongSelect songSelect && songSelect.BeatmapSetsLoaded);
AddStep("set convert to false", () => Game.LocalConfig.SetValue(OsuSetting.ShowConvertedBeatmaps, false));
var firstImport = importScore(1, new CatchRuleset().RulesetInfo);
presentAndConfirm(firstImport, type);
}
2020-06-15 19:32:27 +08:00
[Test]
public void TestFromSongSelect([Values] ScorePresentType type)
{
2023-11-24 14:06:51 +08:00
AddStep("enter song select", () => Game.ChildrenOfType<ButtonSystem>().Single().OnSolo?.Invoke());
AddUntilStep("song select is current", () => Game.ScreenStack.CurrentScreen is PlaySongSelect songSelect && songSelect.BeatmapSetsLoaded);
2020-06-15 19:32:27 +08:00
var firstImport = importScore(1);
presentAndConfirm(firstImport, type);
var secondImport = importScore(3);
presentAndConfirm(secondImport, type);
2020-06-15 19:32:27 +08:00
}
[Test]
public void TestFromSongSelectDifferentRuleset([Values] ScorePresentType type)
{
2023-11-24 14:06:51 +08:00
AddStep("enter song select", () => Game.ChildrenOfType<ButtonSystem>().Single().OnSolo?.Invoke());
AddUntilStep("song select is current", () => Game.ScreenStack.CurrentScreen is PlaySongSelect songSelect && songSelect.BeatmapSetsLoaded);
2020-06-15 19:32:27 +08:00
var firstImport = importScore(1);
presentAndConfirm(firstImport, type);
var secondImport = importScore(3, new ManiaRuleset().RulesetInfo);
presentAndConfirm(secondImport, type);
2024-05-14 17:13:06 +08:00
}
[Test]
public void TestPresentTwoImportsWithSameOnlineIDButDifferentHashes([Values] ScorePresentType type)
{
AddStep("enter song select", () => Game.ChildrenOfType<ButtonSystem>().Single().OnSolo?.Invoke());
AddUntilStep("song select is current", () => Game.ScreenStack.CurrentScreen is PlaySongSelect songSelect && songSelect.BeatmapSetsLoaded);
var firstImport = importScore(1);
presentAndConfirm(firstImport, type);
var secondImport = importScore(1);
presentAndConfirm(secondImport, type);
2020-06-15 19:32:27 +08:00
}
2024-05-20 20:48:02 +08:00
[Test]
public void TestScoreRefetchIgnoresEmptyHash()
{
AddStep("enter song select", () => Game.ChildrenOfType<ButtonSystem>().Single().OnSolo?.Invoke());
AddUntilStep("song select is current", () => Game.ScreenStack.CurrentScreen is PlaySongSelect songSelect && songSelect.BeatmapSetsLoaded);
importScore(-1, hash: string.Empty);
importScore(3, hash: @"deadbeef");
// oftentimes a `PresentScore()` call will be given a `ScoreInfo` which is converted from an online score,
// in which cases the hash will generally not be available.
AddStep("present score", () => Game.PresentScore(new ScoreInfo { OnlineID = 3, Hash = string.Empty }));
AddUntilStep("wait for results", () => lastWaitedScreen != Game.ScreenStack.CurrentScreen && Game.ScreenStack.CurrentScreen is ResultsScreen);
AddUntilStep("correct score displayed", () =>
{
var score = ((ResultsScreen)Game.ScreenStack.CurrentScreen).Score!;
return score.OnlineID == 3 && score.Hash == "deadbeef";
});
}
2020-06-15 19:32:27 +08:00
private void returnToMenu()
{
// if we don't pause, there's a chance the track may change at the main menu out of our control (due to reaching the end of the track).
AddStep("pause audio", () =>
{
if (Game.MusicController.IsPlaying)
Game.MusicController.TogglePause();
});
2020-06-15 19:32:27 +08:00
AddStep("return to menu", () => Game.ScreenStack.CurrentScreen.Exit());
AddUntilStep("wait for menu", () => Game.ScreenStack.CurrentScreen is MainMenu);
}
2024-05-20 20:48:02 +08:00
private Func<ScoreInfo> importScore(int i, RulesetInfo? ruleset = null, string? hash = null)
2020-06-15 19:32:27 +08:00
{
2024-05-20 20:46:28 +08:00
ScoreInfo? imported = null;
2020-06-15 19:32:27 +08:00
AddStep($"import score {i}", () =>
{
imported = Game.ScoreManager.Import(new ScoreInfo
{
2024-05-20 20:48:02 +08:00
Hash = hash ?? Guid.NewGuid().ToString(),
2021-12-10 14:37:12 +08:00
OnlineID = i,
BeatmapInfo = beatmap.Beatmaps.First(),
Ruleset = ruleset ?? new OsuRuleset().RulesetInfo,
User = new GuestUser(),
2024-04-23 02:23:38 +08:00
})!.Value;
2020-06-15 19:32:27 +08:00
});
AddAssert($"import {i} succeeded", () => imported != null);
2024-05-20 20:46:28 +08:00
return () => imported!;
2020-06-15 19:32:27 +08:00
}
/// <summary>
/// Some tests test waiting for a particular screen twice in a row, but expect a new instance each time.
/// There's a case where they may succeed incorrectly if we don't compare against the previous instance.
/// </summary>
2024-05-20 20:46:28 +08:00
private IScreen lastWaitedScreen = null!;
2020-06-15 19:32:27 +08:00
private void presentAndConfirm(Func<ScoreInfo> getImport, ScorePresentType type)
{
AddStep("present score", () => Game.PresentScore(getImport(), type));
switch (type)
{
case ScorePresentType.Results:
AddUntilStep("wait for results", () => lastWaitedScreen != Game.ScreenStack.CurrentScreen && Game.ScreenStack.CurrentScreen is ResultsScreen);
AddStep("store last waited screen", () => lastWaitedScreen = Game.ScreenStack.CurrentScreen);
2024-01-29 15:43:16 +08:00
AddUntilStep("correct score displayed", () => ((ResultsScreen)Game.ScreenStack.CurrentScreen).Score!.Equals(getImport()));
AddAssert("correct ruleset selected", () => Game.Ruleset.Value.Equals(getImport().Ruleset));
2020-06-15 19:32:27 +08:00
break;
case ScorePresentType.Gameplay:
AddUntilStep("wait for player loader", () => lastWaitedScreen != Game.ScreenStack.CurrentScreen && Game.ScreenStack.CurrentScreen is ReplayPlayerLoader);
AddStep("store last waited screen", () => lastWaitedScreen = Game.ScreenStack.CurrentScreen);
AddUntilStep("correct score displayed", () => ((ReplayPlayerLoader)Game.ScreenStack.CurrentScreen).Score.Equals(getImport()));
AddAssert("correct ruleset selected", () => Game.Ruleset.Value.Equals(getImport().Ruleset));
2020-06-15 19:32:27 +08:00
break;
}
}
}
}