1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-05-04 22:17:39 +08:00
hybridgroup.gobot/platforms/leap/leap_motion_driver_test.go
2014-12-18 14:07:48 -08:00

61 lines
1.5 KiB
Go

package leap
import (
"io"
"io/ioutil"
"testing"
"github.com/hybridgroup/gobot"
)
type NullReadWriteCloser struct{}
func (NullReadWriteCloser) Write(p []byte) (int, error) {
return len(p), nil
}
func (NullReadWriteCloser) Read(b []byte) (int, error) {
return len(b), nil
}
func (NullReadWriteCloser) Close() error {
return nil
}
func initTestLeapMotionDriver() *LeapMotionDriver {
a := NewLeapMotionAdaptor("bot", "")
a.connect = func(l *LeapMotionAdaptor) (err error) {
l.ws = new(NullReadWriteCloser)
return nil
}
a.Connect()
receive = func(ws io.ReadWriteCloser) []byte {
file, _ := ioutil.ReadFile("./test/support/example_frame.json")
return file
}
return NewLeapMotionDriver(a, "bot")
}
func TestLeapMotionDriverStart(t *testing.T) {
d := initTestLeapMotionDriver()
gobot.Assert(t, len(d.Start()), 0)
}
func TestLeapMotionDriverHalt(t *testing.T) {
d := initTestLeapMotionDriver()
gobot.Assert(t, len(d.Halt()), 0)
}
func TestLeapMotionDriverParser(t *testing.T) {
d := initTestLeapMotionDriver()
file, _ := ioutil.ReadFile("./test/support/example_frame.json")
parsedFrame := d.ParseFrame(file)
if parsedFrame.Hands == nil || parsedFrame.Pointables == nil || parsedFrame.Gestures == nil {
t.Errorf("ParseFrame incorrectly parsed frame")
}
gobot.Assert(t, parsedFrame.Timestamp, 4729292670)
gobot.Assert(t, parsedFrame.Hands[0].X(), 117.546)
gobot.Assert(t, parsedFrame.Hands[0].Y(), 236.007)
gobot.Assert(t, parsedFrame.Hands[0].Z(), 76.3394)
}