A game framework written with osu! in mind.
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2// See the LICENCE file in the repository root for full licence text.
3
4using System.Linq;
5using NUnit.Framework;
6using osu.Framework.Graphics;
7using osu.Framework.Graphics.UserInterface;
8using osu.Framework.Input;
9using osu.Framework.Testing;
10using osu.Framework.Testing.Input;
11using osuTK;
12using osuTK.Input;
13
14namespace osu.Framework.Tests.Visual.Testing
15{
16 public class TestSceneManualInputManagerTestScene : ManualInputManagerTestScene
17 {
18 protected override Vector2 InitialMousePosition => new Vector2(10f);
19
20 [Test]
21 public void TestResetInput()
22 {
23 AddStep("move mouse", () => InputManager.MoveMouseTo(Vector2.Zero));
24 AddStep("press mouse", () => InputManager.PressButton(MouseButton.Left));
25 AddStep("press key", () => InputManager.PressKey(Key.Z));
26 AddStep("press joystick", () => InputManager.PressJoystickButton(JoystickButton.Button1));
27
28 AddStep("reset input", ResetInput);
29
30 AddAssert("mouse position reset", () => InputManager.CurrentState.Mouse.Position == InitialMousePosition);
31 AddAssert("all input states released", () =>
32 !InputManager.CurrentState.Mouse.Buttons.HasAnyButtonPressed &&
33 !InputManager.CurrentState.Keyboard.Keys.HasAnyButtonPressed &&
34 !InputManager.CurrentState.Joystick.Buttons.HasAnyButtonPressed);
35 }
36
37 [Test]
38 public void TestPlatformAction()
39 {
40 BasicTextBox textbox = null;
41
42 AddStep("add textbox", () => Child = textbox = new BasicTextBox
43 {
44 Anchor = Anchor.Centre,
45 Origin = Anchor.Centre,
46 Size = new Vector2(100, 20),
47 Text = "test text"
48 });
49
50 AddStep("focus textbox", () =>
51 {
52 InputManager.MoveMouseTo(textbox);
53 InputManager.Click(MouseButton.Left);
54 });
55
56 AddAssert("text is not selected", () => string.IsNullOrEmpty(textbox.SelectedText));
57
58 AddStep("press platform action", () => InputManager.Keys(PlatformAction.SelectAll));
59
60 AddAssert("text is selected", () => textbox.SelectedText == "test text");
61 }
62
63 [Test]
64 public void TestHoldLeftFromMaskedPosition()
65 {
66 TestCursor cursor = null;
67
68 AddStep("retrieve cursor", () => cursor = (TestCursor)InputManager.ChildrenOfType<TestCursorContainer>().Single().ActiveCursor);
69
70 AddStep("move mouse to screen zero", () => InputManager.MoveMouseTo(Vector2.Zero));
71 AddAssert("ensure cursor masked away", () => cursor.IsMaskedAway);
72
73 AddStep("hold left button", () => InputManager.PressButton(MouseButton.Left));
74 AddAssert("cursor updated to hold", () => cursor.Left.IsPresent);
75
76 AddStep("move mouse to content", () => InputManager.MoveMouseTo(Content));
77 AddAssert("cursor still holding", () => cursor.Left.IsPresent);
78 }
79
80 [Test]
81 public void TestMousePositionSetToInitial() => AddAssert("mouse position set to initial", () => InputManager.CurrentState.Mouse.Position == InitialMousePosition);
82 }
83}