2017-04-16 20:22:45 +02:00
|
|
|
package mavlink
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/gobottest"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ gobot.Adaptor = (*UDPAdaptor)(nil)
|
|
|
|
|
|
|
|
func initTestMavlinkUDPAdaptor() *UDPAdaptor {
|
|
|
|
m := NewUDPAdaptor(":14550")
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMavlinkUDPAdaptor(t *testing.T) {
|
|
|
|
a := initTestMavlinkUDPAdaptor()
|
|
|
|
gobottest.Assert(t, a.Port(), ":14550")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMavlinkUDPAdaptorName(t *testing.T) {
|
|
|
|
a := initTestMavlinkUDPAdaptor()
|
|
|
|
gobottest.Assert(t, strings.HasPrefix(a.Name(), "Mavlink"), true)
|
|
|
|
a.SetName("NewName")
|
|
|
|
gobottest.Assert(t, a.Name(), "NewName")
|
|
|
|
}
|
|
|
|
|
2017-04-17 12:36:36 +02:00
|
|
|
func TestMavlinkUDPAdaptorConnectAndFinalize(t *testing.T) {
|
2017-04-16 20:22:45 +02:00
|
|
|
a := initTestMavlinkUDPAdaptor()
|
|
|
|
gobottest.Assert(t, a.Connect(), nil)
|
2017-04-17 12:36:36 +02:00
|
|
|
gobottest.Assert(t, a.Finalize(), nil)
|
2017-04-16 20:22:45 +02:00
|
|
|
}
|
|
|
|
|
2017-04-17 12:36:36 +02:00
|
|
|
func TestMavlinkUDPAdaptorWrite(t *testing.T) {
|
2017-04-16 20:22:45 +02:00
|
|
|
a := initTestMavlinkUDPAdaptor()
|
2017-04-17 12:36:36 +02:00
|
|
|
a.Connect()
|
|
|
|
defer a.Finalize()
|
|
|
|
|
|
|
|
i, err := a.Write([]byte{0x01, 0x02, 0x03})
|
|
|
|
gobottest.Assert(t, i, 3)
|
|
|
|
gobottest.Assert(t, err, nil)
|
2017-04-16 20:22:45 +02:00
|
|
|
}
|