Remove MultiplayerTestScene inheritance from simple test scenes

This commit is contained in:
smoogipoo
2021-06-24 21:02:04 +09:00
parent 5820793d11
commit 8fba7d2423
2 changed files with 66 additions and 57 deletions

View File

@ -7,14 +7,17 @@ using osu.Game.Screens.OnlinePlay;
namespace osu.Game.Tests.Visual.Multiplayer namespace osu.Game.Tests.Visual.Multiplayer
{ {
public class TestSceneFreeModSelectOverlay : MultiplayerTestScene public class TestSceneFreeModSelectOverlay : OsuTestScene
{ {
[SetUp] [SetUp]
public new void Setup() => Schedule(() => public void Setup() => Schedule(() =>
{ {
Child = new FreeModSelectOverlay Child = new TestMultiplayerRoomContainer
{ {
State = { Value = Visibility.Visible } Child = new FreeModSelectOverlay
{
State = { Value = Visibility.Visible }
}
}; };
}); });
} }

View File

@ -1,15 +1,18 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using JetBrains.Annotations;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Framework.Threading;
using osu.Framework.Timing; using osu.Framework.Timing;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Online.Spectator; using osu.Game.Online.Spectator;
@ -21,61 +24,38 @@ using osu.Game.Users;
namespace osu.Game.Tests.Visual.Multiplayer namespace osu.Game.Tests.Visual.Multiplayer
{ {
public class TestSceneMultiSpectatorLeaderboard : MultiplayerTestScene public class TestSceneMultiSpectatorLeaderboard : OsuTestScene
{ {
[Cached(typeof(SpectatorClient))] private Dictionary<int, ManualClock> clocks;
private TestSpectatorClient spectatorClient = new TestSpectatorClient();
[Cached(typeof(UserLookupCache))] private MultiSpectatorLeaderboard leaderboard;
private UserLookupCache lookupCache = new TestUserLookupCache(); private TestContainer container;
protected override Container<Drawable> Content => content;
private readonly Container content;
private readonly Dictionary<int, ManualClock> clocks = new Dictionary<int, ManualClock>
{
{ PLAYER_1_ID, new ManualClock() },
{ PLAYER_2_ID, new ManualClock() }
};
public TestSceneMultiSpectatorLeaderboard()
{
base.Content.AddRange(new Drawable[]
{
spectatorClient,
lookupCache,
content = new Container { RelativeSizeAxes = Axes.Both }
});
}
[SetUpSteps] [SetUpSteps]
public new void SetUpSteps() public void SetUpSteps()
{ {
MultiSpectatorLeaderboard leaderboard = null;
AddStep("reset", () => AddStep("reset", () =>
{ {
Clear(); clocks = new Dictionary<int, ManualClock>
foreach (var (userId, clock) in clocks)
{ {
spectatorClient.EndPlay(userId); { MultiplayerTestScene.PLAYER_1_ID, new ManualClock() },
clock.CurrentTime = 0; { MultiplayerTestScene.PLAYER_2_ID, new ManualClock() }
} };
Child = container = new TestContainer();
foreach (var (userId, _) in clocks)
container.SpectatorClient.StartPlay(userId, 0);
}); });
AddStep("create leaderboard", () => AddStep("create leaderboard", () =>
{ {
foreach (var (userId, _) in clocks)
spectatorClient.StartPlay(userId, 0);
Beatmap.Value = CreateWorkingBeatmap(Ruleset.Value); Beatmap.Value = CreateWorkingBeatmap(Ruleset.Value);
var playable = Beatmap.Value.GetPlayableBeatmap(Ruleset.Value); var playable = Beatmap.Value.GetPlayableBeatmap(Ruleset.Value);
var scoreProcessor = new OsuScoreProcessor(); var scoreProcessor = new OsuScoreProcessor();
scoreProcessor.ApplyBeatmap(playable); scoreProcessor.ApplyBeatmap(playable);
LoadComponentAsync(leaderboard = new MultiSpectatorLeaderboard(scoreProcessor, clocks.Keys.ToArray()) { Expanded = { Value = true } }, Add); container.LoadComponentAsync(leaderboard = new MultiSpectatorLeaderboard(scoreProcessor, clocks.Keys.ToArray()) { Expanded = { Value = true } }, container.Add);
}); });
AddUntilStep("wait for load", () => leaderboard.IsLoaded); AddUntilStep("wait for load", () => leaderboard.IsLoaded);
@ -96,42 +76,42 @@ namespace osu.Game.Tests.Visual.Multiplayer
// For player 2, send frames in sets of 10. // For player 2, send frames in sets of 10.
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
{ {
spectatorClient.SendFrames(PLAYER_1_ID, i, 1); container.SpectatorClient.SendFrames(MultiplayerTestScene.PLAYER_1_ID, i, 1);
if (i % 10 == 0) if (i % 10 == 0)
spectatorClient.SendFrames(PLAYER_2_ID, i, 10); container.SpectatorClient.SendFrames(MultiplayerTestScene.PLAYER_2_ID, i, 10);
} }
}); });
assertCombo(PLAYER_1_ID, 1); assertCombo(MultiplayerTestScene.PLAYER_1_ID, 1);
assertCombo(PLAYER_2_ID, 10); assertCombo(MultiplayerTestScene.PLAYER_2_ID, 10);
// Advance to a point where only user player 1's frame changes. // Advance to a point where only user player 1's frame changes.
setTime(500); setTime(500);
assertCombo(PLAYER_1_ID, 5); assertCombo(MultiplayerTestScene.PLAYER_1_ID, 5);
assertCombo(PLAYER_2_ID, 10); assertCombo(MultiplayerTestScene.PLAYER_2_ID, 10);
// Advance to a point where both user's frame changes. // Advance to a point where both user's frame changes.
setTime(1100); setTime(1100);
assertCombo(PLAYER_1_ID, 11); assertCombo(MultiplayerTestScene.PLAYER_1_ID, 11);
assertCombo(PLAYER_2_ID, 20); assertCombo(MultiplayerTestScene.PLAYER_2_ID, 20);
// Advance user player 2 only to a point where its frame changes. // Advance user player 2 only to a point where its frame changes.
setTime(PLAYER_2_ID, 2100); setTime(MultiplayerTestScene.PLAYER_2_ID, 2100);
assertCombo(PLAYER_1_ID, 11); assertCombo(MultiplayerTestScene.PLAYER_1_ID, 11);
assertCombo(PLAYER_2_ID, 30); assertCombo(MultiplayerTestScene.PLAYER_2_ID, 30);
// Advance both users beyond their last frame // Advance both users beyond their last frame
setTime(101 * 100); setTime(101 * 100);
assertCombo(PLAYER_1_ID, 100); assertCombo(MultiplayerTestScene.PLAYER_1_ID, 100);
assertCombo(PLAYER_2_ID, 100); assertCombo(MultiplayerTestScene.PLAYER_2_ID, 100);
} }
[Test] [Test]
public void TestNoFrames() public void TestNoFrames()
{ {
assertCombo(PLAYER_1_ID, 0); assertCombo(MultiplayerTestScene.PLAYER_1_ID, 0);
assertCombo(PLAYER_2_ID, 0); assertCombo(MultiplayerTestScene.PLAYER_2_ID, 0);
} }
private void setTime(double time) => AddStep($"set time {time}", () => private void setTime(double time) => AddStep($"set time {time}", () =>
@ -146,6 +126,32 @@ namespace osu.Game.Tests.Visual.Multiplayer
private void assertCombo(int userId, int expectedCombo) private void assertCombo(int userId, int expectedCombo)
=> AddUntilStep($"player {userId} has {expectedCombo} combo", () => this.ChildrenOfType<GameplayLeaderboardScore>().Single(s => s.User?.Id == userId).Combo.Value == expectedCombo); => AddUntilStep($"player {userId} has {expectedCombo} combo", () => this.ChildrenOfType<GameplayLeaderboardScore>().Single(s => s.User?.Id == userId).Combo.Value == expectedCombo);
private class TestContainer : TestMultiplayerRoomContainer
{
[Cached(typeof(SpectatorClient))]
public readonly TestSpectatorClient SpectatorClient = new TestSpectatorClient();
[Cached(typeof(UserLookupCache))]
public readonly UserLookupCache LookupCache = new TestUserLookupCache();
protected override Container<Drawable> Content => content;
private readonly Container content;
public TestContainer()
{
AddRangeInternal(new Drawable[]
{
SpectatorClient,
LookupCache,
content = new Container { RelativeSizeAxes = Axes.Both }
});
}
public new Task LoadComponentAsync<TLoadable>([NotNull] TLoadable component, Action<TLoadable> onLoaded = null, CancellationToken cancellation = default, Scheduler scheduler = null)
where TLoadable : Drawable
=> base.LoadComponentAsync(component, onLoaded, cancellation, scheduler);
}
private class TestUserLookupCache : UserLookupCache private class TestUserLookupCache : UserLookupCache
{ {
protected override Task<User> ComputeValueAsync(int lookup, CancellationToken token = default) protected override Task<User> ComputeValueAsync(int lookup, CancellationToken token = default)