1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-24 13:48:49 +08:00
hybridgroup.gobot/platforms/opencv/camera_driver_test.go

65 lines
1.3 KiB
Go
Raw Normal View History

//go:build gocv
// +build gocv
2014-04-27 16:58:34 -07:00
package opencv
import (
"strings"
2014-06-13 13:45:50 -07:00
"testing"
2014-07-23 16:38:46 -07:00
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gobot.io/x/gobot/v2"
)
var _ gobot.Driver = (*CameraDriver)(nil)
2014-06-13 16:01:39 -07:00
func initTestCameraDriver() *CameraDriver {
d := NewCameraDriver("")
d.start = func(c *CameraDriver) 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-12-19 11:57:35 -08:00
func TestCameraDriver(t *testing.T) {
d := initTestCameraDriver()
assert.Equal(t, "Camera", d.Name())
assert.Equal(t, (gobot.Connection)(nil), d.Connection())
2014-12-19 11:57:35 -08:00
}
func TestCameraDriverName(t *testing.T) {
d := initTestCameraDriver()
assert.True(t, strings.HasPrefix(d.Name(), "Camera"))
d.SetName("NewName")
assert.Equal(t, "NewName", d.Name())
}
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()
require.NoError(t, d.Start())
d.On(d.Event("frame"), func(data interface{}) {
2014-07-23 16:38:46 -07:00
sem <- true
})
select {
case <-sem:
case <-time.After(100 * time.Millisecond):
require.Fail(t, "Event \"frame\" was not published")
2014-07-23 16:38:46 -07:00
}
2014-06-13 13:45:50 -07:00
d = NewCameraDriver("")
require.NoError(t, d.Start())
2014-07-16 16:37:58 -05:00
d = NewCameraDriver(true)
assert.NotNil(t, d.Start())
2014-07-16 16:37:58 -05:00
}
2014-06-13 16:01:39 -07:00
func TestCameraDriverHalt(t *testing.T) {
d := initTestCameraDriver()
require.NoError(t, d.Halt())
2014-06-13 13:45:50 -07:00
}