diff --git a/remote/volume.go b/remote/volume.go index 11ae63a..3876ff6 100644 --- a/remote/volume.go +++ b/remote/volume.go @@ -67,7 +67,7 @@ func (c *Control) GetVolumeMute() (bool, error) { return false, err } - resp := [4]byte{} + resp := [5]byte{} _, err = c.conn.Read(resp[:]) if err != nil { return false, err diff --git a/remote/volume_test.go b/remote/volume_test.go new file mode 100644 index 0000000..09e01f7 --- /dev/null +++ b/remote/volume_test.go @@ -0,0 +1,104 @@ +package remote + +import ( + "testing" +) + +func TestSetVolume(t *testing.T) { + control, mock := newControlMock() + + err := control.SetVolume(101) + if err == nil { + t.Fail() + } + + err = control.SetVolume(0) + if err != nil || mock.writeBuf.String() != "-v.0\r" { + t.Fail() + } + + mock.Close() + + err = control.SetVolume(100) + if err != nil || mock.writeBuf.String() != "-v.100\r" { + t.Fail() + } +} + +func TestVolumeUp(t *testing.T) { + control, mock := newControlMock() + + err := control.VolumeUp() + if err != nil || mock.writeBuf.String() != "-v.u\r" { + t.Fail() + } +} + +func TestVolumeDown(t *testing.T) { + control, mock := newControlMock() + + err := control.VolumeDown() + if err != nil || mock.writeBuf.String() != "-v.d\r" { + t.Fail() + } +} + +func TestGetVolume(t *testing.T) { + control, mock := newControlMock() + + control.SetVolume(0) + mock.FlushToReader() + + volume, err := control.GetVolume() + if err != nil || volume != 0 { + t.Fail() + } + + mock.Close() + + control.SetVolume(100) + mock.FlushToReader() + + volume, err = control.GetVolume() + if err != nil || volume != 100 { + t.Fail() + } +} + +func TestSetVolumeMute(t *testing.T) { + control, mock := newControlMock() + + err := control.SetVolumeMute(false) + if err != nil || mock.writeBuf.String() != "-m.0\r" { + t.Fail() + } + + mock.Close() + + err = control.SetVolumeMute(true) + if err != nil || mock.writeBuf.String() != "-m.1\r" { + t.Fail() + } +} + +func TestGetVolumeMute(t *testing.T) { + control, mock := newControlMock() + + control.SetVolumeMute(false) + mock.FlushToReader() + + muted, err := control.GetVolumeMute() + if err != nil || muted { + t.Fail() + } + + mock.Close() + + control.SetVolumeMute(true) + mock.FlushToReader() + + muted, err = control.GetVolumeMute() + if err != nil || !muted { + t.Fail() + } +}