mirror of
https://github.com/ppy/osu
synced 2024-12-18 21:06:38 +00:00
Add basic tests
This commit is contained in:
parent
42dfb341da
commit
e667ef4eea
@ -6,9 +6,11 @@ using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Multiplayer.Queueing;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Rulesets;
|
||||
@ -16,6 +18,8 @@ using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Screens.OnlinePlay.Lounge;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
|
||||
using osu.Game.Screens.Play;
|
||||
using osu.Game.Tests.Resources;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer.QueueingModes
|
||||
@ -24,14 +28,20 @@ namespace osu.Game.Tests.Visual.Multiplayer.QueueingModes
|
||||
{
|
||||
protected abstract QueueModes Mode { get; }
|
||||
|
||||
protected BeatmapInfo InitialBeatmap { get; private set; }
|
||||
protected BeatmapInfo OtherBeatmap { get; private set; }
|
||||
|
||||
protected IScreen CurrentScreen => multiplayerScreenStack.CurrentScreen;
|
||||
protected IScreen CurrentSubScreen => multiplayerScreenStack.MultiplayerScreen.CurrentSubScreen;
|
||||
|
||||
private BeatmapManager beatmaps;
|
||||
private RulesetStore rulesets;
|
||||
private ILive<BeatmapSetInfo> importedBeatmap;
|
||||
private BeatmapSetInfo importedSet;
|
||||
|
||||
private TestMultiplayerScreenStack multiplayerScreenStack;
|
||||
|
||||
private TestMultiplayerClient client => multiplayerScreenStack.Client;
|
||||
private TestMultiplayerRoomManager roomManager => multiplayerScreenStack.RoomManager;
|
||||
protected TestMultiplayerClient Client => multiplayerScreenStack.Client;
|
||||
protected TestMultiplayerRoomManager RoomManager => multiplayerScreenStack.RoomManager;
|
||||
|
||||
[Cached(typeof(UserLookupCache))]
|
||||
private UserLookupCache lookupCache = new TestUserLookupCache();
|
||||
@ -49,18 +59,10 @@ namespace osu.Game.Tests.Visual.Multiplayer.QueueingModes
|
||||
|
||||
AddStep("import beatmap", () =>
|
||||
{
|
||||
var beatmap1 = CreateBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo;
|
||||
beatmap1.Version = "1";
|
||||
|
||||
var beatmap2 = CreateBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo;
|
||||
beatmap2.Version = "2";
|
||||
|
||||
// Move beatmap2 to beatmap1's set.
|
||||
var beatmapSet = beatmap1.BeatmapSet;
|
||||
beatmapSet.Beatmaps.Add(beatmap2);
|
||||
beatmap2.BeatmapSet = beatmapSet;
|
||||
|
||||
importedBeatmap = beatmaps.Import(beatmapSet).Result;
|
||||
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).Wait();
|
||||
importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First();
|
||||
InitialBeatmap = importedSet.Beatmaps.First(b => b.RulesetID == 0);
|
||||
OtherBeatmap = importedSet.Beatmaps.Last(b => b.RulesetID == 0);
|
||||
});
|
||||
|
||||
AddStep("load multiplayer", () => LoadScreen(multiplayerScreenStack = new TestMultiplayerScreenStack()));
|
||||
@ -76,8 +78,8 @@ namespace osu.Game.Tests.Visual.Multiplayer.QueueingModes
|
||||
{
|
||||
new PlaylistItem
|
||||
{
|
||||
Beatmap = { Value = importedBeatmap.Value.Beatmaps.First() },
|
||||
Ruleset = { Value = new OsuRuleset().RulesetInfo }
|
||||
Beatmap = { Value = InitialBeatmap },
|
||||
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
||||
}
|
||||
}
|
||||
}));
|
||||
@ -91,13 +93,33 @@ namespace osu.Game.Tests.Visual.Multiplayer.QueueingModes
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
AddUntilStep("wait for join", () => client.Room != null);
|
||||
AddUntilStep("wait for join", () => Client.Room != null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreatedWithCorrectMode()
|
||||
{
|
||||
AddAssert("room created with correct mode", () => client.APIRoom?.QueueMode.Value == Mode);
|
||||
AddAssert("room created with correct mode", () => Client.APIRoom?.QueueMode.Value == Mode);
|
||||
}
|
||||
|
||||
protected void RunGameplay()
|
||||
{
|
||||
AddStep("click ready button", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(this.ChildrenOfType<MultiplayerReadyButton>().Single());
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
AddUntilStep("wait for ready", () => Client.LocalUser?.State == MultiplayerUserState.Ready);
|
||||
|
||||
AddStep("click ready button", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(this.ChildrenOfType<MultiplayerReadyButton>().Single());
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
AddUntilStep("wait for player", () => multiplayerScreenStack.CurrentScreen is Player player && player.IsLoaded);
|
||||
AddStep("exit player", () => multiplayerScreenStack.MultiplayerScreen.MakeCurrent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,65 @@
|
||||
// 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.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.Multiplayer.Queueing;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer.QueueingModes
|
||||
{
|
||||
public class TestSceneHostOnlyQueueingMode : QueueModeTestScene
|
||||
{
|
||||
protected override QueueModes Mode => QueueModes.HostOnly;
|
||||
|
||||
[Test]
|
||||
public void TestItemStillSelectedAfterChange()
|
||||
{
|
||||
selectNewItem(() => OtherBeatmap);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestNewItemCreatedAfterGameplayFinished()
|
||||
{
|
||||
RunGameplay();
|
||||
|
||||
AddAssert("playlist contains two items", () => Client.APIRoom?.Playlist.Count == 2);
|
||||
AddAssert("first playlist item expired", () => Client.APIRoom?.Playlist[0].Expired == true);
|
||||
AddAssert("second playlist item not expired", () => Client.APIRoom?.Playlist[1].Expired == false);
|
||||
AddAssert("second playlist item selected", () => Client.CurrentMatchPlayingItem.Value == Client.APIRoom?.Playlist[1]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestOnlyLastItemChangedAfterGameplayFinished()
|
||||
{
|
||||
RunGameplay();
|
||||
|
||||
BeatmapInfo firstBeatmap = null;
|
||||
AddStep("get first playlist item beatmap", () => firstBeatmap = Client.APIRoom?.Playlist[0].Beatmap.Value);
|
||||
|
||||
selectNewItem(() => OtherBeatmap);
|
||||
|
||||
AddAssert("first playlist item hasn't changed", () => Client.APIRoom?.Playlist[0].Beatmap.Value == firstBeatmap);
|
||||
AddAssert("second playlist item changed", () => Client.APIRoom?.Playlist[1].Beatmap.Value != firstBeatmap);
|
||||
}
|
||||
|
||||
private void selectNewItem(Func<BeatmapInfo> beatmap)
|
||||
{
|
||||
AddStep("click edit button", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(this.ChildrenOfType<MultiplayerMatchSubScreen>().Single().AddOrEditPlaylistButton);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
AddUntilStep("wait for song select", () => CurrentSubScreen is Screens.Select.SongSelect select && select.IsLoaded);
|
||||
|
||||
AddStep("select other beatmap", () => ((Screens.Select.SongSelect)CurrentSubScreen).FinaliseSelection(beatmap()));
|
||||
AddUntilStep("wait for return to match", () => CurrentSubScreen is MultiplayerMatchSubScreen);
|
||||
AddUntilStep("selected item is new beatmap", () => Client.CurrentMatchPlayingItem.Value?.Beatmap.Value?.OnlineID == OtherBeatmap.OnlineID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
[CanBeNull]
|
||||
private IDisposable readyClickOperation;
|
||||
|
||||
private OsuButton addOrEditPlaylistButton;
|
||||
public OsuButton AddOrEditPlaylistButton { get; private set; }
|
||||
|
||||
public MultiplayerMatchSubScreen(Room room)
|
||||
: base(room)
|
||||
@ -134,7 +134,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
new Drawable[] { new OverlinedHeader("Beatmap") },
|
||||
new Drawable[]
|
||||
{
|
||||
addOrEditPlaylistButton = new PurpleTriangleButton
|
||||
AddOrEditPlaylistButton = new PurpleTriangleButton
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 40,
|
||||
@ -386,18 +386,18 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
switch (client.Room.Settings.QueueMode)
|
||||
{
|
||||
case QueueModes.HostOnly:
|
||||
addOrEditPlaylistButton.Text = "Edit beatmap";
|
||||
addOrEditPlaylistButton.Alpha = client.Room.Host?.User?.Equals(client.LocalUser?.User) == true ? 1 : 0;
|
||||
AddOrEditPlaylistButton.Text = "Edit beatmap";
|
||||
AddOrEditPlaylistButton.Alpha = client.Room.Host?.User?.Equals(client.LocalUser?.User) == true ? 1 : 0;
|
||||
break;
|
||||
|
||||
case QueueModes.FreeForAll:
|
||||
case QueueModes.FairRotate:
|
||||
addOrEditPlaylistButton.Text = "Add beatmap";
|
||||
addOrEditPlaylistButton.Alpha = 1;
|
||||
AddOrEditPlaylistButton.Text = "Add beatmap";
|
||||
AddOrEditPlaylistButton.Alpha = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
addOrEditPlaylistButton.Alpha = 0;
|
||||
AddOrEditPlaylistButton.Alpha = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -211,7 +211,7 @@ namespace osu.Game.Screens.OnlinePlay
|
||||
((IBindable<UserActivity>)Activity).BindTo(newOsuScreen.Activity);
|
||||
}
|
||||
|
||||
protected IScreen CurrentSubScreen => screenStack.CurrentScreen;
|
||||
public IScreen CurrentSubScreen => screenStack.CurrentScreen;
|
||||
|
||||
protected abstract string ScreenTitle { get; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user