2021-07-01 15:55:44 +08:00
|
|
|
// 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.
|
|
|
|
|
2021-07-11 08:35:35 +08:00
|
|
|
using System;
|
2021-07-01 15:55:44 +08:00
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Screens;
|
2021-07-07 13:58:01 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2021-07-01 15:55:44 +08:00
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Online.Rooms;
|
|
|
|
using osu.Game.Online.Solo;
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2021-07-11 08:35:35 +08:00
|
|
|
using osu.Game.Rulesets.Osu;
|
2021-07-04 16:26:46 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Judgements;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2021-07-01 15:55:44 +08:00
|
|
|
using osu.Game.Screens.Ranking;
|
2021-07-07 13:58:01 +08:00
|
|
|
using osu.Game.Tests.Beatmaps;
|
2021-07-01 15:55:44 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
|
|
|
{
|
2021-07-11 08:35:35 +08:00
|
|
|
public class TestScenePlayerScoreSubmission : PlayerTestScene
|
2021-07-01 15:55:44 +08:00
|
|
|
{
|
2021-07-02 13:21:48 +08:00
|
|
|
protected override bool AllowFail => allowFail;
|
|
|
|
|
|
|
|
private bool allowFail;
|
2021-07-01 15:55:44 +08:00
|
|
|
|
2021-07-11 08:35:35 +08:00
|
|
|
private Func<RulesetInfo, IBeatmap> createCustomBeatmap;
|
|
|
|
private Func<Ruleset> createCustomRuleset;
|
|
|
|
|
2021-07-01 15:55:44 +08:00
|
|
|
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
|
|
|
|
|
2021-07-01 16:20:40 +08:00
|
|
|
protected override bool HasCustomSteps => true;
|
|
|
|
|
2021-07-11 08:35:35 +08:00
|
|
|
protected override TestPlayer CreatePlayer(Ruleset ruleset) => new TestPlayer(false);
|
|
|
|
|
|
|
|
protected override Ruleset CreatePlayerRuleset() => createCustomRuleset?.Invoke() ?? new OsuRuleset();
|
|
|
|
|
|
|
|
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) => createCustomBeatmap?.Invoke(ruleset) ?? createTestBeatmap(ruleset);
|
|
|
|
|
|
|
|
private IBeatmap createTestBeatmap(RulesetInfo ruleset)
|
2021-07-07 13:58:01 +08:00
|
|
|
{
|
|
|
|
var beatmap = (TestBeatmap)base.CreateBeatmap(ruleset);
|
|
|
|
|
|
|
|
beatmap.HitObjects = beatmap.HitObjects.Take(10).ToList();
|
|
|
|
|
|
|
|
return beatmap;
|
|
|
|
}
|
|
|
|
|
2021-07-01 16:20:40 +08:00
|
|
|
[Test]
|
|
|
|
public void TestNoSubmissionOnResultsWithNoToken()
|
2021-07-01 15:55:44 +08:00
|
|
|
{
|
2021-07-01 16:20:40 +08:00
|
|
|
prepareTokenResponse(false);
|
2021-07-01 15:55:44 +08:00
|
|
|
|
2021-07-11 08:35:35 +08:00
|
|
|
createPlayerTest();
|
2021-07-01 15:55:44 +08:00
|
|
|
|
2021-07-01 16:20:40 +08:00
|
|
|
AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
|
2021-07-01 15:55:44 +08:00
|
|
|
|
|
|
|
AddUntilStep("wait for track to start running", () => Beatmap.Value.Track.IsRunning);
|
2021-07-04 20:34:52 +08:00
|
|
|
|
|
|
|
addFakeHit();
|
|
|
|
|
2021-07-01 16:20:40 +08:00
|
|
|
AddStep("seek to completion", () => Player.GameplayClockContainer.Seek(Player.DrawableRuleset.Objects.Last().GetEndTime()));
|
|
|
|
|
|
|
|
AddUntilStep("results displayed", () => Player.GetChildScreen() is ResultsScreen);
|
|
|
|
|
2021-07-01 16:38:28 +08:00
|
|
|
AddAssert("ensure no submission", () => Player.SubmittedScore == null);
|
2021-07-01 15:55:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestSubmissionOnResults()
|
|
|
|
{
|
2021-07-01 16:20:40 +08:00
|
|
|
prepareTokenResponse(true);
|
|
|
|
|
2021-07-11 08:35:35 +08:00
|
|
|
createPlayerTest();
|
2021-07-01 16:20:40 +08:00
|
|
|
|
2021-07-01 15:55:44 +08:00
|
|
|
AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
|
|
|
|
|
2021-07-01 16:20:40 +08:00
|
|
|
AddUntilStep("wait for track to start running", () => Beatmap.Value.Track.IsRunning);
|
2021-07-04 16:26:46 +08:00
|
|
|
|
|
|
|
addFakeHit();
|
|
|
|
|
2021-07-01 15:55:44 +08:00
|
|
|
AddStep("seek to completion", () => Player.GameplayClockContainer.Seek(Player.DrawableRuleset.Objects.Last().GetEndTime()));
|
|
|
|
|
|
|
|
AddUntilStep("results displayed", () => Player.GetChildScreen() is ResultsScreen);
|
2021-07-01 16:38:28 +08:00
|
|
|
AddAssert("ensure passing submission", () => Player.SubmittedScore?.ScoreInfo.Passed == true);
|
2021-07-01 16:20:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestNoSubmissionOnExitWithNoToken()
|
|
|
|
{
|
|
|
|
prepareTokenResponse(false);
|
|
|
|
|
2021-07-11 08:35:35 +08:00
|
|
|
createPlayerTest();
|
2021-07-01 16:38:28 +08:00
|
|
|
|
|
|
|
AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
|
|
|
|
|
2021-07-04 20:34:52 +08:00
|
|
|
AddUntilStep("wait for track to start running", () => Beatmap.Value.Track.IsRunning);
|
|
|
|
|
|
|
|
addFakeHit();
|
|
|
|
|
2021-07-01 16:38:28 +08:00
|
|
|
AddStep("exit", () => Player.Exit());
|
|
|
|
AddAssert("ensure no submission", () => Player.SubmittedScore == null);
|
|
|
|
}
|
|
|
|
|
2021-07-04 16:26:46 +08:00
|
|
|
[Test]
|
|
|
|
public void TestNoSubmissionOnEmptyFail()
|
|
|
|
{
|
|
|
|
prepareTokenResponse(true);
|
|
|
|
|
2021-07-11 08:35:35 +08:00
|
|
|
createPlayerTest(true);
|
2021-07-04 16:26:46 +08:00
|
|
|
|
|
|
|
AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
|
|
|
|
|
|
|
|
AddUntilStep("wait for fail", () => Player.HasFailed);
|
|
|
|
AddStep("exit", () => Player.Exit());
|
|
|
|
|
|
|
|
AddAssert("ensure no submission", () => Player.SubmittedScore == null);
|
|
|
|
}
|
|
|
|
|
2021-07-01 16:38:28 +08:00
|
|
|
[Test]
|
|
|
|
public void TestSubmissionOnFail()
|
|
|
|
{
|
|
|
|
prepareTokenResponse(true);
|
|
|
|
|
2021-07-11 08:35:35 +08:00
|
|
|
createPlayerTest(true);
|
2021-07-01 16:20:40 +08:00
|
|
|
|
|
|
|
AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
|
2021-07-04 16:26:46 +08:00
|
|
|
|
|
|
|
addFakeHit();
|
|
|
|
|
2021-07-01 16:38:28 +08:00
|
|
|
AddUntilStep("wait for fail", () => Player.HasFailed);
|
2021-07-01 16:20:40 +08:00
|
|
|
AddStep("exit", () => Player.Exit());
|
|
|
|
|
2021-07-01 16:38:28 +08:00
|
|
|
AddAssert("ensure failing submission", () => Player.SubmittedScore?.ScoreInfo.Passed == false);
|
2021-07-01 15:55:44 +08:00
|
|
|
}
|
|
|
|
|
2021-07-04 16:26:46 +08:00
|
|
|
[Test]
|
|
|
|
public void TestNoSubmissionOnEmptyExit()
|
|
|
|
{
|
|
|
|
prepareTokenResponse(true);
|
|
|
|
|
2021-07-11 08:35:35 +08:00
|
|
|
createPlayerTest();
|
2021-07-04 16:26:46 +08:00
|
|
|
|
|
|
|
AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
|
|
|
|
|
|
|
|
AddStep("exit", () => Player.Exit());
|
|
|
|
AddAssert("ensure no submission", () => Player.SubmittedScore == null);
|
|
|
|
}
|
|
|
|
|
2021-07-01 15:55:44 +08:00
|
|
|
[Test]
|
|
|
|
public void TestSubmissionOnExit()
|
|
|
|
{
|
2021-07-01 16:20:40 +08:00
|
|
|
prepareTokenResponse(true);
|
|
|
|
|
2021-07-11 08:35:35 +08:00
|
|
|
createPlayerTest();
|
2021-07-01 16:20:40 +08:00
|
|
|
|
2021-07-01 15:55:44 +08:00
|
|
|
AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
|
2021-07-04 16:26:46 +08:00
|
|
|
|
|
|
|
addFakeHit();
|
|
|
|
|
2021-07-01 15:55:44 +08:00
|
|
|
AddStep("exit", () => Player.Exit());
|
2021-07-01 16:38:28 +08:00
|
|
|
AddAssert("ensure failing submission", () => Player.SubmittedScore?.ScoreInfo.Passed == false);
|
2021-07-01 15:55:44 +08:00
|
|
|
}
|
2021-07-01 16:20:40 +08:00
|
|
|
|
2021-07-11 08:35:35 +08:00
|
|
|
[Test]
|
|
|
|
public void TestNoSubmissionOnLocalBeatmap()
|
2021-07-04 16:26:46 +08:00
|
|
|
{
|
2021-07-11 08:35:35 +08:00
|
|
|
prepareTokenResponse(true);
|
2021-07-04 16:26:46 +08:00
|
|
|
|
2021-07-11 08:35:35 +08:00
|
|
|
createPlayerTest(false, r =>
|
2021-07-04 16:26:46 +08:00
|
|
|
{
|
2021-07-11 08:35:35 +08:00
|
|
|
var beatmap = createTestBeatmap(r);
|
|
|
|
beatmap.BeatmapInfo.OnlineBeatmapID = null;
|
|
|
|
return beatmap;
|
2021-07-04 16:26:46 +08:00
|
|
|
});
|
2021-07-11 08:35:35 +08:00
|
|
|
|
|
|
|
AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
|
|
|
|
|
|
|
|
addFakeHit();
|
|
|
|
|
|
|
|
AddStep("exit", () => Player.Exit());
|
|
|
|
AddAssert("ensure no submission", () => Player.SubmittedScore == null);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestNoSubmissionOnCustomRuleset()
|
|
|
|
{
|
|
|
|
prepareTokenResponse(true);
|
|
|
|
|
|
|
|
createPlayerTest(false, createRuleset: () => new OsuRuleset { RulesetInfo = { ID = 10 } });
|
|
|
|
|
|
|
|
AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
|
|
|
|
|
|
|
|
addFakeHit();
|
|
|
|
|
|
|
|
AddStep("exit", () => Player.Exit());
|
|
|
|
AddAssert("ensure no submission", () => Player.SubmittedScore == null);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void createPlayerTest(bool allowFail = false, Func<RulesetInfo, IBeatmap> createBeatmap = null, Func<Ruleset> createRuleset = null)
|
|
|
|
{
|
|
|
|
CreateTest(() => AddStep("set up requirements", () =>
|
|
|
|
{
|
|
|
|
this.allowFail = allowFail;
|
|
|
|
createCustomBeatmap = createBeatmap;
|
|
|
|
createCustomRuleset = createRuleset;
|
|
|
|
}));
|
2021-07-04 16:26:46 +08:00
|
|
|
}
|
|
|
|
|
2021-07-01 16:20:40 +08:00
|
|
|
private void prepareTokenResponse(bool validToken)
|
|
|
|
{
|
|
|
|
AddStep("Prepare test API", () =>
|
|
|
|
{
|
|
|
|
dummyAPI.HandleRequest = request =>
|
|
|
|
{
|
|
|
|
switch (request)
|
|
|
|
{
|
|
|
|
case CreateSoloScoreRequest tokenRequest:
|
|
|
|
if (validToken)
|
|
|
|
tokenRequest.TriggerSuccess(new APIScoreToken { ID = 1234 });
|
|
|
|
else
|
2021-07-01 16:54:59 +08:00
|
|
|
tokenRequest.TriggerFailure(new APIException("something went wrong!", null));
|
2021-07-01 16:20:40 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
2021-07-11 08:35:35 +08:00
|
|
|
|
|
|
|
private void addFakeHit()
|
|
|
|
{
|
|
|
|
AddUntilStep("wait for first result", () => Player.Results.Count > 0);
|
|
|
|
|
|
|
|
AddStep("force successfuly hit", () =>
|
|
|
|
{
|
|
|
|
Player.ScoreProcessor.RevertResult(Player.Results.First());
|
|
|
|
Player.ScoreProcessor.ApplyResult(new OsuJudgementResult(Beatmap.Value.Beatmap.HitObjects.First(), new OsuJudgement())
|
|
|
|
{
|
|
|
|
Type = HitResult.Great,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2021-07-01 15:55:44 +08:00
|
|
|
}
|
|
|
|
}
|