1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-05-01 13:48:57 +08:00
hybridgroup.gobot/platforms/leap/leap_motion_driver_test.go

49 lines
1.2 KiB
Go
Raw Normal View History

2014-06-13 13:35:19 -07:00
package leap
import (
2014-11-07 13:15:45 -08:00
"io"
2014-06-13 13:35:19 -07:00
"io/ioutil"
"testing"
2014-11-07 13:15:45 -08:00
"github.com/hybridgroup/gobot"
2014-06-13 13:35:19 -07:00
)
2014-06-13 16:01:39 -07:00
func initTestLeapMotionDriver() *LeapMotionDriver {
2014-11-07 13:15:45 -08:00
a := NewLeapMotionAdaptor("bot", "")
a.connect = func(l *LeapMotionAdaptor) {
l.ws = new(gobot.NullReadWriteCloser)
}
a.Connect()
receive = func(ws io.ReadWriteCloser) []byte {
file, _ := ioutil.ReadFile("./test/support/example_frame.json")
return file
}
return NewLeapMotionDriver(a, "bot")
2014-06-13 13:35:19 -07:00
}
2014-06-13 16:01:39 -07:00
func TestLeapMotionDriverStart(t *testing.T) {
2014-11-07 13:15:45 -08:00
//t.SkipNow()
2014-06-13 16:01:39 -07:00
d := initTestLeapMotionDriver()
gobot.Assert(t, d.Start(), nil)
2014-06-13 13:35:19 -07:00
}
2014-06-13 16:01:39 -07:00
func TestLeapMotionDriverHalt(t *testing.T) {
d := initTestLeapMotionDriver()
gobot.Assert(t, d.Halt(), nil)
2014-06-13 13:35:19 -07:00
}
2014-06-13 16:01:39 -07:00
func TestLeapMotionDriverParser(t *testing.T) {
d := initTestLeapMotionDriver()
2014-06-13 13:35:19 -07:00
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")
}
2014-11-07 13:15:45 -08:00
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)
2014-06-13 13:35:19 -07:00
}