2014-04-27 18:02:39 -07:00
|
|
|
package joystick
|
2014-04-26 03:11:51 -07:00
|
|
|
|
|
|
|
import (
|
2014-11-19 18:54:31 -08:00
|
|
|
"errors"
|
2014-06-13 12:54:21 -07:00
|
|
|
"testing"
|
2014-07-22 13:55:19 -07:00
|
|
|
|
2016-08-26 14:23:03 +02:00
|
|
|
"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-09-25 21:07:36 +02:00
|
|
|
var _ gobot.Adaptor = (*Adaptor)(nil)
|
2016-08-26 14:23:03 +02:00
|
|
|
|
2016-09-25 21:07:36 +02:00
|
|
|
func initTestAdaptor() *Adaptor {
|
|
|
|
a := NewAdaptor()
|
|
|
|
a.connect = func(j *Adaptor) (err error) {
|
2014-07-22 13:55:19 -07:00
|
|
|
j.joystick = &testJoystick{}
|
2014-11-19 15:45:59 -08:00
|
|
|
return nil
|
2014-07-22 13:55:19 -07:00
|
|
|
}
|
|
|
|
return a
|
2014-06-13 12:54:21 -07:00
|
|
|
}
|
2014-04-26 03:11:51 -07:00
|
|
|
|
2016-09-25 21:07:36 +02:00
|
|
|
func TestAdaptorConnect(t *testing.T) {
|
|
|
|
a := initTestAdaptor()
|
2016-11-07 19:32:12 +01:00
|
|
|
gobottest.Assert(t, a.Connect(), nil)
|
2014-11-19 18:54:31 -08:00
|
|
|
|
2016-09-25 21:07:36 +02:00
|
|
|
a = NewAdaptor()
|
2016-11-07 19:32:12 +01:00
|
|
|
gobottest.Assert(t, a.Connect(), errors.New("No joystick available"))
|
2014-06-13 12:54:21 -07:00
|
|
|
}
|
2014-06-13 16:01:39 -07:00
|
|
|
|
2016-09-25 21:07:36 +02:00
|
|
|
func TestAdaptorFinalize(t *testing.T) {
|
|
|
|
a := initTestAdaptor()
|
2014-07-22 13:55:19 -07:00
|
|
|
a.Connect()
|
2016-11-07 19:32:12 +01:00
|
|
|
gobottest.Assert(t, a.Finalize(), nil)
|
2014-06-13 12:54:21 -07:00
|
|
|
}
|