Add new automated tests for logofacade, reset interpolation

This commit is contained in:
David Zhao
2019-03-27 20:04:01 +09:00
parent 2e3791be1c
commit 061527a260
3 changed files with 103 additions and 27 deletions

View File

@ -7,8 +7,10 @@ using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Screens;
using osu.Game.Configuration;
using osu.Game.Graphics.Containers;
using osu.Game.Screens;
@ -25,7 +27,6 @@ namespace osu.Game.Tests.Visual
{
typeof(PlayerLoader),
typeof(Player),
typeof(LogoFacadeContainer.Facade),
typeof(LogoFacadeContainer),
typeof(ButtonSystem),
typeof(ButtonSystemState),
@ -47,36 +48,65 @@ namespace osu.Game.Tests.Visual
private void load(OsuConfigManager config)
{
config.BindWith(OsuSetting.UIScale, uiScale);
AddSliderStep("Adjust scale", 1f, 1.5f, 1f, v => uiScale.Value = v);
AddSliderStep("Adjust scale", 0.8f, 1.5f, 1f, v => uiScale.Value = v);
}
/// <summary>
/// Move the facade to 0,0, then move it to a random new location while the logo is still transforming to it.
/// Check if the logo is still tracking the facade.
/// </summary>
[Test]
public void IsolatedTest()
public void MoveFacadeTest()
{
TestScreen screen = null;
bool randomPositions = false;
AddToggleStep("Toggle move continuously", b => randomPositions = b);
AddStep("Move facade to random position", () => LoadScreen(new TestScreen(randomPositions)));
AddStep("Move facade to random position", () => LoadScreen(screen = new TestScreen(randomPositions)));
AddUntilStep("Screen is current", () => screen.IsCurrentScreen());
waitForMove();
AddAssert("Logo is tracking", () => screen.IsLogoTracking);
}
private class TestLogoFacadeContainer : LogoFacadeContainer
/// <summary>
/// Check if the facade is removed from the container, the logo stops tracking.
/// </summary>
[Test]
public void RemoveFacadeTest()
{
protected override Facade CreateFacade() => new Facade
{
Colour = Color4.Tomato,
Alpha = 0.35f,
Child = new Box
{
Colour = Color4.Tomato,
RelativeSizeAxes = Axes.Both,
},
};
TestScreen screen = null;
AddStep("Move facade to random position", () => LoadScreen(screen = new TestScreen()));
AddUntilStep("Screen is current", () => screen.IsCurrentScreen());
AddStep("Remove facade from FacadeContainer", () => screen.RemoveFacade());
waitForMove();
AddAssert("Logo is not tracking", () => !screen.IsLogoTracking);
}
/// <summary>
/// Check if the facade gets added to a new container, tracking starts on the new facade.
/// </summary>
[Test]
public void TransferFacadeTest()
{
TestScreen screen = null;
AddStep("Move facade to random position", () => LoadScreen(screen = new TestScreen()));
AddUntilStep("Screen is current", () => screen.IsCurrentScreen());
AddStep("Remove facade from FacadeContainer", () => screen.RemoveFacade());
AddStep("Transfer facade to a new container", () => screen.TransferFacade());
waitForMove();
AddAssert("Logo is tracking", () => screen.IsLogoTracking);
}
private void waitForMove() => AddWaitStep("Wait for transforms to finish", 5);
private class TestScreen : OsuScreen
{
private TestLogoFacadeContainer logoFacadeContainer;
private LogoFacadeContainer.Facade facadeFlowComponent;
private LogoFacadeContainer logoFacadeContainer;
private Container transferContainer;
private Container logoFacade;
private readonly bool randomPositions;
private OsuLogo logo;
private Box visualBox;
private Box transferContainerBox;
public TestScreen(bool randomPositions = false)
{
@ -86,13 +116,55 @@ namespace osu.Game.Tests.Visual
[BackgroundDependencyLoader]
private void load()
{
InternalChild = logoFacadeContainer = new TestLogoFacadeContainer();
logoFacadeContainer.Child = facadeFlowComponent = logoFacadeContainer.LogoFacade;
InternalChildren = new Drawable[]
{
logoFacadeContainer = new LogoFacadeContainer
{
Alpha = 0.35f,
RelativeSizeAxes = Axes.None,
Size = new Vector2(107),
Child = visualBox = new Box
{
Colour = Color4.Tomato,
RelativeSizeAxes = Axes.Both,
}
},
transferContainer = new Container
{
Alpha = 0.35f,
RelativeSizeAxes = Axes.None,
Size = new Vector2(107),
Child = transferContainerBox = new Box
{
Colour = Color4.White,
RelativeSizeAxes = Axes.Both,
}
},
};
logoFacadeContainer.Add(logoFacade = logoFacadeContainer.LogoFacade);
}
public bool IsLogoTracking => logo.Position == logo.Parent.ToLocalSpace(logoFacadeContainer.LogoFacade.ScreenSpaceDrawQuad.Centre);
public void RemoveFacade()
{
logoFacadeContainer.Remove(logoFacade);
visualBox.Colour = Color4.White;
moveLogoFacade();
}
public void TransferFacade()
{
transferContainer.Add(logoFacade);
transferContainerBox.Colour = Color4.Tomato;
moveLogoFacade();
}
protected override void LogoArriving(OsuLogo logo, bool resuming)
{
base.LogoArriving(logo, resuming);
this.logo = logo;
logo.FadeIn(350);
logo.ScaleTo(new Vector2(0.15f), 350, Easing.In);
logoFacadeContainer.SetLogo(logo, 0.3f, 1000, Easing.InOutQuint);
@ -109,9 +181,10 @@ namespace osu.Game.Tests.Visual
private void moveLogoFacade()
{
Random random = new Random();
if (facadeFlowComponent.Transforms.Count == 0)
if (logoFacade.Transforms.Count == 0 && transferContainer.Transforms.Count == 0)
{
facadeFlowComponent.Delay(500).MoveTo(new Vector2(random.Next(0, (int)DrawWidth), random.Next(0, (int)DrawHeight)), 300);
logoFacadeContainer.Delay(500).MoveTo(new Vector2(random.Next(0, (int)DrawWidth), random.Next(0, (int)DrawHeight)), 300);
transferContainer.Delay(500).MoveTo(new Vector2(random.Next(0, (int)DrawWidth), random.Next(0, (int)DrawHeight)), 300);
}
if (randomPositions)