osu/osu.Game.Tests/Visual/TestCaseKeyCounter.cs

73 lines
2.6 KiB
C#
Raw Normal View History

2018-09-15 07:24:06 +00:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
2018-04-13 09:19:50 +00:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using NUnit.Framework;
using osu.Framework.Graphics;
2018-07-28 20:24:03 +00:00
using osu.Framework.Input.EventArgs;
2018-04-13 09:19:50 +00:00
using osu.Framework.MathUtils;
2018-07-28 20:24:03 +00:00
using osu.Framework.Timing;
2018-04-13 09:19:50 +00:00
using osu.Game.Screens.Play;
using OpenTK.Input;
namespace osu.Game.Tests.Visual
{
[TestFixture]
public class TestCaseKeyCounter : OsuTestCase
{
2018-09-15 07:24:06 +00:00
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(KeyCounterKeyboard),
typeof(KeyCounterMouse),
typeof(KeyCounterCollection)
};
2018-07-28 20:24:03 +00:00
2018-04-13 09:19:50 +00:00
public TestCaseKeyCounter()
{
2018-07-28 20:24:03 +00:00
KeyCounterKeyboard rewindTestKeyCounterKeyboard;
2018-04-13 09:19:50 +00:00
KeyCounterCollection kc = new KeyCounterCollection
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Children = new KeyCounter[]
{
2018-07-28 20:24:03 +00:00
rewindTestKeyCounterKeyboard = new KeyCounterKeyboard(rewind_test_key),
2018-04-13 09:19:50 +00:00
new KeyCounterKeyboard(Key.X),
new KeyCounterMouse(MouseButton.Left),
new KeyCounterMouse(MouseButton.Right),
},
};
AddStep("Add random", () =>
{
Key key = (Key)((int)Key.A + RNG.Next(26));
kc.Add(new KeyCounterKeyboard(key));
});
AddSliderStep("Fade time", 0, 200, 50, v => kc.FadeTime = v);
2018-07-28 20:24:03 +00:00
var expectedCountPresses = rewindTestKeyCounterKeyboard.CountPresses + 1;
AddStep($"Press {rewind_test_key} key", () =>
{
rewindTestKeyCounterKeyboard.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = rewind_test_key, Repeat = false });
rewindTestKeyCounterKeyboard.TriggerOnKeyUp(null, new KeyUpEventArgs { Key = rewind_test_key });
});
AddAssert($"Check {rewind_test_key} counter after keypress", () => rewindTestKeyCounterKeyboard.CountPresses == expectedCountPresses);
IFrameBasedClock counterClock = null;
AddStep($"Rewind {rewind_test_key} counter", () =>
{
counterClock = rewindTestKeyCounterKeyboard.Clock;
rewindTestKeyCounterKeyboard.Clock = new DecoupleableInterpolatingFramedClock();
});
AddAssert($"Check {rewind_test_key} counter after rewind", () =>
{
rewindTestKeyCounterKeyboard.Clock = counterClock;
return rewindTestKeyCounterKeyboard.CountPresses == 0;
});
2018-04-13 09:19:50 +00:00
Add(kc);
}
}
}