Mock out window creation in test

This commit is contained in:
Adrian Zankich 2014-07-23 16:54:39 -07:00
parent c081f46609
commit 201b54d56e
3 changed files with 19 additions and 3 deletions

View File

@ -16,3 +16,11 @@ func (c *testCapture) RetrieveFrame(i int) *cv.IplImage {
func (c *testCapture) GrabFrame() bool {
return true
}
type window interface {
ShowImage(*cv.IplImage)
}
type testWindow struct{}
func (w *testWindow) ShowImage(i *cv.IplImage) { return }

View File

@ -7,7 +7,8 @@ import (
type WindowDriver struct {
gobot.Driver
window *cv.Window
window window
start func(*WindowDriver)
}
func NewWindowDriver(name string) *WindowDriver {
@ -16,12 +17,15 @@ func NewWindowDriver(name string) *WindowDriver {
name,
"WindowDriver",
),
start: func(w *WindowDriver) {
w.window = cv.NewWindow(w.Name(), cv.CV_WINDOW_NORMAL)
},
}
}
func (w *WindowDriver) Start() bool {
cv.StartWindowThread()
w.window = cv.NewWindow(w.Name(), cv.CV_WINDOW_NORMAL)
w.start(w)
return true
}

View File

@ -10,7 +10,11 @@ import (
)
func initTestWindowDriver() *WindowDriver {
return NewWindowDriver("bot")
d := NewWindowDriver("bot")
d.start = func(w *WindowDriver) {
w.window = &testWindow{}
}
return d
}
func TestWindowDriverStart(t *testing.T) {