2014-06-14 04:35:19 +08:00
|
|
|
package leap
|
|
|
|
|
|
|
|
import (
|
2014-12-19 07:13:53 +08:00
|
|
|
"errors"
|
|
|
|
"io"
|
2014-06-14 04:35:19 +08:00
|
|
|
"testing"
|
2014-11-29 09:52:01 +08:00
|
|
|
|
2016-12-08 20:24:03 +08:00
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/gobottest"
|
2014-06-14 04:35:19 +08:00
|
|
|
)
|
|
|
|
|
2016-09-26 03:36:01 +08:00
|
|
|
var _ gobot.Adaptor = (*Adaptor)(nil)
|
2016-08-27 17:56:01 +08:00
|
|
|
|
2016-09-26 03:36:01 +08:00
|
|
|
func initTestLeapMotionAdaptor() *Adaptor {
|
|
|
|
a := NewAdaptor("")
|
2014-12-19 07:13:53 +08:00
|
|
|
a.connect = func(port string) (io.ReadWriteCloser, error) { return nil, nil }
|
2014-11-08 05:15:45 +08:00
|
|
|
return a
|
2014-06-14 04:35:19 +08:00
|
|
|
}
|
|
|
|
|
2014-12-19 07:13:53 +08:00
|
|
|
func TestLeapMotionAdaptor(t *testing.T) {
|
2016-09-26 03:36:01 +08:00
|
|
|
a := NewAdaptor("127.0.0.1")
|
2016-02-22 13:21:24 +08:00
|
|
|
gobottest.Assert(t, a.Port(), "127.0.0.1")
|
2014-12-19 07:13:53 +08:00
|
|
|
}
|
2014-06-14 07:01:39 +08:00
|
|
|
func TestLeapMotionAdaptorConnect(t *testing.T) {
|
|
|
|
a := initTestLeapMotionAdaptor()
|
2016-11-08 02:38:18 +08:00
|
|
|
gobottest.Assert(t, a.Connect(), nil)
|
2014-12-19 07:13:53 +08:00
|
|
|
|
|
|
|
a.connect = func(port string) (io.ReadWriteCloser, error) {
|
|
|
|
return nil, errors.New("connection error")
|
|
|
|
}
|
2016-11-08 02:38:18 +08:00
|
|
|
gobottest.Assert(t, a.Connect(), errors.New("connection error"))
|
2014-06-14 04:35:19 +08:00
|
|
|
}
|
2014-06-14 07:01:39 +08:00
|
|
|
|
|
|
|
func TestLeapMotionAdaptorFinalize(t *testing.T) {
|
|
|
|
a := initTestLeapMotionAdaptor()
|
2016-11-08 02:38:18 +08:00
|
|
|
gobottest.Assert(t, a.Finalize(), nil)
|
2014-06-14 04:35:19 +08:00
|
|
|
}
|