1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 19:22:54 +08:00

Refactor test

This commit is contained in:
Dean Herbert 2019-03-22 16:03:08 +09:00
parent c43b1afa30
commit 670c25d5e8

View File

@ -7,7 +7,6 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Graphics.Containers;
using osu.Game.Screens; using osu.Game.Screens;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osuTK.Graphics; using osuTK.Graphics;
@ -17,26 +16,30 @@ namespace osu.Game.Tests.Visual
[TestFixture] [TestFixture]
public class TestCaseOsuScreenStack : OsuTestCase public class TestCaseOsuScreenStack : OsuTestCase
{ {
private NoParallaxTestScreen baseScreen;
private TestScreen newScreen;
private TestOsuScreenStack stack; private TestOsuScreenStack stack;
[SetUpSteps] [SetUpSteps]
public void Setup() public void SetUpSteps()
{ {
AddStep("Create new screen stack", () => { Child = stack = new TestOsuScreenStack { RelativeSizeAxes = Axes.Both }; }); AddStep("Create new screen stack", () => { Child = stack = new TestOsuScreenStack { RelativeSizeAxes = Axes.Both }; });
AddStep("Push new base screen", () => stack.Push(baseScreen = new NoParallaxTestScreen("THIS IS SCREEN 1. THIS SCREEN SHOULD HAVE NO PARALLAX.")));
AddUntilStep("Wait for Screen 1 to be current", () => baseScreen.IsLoaded);
} }
[Test] [Test]
public void ParallaxAssignmentTest() public void ParallaxAssignmentTest()
{ {
AddStep("Push new screen to base screen", () => baseScreen.Push(newScreen = new TestScreen("THIS IS SCREEN 2. THIS SCREEN SHOULD HAVE PARALLAX."))); NoParallaxTestScreen noParallaxScreen = null;
AddUntilStep("Wait for Screen 2 to be current", () => newScreen.IsLoaded); TestScreen parallaxScreen = null;
AddAssert("Parallax is correct", () => stack.IsParallaxSet);
AddStep("Exit from new screen", () => { baseScreen.MakeCurrent(); }); AddStep("Push no parallax", () => stack.Push(noParallaxScreen = new NoParallaxTestScreen("NO PARALLAX")));
AddAssert("Parallax is correct", () => stack.IsParallaxSet); AddUntilStep("Wait for current", () => noParallaxScreen.IsLoaded);
AddAssert("Parallax is off", () => stack.ParallaxAmount == 0);
AddStep("Push parallax", () => noParallaxScreen.Push(parallaxScreen = new TestScreen("PARALLAX")));
AddUntilStep("Wait for current", () => parallaxScreen.IsLoaded);
AddAssert("Parallax is on", () => stack.ParallaxAmount > 0);
AddStep("Exit from new screen", () => { noParallaxScreen.MakeCurrent(); });
AddAssert("Parallax is off", () => stack.ParallaxAmount == 0);
} }
private class TestScreen : ScreenWithBeatmapBackground private class TestScreen : ScreenWithBeatmapBackground
@ -54,7 +57,9 @@ namespace osu.Game.Tests.Visual
AddInternal(new SpriteText AddInternal(new SpriteText
{ {
Text = screenText, Text = screenText,
Colour = Color4.White Colour = Color4.White,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}); });
} }
} }
@ -71,7 +76,7 @@ namespace osu.Game.Tests.Visual
private class TestOsuScreenStack : OsuScreenStack private class TestOsuScreenStack : OsuScreenStack
{ {
public bool IsParallaxSet => ParallaxAmount == ((TestScreen)CurrentScreen).BackgroundParallaxAmount * ParallaxContainer.DEFAULT_PARALLAX_AMOUNT; public new float ParallaxAmount => base.ParallaxAmount;
} }
} }
} }