2014-04-27 17:17:05 -07:00
|
|
|
package neurosky
|
2014-04-26 03:11:51 -07:00
|
|
|
|
|
|
|
import (
|
2014-12-18 14:42:59 -08:00
|
|
|
"errors"
|
|
|
|
"io"
|
2014-06-13 13:40:24 -07:00
|
|
|
"testing"
|
2014-07-22 18:00:54 -07:00
|
|
|
|
2016-08-27 11:56:01 +02:00
|
|
|
"github.com/hybridgroup/gobot"
|
2016-02-22 00:21:24 -05:00
|
|
|
"github.com/hybridgroup/gobot/gobottest"
|
2014-04-26 03:11:51 -07:00
|
|
|
)
|
|
|
|
|
2016-10-01 17:44:12 +02:00
|
|
|
var _ gobot.Adaptor = (*Adaptor)(nil)
|
2016-08-27 11:56:01 +02:00
|
|
|
|
2014-12-18 14:07:48 -08:00
|
|
|
type NullReadWriteCloser struct{}
|
|
|
|
|
|
|
|
func (NullReadWriteCloser) Write(p []byte) (int, error) {
|
|
|
|
return len(p), nil
|
|
|
|
}
|
2014-12-18 14:42:59 -08:00
|
|
|
|
|
|
|
var readError error = nil
|
|
|
|
|
2014-12-18 14:07:48 -08:00
|
|
|
func (NullReadWriteCloser) Read(b []byte) (int, error) {
|
2014-12-18 14:42:59 -08:00
|
|
|
return len(b), readError
|
2014-12-18 14:07:48 -08:00
|
|
|
}
|
2014-12-18 14:42:59 -08:00
|
|
|
|
|
|
|
var closeError error = nil
|
|
|
|
|
2014-12-18 14:07:48 -08:00
|
|
|
func (NullReadWriteCloser) Close() error {
|
2014-12-18 14:42:59 -08:00
|
|
|
return closeError
|
2014-12-18 14:07:48 -08:00
|
|
|
}
|
|
|
|
|
2016-10-01 17:44:12 +02:00
|
|
|
func initTestNeuroskyAdaptor() *Adaptor {
|
|
|
|
a := NewAdaptor("/dev/null")
|
|
|
|
a.connect = func(n *Adaptor) (io.ReadWriteCloser, error) {
|
2014-12-18 14:42:59 -08:00
|
|
|
return &NullReadWriteCloser{}, nil
|
2014-07-22 18:00:54 -07:00
|
|
|
}
|
|
|
|
return a
|
2014-06-13 13:40:24 -07:00
|
|
|
}
|
2014-04-26 03:11:51 -07:00
|
|
|
|
2014-12-18 14:42:59 -08:00
|
|
|
func TestNeuroskyAdaptor(t *testing.T) {
|
2016-10-01 17:44:12 +02:00
|
|
|
a := NewAdaptor("/dev/null")
|
2016-02-22 00:21:24 -05:00
|
|
|
gobottest.Assert(t, a.Port(), "/dev/null")
|
2014-12-18 14:42:59 -08:00
|
|
|
}
|
2016-10-01 17:44:12 +02:00
|
|
|
|
2014-06-13 16:01:39 -07:00
|
|
|
func TestNeuroskyAdaptorConnect(t *testing.T) {
|
|
|
|
a := initTestNeuroskyAdaptor()
|
2016-02-22 00:21:24 -05:00
|
|
|
gobottest.Assert(t, len(a.Connect()), 0)
|
2014-12-18 14:42:59 -08:00
|
|
|
|
2016-10-01 17:44:12 +02:00
|
|
|
a.connect = func(n *Adaptor) (io.ReadWriteCloser, error) {
|
2014-12-18 14:42:59 -08:00
|
|
|
return nil, errors.New("connection error")
|
|
|
|
}
|
2016-02-22 00:21:24 -05:00
|
|
|
gobottest.Assert(t, a.Connect()[0], errors.New("connection error"))
|
2014-06-13 13:40:24 -07:00
|
|
|
}
|
2014-07-22 18:00:54 -07:00
|
|
|
|
|
|
|
func TestNeuroskyAdaptorFinalize(t *testing.T) {
|
|
|
|
a := initTestNeuroskyAdaptor()
|
|
|
|
a.Connect()
|
2016-02-22 00:21:24 -05:00
|
|
|
gobottest.Assert(t, len(a.Finalize()), 0)
|
2014-12-18 14:42:59 -08:00
|
|
|
|
|
|
|
closeError = errors.New("close error")
|
|
|
|
a.Connect()
|
2016-02-22 00:21:24 -05:00
|
|
|
gobottest.Assert(t, a.Finalize()[0], errors.New("close error"))
|
2014-07-22 18:00:54 -07:00
|
|
|
}
|