Skip to content

Commit

Permalink
Add touch pad test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
bendahl committed May 2, 2018
1 parent dd4a9c5 commit c6a3b0c
Showing 1 changed file with 132 additions and 1 deletion.
133 changes: 132 additions & 1 deletion touchpad_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package uinput

import "testing"
import (
"fmt"
"testing"
)

func TestBasicTouchPadMoves(t *testing.T) {
absDev, err := CreateTouchPad("/dev/uinput", []byte("Test TouchPad"), 0, 1024, 0, 768)
Expand Down Expand Up @@ -52,3 +55,131 @@ func TestBasicTouchPadMoves(t *testing.T) {
t.Fatalf("Failed to close device. Last error was: %s\n", err)
}
}

func TestTouchPadCreationFailsOnEmptyPath(t *testing.T) {
expected := "device path must not be empty"
defer func() {
if r := recover(); r != nil {
actual := r.(string)
if actual != expected {
t.Fatalf("Expected: %s\nActual: %s", expected, actual)
}
}
}()
CreateTouchPad("", []byte("TouchDevice"), 0, 1024, 0, 768)
t.Fatalf("Empty path did not yield a panic")
}

func TestTouchPadCreationFailsOnNonExistentPathName(t *testing.T) {
path := "/some/bogus/path"
expected := "device path '" + path + "' does not exist"
defer func() {
if r := recover(); r != nil {
actual := r.(string)
if actual != expected {
t.Fatalf("Expected: %s\nActual: %s", expected, actual)
}
}
}()
CreateTouchPad(path, []byte("TouchDevice"), 0, 1024, 0, 768)
t.Fatalf("Invalid path did not yield a panic")
}

func TestTouchPadCreationFailsIfNameIsTooLong(t *testing.T) {
name := "adsfdsferqewoirueworiuejdsfjdfa;ljoewrjeworiewuoruew;rj;kdlfjoeai;jfewoaifjef;das"
expected := fmt.Sprintf("device name %s is too long (maximum of %d characters allowed)", name, uinputMaxNameSize)
defer func() {
if r := recover(); r != nil {
actual := r.(string)
if actual != expected {
t.Fatalf("Expected: %s\nActual: %s", expected, actual)
}
}
}()
CreateTouchPad("/dev/uinput", []byte(name), 0, 1024, 0, 768)
t.Fatalf("Invalid name did not yield a panic")
}

func TestTouchPadMoveToFailsOnClosedDevice(t *testing.T) {
absDev, err := CreateTouchPad("/dev/uinput", []byte("Test TouchPad"), 0, 1024, 0, 768)
if err != nil {
t.Fatalf("Failed to create the virtual touch pad. Last error was: %s\n", err)
}
absDev.Close()
err = absDev.MoveTo(1, 1)
if err == nil {
t.Fatalf("Expected error due to closed device, but no error was returned.")
}
}

func TestTouchPadLeftClickFailsOnClosedDevice(t *testing.T) {
absDev, err := CreateTouchPad("/dev/uinput", []byte("Test TouchPad"), 0, 1024, 0, 768)
if err != nil {
t.Fatalf("Failed to create the virtual touch pad. Last error was: %s\n", err)
}
absDev.Close()
err = absDev.LeftClick()
if err == nil {
t.Fatalf("Expected error due to closed device, but no error was returned.")
}
}

func TestTouchPadLeftPressFailsOnClosedDevice(t *testing.T) {
absDev, err := CreateTouchPad("/dev/uinput", []byte("Test TouchPad"), 0, 1024, 0, 768)
if err != nil {
t.Fatalf("Failed to create the virtual touch pad. Last error was: %s\n", err)
}
absDev.Close()
err = absDev.LeftPress()
if err == nil {
t.Fatalf("Expected error due to closed device, but no error was returned.")
}
}

func TestTouchPadLeftReleaseFailsOnClosedDevice(t *testing.T) {
absDev, err := CreateTouchPad("/dev/uinput", []byte("Test TouchPad"), 0, 1024, 0, 768)
if err != nil {
t.Fatalf("Failed to create the virtual touch pad. Last error was: %s\n", err)
}
absDev.Close()
err = absDev.LeftRelease()
if err == nil {
t.Fatalf("Expected error due to closed device, but no error was returned.")
}
}

func TestTouchPadRightClickFailsOnClosedDevice(t *testing.T) {
absDev, err := CreateTouchPad("/dev/uinput", []byte("Test TouchPad"), 0, 1024, 0, 768)
if err != nil {
t.Fatalf("Failed to create the virtual touch pad. Last error was: %s\n", err)
}
absDev.Close()
err = absDev.RightClick()
if err == nil {
t.Fatalf("Expected error due to closed device, but no error was returned.")
}
}

func TestTouchPadRightPressFailsOnClosedDevice(t *testing.T) {
absDev, err := CreateTouchPad("/dev/uinput", []byte("Test TouchPad"), 0, 1024, 0, 768)
if err != nil {
t.Fatalf("Failed to create the virtual touch pad. Last error was: %s\n", err)
}
absDev.Close()
err = absDev.RightPress()
if err == nil {
t.Fatalf("Expected error due to closed device, but no error was returned.")
}
}

func TestTouchPadRightReleaseFailsOnClosedDevice(t *testing.T) {
absDev, err := CreateTouchPad("/dev/uinput", []byte("Test TouchPad"), 0, 1024, 0, 768)
if err != nil {
t.Fatalf("Failed to create the virtual touch pad. Last error was: %s\n", err)
}
absDev.Close()
err = absDev.RightRelease()
if err == nil {
t.Fatalf("Expected error due to closed device, but no error was returned.")
}
}

0 comments on commit c6a3b0c

Please sign in to comment.