Inheritance Hierarchy
DeltaEngine.Platforms TestWithMocksOrVisually
DeltaEngine.Input.Tests KeyboardTests
Namespace: DeltaEngine.Input.Tests
Assembly: DeltaEngine.Input.Tests (in DeltaEngine.Input.Tests.dll) Version: 1.1.1.0 (1.1.1)
Syntax
The KeyboardTests type exposes the following members.
Constructors
Name | Description | |
---|---|---|
KeyboardTests | Initializes a new instance of the KeyboardTests class |
Methods
Properties
Name | Description | |
---|---|---|
IsMockResolver | (Inherited from TestWithMocksOrVisually.) |
Examples
[TestFixtureTearDown] public void Dispose() { keyboard.Dispose(); }
[Test] public void PressKeyToShowCircle() { new FontText(Font.Default, "Press A on Keyboard to show red circle", Rectangle.One); var ellipse = new Ellipse(new Rectangle(0.1f, 0.1f, 0.1f, 0.1f), Color.Red); new Command(() => ellipse.Center = Vector2D.Half).Add(new KeyTrigger(Key.A, State.Pressed)); new Command(() => ellipse.Center = Vector2D.Zero).Add(new KeyTrigger(Key.A, State.Released)); }
[Test, CloseAfterFirstFrame] public void TestSpaceKeyPress() { bool isSpacePressed = false; new Command(() => isSpacePressed = true).Add(new KeyTrigger(Key.Space, State.Pressed)); Assert.IsFalse(isSpacePressed); if (mockKeyboard == null) return; //ncrunch: no coverage mockKeyboard.SetKeyboardState(Key.Space, State.Pressed); AdvanceTimeAndUpdateEntities(); Assert.IsTrue(isSpacePressed); Assert.IsTrue(mockKeyboard.IsAvailable); }
[Test] public void CountKeyPressingAndReleasing() { int pressed = 0; int released = 0; var fontText = new FontText(Font.Default, "'A' pressed: 0 released: 0", Rectangle.One); new Command(() => fontText.Text = "'A' pressed: " + ++pressed + " released: " + released). Add(new KeyTrigger(Key.A)); new Command(() => fontText.Text = "'A' pressed: " + pressed + " released: " + ++released). Add(new KeyTrigger(Key.A, State.Releasing)); }
[Test, CloseAfterFirstFrame] public void HandleInput() { if (mockKeyboard == null) return; //ncrunch: no coverage Assert.AreEqual("", keyboard.HandleInput("")); mockKeyboard.SetKeyboardState(Key.A, State.Pressing); mockKeyboard.SetKeyboardState(Key.Z, State.Pressing); Assert.AreEqual("az", keyboard.HandleInput("")); mockKeyboard.SetKeyboardState(Key.A, State.Pressing); mockKeyboard.SetKeyboardState(Key.Backspace, State.Pressing); Assert.AreEqual("", keyboard.HandleInput("")); mockKeyboard.SetKeyboardState(Key.Escape, State.Pressing); Assert.AreEqual("", keyboard.HandleInput("")); mockKeyboard.SetKeyboardState(Key.Space, State.Pressing); mockKeyboard.SetKeyboardState(Key.D9, State.Pressing); Assert.AreEqual(" 9", keyboard.HandleInput("")); }
[Test] public void HandleInputVisually() { var text = new FontText(Font.Default, "Type some text", Rectangle.One); text.Start<ContinousInputHandler>(); }
[Test, CloseAfterFirstFrame] public void VerifyNumberKeyPress() { VerifyKeyPressIsHandled("xx1", "xx", Key.D1); }
[Test, CloseAfterFirstFrame] public void VerifyNumpadNumberKeyPress() { VerifyKeyPressIsHandled("xx2", "xx", Key.NumPad2); }
[Test, CloseAfterFirstFrame] public void VerifyLetterKeyPress() { if (mockKeyboard == null) return; //ncrunch: no coverage VerifyKeyPressesAreHandled("12az", "12", new List<Key> { Key.A, Key.Z });
[Test, CloseAfterFirstFrame] public void VerifySpaceKeyPress() { VerifyKeyPressIsHandled("xx ", "xx", Key.Space); }
[Test, CloseAfterFirstFrame] public void VerifyBackspaceKeyPress() { VerifyKeyPressIsHandled("", "", Key.Backspace); VerifyKeyPressIsHandled("1234", "12345", Key.Backspace); }
[Test, CloseAfterFirstFrame] public void VerifyCommaKeyPress() { VerifyKeyPressIsHandled("1234,", "1234", Key.Comma); }
[Test, CloseAfterFirstFrame] public void VerifyDecimalPointKeyPress() { VerifyKeyPressIsHandled("1234.", "1234", Key.Decimal); VerifyKeyPressIsHandled("5678.", "5678", Key.Period); }
[Test, CloseAfterFirstFrame] public void VerifyUnknownKeyPressIsIgnored() { VerifyKeyPressIsHandled("1234", "1234", Key.CapsLock); }
See Also