mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Rework MultiplayerTestScene to make use of OnlinePlayTestScene
This commit is contained in:
@ -7,6 +7,7 @@ using NUnit.Framework;
|
||||
using osu.Framework.Extensions.ObjectExtensions;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Tests.Visual.Multiplayer;
|
||||
using osu.Game.Users;
|
||||
|
||||
@ -50,7 +51,10 @@ namespace osu.Game.Tests.NonVisual.Multiplayer
|
||||
|
||||
AddStep("create room initially in gameplay", () =>
|
||||
{
|
||||
Room.RoomID.Value = null;
|
||||
var newRoom = new Room();
|
||||
newRoom.CopyFrom(SelectedRoom.Value);
|
||||
|
||||
newRoom.RoomID.Value = null;
|
||||
Client.RoomSetupAction = room =>
|
||||
{
|
||||
room.State = MultiplayerRoomState.Playing;
|
||||
@ -61,7 +65,7 @@ namespace osu.Game.Tests.NonVisual.Multiplayer
|
||||
});
|
||||
};
|
||||
|
||||
RoomManager.CreateRoom(Room);
|
||||
RoomManager.CreateRoom(newRoom);
|
||||
});
|
||||
|
||||
AddUntilStep("wait for room join", () => Client.Room != null);
|
||||
|
@ -7,17 +7,14 @@ using osu.Game.Screens.OnlinePlay;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneFreeModSelectOverlay : OsuTestScene
|
||||
public class TestSceneFreeModSelectOverlay : MultiplayerTestScene
|
||||
{
|
||||
[SetUp]
|
||||
public void Setup() => Schedule(() =>
|
||||
{
|
||||
Child = new TestMultiplayerRoomContainer
|
||||
public new void Setup() => Schedule(() =>
|
||||
{
|
||||
Child = new FreeModSelectOverlay
|
||||
{
|
||||
State = { Value = Visibility.Visible }
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Online.Rooms;
|
||||
@ -22,8 +21,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
private RoomsContainer container;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
[SetUp]
|
||||
public new void Setup() => Schedule(() =>
|
||||
{
|
||||
Child = container = new RoomsContainer
|
||||
{
|
||||
@ -32,7 +31,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
Width = 0.5f,
|
||||
JoinRequested = joinRequested
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
[Test]
|
||||
public void TestBasicListChanges()
|
||||
@ -113,14 +112,14 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
AddStep("add rooms", () => RoomManager.AddRooms(2, new OsuRuleset().RulesetInfo));
|
||||
AddStep("add rooms", () => RoomManager.AddRooms(3, new CatchRuleset().RulesetInfo));
|
||||
|
||||
// Todo: What even is this case...?
|
||||
AddStep("set empty filter criteria", () => container.Filter(null));
|
||||
AddUntilStep("5 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 5);
|
||||
|
||||
AddStep("filter osu! rooms", () => container.Filter(new FilterCriteria { Ruleset = new OsuRuleset().RulesetInfo }));
|
||||
|
||||
AddUntilStep("2 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 2);
|
||||
|
||||
AddStep("filter catch rooms", () => container.Filter(new FilterCriteria { Ruleset = new CatchRuleset().RulesetInfo }));
|
||||
|
||||
AddUntilStep("3 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 3);
|
||||
}
|
||||
|
||||
|
@ -1,51 +1,48 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Online.Spectator;
|
||||
using osu.Game.Rulesets.Osu.Scoring;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate;
|
||||
using osu.Game.Screens.Play.HUD;
|
||||
using osu.Game.Tests.Visual.OnlinePlay;
|
||||
using osu.Game.Tests.Visual.Spectator;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneMultiSpectatorLeaderboard : OsuTestScene
|
||||
public class TestSceneMultiSpectatorLeaderboard : MultiplayerTestScene
|
||||
{
|
||||
private Dictionary<int, ManualClock> clocks;
|
||||
public TestSpectatorClient SpectatorClient => RoomDependencies?.SpectatorClient;
|
||||
|
||||
protected new TestDependencies RoomDependencies => (TestDependencies)base.RoomDependencies;
|
||||
|
||||
private Dictionary<int, ManualClock> clocks;
|
||||
private MultiSpectatorLeaderboard leaderboard;
|
||||
private TestContainer container;
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetUpSteps()
|
||||
public new void SetUpSteps()
|
||||
{
|
||||
AddStep("reset", () =>
|
||||
{
|
||||
Clear();
|
||||
|
||||
clocks = new Dictionary<int, ManualClock>
|
||||
{
|
||||
{ MultiplayerTestScene.PLAYER_1_ID, new ManualClock() },
|
||||
{ MultiplayerTestScene.PLAYER_2_ID, new ManualClock() }
|
||||
{ PLAYER_1_ID, new ManualClock() },
|
||||
{ PLAYER_2_ID, new ManualClock() }
|
||||
};
|
||||
|
||||
Child = container = new TestContainer();
|
||||
|
||||
foreach (var (userId, _) in clocks)
|
||||
container.SpectatorClient.StartPlay(userId, 0);
|
||||
SpectatorClient.StartPlay(userId, 0);
|
||||
});
|
||||
|
||||
AddStep("create leaderboard", () =>
|
||||
@ -55,7 +52,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
var scoreProcessor = new OsuScoreProcessor();
|
||||
scoreProcessor.ApplyBeatmap(playable);
|
||||
|
||||
container.LoadComponentAsync(leaderboard = new MultiSpectatorLeaderboard(scoreProcessor, clocks.Keys.ToArray()) { Expanded = { Value = true } }, container.Add);
|
||||
LoadComponentAsync(leaderboard = new MultiSpectatorLeaderboard(scoreProcessor, clocks.Keys.ToArray()) { Expanded = { Value = true } }, Add);
|
||||
});
|
||||
|
||||
AddUntilStep("wait for load", () => leaderboard.IsLoaded);
|
||||
@ -76,42 +73,42 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
// For player 2, send frames in sets of 10.
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
container.SpectatorClient.SendFrames(MultiplayerTestScene.PLAYER_1_ID, i, 1);
|
||||
SpectatorClient.SendFrames(PLAYER_1_ID, i, 1);
|
||||
|
||||
if (i % 10 == 0)
|
||||
container.SpectatorClient.SendFrames(MultiplayerTestScene.PLAYER_2_ID, i, 10);
|
||||
SpectatorClient.SendFrames(PLAYER_2_ID, i, 10);
|
||||
}
|
||||
});
|
||||
|
||||
assertCombo(MultiplayerTestScene.PLAYER_1_ID, 1);
|
||||
assertCombo(MultiplayerTestScene.PLAYER_2_ID, 10);
|
||||
assertCombo(PLAYER_1_ID, 1);
|
||||
assertCombo(PLAYER_2_ID, 10);
|
||||
|
||||
// Advance to a point where only user player 1's frame changes.
|
||||
setTime(500);
|
||||
assertCombo(MultiplayerTestScene.PLAYER_1_ID, 5);
|
||||
assertCombo(MultiplayerTestScene.PLAYER_2_ID, 10);
|
||||
assertCombo(PLAYER_1_ID, 5);
|
||||
assertCombo(PLAYER_2_ID, 10);
|
||||
|
||||
// Advance to a point where both user's frame changes.
|
||||
setTime(1100);
|
||||
assertCombo(MultiplayerTestScene.PLAYER_1_ID, 11);
|
||||
assertCombo(MultiplayerTestScene.PLAYER_2_ID, 20);
|
||||
assertCombo(PLAYER_1_ID, 11);
|
||||
assertCombo(PLAYER_2_ID, 20);
|
||||
|
||||
// Advance user player 2 only to a point where its frame changes.
|
||||
setTime(MultiplayerTestScene.PLAYER_2_ID, 2100);
|
||||
assertCombo(MultiplayerTestScene.PLAYER_1_ID, 11);
|
||||
assertCombo(MultiplayerTestScene.PLAYER_2_ID, 30);
|
||||
setTime(PLAYER_2_ID, 2100);
|
||||
assertCombo(PLAYER_1_ID, 11);
|
||||
assertCombo(PLAYER_2_ID, 30);
|
||||
|
||||
// Advance both users beyond their last frame
|
||||
setTime(101 * 100);
|
||||
assertCombo(MultiplayerTestScene.PLAYER_1_ID, 100);
|
||||
assertCombo(MultiplayerTestScene.PLAYER_2_ID, 100);
|
||||
assertCombo(PLAYER_1_ID, 100);
|
||||
assertCombo(PLAYER_2_ID, 100);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestNoFrames()
|
||||
{
|
||||
assertCombo(MultiplayerTestScene.PLAYER_1_ID, 0);
|
||||
assertCombo(MultiplayerTestScene.PLAYER_2_ID, 0);
|
||||
assertCombo(PLAYER_1_ID, 0);
|
||||
assertCombo(PLAYER_2_ID, 0);
|
||||
}
|
||||
|
||||
private void setTime(double time) => AddStep($"set time {time}", () =>
|
||||
@ -126,30 +123,18 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
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);
|
||||
|
||||
private class TestContainer : TestMultiplayerRoomContainer
|
||||
{
|
||||
[Cached(typeof(SpectatorClient))]
|
||||
public readonly TestSpectatorClient SpectatorClient = new TestSpectatorClient();
|
||||
protected override RoomTestDependencies CreateRoomDependencies() => new TestDependencies();
|
||||
|
||||
[Cached(typeof(UserLookupCache))]
|
||||
protected class TestDependencies : MultiplayerRoomTestDependencies
|
||||
{
|
||||
public readonly TestSpectatorClient SpectatorClient = new TestSpectatorClient();
|
||||
public readonly UserLookupCache LookupCache = new TestUserLookupCache();
|
||||
|
||||
protected override Container<Drawable> Content => content;
|
||||
private readonly Container content;
|
||||
|
||||
public TestContainer()
|
||||
public TestDependencies()
|
||||
{
|
||||
AddRangeInternal(new Drawable[]
|
||||
{
|
||||
SpectatorClient,
|
||||
LookupCache,
|
||||
content = new Container { RelativeSizeAxes = Axes.Both }
|
||||
});
|
||||
CacheAs<SpectatorClient>(SpectatorClient);
|
||||
CacheAs(LookupCache);
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -15,6 +15,7 @@ using osu.Game.Online.Spectator;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate;
|
||||
using osu.Game.Screens.Play;
|
||||
using osu.Game.Tests.Beatmaps.IO;
|
||||
using osu.Game.Tests.Visual.OnlinePlay;
|
||||
using osu.Game.Tests.Visual.Spectator;
|
||||
using osu.Game.Users;
|
||||
|
||||
@ -22,11 +23,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneMultiSpectatorScreen : MultiplayerTestScene
|
||||
{
|
||||
[Cached(typeof(SpectatorClient))]
|
||||
private TestSpectatorClient spectatorClient = new TestSpectatorClient();
|
||||
public TestSpectatorClient SpectatorClient => RoomDependencies?.SpectatorClient;
|
||||
|
||||
[Cached(typeof(UserLookupCache))]
|
||||
private UserLookupCache lookupCache = new TestUserLookupCache();
|
||||
protected new TestDependencies RoomDependencies => (TestDependencies)base.RoomDependencies;
|
||||
|
||||
[Resolved]
|
||||
private OsuGameBase game { get; set; }
|
||||
@ -51,25 +50,12 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
importedBeatmapId = importedBeatmap.OnlineBeatmapID ?? -1;
|
||||
}
|
||||
|
||||
public override void SetUpSteps()
|
||||
[SetUp]
|
||||
public new void Setup() => Schedule(() =>
|
||||
{
|
||||
base.SetUpSteps();
|
||||
|
||||
AddStep("reset sent frames", () => nextFrame.Clear());
|
||||
|
||||
AddStep("add streaming client", () =>
|
||||
{
|
||||
Remove(spectatorClient);
|
||||
Add(spectatorClient);
|
||||
});
|
||||
|
||||
AddStep("finish previous gameplay", () =>
|
||||
{
|
||||
foreach (var id in playingUserIds)
|
||||
spectatorClient.EndPlay(id);
|
||||
nextFrame.Clear();
|
||||
playingUserIds.Clear();
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDelayedStart()
|
||||
@ -87,11 +73,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
loadSpectateScreen(false);
|
||||
|
||||
AddWaitStep("wait a bit", 10);
|
||||
AddStep("load player first_player_id", () => spectatorClient.StartPlay(PLAYER_1_ID, importedBeatmapId));
|
||||
AddStep("load player first_player_id", () => SpectatorClient.StartPlay(PLAYER_1_ID, importedBeatmapId));
|
||||
AddUntilStep("one player added", () => spectatorScreen.ChildrenOfType<Player>().Count() == 1);
|
||||
|
||||
AddWaitStep("wait a bit", 10);
|
||||
AddStep("load player second_player_id", () => spectatorClient.StartPlay(PLAYER_2_ID, importedBeatmapId));
|
||||
AddStep("load player second_player_id", () => SpectatorClient.StartPlay(PLAYER_2_ID, importedBeatmapId));
|
||||
AddUntilStep("two players added", () => spectatorScreen.ChildrenOfType<Player>().Count() == 2);
|
||||
}
|
||||
|
||||
@ -251,7 +237,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
foreach (int id in userIds)
|
||||
{
|
||||
Client.CurrentMatchPlayingUserIds.Add(id);
|
||||
spectatorClient.StartPlay(id, beatmapId ?? importedBeatmapId);
|
||||
SpectatorClient.StartPlay(id, beatmapId ?? importedBeatmapId);
|
||||
playingUserIds.Add(id);
|
||||
nextFrame[id] = 0;
|
||||
}
|
||||
@ -262,7 +248,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
AddStep("end play", () =>
|
||||
{
|
||||
spectatorClient.EndPlay(userId);
|
||||
SpectatorClient.EndPlay(userId);
|
||||
playingUserIds.Remove(userId);
|
||||
nextFrame.Remove(userId);
|
||||
});
|
||||
@ -276,7 +262,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
foreach (int id in userIds)
|
||||
{
|
||||
spectatorClient.SendFrames(id, nextFrame[id], count);
|
||||
SpectatorClient.SendFrames(id, nextFrame[id], count);
|
||||
nextFrame[id] += count;
|
||||
}
|
||||
});
|
||||
@ -298,6 +284,20 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
private PlayerArea getInstance(int userId) => spectatorScreen.ChildrenOfType<PlayerArea>().Single(p => p.UserId == userId);
|
||||
|
||||
protected override RoomTestDependencies CreateRoomDependencies() => new TestDependencies();
|
||||
|
||||
protected class TestDependencies : MultiplayerRoomTestDependencies
|
||||
{
|
||||
public readonly TestSpectatorClient SpectatorClient = new TestSpectatorClient();
|
||||
public readonly UserLookupCache LookupCache = new TestUserLookupCache();
|
||||
|
||||
public TestDependencies()
|
||||
{
|
||||
CacheAs<SpectatorClient>(SpectatorClient);
|
||||
CacheAs(LookupCache);
|
||||
}
|
||||
}
|
||||
|
||||
internal class TestUserLookupCache : UserLookupCache
|
||||
{
|
||||
protected override Task<User> ComputeValueAsync(int lookup, CancellationToken token = default)
|
||||
|
@ -29,7 +29,7 @@ using osu.Game.Screens.Select;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneMultiplayerMatchSongSelect : ScreenTestScene
|
||||
public class TestSceneMultiplayerMatchSongSelect : MultiplayerTestScene
|
||||
{
|
||||
private BeatmapManager manager;
|
||||
private RulesetStore rulesets;
|
||||
|
@ -49,13 +49,13 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
[SetUp]
|
||||
public new void Setup() => Schedule(() =>
|
||||
{
|
||||
Room.Name.Value = "Test Room";
|
||||
SelectedRoom.Value = new Room { Name = { Value = "Test Room" } };
|
||||
});
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetupSteps()
|
||||
{
|
||||
AddStep("load match", () => LoadScreen(screen = new MultiplayerMatchSubScreen(Room)));
|
||||
AddStep("load match", () => LoadScreen(screen = new MultiplayerMatchSubScreen(SelectedRoom.Value)));
|
||||
AddUntilStep("wait for load", () => screen.IsCurrentScreen());
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
AddStep("set playlist", () =>
|
||||
{
|
||||
Room.Playlist.Add(new PlaylistItem
|
||||
SelectedRoom.Value.Playlist.Add(new PlaylistItem
|
||||
{
|
||||
Beatmap = { Value = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo },
|
||||
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
||||
@ -81,7 +81,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
AddStep("set playlist", () =>
|
||||
{
|
||||
Room.Playlist.Add(new PlaylistItem
|
||||
SelectedRoom.Value.Playlist.Add(new PlaylistItem
|
||||
{
|
||||
Beatmap = { Value = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo },
|
||||
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
||||
@ -102,7 +102,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
AddStep("set playlist", () =>
|
||||
{
|
||||
Room.Playlist.Add(new PlaylistItem
|
||||
SelectedRoom.Value.Playlist.Add(new PlaylistItem
|
||||
{
|
||||
Beatmap = { Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First()).BeatmapInfo },
|
||||
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
||||
|
@ -27,7 +27,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
public class TestSceneMultiplayerReadyButton : MultiplayerTestScene
|
||||
{
|
||||
private MultiplayerReadyButton button;
|
||||
private OnlinePlayBeatmapAvailabilityTracker beatmapTracker;
|
||||
private BeatmapSetInfo importedSet;
|
||||
|
||||
private readonly Bindable<PlaylistItem> selectedItem = new Bindable<PlaylistItem>();
|
||||
@ -43,18 +42,13 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
|
||||
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));
|
||||
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).Wait();
|
||||
|
||||
Add(beatmapTracker = new OnlinePlayBeatmapAvailabilityTracker
|
||||
{
|
||||
SelectedItem = { BindTarget = selectedItem }
|
||||
});
|
||||
|
||||
Dependencies.Cache(beatmapTracker);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public new void Setup() => Schedule(() =>
|
||||
{
|
||||
AvailabilityTracker.SelectedItem.BindTo(selectedItem);
|
||||
|
||||
importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First();
|
||||
Beatmap.Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First());
|
||||
selectedItem.Value = new PlaylistItem
|
||||
|
@ -3,37 +3,38 @@
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
using osu.Game.Tests.Beatmaps;
|
||||
using osu.Game.Tests.Visual.OnlinePlay;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
[HeadlessTest]
|
||||
public class TestSceneMultiplayerRoomManager : OsuTestScene
|
||||
public class TestSceneMultiplayerRoomManager : MultiplayerTestScene
|
||||
{
|
||||
private TestMultiplayerRoomContainer roomContainer;
|
||||
private TestMultiplayerRoomManager roomManager => roomContainer.RoomManager;
|
||||
protected override RoomTestDependencies CreateRoomDependencies() => new TestDependencies();
|
||||
|
||||
public TestSceneMultiplayerRoomManager()
|
||||
: base(false)
|
||||
{
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPollsInitially()
|
||||
{
|
||||
AddStep("create room manager with a few rooms", () =>
|
||||
{
|
||||
createRoomManager().With(d => d.OnLoadComplete += _ =>
|
||||
{
|
||||
roomManager.CreateRoom(createRoom(r => r.Name.Value = "1"));
|
||||
roomManager.PartRoom();
|
||||
roomManager.CreateRoom(createRoom(r => r.Name.Value = "2"));
|
||||
roomManager.PartRoom();
|
||||
roomManager.ClearRooms();
|
||||
});
|
||||
RoomManager.CreateRoom(createRoom(r => r.Name.Value = "1"));
|
||||
RoomManager.PartRoom();
|
||||
RoomManager.CreateRoom(createRoom(r => r.Name.Value = "2"));
|
||||
RoomManager.PartRoom();
|
||||
RoomManager.ClearRooms();
|
||||
});
|
||||
|
||||
AddAssert("manager polled for rooms", () => ((RoomManager)roomManager).Rooms.Count == 2);
|
||||
AddAssert("initial rooms received", () => roomManager.InitialRoomsReceived.Value);
|
||||
AddAssert("manager polled for rooms", () => ((RoomManager)RoomManager).Rooms.Count == 2);
|
||||
AddAssert("initial rooms received", () => RoomManager.InitialRoomsReceived.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -41,19 +42,16 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
AddStep("create room manager with a few rooms", () =>
|
||||
{
|
||||
createRoomManager().With(d => d.OnLoadComplete += _ =>
|
||||
{
|
||||
roomManager.CreateRoom(createRoom());
|
||||
roomManager.PartRoom();
|
||||
roomManager.CreateRoom(createRoom());
|
||||
roomManager.PartRoom();
|
||||
});
|
||||
RoomManager.CreateRoom(createRoom());
|
||||
RoomManager.PartRoom();
|
||||
RoomManager.CreateRoom(createRoom());
|
||||
RoomManager.PartRoom();
|
||||
});
|
||||
|
||||
AddStep("disconnect", () => roomContainer.Client.Disconnect());
|
||||
AddStep("disconnect", () => Client.Disconnect());
|
||||
|
||||
AddAssert("rooms cleared", () => ((RoomManager)roomManager).Rooms.Count == 0);
|
||||
AddAssert("initial rooms not received", () => !roomManager.InitialRoomsReceived.Value);
|
||||
AddAssert("rooms cleared", () => ((RoomManager)RoomManager).Rooms.Count == 0);
|
||||
AddAssert("initial rooms not received", () => !RoomManager.InitialRoomsReceived.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -61,20 +59,17 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
AddStep("create room manager with a few rooms", () =>
|
||||
{
|
||||
createRoomManager().With(d => d.OnLoadComplete += _ =>
|
||||
{
|
||||
roomManager.CreateRoom(createRoom());
|
||||
roomManager.PartRoom();
|
||||
roomManager.CreateRoom(createRoom());
|
||||
roomManager.PartRoom();
|
||||
});
|
||||
RoomManager.CreateRoom(createRoom());
|
||||
RoomManager.PartRoom();
|
||||
RoomManager.CreateRoom(createRoom());
|
||||
RoomManager.PartRoom();
|
||||
});
|
||||
|
||||
AddStep("disconnect", () => roomContainer.Client.Disconnect());
|
||||
AddStep("connect", () => roomContainer.Client.Connect());
|
||||
AddStep("disconnect", () => Client.Disconnect());
|
||||
AddStep("connect", () => Client.Connect());
|
||||
|
||||
AddAssert("manager polled for rooms", () => ((RoomManager)roomManager).Rooms.Count == 2);
|
||||
AddAssert("initial rooms received", () => roomManager.InitialRoomsReceived.Value);
|
||||
AddAssert("manager polled for rooms", () => ((RoomManager)RoomManager).Rooms.Count == 2);
|
||||
AddAssert("initial rooms received", () => RoomManager.InitialRoomsReceived.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -82,15 +77,12 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
AddStep("create room manager with a room", () =>
|
||||
{
|
||||
createRoomManager().With(d => d.OnLoadComplete += _ =>
|
||||
{
|
||||
roomManager.CreateRoom(createRoom());
|
||||
roomManager.ClearRooms();
|
||||
});
|
||||
RoomManager.CreateRoom(createRoom());
|
||||
RoomManager.ClearRooms();
|
||||
});
|
||||
|
||||
AddAssert("manager not polled for rooms", () => ((RoomManager)roomManager).Rooms.Count == 0);
|
||||
AddAssert("initial rooms not received", () => !roomManager.InitialRoomsReceived.Value);
|
||||
AddAssert("manager not polled for rooms", () => ((RoomManager)RoomManager).Rooms.Count == 0);
|
||||
AddAssert("initial rooms not received", () => !RoomManager.InitialRoomsReceived.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -98,13 +90,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
AddStep("create room manager with a room", () =>
|
||||
{
|
||||
createRoomManager().With(d => d.OnLoadComplete += _ =>
|
||||
{
|
||||
roomManager.CreateRoom(createRoom());
|
||||
});
|
||||
RoomManager.CreateRoom(createRoom());
|
||||
});
|
||||
|
||||
AddUntilStep("multiplayer room joined", () => roomContainer.Client.Room != null);
|
||||
AddUntilStep("multiplayer room joined", () => Client.Room != null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -112,31 +101,25 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
AddStep("create room manager with a room", () =>
|
||||
{
|
||||
createRoomManager().With(d => d.OnLoadComplete += _ =>
|
||||
{
|
||||
roomManager.CreateRoom(createRoom());
|
||||
roomManager.PartRoom();
|
||||
});
|
||||
RoomManager.CreateRoom(createRoom());
|
||||
RoomManager.PartRoom();
|
||||
});
|
||||
|
||||
AddAssert("multiplayer room parted", () => roomContainer.Client.Room == null);
|
||||
AddAssert("multiplayer room parted", () => Client.Room == null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMultiplayerRoomJoinedWhenAPIRoomJoined()
|
||||
{
|
||||
AddStep("create room manager with a room", () =>
|
||||
{
|
||||
createRoomManager().With(d => d.OnLoadComplete += _ =>
|
||||
{
|
||||
var r = createRoom();
|
||||
roomManager.CreateRoom(r);
|
||||
roomManager.PartRoom();
|
||||
roomManager.JoinRoom(r);
|
||||
});
|
||||
RoomManager.CreateRoom(r);
|
||||
RoomManager.PartRoom();
|
||||
RoomManager.JoinRoom(r);
|
||||
});
|
||||
|
||||
AddUntilStep("multiplayer room joined", () => roomContainer.Client.Room != null);
|
||||
AddUntilStep("multiplayer room joined", () => Client.Room != null);
|
||||
}
|
||||
|
||||
private Room createRoom(Action<Room> initFunc = null)
|
||||
@ -161,18 +144,13 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
return room;
|
||||
}
|
||||
|
||||
private TestMultiplayerRoomManager createRoomManager()
|
||||
private class TestDependencies : MultiplayerRoomTestDependencies
|
||||
{
|
||||
Child = roomContainer = new TestMultiplayerRoomContainer
|
||||
public TestDependencies()
|
||||
{
|
||||
RoomManager =
|
||||
{
|
||||
TimeBetweenListingPolls = { Value = 1 },
|
||||
TimeBetweenSelectionPolls = { Value = 1 }
|
||||
}
|
||||
};
|
||||
|
||||
return roomManager;
|
||||
RoomManager.TimeBetweenListingPolls.Value = 1;
|
||||
RoomManager.TimeBetweenSelectionPolls.Value = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,40 +37,19 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
private IDisposable readyClickOperation;
|
||||
|
||||
protected override Container<Drawable> Content => content;
|
||||
private readonly Container content;
|
||||
|
||||
public TestSceneMultiplayerSpectateButton()
|
||||
{
|
||||
base.Content.Add(content = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both
|
||||
});
|
||||
}
|
||||
|
||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||
{
|
||||
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
||||
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(GameHost host, AudioManager audio)
|
||||
{
|
||||
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
|
||||
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));
|
||||
|
||||
var beatmapTracker = new OnlinePlayBeatmapAvailabilityTracker { SelectedItem = { BindTarget = selectedItem } };
|
||||
base.Content.Add(beatmapTracker);
|
||||
Dependencies.Cache(beatmapTracker);
|
||||
|
||||
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).Wait();
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public new void Setup() => Schedule(() =>
|
||||
{
|
||||
AvailabilityTracker.SelectedItem.BindTo(selectedItem);
|
||||
|
||||
importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First();
|
||||
Beatmap.Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First());
|
||||
selectedItem.Value = new PlaylistItem
|
||||
|
@ -1,17 +0,0 @@
|
||||
// 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 osu.Game.Tests.Visual.OnlinePlay;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class MultiplayerSubScreenTestScene : OnlinePlayTestScene, IMultiplayerRoomTestDependencies
|
||||
{
|
||||
public TestMultiplayerClient Client => RoomDependencies.Client;
|
||||
public new TestMultiplayerRoomManager RoomManager => RoomDependencies.RoomManager;
|
||||
|
||||
protected new MultiplayerRoomTestDependencies RoomDependencies => (MultiplayerRoomTestDependencies)base.RoomDependencies;
|
||||
|
||||
protected override RoomTestDependencies CreateRoomDependencies() => new MultiplayerRoomTestDependencies();
|
||||
}
|
||||
}
|
@ -2,66 +2,51 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Screens.OnlinePlay;
|
||||
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
||||
using osu.Game.Tests.Beatmaps;
|
||||
using osu.Game.Tests.Visual.OnlinePlay;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public abstract class MultiplayerTestScene : RoomTestScene
|
||||
public abstract class MultiplayerTestScene : OnlinePlayTestScene
|
||||
{
|
||||
public const int PLAYER_1_ID = 55;
|
||||
public const int PLAYER_2_ID = 56;
|
||||
|
||||
[Cached(typeof(MultiplayerClient))]
|
||||
public TestMultiplayerClient Client { get; }
|
||||
public TestMultiplayerClient Client => RoomDependencies.Client;
|
||||
public new TestMultiplayerRoomManager RoomManager => RoomDependencies.RoomManager;
|
||||
|
||||
[Cached(typeof(IRoomManager))]
|
||||
public TestMultiplayerRoomManager RoomManager { get; }
|
||||
protected new MultiplayerRoomTestDependencies RoomDependencies => (MultiplayerRoomTestDependencies)base.RoomDependencies;
|
||||
|
||||
[Cached]
|
||||
public Bindable<FilterCriteria> Filter { get; }
|
||||
|
||||
[Cached]
|
||||
public OngoingOperationTracker OngoingOperationTracker { get; }
|
||||
|
||||
protected override Container<Drawable> Content => content;
|
||||
private readonly TestMultiplayerRoomContainer content;
|
||||
protected override RoomTestDependencies CreateRoomDependencies() => new MultiplayerRoomTestDependencies();
|
||||
|
||||
private readonly bool joinRoom;
|
||||
|
||||
protected MultiplayerTestScene(bool joinRoom = true)
|
||||
{
|
||||
this.joinRoom = joinRoom;
|
||||
base.Content.Add(content = new TestMultiplayerRoomContainer { RelativeSizeAxes = Axes.Both });
|
||||
|
||||
Client = content.Client;
|
||||
RoomManager = content.RoomManager;
|
||||
Filter = content.Filter;
|
||||
OngoingOperationTracker = content.OngoingOperationTracker;
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public new void Setup() => Schedule(() =>
|
||||
{
|
||||
RoomManager.Schedule(() => RoomManager.PartRoom());
|
||||
|
||||
if (joinRoom)
|
||||
{
|
||||
Room.Name.Value = "test name";
|
||||
Room.Playlist.Add(new PlaylistItem
|
||||
var room = new Room
|
||||
{
|
||||
Name = { Value = "test name" },
|
||||
Playlist =
|
||||
{
|
||||
new PlaylistItem
|
||||
{
|
||||
Beatmap = { Value = new TestBeatmap(Ruleset.Value).BeatmapInfo },
|
||||
Ruleset = { Value = Ruleset.Value }
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
RoomManager.Schedule(() => RoomManager.CreateRoom(Room));
|
||||
RoomManager.CreateRoom(room);
|
||||
SelectedRoom.Value = room;
|
||||
}
|
||||
});
|
||||
|
||||
@ -70,7 +55,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
base.SetUpSteps();
|
||||
|
||||
if (joinRoom)
|
||||
{
|
||||
AddUntilStep("wait for room join", () => Client.Room != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,48 +0,0 @@
|
||||
// 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 osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Screens.OnlinePlay;
|
||||
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestMultiplayerRoomContainer : Container
|
||||
{
|
||||
protected override Container<Drawable> Content => content;
|
||||
private readonly Container content;
|
||||
|
||||
[Cached(typeof(MultiplayerClient))]
|
||||
public readonly TestMultiplayerClient Client;
|
||||
|
||||
[Cached(typeof(IRoomManager))]
|
||||
public readonly TestMultiplayerRoomManager RoomManager;
|
||||
|
||||
[Cached]
|
||||
public readonly Bindable<FilterCriteria> Filter = new Bindable<FilterCriteria>(new FilterCriteria());
|
||||
|
||||
[Cached]
|
||||
public readonly OngoingOperationTracker OngoingOperationTracker;
|
||||
|
||||
public TestMultiplayerRoomContainer()
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
RoomManager = new TestMultiplayerRoomManager();
|
||||
Client = new TestMultiplayerClient(RoomManager);
|
||||
OngoingOperationTracker = new OngoingOperationTracker();
|
||||
|
||||
AddRangeInternal(new Drawable[]
|
||||
{
|
||||
Client,
|
||||
RoomManager,
|
||||
OngoingOperationTracker,
|
||||
content = new Container { RelativeSizeAxes = Axes.Both }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -29,10 +29,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
public new readonly List<Room> Rooms = new List<Room>();
|
||||
|
||||
protected override void LoadComplete()
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
int currentScoreId = 0;
|
||||
int currentRoomId = 0;
|
||||
int currentPlaylistItemId = 0;
|
||||
|
@ -1,33 +0,0 @@
|
||||
// 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 NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Online.Rooms;
|
||||
|
||||
namespace osu.Game.Tests.Visual
|
||||
{
|
||||
public abstract class RoomTestScene : ScreenTestScene
|
||||
{
|
||||
[Cached]
|
||||
private readonly Bindable<Room> currentRoom = new Bindable<Room>();
|
||||
|
||||
protected Room Room => currentRoom.Value;
|
||||
|
||||
private CachedModelDependencyContainer<Room> dependencies;
|
||||
|
||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||
{
|
||||
dependencies = new CachedModelDependencyContainer<Room>(base.CreateChildDependencies(parent));
|
||||
dependencies.Model.BindTo(currentRoom);
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void Setup() => Schedule(() =>
|
||||
{
|
||||
currentRoom.Value = new Room();
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user