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 11:04:51 +08:00
|
|
|
"os/exec"
|
2016-05-14 07:09:36 +08:00
|
|
|
"testing"
|
|
|
|
|
2016-08-26 20:23:03 +08:00
|
|
|
"github.com/hybridgroup/gobot"
|
2016-05-14 07:09:36 +08:00
|
|
|
"github.com/hybridgroup/gobot/gobottest"
|
|
|
|
)
|
|
|
|
|
2016-09-25 18:17:01 +08:00
|
|
|
var _ gobot.Adaptor = (*Adaptor)(nil)
|
2016-08-26 20:23:03 +08:00
|
|
|
|
2016-05-14 07:09:36 +08:00
|
|
|
func TestAudioAdaptor(t *testing.T) {
|
2016-09-25 18:17:01 +08:00
|
|
|
a := NewAdaptor()
|
2016-05-14 07:09:36 +08:00
|
|
|
|
|
|
|
gobottest.Assert(t, len(a.Connect()), 0)
|
|
|
|
gobottest.Assert(t, len(a.Finalize()), 0)
|
|
|
|
}
|
2016-05-25 08:57:59 +08:00
|
|
|
|
|
|
|
func TestAudioAdaptorCommandsWav(t *testing.T) {
|
|
|
|
cmd, _ := CommandName("whatever.wav")
|
|
|
|
gobottest.Assert(t, cmd, "aplay")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAudioAdaptorCommandsMp3(t *testing.T) {
|
|
|
|
cmd, _ := CommandName("whatever.mp3")
|
|
|
|
gobottest.Assert(t, cmd, "mpg123")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAudioAdaptorCommandsUnknown(t *testing.T) {
|
|
|
|
cmd, err := CommandName("whatever.unk")
|
|
|
|
gobottest.Refute(t, cmd, "mpg123")
|
|
|
|
gobottest.Assert(t, err.Error(), "Unknown filetype for audio file.")
|
|
|
|
}
|
2016-05-25 09:49:58 +08:00
|
|
|
|
|
|
|
func TestAudioAdaptorSoundWithNoFilename(t *testing.T) {
|
2016-09-25 18:17:01 +08:00
|
|
|
a := NewAdaptor()
|
2016-05-25 09:49:58 +08:00
|
|
|
|
|
|
|
errors := a.Sound("")
|
|
|
|
gobottest.Assert(t, errors[0].Error(), "Requires filename for audio file.")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAudioAdaptorSoundWithNonexistingFilename(t *testing.T) {
|
2016-09-25 18:17:01 +08:00
|
|
|
a := NewAdaptor()
|
2016-05-25 09:49:58 +08:00
|
|
|
|
|
|
|
errors := a.Sound("doesnotexist.mp3")
|
|
|
|
gobottest.Assert(t, errors[0].Error(), "stat doesnotexist.mp3: no such file or directory")
|
|
|
|
}
|
2016-05-25 11:04:51 +08:00
|
|
|
|
|
|
|
func TestAudioAdaptorSoundWithValidMP3Filename(t *testing.T) {
|
2016-05-25 12:01:16 +08:00
|
|
|
execCommand = gobottest.ExecCommand
|
2016-05-25 11:04:51 +08:00
|
|
|
|
2016-09-25 18:17:01 +08:00
|
|
|
a := NewAdaptor()
|
2016-05-25 11:04:51 +08:00
|
|
|
defer func() { execCommand = exec.Command }()
|
|
|
|
|
|
|
|
errors := a.Sound("../../examples/laser.mp3")
|
|
|
|
|
|
|
|
gobottest.Assert(t, len(errors), 0)
|
|
|
|
}
|