52 lines
1.0 KiB
Go
52 lines
1.0 KiB
Go
package opencv
|
|
|
|
import (
|
|
"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 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)
|
|
}
|