-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathusb_driver_test.go
More file actions
113 lines (108 loc) · 1.91 KB
/
usb_driver_test.go
File metadata and controls
113 lines (108 loc) · 1.91 KB
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
package bootcommand
import (
"context"
"testing"
"time"
"golang.org/x/mobile/event/key"
)
func TestUSBDriver(t *testing.T) {
tc := []struct {
command string
code key.Code
shift bool
}{
{
"<leftShift>",
key.CodeLeftShift,
false,
},
{
"<pageUp>",
key.CodePageUp,
false,
},
{
"<pageDown>",
key.CodePageDown,
false,
},
{
"<leftShiftOff>",
key.CodeLeftShift,
false,
},
{
"<leftShiftOn>",
key.CodeLeftShift,
true,
},
{
"<leftsuper>",
key.CodeLeftGUI,
false,
},
{
"<spacebar>",
key.CodeSpacebar,
false,
},
{
"<return>",
key.CodeReturnEnter,
false,
},
{
"a",
key.CodeA,
false,
},
{
"A",
key.CodeA,
true,
},
{
"_",
key.CodeHyphenMinus,
true,
},
}
for _, tt := range tc {
t.Run(tt.command, func(t *testing.T) {
var code key.Code
var shift bool
sendCodes := func(c key.Code, d bool) error {
code = c
shift = d
return nil
}
d := NewUSBDriver(sendCodes, time.Duration(0))
seq, err := GenerateExpressionSequence(tt.command)
if err != nil {
t.Fatalf("bad: not expected error: %s", err.Error())
}
err = seq.Do(context.Background(), d)
if err != nil {
t.Fatalf("bad: not expected error: %s", err.Error())
}
if code != tt.code {
t.Fatalf("bad: wrong scan code: \n expected: %s \n actual: %s", tt.code, code)
}
if shift != tt.shift {
t.Fatalf("bad: wrong shift: \n expected: %t \n actual: %t", tt.shift, shift)
}
})
}
}
func TestUSBDriver_KeyIntervalNotGiven(t *testing.T) {
d := NewUSBDriver(nil, time.Duration(0))
if d.interval != time.Duration(100)*time.Millisecond {
t.Fatal("not expected key interval")
}
}
func TestUSBDriver_KeyIntervalGiven(t *testing.T) {
d := NewUSBDriver(nil, time.Duration(5000)*time.Millisecond)
if d.interval != time.Duration(5000)*time.Millisecond {
t.Fatal("not expected key interval")
}
}