forked from bendahl/uinput
-
Notifications
You must be signed in to change notification settings - Fork 0
/
touchpad_test.go
185 lines (165 loc) · 5.4 KB
/
touchpad_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package uinput
import (
"fmt"
"testing"
)
func TestBasicTouchPadMoves(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)
}
err = absDev.MoveTo(0, 0)
if err != nil {
t.Fatalf("Failed to move cursor to initial position. Last error was: %s\n", err)
}
err = absDev.MoveTo(100, 200)
if err != nil {
t.Fatalf("Failed to move cursor to position x:100, y:200. Last error was: %s\n", err)
}
err = absDev.RightClick()
if err != nil {
t.Fatalf("Failed to perform right click. Last error was: %s\n", err)
}
err = absDev.LeftClick()
if err != nil {
t.Fatalf("Failed to perform right click. Last error was: %s\n", err)
}
err = absDev.LeftPress()
if err != nil {
t.Fatalf("Failed to perform left key press. Last error was: %s\n", err)
}
err = absDev.LeftRelease()
if err != nil {
t.Fatalf("Failed to perform left key release. Last error was: %s\n", err)
}
err = absDev.RightPress()
if err != nil {
t.Fatalf("Failed to perform right key press. Last error was: %s\n", err)
}
err = absDev.RightRelease()
if err != nil {
t.Fatalf("Failed to perform right key release. Last error was: %s\n", err)
}
err = absDev.Close()
if err != nil {
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.")
}
}