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"
|
2017-04-06 15:50:01 +08:00
|
|
|
"strings"
|
2016-05-25 12:05:27 +08:00
|
|
|
"testing"
|
2016-05-14 07:09:36 +08:00
|
|
|
|
2016-12-08 20:24:03 +08:00
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/gobottest"
|
2016-05-14 07:09:36 +08:00
|
|
|
)
|
|
|
|
|
2016-09-25 18:17:01 +08:00
|
|
|
var _ gobot.Driver = (*Driver)(nil)
|
2016-08-26 20:23:03 +08:00
|
|
|
|
2016-05-14 07:09:36 +08:00
|
|
|
func TestAudioDriver(t *testing.T) {
|
2016-09-25 18:17:01 +08:00
|
|
|
d := NewDriver(NewAdaptor(), "../../examples/laser.mp3")
|
2016-05-14 07:09:36 +08:00
|
|
|
|
2016-05-25 12:01:16 +08:00
|
|
|
gobottest.Assert(t, d.Filename(), "../../examples/laser.mp3")
|
|
|
|
|
2016-09-25 18:17:01 +08:00
|
|
|
gobottest.Refute(t, d.Connection(), nil)
|
2016-05-14 07:09:36 +08:00
|
|
|
|
2016-11-08 00:27:49 +08:00
|
|
|
gobottest.Assert(t, d.Start(), nil)
|
2016-05-14 07:09:36 +08:00
|
|
|
|
2016-11-08 00:27:49 +08:00
|
|
|
gobottest.Assert(t, d.Halt(), nil)
|
2016-05-14 07:09:36 +08:00
|
|
|
}
|
2016-05-25 11:21:49 +08:00
|
|
|
|
2017-04-06 15:50:01 +08:00
|
|
|
func TestAudioDriverName(t *testing.T) {
|
|
|
|
d := NewDriver(NewAdaptor(), "")
|
|
|
|
gobottest.Assert(t, strings.HasPrefix(d.Name(), "Audio"), true)
|
|
|
|
d.SetName("NewName")
|
|
|
|
gobottest.Assert(t, d.Name(), "NewName")
|
|
|
|
}
|
|
|
|
|
2016-05-25 11:21:49 +08:00
|
|
|
func TestAudioDriverSoundWithNoFilename(t *testing.T) {
|
2016-09-25 18:17:01 +08:00
|
|
|
d := NewDriver(NewAdaptor(), "")
|
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 }()
|
|
|
|
|
2016-09-25 18:17:01 +08:00
|
|
|
d := NewDriver(NewAdaptor(), "../../examples/laser.mp3")
|
2016-05-25 12:01:16 +08:00
|
|
|
|
|
|
|
errors := d.Play()
|
|
|
|
gobottest.Assert(t, len(errors), 0)
|
|
|
|
}
|