2014-04-28 11:23:12 -07:00
|
|
|
package ardrone
|
2014-04-26 03:11:51 -07:00
|
|
|
|
|
|
|
import (
|
2014-12-18 13:33:33 -08:00
|
|
|
"errors"
|
2017-04-06 11:05:23 +02:00
|
|
|
"strings"
|
2014-06-12 16:07:40 -07:00
|
|
|
"testing"
|
2014-11-22 18:56:23 -08:00
|
|
|
|
2016-12-08 13:24:03 +01:00
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/gobottest"
|
2014-04-26 03:11:51 -07:00
|
|
|
)
|
|
|
|
|
2016-09-25 11:46:55 +02:00
|
|
|
var _ gobot.Adaptor = (*Adaptor)(nil)
|
2016-07-13 11:01:36 -06:00
|
|
|
|
2016-09-25 11:46:55 +02:00
|
|
|
func initTestArdroneAdaptor() *Adaptor {
|
|
|
|
a := NewAdaptor()
|
|
|
|
a.connect = func(a *Adaptor) (drone, error) {
|
2014-12-18 13:33:33 -08:00
|
|
|
return &testDrone{}, nil
|
2014-06-12 16:07:40 -07:00
|
|
|
}
|
2014-06-14 13:55:12 -07:00
|
|
|
return a
|
2014-06-12 16:07:40 -07:00
|
|
|
}
|
2014-04-26 03:11:51 -07:00
|
|
|
|
2014-12-18 13:33:33 -08:00
|
|
|
func TestArdroneAdaptor(t *testing.T) {
|
2016-09-25 11:46:55 +02:00
|
|
|
a := NewAdaptor()
|
2016-02-22 00:21:24 -05:00
|
|
|
gobottest.Assert(t, a.config.Ip, "192.168.1.1")
|
2014-12-18 13:33:33 -08:00
|
|
|
|
2016-09-25 11:46:55 +02:00
|
|
|
a = NewAdaptor("192.168.100.100")
|
2016-02-22 00:21:24 -05:00
|
|
|
gobottest.Assert(t, a.config.Ip, "192.168.100.100")
|
2014-12-18 13:33:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestArdroneAdaptorConnect(t *testing.T) {
|
2014-06-14 13:55:12 -07:00
|
|
|
a := initTestArdroneAdaptor()
|
2016-11-07 17:25:55 +01:00
|
|
|
gobottest.Assert(t, a.Connect(), nil)
|
2014-12-18 13:33:33 -08:00
|
|
|
|
2016-09-25 11:46:55 +02:00
|
|
|
a.connect = func(a *Adaptor) (drone, error) {
|
2014-12-18 13:33:33 -08:00
|
|
|
return nil, errors.New("connection error")
|
|
|
|
}
|
2016-11-07 17:25:55 +01:00
|
|
|
gobottest.Assert(t, a.Connect(), errors.New("connection error"))
|
2014-06-12 16:07:40 -07:00
|
|
|
}
|
|
|
|
|
2017-04-06 11:05:23 +02:00
|
|
|
func TestArdroneAdaptorName(t *testing.T) {
|
|
|
|
a := initTestArdroneAdaptor()
|
|
|
|
gobottest.Assert(t, strings.HasPrefix(a.Name(), "ARDrone"), true)
|
|
|
|
a.SetName("NewName")
|
|
|
|
gobottest.Assert(t, a.Name(), "NewName")
|
|
|
|
}
|
|
|
|
|
2014-12-18 13:33:33 -08:00
|
|
|
func TestArdroneAdaptorFinalize(t *testing.T) {
|
2014-06-14 13:55:12 -07:00
|
|
|
a := initTestArdroneAdaptor()
|
2016-11-07 17:25:55 +01:00
|
|
|
gobottest.Assert(t, a.Finalize(), nil)
|
2014-06-12 16:07:40 -07:00
|
|
|
}
|