2014-06-13 13:35:19 -07:00
|
|
|
package leap
|
|
|
|
|
|
|
|
import (
|
2014-12-18 15:13:53 -08:00
|
|
|
"errors"
|
|
|
|
"io"
|
2017-04-06 10:51:11 +02:00
|
|
|
"strings"
|
2014-06-13 13:35:19 -07:00
|
|
|
"testing"
|
2014-11-28 17:52:01 -08:00
|
|
|
|
2023-10-20 10:27:09 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2023-05-20 14:25:21 +02:00
|
|
|
"gobot.io/x/gobot/v2"
|
2014-06-13 13:35:19 -07:00
|
|
|
)
|
|
|
|
|
2016-09-25 21:36:01 +02:00
|
|
|
var _ gobot.Adaptor = (*Adaptor)(nil)
|
2016-08-27 11:56:01 +02:00
|
|
|
|
2016-09-25 21:36:01 +02:00
|
|
|
func initTestLeapMotionAdaptor() *Adaptor {
|
|
|
|
a := NewAdaptor("")
|
2014-12-18 15:13:53 -08:00
|
|
|
a.connect = func(port string) (io.ReadWriteCloser, error) { return nil, nil }
|
2014-11-07 13:15:45 -08:00
|
|
|
return a
|
2014-06-13 13:35:19 -07:00
|
|
|
}
|
|
|
|
|
2014-12-18 15:13:53 -08:00
|
|
|
func TestLeapMotionAdaptor(t *testing.T) {
|
2016-09-25 21:36:01 +02:00
|
|
|
a := NewAdaptor("127.0.0.1")
|
2023-10-20 10:27:09 +02:00
|
|
|
assert.Equal(t, "127.0.0.1", a.Port())
|
2014-12-18 15:13:53 -08:00
|
|
|
}
|
2017-04-06 10:51:11 +02:00
|
|
|
|
|
|
|
func TestLeapMotionAdaptorName(t *testing.T) {
|
|
|
|
a := NewAdaptor("127.0.0.1")
|
2023-10-20 10:27:09 +02:00
|
|
|
assert.True(t, strings.HasPrefix(a.Name(), "Leap"))
|
2017-04-06 10:51:11 +02:00
|
|
|
a.SetName("NewName")
|
2023-10-20 10:27:09 +02:00
|
|
|
assert.Equal(t, "NewName", a.Name())
|
2017-04-06 10:51:11 +02:00
|
|
|
}
|
|
|
|
|
2014-06-13 16:01:39 -07:00
|
|
|
func TestLeapMotionAdaptorConnect(t *testing.T) {
|
|
|
|
a := initTestLeapMotionAdaptor()
|
2023-10-20 10:27:09 +02:00
|
|
|
assert.Nil(t, a.Connect())
|
2014-12-18 15:13:53 -08:00
|
|
|
|
|
|
|
a.connect = func(port string) (io.ReadWriteCloser, error) {
|
|
|
|
return nil, errors.New("connection error")
|
|
|
|
}
|
2023-10-21 10:08:03 +02:00
|
|
|
assert.Error(t, a.Connect(), "connection error")
|
2014-06-13 13:35:19 -07:00
|
|
|
}
|
2014-06-13 16:01:39 -07:00
|
|
|
|
|
|
|
func TestLeapMotionAdaptorFinalize(t *testing.T) {
|
|
|
|
a := initTestLeapMotionAdaptor()
|
2023-10-20 10:27:09 +02:00
|
|
|
assert.Nil(t, a.Finalize())
|
2014-06-13 13:35:19 -07:00
|
|
|
}
|