2016-05-14 07:09:36 +08:00
|
|
|
// Based on aplay audio adaptor written by @colemanserious (https://github.com/colemanserious)
|
|
|
|
|
|
|
|
package audio
|
|
|
|
|
|
|
|
import (
|
2016-05-25 12:01:16 +08:00
|
|
|
"os/exec"
|
2016-05-25 12:05:27 +08:00
|
|
|
"testing"
|
2016-05-14 07:09:36 +08:00
|
|
|
|
|
|
|
"github.com/hybridgroup/gobot/gobottest"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAudioDriver(t *testing.T) {
|
2016-05-25 12:01:16 +08:00
|
|
|
d := NewAudioDriver(NewAudioAdaptor("conn"), "dev", "../../examples/laser.mp3")
|
2016-05-14 07:09:36 +08:00
|
|
|
|
|
|
|
gobottest.Assert(t, d.Name(), "dev")
|
2016-05-25 12:01:16 +08:00
|
|
|
gobottest.Assert(t, d.Filename(), "../../examples/laser.mp3")
|
|
|
|
|
2016-05-14 07:09:36 +08:00
|
|
|
gobottest.Assert(t, d.Connection().Name(), "conn")
|
|
|
|
|
|
|
|
gobottest.Assert(t, len(d.Start()), 0)
|
|
|
|
|
|
|
|
gobottest.Assert(t, len(d.Halt()), 0)
|
|
|
|
}
|
2016-05-25 11:21:49 +08:00
|
|
|
|
|
|
|
func TestAudioDriverSoundWithNoFilename(t *testing.T) {
|
2016-05-25 12:01:16 +08:00
|
|
|
d := NewAudioDriver(NewAudioAdaptor("conn"), "dev", "")
|
2016-05-25 11:21:49 +08:00
|
|
|
|
|
|
|
errors := d.Sound("")
|
|
|
|
gobottest.Assert(t, errors[0].Error(), "Requires filename for audio file.")
|
|
|
|
}
|
2016-05-25 12:01:16 +08:00
|
|
|
|
|
|
|
func TestAudioDriverSoundWithDefaultFilename(t *testing.T) {
|
|
|
|
execCommand = gobottest.ExecCommand
|
|
|
|
defer func() { execCommand = exec.Command }()
|
|
|
|
|
|
|
|
d := NewAudioDriver(NewAudioAdaptor("conn"), "dev", "../../examples/laser.mp3")
|
|
|
|
|
|
|
|
errors := d.Play()
|
|
|
|
gobottest.Assert(t, len(errors), 0)
|
|
|
|
}
|