2014-04-27 16:58:34 -07:00
|
|
|
package opencv
|
2014-04-26 03:11:51 -07:00
|
|
|
|
|
|
|
import (
|
2014-06-13 13:45:50 -07:00
|
|
|
"testing"
|
2014-07-23 16:38:46 -07:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/hybridgroup/gobot"
|
2016-02-22 00:21:24 -05:00
|
|
|
"github.com/hybridgroup/gobot/gobottest"
|
2014-04-26 03:11:51 -07:00
|
|
|
)
|
|
|
|
|
2016-08-27 11:56:01 +02:00
|
|
|
var _ gobot.Driver = (*CameraDriver)(nil)
|
|
|
|
|
2014-06-13 16:01:39 -07:00
|
|
|
func initTestCameraDriver() *CameraDriver {
|
2014-07-23 16:38:46 -07:00
|
|
|
d := NewCameraDriver("bot", "")
|
2014-11-19 15:59:17 -08:00
|
|
|
d.start = func(c *CameraDriver) (err error) {
|
2014-07-23 16:38:46 -07:00
|
|
|
d.camera = &testCapture{}
|
2014-11-19 15:59:17 -08:00
|
|
|
return nil
|
2014-07-23 16:38:46 -07:00
|
|
|
}
|
|
|
|
return d
|
2014-06-13 13:45:50 -07:00
|
|
|
}
|
2014-04-26 03:11:51 -07:00
|
|
|
|
2014-12-19 11:57:35 -08:00
|
|
|
func TestCameraDriver(t *testing.T) {
|
|
|
|
d := initTestCameraDriver()
|
2016-02-22 00:21:24 -05:00
|
|
|
gobottest.Assert(t, d.Name(), "bot")
|
|
|
|
gobottest.Assert(t, d.Connection(), (gobot.Connection)(nil))
|
2014-12-19 11:57:35 -08:00
|
|
|
}
|
2014-06-13 16:01:39 -07:00
|
|
|
func TestCameraDriverStart(t *testing.T) {
|
2014-07-23 16:38:46 -07:00
|
|
|
sem := make(chan bool)
|
2014-06-13 16:01:39 -07:00
|
|
|
d := initTestCameraDriver()
|
2016-02-22 00:21:24 -05:00
|
|
|
gobottest.Assert(t, len(d.Start()), 0)
|
2014-07-23 16:38:46 -07:00
|
|
|
gobot.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")
|
|
|
|
}
|
2014-06-13 13:45:50 -07:00
|
|
|
|
2014-12-19 11:57:35 -08:00
|
|
|
d = NewCameraDriver("bot", "")
|
2016-02-22 00:21:24 -05:00
|
|
|
gobottest.Assert(t, len(d.Start()), 0)
|
2014-07-16 16:37:58 -05:00
|
|
|
|
2014-07-23 16:38:46 -07:00
|
|
|
d = NewCameraDriver("bot", true)
|
2016-02-22 00:21:24 -05:00
|
|
|
gobottest.Refute(t, len(d.Start()), 0)
|
2014-12-19 11:57:35 -08:00
|
|
|
|
2014-07-16 16:37:58 -05:00
|
|
|
}
|
|
|
|
|
2014-06-13 16:01:39 -07:00
|
|
|
func TestCameraDriverHalt(t *testing.T) {
|
|
|
|
d := initTestCameraDriver()
|
2016-02-22 00:21:24 -05:00
|
|
|
gobottest.Assert(t, len(d.Halt()), 0)
|
2014-06-13 13:45:50 -07:00
|
|
|
}
|