Skip to content

Commit

Permalink
gpio: increase test coverage for button, buzzer, direct pin, led, mot…
Browse files Browse the repository at this point in the history
…or, and rgb led drivers

Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Mar 21, 2017
1 parent 2314d96 commit 2d541ca
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 3 deletions.
12 changes: 12 additions & 0 deletions drivers/gpio/button_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gpio

import (
"errors"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -103,3 +104,14 @@ func TestButtonDriverStart(t *testing.T) {
}

}

func TestButtonDriverDefaultName(t *testing.T) {
g := initTestButtonDriver()
gobottest.Assert(t, strings.HasPrefix(g.Name(), "Button"), true)
}

func TestButtonDriverSetName(t *testing.T) {
g := initTestButtonDriver()
g.SetName("mybot")
gobottest.Assert(t, g.Name(), "mybot")
}
9 changes: 7 additions & 2 deletions drivers/gpio/buzzer_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ func initTestBuzzerDriver(conn DigitalWriter) *BuzzerDriver {
return NewBuzzerDriver(conn, "1")
}

func TestBuzzerDriverName(t *testing.T) {
func TestBuzzerDriverDefaultName(t *testing.T) {
g := initTestBuzzerDriver(newGpioTestAdaptor())
gobottest.Refute(t, g.Connection(), nil)
gobottest.Assert(t, strings.HasPrefix(g.Name(), "Buzzer"), true)
}

func TestBuzzerDriverSetName(t *testing.T) {
g := initTestBuzzerDriver(newGpioTestAdaptor())
g.SetName("mybot")
gobottest.Assert(t, g.Name(), "mybot")
}

func TestBuzzerDriverStart(t *testing.T) {
d := initTestBuzzerDriver(newGpioTestAdaptor())
gobottest.Assert(t, d.Start(), nil)
Expand Down
14 changes: 13 additions & 1 deletion drivers/gpio/direct_pin_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gpio

import (
"errors"
"strings"
"testing"

"gobot.io/x/gobot"
Expand Down Expand Up @@ -102,10 +103,21 @@ func TestDirectPinDriverPwmWrite(t *testing.T) {
gobottest.Assert(t, d.PwmWrite(1), ErrPwmWriteUnsupported)
}

func TestDirectPinDriverDigitalWrie(t *testing.T) {
func TestDirectPinDriverServoWrite(t *testing.T) {
d := initTestDirectPinDriver(newGpioTestAdaptor())
gobottest.Refute(t, d.ServoWrite(1), nil)

d = initTestDirectPinDriver(&gpioTestBareAdaptor{})
gobottest.Assert(t, d.ServoWrite(1), ErrServoWriteUnsupported)
}

func TestDirectPinDriverDefaultName(t *testing.T) {
d := initTestDirectPinDriver(newGpioTestAdaptor())
gobottest.Assert(t, strings.HasPrefix(d.Name(), "Direct"), true)
}

func TestDirectPinDriverSetName(t *testing.T) {
d := initTestDirectPinDriver(newGpioTestAdaptor())
d.SetName("mybot")
gobottest.Assert(t, d.Name(), "mybot")
}
12 changes: 12 additions & 0 deletions drivers/gpio/led_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gpio

import (
"errors"
"strings"
"testing"

"gobot.io/x/gobot"
Expand Down Expand Up @@ -79,3 +80,14 @@ func TestLedDriverBrightness(t *testing.T) {
}
gobottest.Assert(t, d.Brightness(150), errors.New("pwm error"))
}

func TestLEDDriverDefaultName(t *testing.T) {
d := initTestLedDriver(&gpioTestDigitalWriter{})
gobottest.Assert(t, strings.HasPrefix(d.Name(), "LED"), true)
}

func TestLEDDriverSetName(t *testing.T) {
d := initTestLedDriver(&gpioTestDigitalWriter{})
d.SetName("mybot")
gobottest.Assert(t, d.Name(), "mybot")
}
12 changes: 12 additions & 0 deletions drivers/gpio/motor_driver_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gpio

import (
"strings"
"testing"

"gobot.io/x/gobot"
Expand Down Expand Up @@ -110,3 +111,14 @@ func TestMotorDriverDirection(t *testing.T) {
d.Direction("forward")
d.Direction("backward")
}

func TestMotorDriverDefaultName(t *testing.T) {
d := initTestMotorDriver()
gobottest.Assert(t, strings.HasPrefix(d.Name(), "Motor"), true)
}

func TestMotorDriverSetName(t *testing.T) {
d := initTestMotorDriver()
d.SetName("mybot")
gobottest.Assert(t, d.Name(), "mybot")
}
12 changes: 12 additions & 0 deletions drivers/gpio/rgb_led_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gpio

import (
"errors"
"strings"
"testing"

"gobot.io/x/gobot"
Expand Down Expand Up @@ -82,3 +83,14 @@ func TestRgbLedDriverSetLevel(t *testing.T) {
}
gobottest.Assert(t, d.SetLevel("1", 150), errors.New("pwm error"))
}

func TestRgbLedDriverDefaultName(t *testing.T) {
d := initTestRgbLedDriver(&gpioTestDigitalWriter{})
gobottest.Assert(t, strings.HasPrefix(d.Name(), "RGB"), true)
}

func TestRgbLedDriverSetName(t *testing.T) {
d := initTestRgbLedDriver(&gpioTestDigitalWriter{})
d.SetName("mybot")
gobottest.Assert(t, d.Name(), "mybot")
}

0 comments on commit 2d541ca

Please sign in to comment.