1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-27 13:48:56 +08:00
hybridgroup.gobot/platforms/neurosky/neurosky_adaptor_test.go

64 lines
1.3 KiB
Go
Raw Normal View History

2014-04-27 17:17:05 -07:00
package neurosky
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
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/gobottest"
)
var _ gobot.Adaptor = (*Adaptor)(nil)
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
func (NullReadWriteCloser) Read(b []byte) (int, error) {
2014-12-18 14:42:59 -08:00
return len(b), readError
}
2014-12-18 14:42:59 -08:00
var closeError error = nil
func (NullReadWriteCloser) Close() error {
2014-12-18 14:42:59 -08:00
return closeError
}
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-12-18 14:42:59 -08:00
func TestNeuroskyAdaptor(t *testing.T) {
a := NewAdaptor("/dev/null")
gobottest.Assert(t, a.Port(), "/dev/null")
2014-12-18 14:42:59 -08:00
}
2014-06-13 16:01:39 -07:00
func TestNeuroskyAdaptorConnect(t *testing.T) {
a := initTestNeuroskyAdaptor()
gobottest.Assert(t, len(a.Connect()), 0)
2014-12-18 14:42:59 -08:00
a.connect = func(n *Adaptor) (io.ReadWriteCloser, error) {
2014-12-18 14:42:59 -08:00
return nil, errors.New("connection error")
}
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()
gobottest.Assert(t, len(a.Finalize()), 0)
2014-12-18 14:42:59 -08:00
closeError = errors.New("close error")
a.Connect()
gobottest.Assert(t, a.Finalize()[0], errors.New("close error"))
2014-07-22 18:00:54 -07:00
}