From 7004d3dd6f7c3b40b79374d693b50146951a8bf4 Mon Sep 17 00:00:00 2001 From: Benjamin Dahlmanns Date: Tue, 1 May 2018 20:41:20 +0200 Subject: [PATCH] Test out of range errors for all keyboard functions --- keyboard_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/keyboard_test.go b/keyboard_test.go index d939b4d..34e08bc 100644 --- a/keyboard_test.go +++ b/keyboard_test.go @@ -67,6 +67,43 @@ func TestKeyOutsideOfRangeKeyPressFails(t *testing.T) { t.Fatalf("Expected key press to fail due to invalid key code, but got no error.") } +} +func TestKeyOutsideOfRangeKeyUpFails(t *testing.T) { + vk, err := CreateKeyboard("/dev/uinput", []byte("Test Basic Keyboard")) + if err != nil { + t.Fatalf("Failed to create the virtual keyboard. Last error was: %s\n", err) + } + defer vk.Close() + + err = vk.KeyUp(249) + if err == nil { + t.Fatalf("Expected key press to fail due to invalid key code, but got no error.") + } + + err = vk.KeyUp(-1) + if err == nil { + t.Fatalf("Expected key press to fail due to invalid key code, but got no error.") + } + +} + +func TestKeyOutsideOfRangeKeyDownFails(t *testing.T) { + vk, err := CreateKeyboard("/dev/uinput", []byte("Test Basic Keyboard")) + if err != nil { + t.Fatalf("Failed to create the virtual keyboard. Last error was: %s\n", err) + } + defer vk.Close() + + err = vk.KeyDown(249) + if err == nil { + t.Fatalf("Expected key press to fail due to invalid key code, but got no error.") + } + + err = vk.KeyDown(-1) + if err == nil { + t.Fatalf("Expected key press to fail due to invalid key code, but got no error.") + } + } func TestKeyPressFailsIfDeviceIsClosed(t *testing.T) {