2014-04-28 09:02:39 +08:00
|
|
|
package joystick
|
2014-04-26 18:11:51 +08:00
|
|
|
|
|
|
|
import (
|
2017-04-06 16:00:58 +08:00
|
|
|
"strings"
|
2014-06-14 03:54:21 +08:00
|
|
|
"testing"
|
2014-07-23 04:55:19 +08:00
|
|
|
|
2023-09-23 18:32:31 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2023-11-12 21:17:02 +08:00
|
|
|
"github.com/stretchr/testify/require"
|
2023-09-23 18:32:31 +08:00
|
|
|
|
2023-05-20 20:25:21 +08:00
|
|
|
"gobot.io/x/gobot/v2"
|
2014-04-26 18:11:51 +08:00
|
|
|
)
|
|
|
|
|
2016-09-26 03:07:36 +08:00
|
|
|
var _ gobot.Adaptor = (*Adaptor)(nil)
|
2016-08-26 20:23:03 +08:00
|
|
|
|
2016-09-26 03:07:36 +08:00
|
|
|
func initTestAdaptor() *Adaptor {
|
2023-09-23 18:32:31 +08:00
|
|
|
a := NewAdaptor("6")
|
2023-11-16 03:51:52 +08:00
|
|
|
a.connect = func(j *Adaptor) error {
|
2014-07-23 04:55:19 +08:00
|
|
|
j.joystick = &testJoystick{}
|
2014-11-20 07:45:59 +08:00
|
|
|
return nil
|
2014-07-23 04:55:19 +08:00
|
|
|
}
|
|
|
|
return a
|
2014-06-14 03:54:21 +08:00
|
|
|
}
|
2014-04-26 18:11:51 +08:00
|
|
|
|
2017-04-06 16:00:58 +08:00
|
|
|
func TestJoystickAdaptorName(t *testing.T) {
|
|
|
|
a := initTestAdaptor()
|
2023-09-23 18:32:31 +08:00
|
|
|
assert.True(t, strings.HasPrefix(a.Name(), "Joystick"))
|
2017-04-06 16:00:58 +08:00
|
|
|
a.SetName("NewName")
|
2023-11-12 21:17:02 +08:00
|
|
|
assert.Equal(t, "NewName", a.Name())
|
2017-04-06 16:00:58 +08:00
|
|
|
}
|
|
|
|
|
2016-09-26 03:07:36 +08:00
|
|
|
func TestAdaptorConnect(t *testing.T) {
|
|
|
|
a := initTestAdaptor()
|
2023-11-12 21:17:02 +08:00
|
|
|
require.NoError(t, a.Connect())
|
2014-11-20 10:54:31 +08:00
|
|
|
|
2023-09-23 18:32:31 +08:00
|
|
|
a = NewAdaptor("6")
|
|
|
|
err := a.Connect()
|
2023-11-16 03:51:52 +08:00
|
|
|
require.ErrorContains(t, err, "no joystick available")
|
2014-06-14 03:54:21 +08:00
|
|
|
}
|
2014-06-14 07:01:39 +08:00
|
|
|
|
2016-09-26 03:07:36 +08:00
|
|
|
func TestAdaptorFinalize(t *testing.T) {
|
|
|
|
a := initTestAdaptor()
|
2023-06-13 01:51:25 +08:00
|
|
|
_ = a.Connect()
|
2023-11-12 21:17:02 +08:00
|
|
|
require.NoError(t, a.Finalize())
|
2014-06-14 03:54:21 +08:00
|
|
|
}
|