forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera_driver_test.go
59 lines (49 loc) · 1.23 KB
/
camera_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
package opencv
import (
"strings"
"testing"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
)
var _ gobot.Driver = (*CameraDriver)(nil)
func initTestCameraDriver() *CameraDriver {
d := NewCameraDriver("")
d.start = func(c *CameraDriver) (err error) {
d.camera = &testCapture{}
return nil
}
return d
}
func TestCameraDriver(t *testing.T) {
d := initTestCameraDriver()
gobottest.Assert(t, d.Name(), "Camera")
gobottest.Assert(t, d.Connection(), (gobot.Connection)(nil))
}
func TestCameraDriverName(t *testing.T) {
d := initTestCameraDriver()
gobottest.Assert(t, strings.HasPrefix(d.Name(), "Camera"), true)
d.SetName("NewName")
gobottest.Assert(t, d.Name(), "NewName")
}
func TestCameraDriverStart(t *testing.T) {
sem := make(chan bool)
d := initTestCameraDriver()
gobottest.Assert(t, d.Start(), nil)
d.On(d.Event("frame"), func(data interface{}) {
sem <- true
})
select {
case <-sem:
case <-time.After(100 * time.Millisecond):
t.Errorf("Event \"frame\" was not published")
}
d = NewCameraDriver("")
gobottest.Assert(t, d.Start(), nil)
d = NewCameraDriver(true)
gobottest.Refute(t, d.Start(), nil)
}
func TestCameraDriverHalt(t *testing.T) {
d := initTestCameraDriver()
gobottest.Assert(t, d.Halt(), nil)
}