2014-04-28 07:58:34 +08:00
|
|
|
package opencv
|
2014-04-26 18:11:51 +08:00
|
|
|
|
|
|
|
import (
|
2017-04-06 17:01:57 +08:00
|
|
|
"strings"
|
2014-06-14 04:45:50 +08:00
|
|
|
"testing"
|
2014-07-24 07:38:46 +08:00
|
|
|
"time"
|
|
|
|
|
2016-12-08 20:24:03 +08:00
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/gobottest"
|
2014-04-26 18:11:51 +08:00
|
|
|
)
|
|
|
|
|
2016-08-27 17:56:01 +08:00
|
|
|
var _ gobot.Driver = (*CameraDriver)(nil)
|
|
|
|
|
2014-06-14 07:01:39 +08:00
|
|
|
func initTestCameraDriver() *CameraDriver {
|
2016-10-01 23:53:39 +08:00
|
|
|
d := NewCameraDriver("")
|
2014-11-20 07:59:17 +08:00
|
|
|
d.start = func(c *CameraDriver) (err error) {
|
2014-07-24 07:38:46 +08:00
|
|
|
d.camera = &testCapture{}
|
2014-11-20 07:59:17 +08:00
|
|
|
return nil
|
2014-07-24 07:38:46 +08:00
|
|
|
}
|
|
|
|
return d
|
2014-06-14 04:45:50 +08:00
|
|
|
}
|
2014-04-26 18:11:51 +08:00
|
|
|
|
2014-12-20 03:57:35 +08:00
|
|
|
func TestCameraDriver(t *testing.T) {
|
|
|
|
d := initTestCameraDriver()
|
2016-10-01 23:53:39 +08:00
|
|
|
gobottest.Assert(t, d.Name(), "Camera")
|
2016-02-22 13:21:24 +08:00
|
|
|
gobottest.Assert(t, d.Connection(), (gobot.Connection)(nil))
|
2014-12-20 03:57:35 +08:00
|
|
|
}
|
2016-10-01 23:53:39 +08:00
|
|
|
|
2017-04-06 17:01:57 +08:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2014-06-14 07:01:39 +08:00
|
|
|
func TestCameraDriverStart(t *testing.T) {
|
2014-07-24 07:38:46 +08:00
|
|
|
sem := make(chan bool)
|
2014-06-14 07:01:39 +08:00
|
|
|
d := initTestCameraDriver()
|
2016-11-08 03:06:55 +08:00
|
|
|
gobottest.Assert(t, d.Start(), nil)
|
2016-08-30 23:10:50 +08:00
|
|
|
d.On(d.Event("frame"), func(data interface{}) {
|
2014-07-24 07:38:46 +08:00
|
|
|
sem <- true
|
|
|
|
})
|
|
|
|
select {
|
|
|
|
case <-sem:
|
|
|
|
case <-time.After(100 * time.Millisecond):
|
|
|
|
t.Errorf("Event \"frame\" was not published")
|
|
|
|
}
|
2014-06-14 04:45:50 +08:00
|
|
|
|
2016-10-01 23:53:39 +08:00
|
|
|
d = NewCameraDriver("")
|
2016-11-08 03:06:55 +08:00
|
|
|
gobottest.Assert(t, d.Start(), nil)
|
2014-07-17 05:37:58 +08:00
|
|
|
|
2016-10-01 23:53:39 +08:00
|
|
|
d = NewCameraDriver(true)
|
2016-11-08 03:06:55 +08:00
|
|
|
gobottest.Refute(t, d.Start(), nil)
|
2014-07-17 05:37:58 +08:00
|
|
|
}
|
|
|
|
|
2014-06-14 07:01:39 +08:00
|
|
|
func TestCameraDriverHalt(t *testing.T) {
|
|
|
|
d := initTestCameraDriver()
|
2016-11-08 03:06:55 +08:00
|
|
|
gobottest.Assert(t, d.Halt(), nil)
|
2014-06-14 04:45:50 +08:00
|
|
|
}
|