mirror of https://github.com/ppy/osu
Improve background sprite testcase
This commit is contained in:
parent
de08115e85
commit
1d2db85866
|
@ -2,8 +2,8 @@
|
|||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.Drawables;
|
||||
|
@ -11,12 +11,15 @@
|
|||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Tests.Beatmaps.IO;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
public class TestCaseUpdateableBeatmapBackgroundSprite : OsuTestCase
|
||||
{
|
||||
private TestUpdateableBeatmapBackgroundSprite backgroundSprite;
|
||||
private BeatmapSetInfo testBeatmap;
|
||||
private IAPIProvider api;
|
||||
private RulesetStore rulesets;
|
||||
|
||||
[Resolved]
|
||||
private BeatmapManager beatmaps { get; set; }
|
||||
|
@ -24,40 +27,68 @@ public class TestCaseUpdateableBeatmapBackgroundSprite : OsuTestCase
|
|||
[BackgroundDependencyLoader]
|
||||
private void load(OsuGameBase osu, IAPIProvider api, RulesetStore rulesets)
|
||||
{
|
||||
Bindable<BeatmapInfo> beatmapBindable = new Bindable<BeatmapInfo>();
|
||||
this.api = api;
|
||||
this.rulesets = rulesets;
|
||||
|
||||
var imported = ImportBeatmapTest.LoadOszIntoOsu(osu);
|
||||
testBeatmap = ImportBeatmapTest.LoadOszIntoOsu(osu);
|
||||
}
|
||||
|
||||
Child = backgroundSprite = new TestUpdateableBeatmapBackgroundSprite { RelativeSizeAxes = Axes.Both };
|
||||
[Test]
|
||||
public void TestNullBeatmap()
|
||||
{
|
||||
TestUpdateableBeatmapBackgroundSprite background = null;
|
||||
|
||||
backgroundSprite.Beatmap.BindTo(beatmapBindable);
|
||||
AddStep("load null beatmap", () => Child = background = new TestUpdateableBeatmapBackgroundSprite { RelativeSizeAxes = Axes.Both });
|
||||
AddUntilStep("wait for load", () => background.ContentLoaded);
|
||||
}
|
||||
|
||||
var req = new GetBeatmapSetRequest(1);
|
||||
api.Queue(req);
|
||||
[Test]
|
||||
public void TestLocalBeatmap()
|
||||
{
|
||||
TestUpdateableBeatmapBackgroundSprite background = null;
|
||||
|
||||
AddStep("load null beatmap", () => beatmapBindable.Value = null);
|
||||
AddUntilStep("wait for cleanup...", () => backgroundSprite.ChildCount == 1);
|
||||
AddStep("load imported beatmap", () => beatmapBindable.Value = imported.Beatmaps.First());
|
||||
AddUntilStep("wait for cleanup...", () => backgroundSprite.ChildCount == 1);
|
||||
AddStep("load local beatmap", () =>
|
||||
{
|
||||
Child = background = new TestUpdateableBeatmapBackgroundSprite
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Beatmap = { Value = testBeatmap.Beatmaps.First() }
|
||||
};
|
||||
});
|
||||
|
||||
AddUntilStep("wait for load", () => background.ContentLoaded);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestOnlineBeatmap()
|
||||
{
|
||||
if (api.IsLoggedIn)
|
||||
{
|
||||
var req = new GetBeatmapSetRequest(1);
|
||||
api.Queue(req);
|
||||
|
||||
AddUntilStep("wait for api response", () => req.Result != null);
|
||||
AddStep("load online beatmap", () => beatmapBindable.Value = new BeatmapInfo
|
||||
|
||||
TestUpdateableBeatmapBackgroundSprite background = null;
|
||||
|
||||
AddStep("load online beatmap", () =>
|
||||
{
|
||||
BeatmapSet = req.Result?.ToBeatmapSet(rulesets)
|
||||
Child = background = new TestUpdateableBeatmapBackgroundSprite
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Beatmap = { Value = new BeatmapInfo { BeatmapSet = req.Result?.ToBeatmapSet(rulesets) } }
|
||||
};
|
||||
});
|
||||
AddUntilStep("wait for cleanup...", () => backgroundSprite.ChildCount == 1);
|
||||
|
||||
AddUntilStep("wait for load", () => background.ContentLoaded);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddStep("online (login first)", () => { });
|
||||
}
|
||||
}
|
||||
|
||||
private class TestUpdateableBeatmapBackgroundSprite : UpdateableBeatmapBackgroundSprite
|
||||
{
|
||||
public int ChildCount => InternalChildren.Count;
|
||||
public bool ContentLoaded => ((DelayedLoadUnloadWrapper)InternalChildren.LastOrDefault())?.Content?.IsLoaded ?? false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue