KeyboardTests ClassDelta Engine Documentation
Inheritance Hierarchy

System Object
  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

public class KeyboardTests : TestWithMocksOrVisually

The KeyboardTests type exposes the following members.

Constructors

  NameDescription
Public methodKeyboardTests
Initializes a new instance of the KeyboardTests class
Top
Methods

  NameDescription
Protected methodAdvanceTimeAndUpdateEntities (Inherited from TestWithMocksOrVisually.)
Public methodCountKeyPressingAndReleasing
Public methodDispose
Public methodHandleInput
Public methodHandleInputVisually
Public methodInitializeResolver (Inherited from TestWithMocksOrVisually.)
Public methodPressKeyToShowCircle
Protected methodRegisterMock T  (Inherited from TestWithMocksOrVisually.)
Protected methodResolve T  (Inherited from TestWithMocksOrVisually.)
Protected methodRunAfterFirstFrame (Inherited from TestWithMocksOrVisually.)
Public methodRunTestAndDisposeResolverWhenDone (Inherited from TestWithMocksOrVisually.)
Public methodSetUp
Public methodTestSpaceKeyPress
Public methodVerifyBackspaceKeyPress
Public methodVerifyCommaKeyPress
Public methodVerifyDecimalPointKeyPress
Public methodVerifyLetterKeyPress
Public methodVerifyNumberKeyPress
Public methodVerifyNumpadNumberKeyPress
Public methodVerifySpaceKeyPress
Public methodVerifyUnknownKeyPressIsIgnored
Top
Properties

  NameDescription
Protected propertyIsMockResolver (Inherited from TestWithMocksOrVisually.)
Top
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