forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaip1640_driver_test.go
93 lines (77 loc) · 2.34 KB
/
aip1640_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
package gpio
import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
)
var _ gobot.Driver = (*AIP1640Driver)(nil)
// --------- HELPERS
func initTestAIP1640Driver() (driver *AIP1640Driver) {
driver, _ = initTestAIP1640DriverWithStubbedAdaptor()
return
}
func initTestAIP1640DriverWithStubbedAdaptor() (*AIP1640Driver, *gpioTestAdaptor) {
adaptor := newGpioTestAdaptor()
return NewAIP1640Driver(adaptor, "1", "2"), adaptor
}
// --------- TESTS
func TestAIP1640Driver(t *testing.T) {
var a interface{} = initTestAIP1640Driver()
_, ok := a.(*AIP1640Driver)
if !ok {
t.Errorf("NewAIP1640Driver() should have returned a *AIP1640Driver")
}
}
func TestAIP1640DriverStart(t *testing.T) {
d := initTestAIP1640Driver()
gobottest.Assert(t, d.Start(), nil)
}
func TestAIP1640DriverHalt(t *testing.T) {
d := initTestAIP1640Driver()
gobottest.Assert(t, d.Halt(), nil)
}
func TestAIP1640DriverDefaultName(t *testing.T) {
d := initTestAIP1640Driver()
gobottest.Assert(t, strings.HasPrefix(d.Name(), "AIP1640Driver"), true)
}
func TestAIP1640DriverSetName(t *testing.T) {
d := initTestAIP1640Driver()
d.SetName("mybot")
gobottest.Assert(t, d.Name(), "mybot")
}
func TestAIP1640DriveDrawPixel(t *testing.T) {
d := initTestAIP1640Driver()
d.DrawPixel(2, 3, true)
d.DrawPixel(0, 3, true)
gobottest.Assert(t, uint8(5), d.buffer[7-3])
}
func TestAIP1640DriverDrawRow(t *testing.T) {
d := initTestAIP1640Driver()
d.DrawRow(4, 0x3C)
gobottest.Assert(t, uint8(0x3C), d.buffer[7-4])
}
func TestAIP1640DriverDrawMatrix(t *testing.T) {
d := initTestAIP1640Driver()
drawing := [8]byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}
d.DrawMatrix(drawing)
gobottest.Assert(t, [8]byte{0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01}, d.buffer)
}
func TestAIP1640DriverClear(t *testing.T) {
d := initTestAIP1640Driver()
drawing := [8]byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}
d.DrawMatrix(drawing)
gobottest.Assert(t, [8]byte{0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01}, d.buffer)
d.Clear()
gobottest.Assert(t, [8]byte{}, d.buffer)
}
func TestAIP1640DriverSetIntensity(t *testing.T) {
d := initTestAIP1640Driver()
d.SetIntensity(3)
gobottest.Assert(t, uint8(3), d.intensity)
}
func TestAIP1640DriverSetIntensityHigherThan7(t *testing.T) {
d := initTestAIP1640Driver()
d.SetIntensity(19)
gobottest.Assert(t, uint8(7), d.intensity)
}