hybridgroup.gobot/platforms/ardrone/ardrone_adaptor_test.go

43 lines
926 B
Go
Raw Normal View History

2014-04-29 02:23:12 +08:00
package ardrone
import (
2014-12-19 05:33:33 +08:00
"errors"
2014-06-13 07:07:40 +08:00
"testing"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/gobottest"
)
var _ gobot.Adaptor = (*Adaptor)(nil)
func initTestArdroneAdaptor() *Adaptor {
a := NewAdaptor()
a.connect = func(a *Adaptor) (drone, error) {
2014-12-19 05:33:33 +08:00
return &testDrone{}, nil
2014-06-13 07:07:40 +08:00
}
2014-06-15 04:55:12 +08:00
return a
2014-06-13 07:07:40 +08:00
}
2014-12-19 05:33:33 +08:00
func TestArdroneAdaptor(t *testing.T) {
a := NewAdaptor()
gobottest.Assert(t, a.config.Ip, "192.168.1.1")
2014-12-19 05:33:33 +08:00
a = NewAdaptor("192.168.100.100")
gobottest.Assert(t, a.config.Ip, "192.168.100.100")
2014-12-19 05:33:33 +08:00
}
func TestArdroneAdaptorConnect(t *testing.T) {
2014-06-15 04:55:12 +08:00
a := initTestArdroneAdaptor()
gobottest.Assert(t, len(a.Connect()), 0)
2014-12-19 05:33:33 +08:00
a.connect = func(a *Adaptor) (drone, error) {
2014-12-19 05:33:33 +08:00
return nil, errors.New("connection error")
}
gobottest.Assert(t, a.Connect()[0], errors.New("connection error"))
2014-06-13 07:07:40 +08:00
}
2014-12-19 05:33:33 +08:00
func TestArdroneAdaptorFinalize(t *testing.T) {
2014-06-15 04:55:12 +08:00
a := initTestArdroneAdaptor()
gobottest.Assert(t, len(a.Finalize()), 0)
2014-06-13 07:07:40 +08:00
}