Skip to content

Commit

Permalink
joystick: add some additional test coverage for file-based config
Browse files Browse the repository at this point in the history
Signed-off-by: Ron Evans <[email protected]>
  • Loading branch information
deadprogram committed Aug 14, 2018
1 parent 75ed9df commit 605e6e2
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions platforms/joystick/joystick_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,36 @@ import (

var _ gobot.Driver = (*Driver)(nil)

func initTestDriver() *Driver {
func initTestDriver(config string) *Driver {
a := NewAdaptor()
a.connect = func(j *Adaptor) (err error) {
j.joystick = &testJoystick{}
return nil
}
a.Connect()
d := NewDriver(a, "./configs/xbox360_power_a_mini_proex.json")
d := NewDriver(a, config)
d.poll = func() sdl.Event {
return nil
}
return d
}

func TestJoystickDriverName(t *testing.T) {
d := initTestDriver()
d := initTestDriver("./configs/xbox360_power_a_mini_proex.json")
gobottest.Assert(t, strings.HasPrefix(d.Name(), "Joystick"), true)
d.SetName("NewName")
gobottest.Assert(t, d.Name(), "NewName")
}

func TestDriverStart(t *testing.T) {
d := initTestDriver()
d := initTestDriver("./configs/xbox360_power_a_mini_proex.json")
d.interval = 1 * time.Millisecond
gobottest.Assert(t, d.Start(), nil)
time.Sleep(2 * time.Millisecond)
}

func TestDriverHalt(t *testing.T) {
d := initTestDriver()
d := initTestDriver("./configs/xbox360_power_a_mini_proex.json")
go func() {
<-d.halt
}()
Expand All @@ -50,7 +50,7 @@ func TestDriverHalt(t *testing.T) {

func TestDriverHandleEvent(t *testing.T) {
sem := make(chan bool)
d := initTestDriver()
d := initTestDriver("./configs/xbox360_power_a_mini_proex.json")
d.Start()

// left x stick
Expand Down Expand Up @@ -138,3 +138,9 @@ func TestDriverHandleEvent(t *testing.T) {

gobottest.Assert(t, err.Error(), "Unknown Button: 99")
}

func TestDriverInvalidConfig(t *testing.T) {
d := initTestDriver("./configs/doesnotexist")
err := d.Start()
gobottest.Assert(t, strings.Contains(err.Error(), "open ./configs/doesnotexist: no such file or directory"), true)
}

0 comments on commit 605e6e2

Please sign in to comment.