hybridgroup.gobot/platforms/keyboard/keyboard_driver_test.go

45 lines
905 B
Go
Raw Normal View History

2015-07-10 02:33:46 +08:00
package keyboard
import (
"os"
"strings"
2015-07-10 02:33:46 +08:00
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
2015-07-10 02:33:46 +08:00
)
var _ gobot.Driver = (*Driver)(nil)
func initTestKeyboardDriver() *Driver {
d := NewDriver()
d.connect = func(k *Driver) (err error) {
2015-07-10 02:33:46 +08:00
k.stdin = &os.File{}
return nil
}
d.listen = func(k *Driver) {}
2015-07-10 02:33:46 +08:00
return d
}
func TestKeyboardDriver(t *testing.T) {
d := initTestKeyboardDriver()
gobottest.Assert(t, d.Connection(), (gobot.Connection)(nil))
2015-07-10 02:33:46 +08:00
}
func TestKeyboardDriverName(t *testing.T) {
d := initTestKeyboardDriver()
gobottest.Assert(t, strings.HasPrefix(d.Name(), "Keyboard"), true)
d.SetName("NewName")
gobottest.Assert(t, d.Name(), "NewName")
}
2015-07-10 02:33:46 +08:00
func TestKeyboardDriverStart(t *testing.T) {
d := initTestKeyboardDriver()
gobottest.Assert(t, d.Start(), nil)
2015-07-10 02:33:46 +08:00
}
func TestKeyboardDriverHalt(t *testing.T) {
d := initTestKeyboardDriver()
gobottest.Assert(t, d.Halt(), nil)
2015-07-10 02:33:46 +08:00
}