osu/osu.Game.Tests/Visual/Gameplay/TestSceneKeyCounter.cs

70 lines
2.1 KiB
C#
Raw Normal View History

// 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.
2018-04-13 09:19:50 +00:00
2018-09-15 07:25:37 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
2018-04-13 09:19:50 +00:00
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.MathUtils;
using osu.Game.Screens.Play;
2018-11-20 07:51:59 +00:00
using osuTK.Input;
2018-04-13 09:19:50 +00:00
2019-03-24 16:02:36 +00:00
namespace osu.Game.Tests.Visual.Gameplay
2018-04-13 09:19:50 +00:00
{
[TestFixture]
public class TestSceneKeyCounter : ManualInputManagerTestScene
2018-04-13 09:19:50 +00:00
{
2018-09-15 07:24:06 +00:00
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(KeyCounterKeyboard),
typeof(KeyCounterMouse),
typeof(KeyCounterDisplay)
2018-09-15 07:24:06 +00:00
};
2018-07-28 20:24:03 +00:00
public TestSceneKeyCounter()
2018-04-13 09:19:50 +00:00
{
KeyCounterKeyboard testCounter;
KeyCounterDisplay kc = new KeyCounterDisplay
2018-04-13 09:19:50 +00:00
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Children = new KeyCounter[]
{
testCounter = new KeyCounterKeyboard(Key.X),
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));
});
2018-09-15 07:25:37 +00:00
Key testKey = ((KeyCounterKeyboard)kc.Children.First()).Key;
AddStep($"Press {testKey} key", () =>
2018-07-28 20:24:03 +00:00
{
InputManager.PressKey(testKey);
InputManager.ReleaseKey(testKey);
2018-07-28 20:24:03 +00:00
});
AddAssert($"Check {testKey} counter after keypress", () => testCounter.CountPresses == 1);
2018-07-28 20:24:03 +00:00
2018-09-15 07:25:37 +00:00
AddStep($"Press {testKey} key", () =>
2018-07-28 20:24:03 +00:00
{
InputManager.PressKey(testKey);
InputManager.ReleaseKey(testKey);
2018-07-28 20:24:03 +00:00
});
AddAssert($"Check {testKey} counter after keypress", () => testCounter.CountPresses == 2);
2018-09-15 07:25:37 +00:00
2018-04-13 09:19:50 +00:00
Add(kc);
}
}
}