-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdriver_test.go
136 lines (107 loc) · 2.38 KB
/
driver_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
package luxafor
import (
"testing"
"time"
)
func finishTest(lux Luxafor) {
time.Sleep(250 * time.Millisecond)
lux.Off()
}
func TestEnumerate(t *testing.T) {
luxs := Enumerate()
t.Logf("Number of attached devices: %v", len(luxs))
}
func testSolid(t *testing.T, r, g, b uint8, color string) {
luxs := Enumerate()
if len(luxs) == 0 {
t.Log("No attached devices. Aborting test.")
}
// TODO: 0 always fails. Need to investigate why.
lux := luxs[1]
defer finishTest(lux)
if err := lux.Solid(r, g, b); err != nil {
t.Errorf("Failed to turn solid %s.", color)
}
}
func TestWhite(t *testing.T) {
testSolid(t, 255, 255, 255, "white")
}
func TestRed(t *testing.T) {
testSolid(t, 255, 0, 0, "red")
}
func TestGreen(t *testing.T) {
testSolid(t, 0, 255, 0, "green")
}
func TestBlue(t *testing.T) {
testSolid(t, 0, 0, 255, "blue")
}
func TestCyan(t *testing.T) {
testSolid(t, 0, 255, 255, "cyan")
}
func TestMagenta(t *testing.T) {
testSolid(t, 255, 0, 255, "magenta")
}
func TestYellow(t *testing.T) {
testSolid(t, 255, 255, 0, "yellow")
}
func TestOff(t *testing.T) {
luxs := Enumerate()
if len(luxs) == 0 {
t.Log("No attached devices. Aborting test.")
return
}
lux := luxs[1]
defer finishTest(lux)
lux.Solid(255, 255, 255)
}
func TestSet(t *testing.T) {
luxs := Enumerate()
if len(luxs) == 0 {
t.Log("No attached devices. Aborting test.")
return
}
lux := luxs[1]
defer finishTest(lux)
lux.Set(FrontAll, 255, 0, 0)
time.Sleep(250 * time.Millisecond)
lux.Set(BackAll, 0, 255, 0)
}
func TestSetLEDs(t *testing.T) {
luxs := Enumerate()
if len(luxs) == 0 {
t.Log("No attached devices. Aborting test.")
return
}
lux := luxs[1]
defer finishTest(lux)
if err := lux.Sets([]LED{FrontAll, BackMiddle, BackTop}, 255, 0, 0); err != nil {
t.Error(err.Error())
}
time.Sleep(250 * time.Millisecond)
if err := lux.Sets([]LED{FrontMiddle, FrontBottom}, 123, 53, 98); err != nil {
t.Error(err.Error())
}
}
func TestFade(t *testing.T) {
luxs := Enumerate()
if len(luxs) == 0 {
t.Log("No attached devices. Aborting test.")
return
}
lux := luxs[1]
defer finishTest(lux)
if err := lux.Fade(FrontAll, 0, 0, 255, 255); err != nil {
t.Error(err.Error())
t.Log("asdf")
}
}
func TestPolice(t *testing.T) {
luxs := Enumerate()
if len(luxs) == 0 {
t.Log("No attached devices. Aborting test.")
return
}
lux := luxs[1]
defer finishTest(lux)
lux.Police(100)
}