1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-27 00:23:01 +08:00

Add test coverage

This commit is contained in:
Dean Herbert 2021-06-14 15:06:33 +09:00
parent 83402a70db
commit fcb0b8d825

View File

@ -2,16 +2,22 @@
// 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; using System;
using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Platform;
using osu.Framework.Testing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Online.Leaderboards; using osu.Game.Online.Leaderboards;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Screens.Select.Leaderboards; using osu.Game.Screens.Select.Leaderboards;
using osu.Game.Tests.Resources;
using osu.Game.Users; using osu.Game.Users;
using osuTK; using osuTK;
@ -24,26 +30,73 @@ namespace osu.Game.Tests.Visual.SongSelect
[Cached] [Cached]
private readonly DialogOverlay dialogOverlay; private readonly DialogOverlay dialogOverlay;
private ScoreManager scoreManager;
private RulesetStore rulesetStore;
private BeatmapManager beatmapManager;
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.Cache(rulesetStore = new RulesetStore(ContextFactory));
dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesetStore, null, dependencies.Get<AudioManager>(), Resources, dependencies.Get<GameHost>(), Beatmap.Default));
dependencies.Cache(scoreManager = new ScoreManager(rulesetStore, () => beatmapManager, LocalStorage, null, ContextFactory));
return dependencies;
}
public TestSceneBeatmapLeaderboard() public TestSceneBeatmapLeaderboard()
{ {
Add(dialogOverlay = new DialogOverlay AddRange(new Drawable[]
{ {
Depth = -1 dialogOverlay = new DialogOverlay
}); {
Depth = -1
Add(leaderboard = new FailableLeaderboard },
{ leaderboard = new FailableLeaderboard
Origin = Anchor.Centre, {
Anchor = Anchor.Centre, Origin = Anchor.Centre,
Size = new Vector2(550f, 450f), Anchor = Anchor.Centre,
Scope = BeatmapLeaderboardScope.Global, Size = new Vector2(550f, 450f),
Scope = BeatmapLeaderboardScope.Global,
}
}); });
} }
[Test] [Test]
public void TestScoresDisplay() public void TestLocalScoresDisplay()
{ {
AddStep(@"New Scores", newScores); BeatmapInfo beatmapInfo = null;
AddStep(@"Set scope", () => leaderboard.Scope = BeatmapLeaderboardScope.Local);
AddStep(@"Set beatmap", () =>
{
beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).Wait();
beatmapInfo = beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps.First();
leaderboard.Beatmap = beatmapInfo;
});
clearScores();
checkCount(0);
loadMoreScores(() => beatmapInfo);
checkCount(10);
loadMoreScores(() => beatmapInfo);
checkCount(20);
clearScores();
checkCount(0);
}
[Test]
public void TestGlobalScoresDisplay()
{
AddStep(@"Set scope", () => leaderboard.Scope = BeatmapLeaderboardScope.Global);
AddStep(@"New Scores", () => leaderboard.Scores = generateSampleScores(null));
} }
[Test] [Test]
@ -116,9 +169,26 @@ namespace osu.Game.Tests.Visual.SongSelect
}; };
} }
private void newScores() private void loadMoreScores(Func<BeatmapInfo> beatmapInfo)
{ {
var scores = new[] AddStep(@"Load new scores via manager", () =>
{
foreach (var score in generateSampleScores(beatmapInfo()))
scoreManager.Import(score).Wait();
});
}
private void clearScores()
{
AddStep("Clear all scores", () => scoreManager.Delete(scoreManager.GetAllUsableScores()));
}
private void checkCount(int expected) =>
AddUntilStep("Correct count displayed", () => leaderboard.ChildrenOfType<LeaderboardScore>().Count() == expected);
private static ScoreInfo[] generateSampleScores(BeatmapInfo beatmap)
{
return new[]
{ {
new ScoreInfo new ScoreInfo
{ {
@ -127,6 +197,7 @@ namespace osu.Game.Tests.Visual.SongSelect
MaxCombo = 244, MaxCombo = 244,
TotalScore = 1707827, TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, //Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
Beatmap = beatmap,
User = new User User = new User
{ {
Id = 6602580, Id = 6602580,
@ -145,6 +216,7 @@ namespace osu.Game.Tests.Visual.SongSelect
MaxCombo = 244, MaxCombo = 244,
TotalScore = 1707827, TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, //Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
Beatmap = beatmap,
User = new User User = new User
{ {
Id = 4608074, Id = 4608074,
@ -163,6 +235,7 @@ namespace osu.Game.Tests.Visual.SongSelect
MaxCombo = 244, MaxCombo = 244,
TotalScore = 1707827, TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, //Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
Beatmap = beatmap,
User = new User User = new User
{ {
Id = 1014222, Id = 1014222,
@ -181,6 +254,7 @@ namespace osu.Game.Tests.Visual.SongSelect
MaxCombo = 244, MaxCombo = 244,
TotalScore = 1707827, TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, //Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
Beatmap = beatmap,
User = new User User = new User
{ {
Id = 1541390, Id = 1541390,
@ -199,6 +273,7 @@ namespace osu.Game.Tests.Visual.SongSelect
MaxCombo = 244, MaxCombo = 244,
TotalScore = 1707827, TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, //Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
Beatmap = beatmap,
User = new User User = new User
{ {
Id = 2243452, Id = 2243452,
@ -217,6 +292,7 @@ namespace osu.Game.Tests.Visual.SongSelect
MaxCombo = 244, MaxCombo = 244,
TotalScore = 1707827, TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, //Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
Beatmap = beatmap,
User = new User User = new User
{ {
Id = 2705430, Id = 2705430,
@ -235,6 +311,7 @@ namespace osu.Game.Tests.Visual.SongSelect
MaxCombo = 244, MaxCombo = 244,
TotalScore = 1707827, TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, //Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
Beatmap = beatmap,
User = new User User = new User
{ {
Id = 7151382, Id = 7151382,
@ -253,6 +330,7 @@ namespace osu.Game.Tests.Visual.SongSelect
MaxCombo = 244, MaxCombo = 244,
TotalScore = 1707827, TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, //Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
Beatmap = beatmap,
User = new User User = new User
{ {
Id = 2051389, Id = 2051389,
@ -271,6 +349,7 @@ namespace osu.Game.Tests.Visual.SongSelect
MaxCombo = 244, MaxCombo = 244,
TotalScore = 1707827, TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, //Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
Beatmap = beatmap,
User = new User User = new User
{ {
Id = 6169483, Id = 6169483,
@ -289,6 +368,7 @@ namespace osu.Game.Tests.Visual.SongSelect
MaxCombo = 244, MaxCombo = 244,
TotalScore = 1707827, TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, //Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
Beatmap = beatmap,
User = new User User = new User
{ {
Id = 6702666, Id = 6702666,
@ -301,8 +381,6 @@ namespace osu.Game.Tests.Visual.SongSelect
}, },
}, },
}; };
leaderboard.Scores = scores;
} }
private void showBeatmapWithStatus(BeatmapSetOnlineStatus status) private void showBeatmapWithStatus(BeatmapSetOnlineStatus status)