2015-07-10 02:33:46 +08:00
|
|
|
package keyboard
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2017-04-06 16:49:34 +08:00
|
|
|
"strings"
|
2015-07-10 02:33:46 +08:00
|
|
|
"testing"
|
|
|
|
|
2023-10-20 16:27:09 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2023-05-20 20:25:21 +08:00
|
|
|
"gobot.io/x/gobot/v2"
|
2015-07-10 02:33:46 +08:00
|
|
|
)
|
|
|
|
|
2016-09-26 03:27:37 +08:00
|
|
|
var _ gobot.Driver = (*Driver)(nil)
|
2016-08-27 17:56:01 +08:00
|
|
|
|
2016-09-26 03:27:37 +08:00
|
|
|
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
|
|
|
|
}
|
2016-09-26 03:27:37 +08:00
|
|
|
d.listen = func(k *Driver) {}
|
2015-07-10 02:33:46 +08:00
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestKeyboardDriver(t *testing.T) {
|
|
|
|
d := initTestKeyboardDriver()
|
2023-10-20 16:27:09 +08:00
|
|
|
assert.Equal(t, (gobot.Connection)(nil), d.Connection())
|
2015-07-10 02:33:46 +08:00
|
|
|
}
|
|
|
|
|
2017-04-06 16:49:34 +08:00
|
|
|
func TestKeyboardDriverName(t *testing.T) {
|
|
|
|
d := initTestKeyboardDriver()
|
2023-10-20 16:27:09 +08:00
|
|
|
assert.True(t, strings.HasPrefix(d.Name(), "Keyboard"))
|
2017-04-06 16:49:34 +08:00
|
|
|
d.SetName("NewName")
|
2023-10-20 16:27:09 +08:00
|
|
|
assert.Equal(t, "NewName", d.Name())
|
2017-04-06 16:49:34 +08:00
|
|
|
}
|
|
|
|
|
2015-07-10 02:33:46 +08:00
|
|
|
func TestKeyboardDriverStart(t *testing.T) {
|
|
|
|
d := initTestKeyboardDriver()
|
2023-10-27 02:34:19 +08:00
|
|
|
assert.NoError(t, d.Start())
|
2015-07-10 02:33:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestKeyboardDriverHalt(t *testing.T) {
|
|
|
|
d := initTestKeyboardDriver()
|
2023-10-27 02:34:19 +08:00
|
|
|
assert.NoError(t, d.Halt())
|
2015-07-10 02:33:46 +08:00
|
|
|
}
|