1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 03:22:54 +08:00

Setup tests to run headless, add basic pass support

This commit is contained in:
Dean Herbert 2020-10-26 21:45:37 +09:00
parent 67f6d52e35
commit 593b0a3ada

View File

@ -4,10 +4,13 @@
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Online.Spectator;
using osu.Game.Replays.Legacy;
using osu.Game.Screens.Play;
using osu.Game.Tests.Beatmaps.IO;
using osu.Game.Users;
namespace osu.Game.Tests.Visual.Gameplay
@ -17,14 +20,28 @@ namespace osu.Game.Tests.Visual.Gameplay
[Cached(typeof(SpectatorStreamingClient))]
private TestSpectatorStreamingClient testSpectatorStreamingClient = new TestSpectatorStreamingClient();
private Spectator spectatorScreen;
[Resolved]
private OsuGameBase game { get; set; }
public override void SetUpSteps()
{
base.SetUpSteps();
AddStep("import beatmap", () => ImportBeatmapTest.LoadOszIntoOsu(game, virtualTrack: true).Wait());
AddStep("add streaming client", () =>
{
Remove(testSpectatorStreamingClient);
Add(testSpectatorStreamingClient);
});
}
[Test]
public void TestBasicSpectatingFlow()
{
AddStep("add streaming client", () => Add(testSpectatorStreamingClient));
AddStep("load screen", () => LoadScreen(new Spectator(testSpectatorStreamingClient.StreamingUser)));
beginSpectating();
AddStep("start play", () => testSpectatorStreamingClient.StartPlay());
AddStep("send frames", () => testSpectatorStreamingClient.SendFrames());
}
@ -32,27 +49,68 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test]
public void TestSpectatingDuringGameplay()
{
AddStep("start play", () => testSpectatorStreamingClient.StartPlay());
AddStep("send frames", () => testSpectatorStreamingClient.SendFrames());
// should seek immediately to available frames
beginSpectating();
}
[Test]
public void TestHostStartsPlayingWhileAlreadyWatching()
{
beginSpectating();
AddStep("start play", () => testSpectatorStreamingClient.StartPlay());
AddStep("send frames", () => testSpectatorStreamingClient.SendFrames());
AddStep("start play", () => testSpectatorStreamingClient.StartPlay());
AddStep("send frames", () => testSpectatorStreamingClient.SendFrames());
// should restart either immediately or after running out of frames
}
[Test]
public void TestHostFails()
{
beginSpectating();
AddStep("start play", () => testSpectatorStreamingClient.StartPlay());
AddStep("send frames", () => testSpectatorStreamingClient.SendFrames());
// todo: send fail state
// should replay until running out of frames then fail
}
[Test]
public void TestStopWatchingDuringPlay()
{
beginSpectating();
AddStep("start play", () => testSpectatorStreamingClient.StartPlay());
AddStep("send frames", () => testSpectatorStreamingClient.SendFrames());
AddUntilStep("wait for player", () => Stack.CurrentScreen is Player);
// should immediately exit and unbind from streaming client
AddStep("stop spectating", () => (Stack.CurrentScreen as Player)?.Exit());
AddUntilStep("spectating stopped", () => spectatorScreen.GetParentScreen() == null);
}
[Test]
public void TestWatchingBeatmapThatDoesntExistLocally()
{
beginSpectating();
AddStep("start play", () => testSpectatorStreamingClient.StartPlay());
AddStep("send frames", () => testSpectatorStreamingClient.SendFrames());
// player should never arrive.
}
private void beginSpectating() =>
AddStep("load screen", () => LoadScreen(spectatorScreen = new Spectator(testSpectatorStreamingClient.StreamingUser)));
internal class TestSpectatorStreamingClient : SpectatorStreamingClient
{
[Resolved]
@ -64,7 +122,16 @@ namespace osu.Game.Tests.Visual.Gameplay
{
((ISpectatorClient)this).UserBeganPlaying((int)StreamingUser.Id, new SpectatorState
{
BeatmapID = beatmaps.GetAllUsableBeatmapSets().First().Beatmaps.First().OnlineBeatmapID,
BeatmapID = beatmaps.GetAllUsableBeatmapSets().First().Beatmaps.First(b => b.RulesetID == 0).OnlineBeatmapID,
RulesetID = 0,
});
}
public void EndPlay()
{
((ISpectatorClient)this).UserFinishedPlaying((int)StreamingUser.Id, new SpectatorState
{
BeatmapID = beatmaps.GetAllUsableBeatmapSets().First().Beatmaps.First(b => b.RulesetID == 0).OnlineBeatmapID,
RulesetID = 0,
});
}