-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdualshock_test.go
44 lines (34 loc) · 886 Bytes
/
dualshock_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
package dualshock
import (
"testing"
)
type fakeDevice struct{}
func (f fakeDevice) Read(b []byte) (int, error) {
copy(b, []byte{
1, 134, 127, 128, 126, 8, 4, 88, 255, 0, 141, 219, 9, 188, 255, 4, 0,
167, 255, 250, 6, 212, 31, 51, 254, 0, 0, 0, 0, 0, 27, 0, 0, 1, 252,
129, 115, 70, 27, 130, 62, 97, 32, 0, 128, 0, 0, 0, 128, 0, 0, 0, 0,
128, 0, 0, 0, 128, 0, 0, 0, 0, 128, 0,
})
return 64, nil
}
func TestDualshock(t *testing.T) {
controller := New(fakeDevice{})
result := make(chan State, 1)
go controller.Listen(func(state State) {
result <- state
})
if r := <-result; !r.L2 {
t.Errorf("Invalid state L2 should be true; got %v", r.L2)
}
}
func BenchmarkDualshock(b *testing.B) {
controller := New(fakeDevice{})
result := make(chan State, 1)
go controller.Listen(func(state State) {
result <- state
})
for n := 0; n < b.N; n++ {
<-result
}
}