-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathevent_test.go
More file actions
107 lines (85 loc) · 3.76 KB
/
event_test.go
File metadata and controls
107 lines (85 loc) · 3.76 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
package streamdeck
import (
"testing"
"go.viam.com/test"
)
func TestState(t *testing.T) {
s := State{}
// button 0
myEvent, err := s.Update(nil, []byte{1, 0, 8, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})
test.That(t, err, test.ShouldBeNil)
test.That(t, s.Keys[0], test.ShouldBeTrue)
test.That(t, s.Keys[1], test.ShouldBeFalse)
myEvent, err = s.Update(nil, []byte{1, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})
test.That(t, err, test.ShouldBeNil)
test.That(t, s.Keys[0], test.ShouldBeFalse)
test.That(t, s.Keys[1], test.ShouldBeFalse)
test.That(t, myEvent[0].String(), test.ShouldEqual, "key-released:0")
myEvent, err = s.Update(nil, []byte{1, 0, 8, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})
test.That(t, err, test.ShouldBeNil)
test.That(t, s.Keys[0], test.ShouldBeFalse)
test.That(t, s.Keys[1], test.ShouldBeTrue)
test.That(t, myEvent[0].String(), test.ShouldEqual, "key-pressed:1")
// dial turns
myEvent, err = s.Update(nil, []byte{1, 3, 5, 0, 1, 2})
test.That(t, err, test.ShouldBeNil)
test.That(t, s.DialPos[0], test.ShouldEqual, 52)
test.That(t, myEvent[0].String(), test.ShouldEqual, "dial-turn:0")
myEvent, err = s.Update(nil, []byte{1, 3, 5, 0, 1, 1})
test.That(t, err, test.ShouldBeNil)
test.That(t, s.DialPos[0], test.ShouldEqual, 53)
myEvent, err = s.Update(nil, []byte{1, 3, 5, 0, 1, 50})
test.That(t, err, test.ShouldBeNil)
test.That(t, s.DialPos[0], test.ShouldEqual, 100)
myEvent, err = s.Update(nil, []byte{1, 3, 5, 0, 1, 255})
test.That(t, err, test.ShouldBeNil)
test.That(t, s.DialPos[0], test.ShouldEqual, 99)
myEvent, err = s.Update(nil, []byte{1, 3, 5, 0, 1, 254})
test.That(t, err, test.ShouldBeNil)
test.That(t, s.DialPos[0], test.ShouldEqual, 97)
test.That(t, myEvent[0].String(), test.ShouldEqual, "dial-turn:0")
s.DialPos[0] = 0
myEvent, err = s.Update(nil, []byte{1, 3, 5, 0, 1, 255})
test.That(t, err, test.ShouldBeNil)
test.That(t, s.DialPos[0], test.ShouldEqual, 0)
test.That(t, myEvent[0].String(), test.ShouldEqual, "dial-turn:0")
// dial pushes
myEvent, err = s.Update(nil, []byte{1, 3, 5, 0, 0, 1})
test.That(t, err, test.ShouldBeNil)
test.That(t, s.DialPush[0], test.ShouldBeTrue)
test.That(t, myEvent[0].String(), test.ShouldEqual, "dial-pressed:0")
myEvent, err = s.Update(nil, []byte{1, 3, 5, 0, 0, 0})
test.That(t, err, test.ShouldBeNil)
test.That(t, s.DialPush[0], test.ShouldBeFalse)
test.That(t, myEvent[0].String(), test.ShouldEqual, "dial-released:0")
}
func TestEventString(t *testing.T) {
test.That(t, Event{EventDialPressed, 5}.String(), test.ShouldEqual, "dial-pressed:5")
}
func TestStateOriginal(t *testing.T) {
s := State{}
// button 0
myEvent, err := s.Update(&Original, []byte{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})
t.Logf("myEvent 1: %v", myEvent)
test.That(t, err, test.ShouldBeNil)
test.That(t, s.Keys[0], test.ShouldBeFalse)
test.That(t, s.Keys[1], test.ShouldBeFalse)
test.That(t, s.Keys[4], test.ShouldBeTrue)
test.That(t, myEvent[0].String(), test.ShouldEqual, "key-pressed:4")
myEvent, err = s.Update(&Original, []byte{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})
t.Logf("myEvent 2: %v", myEvent)
test.That(t, err, test.ShouldBeNil)
test.That(t, s.Keys[0], test.ShouldBeFalse)
test.That(t, s.Keys[1], test.ShouldBeFalse)
test.That(t, myEvent[0].String(), test.ShouldEqual, "key-released:4")
// button 10
myEvent, err = s.Update(&Original, []byte{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1})
t.Logf("myEvent 2: %v", myEvent)
test.That(t, err, test.ShouldBeNil)
test.That(t, myEvent[0].String(), test.ShouldEqual, "key-pressed:10")
// button 14
myEvent, err = s.Update(&Original, []byte{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0})
t.Logf("myEvent 3: %v", myEvent)
test.That(t, err, test.ShouldBeNil)
test.That(t, myEvent[0].String(), test.ShouldEqual, "key-pressed:14")
}