about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-01-22 11:10:57 +0000
committerEric Wong <e@80x24.org>2016-01-22 11:10:57 +0000
commit250956d0df7c1f06843b0bc3a0c33ea9f2b2a642 (patch)
treea6c4833d619e22706d06189b210c73028e192124
parentccbb0f705f6f29269e0e8964ecff484b73e62863 (diff)
downloaddtas-mpd.tar.gz
-rw-r--r--lib/dtas/mpd_emu_client.rb25
-rw-r--r--test/test_mpd_emu.rb8
2 files changed, 33 insertions, 0 deletions
diff --git a/lib/dtas/mpd_emu_client.rb b/lib/dtas/mpd_emu_client.rb
index f073b9e..3691ff1 100644
--- a/lib/dtas/mpd_emu_client.rb
+++ b/lib/dtas/mpd_emu_client.rb
@@ -32,6 +32,7 @@ class DTAS::MpdEmuClient # :nodoc:
     @rbuf = ''.b
     @wbuf = nil
     @cmd_listnum = 0
+    @cmd_list = nil
     out("OK #{SERVER}\n")
   end
 
@@ -62,6 +63,10 @@ class DTAS::MpdEmuClient # :nodoc:
     end
   end
 
+  def unknown_cmd(cmd)
+    %Q!#{err(:ERROR_UNKNOWN)} unknown command "#{cmd}"\n!
+  end
+
   def err(sym)
     "[#{ACK[sym]}@#@cmd_listnum {}"
   end
@@ -74,6 +79,26 @@ class DTAS::MpdEmuClient # :nodoc:
     out("OK\n")
   end
 
+  def mpdcmd_command_list_begin
+    if @cmd_list
+      @cmd_list << 'command_list_begin' # will trigger failure
+    else
+      @cmd_list = []
+    end
+  end
+
+  def mpdcmd_command_list_end
+    @cmd_list or return out(unknown_cmd('command_list_end'))
+    list = @cmd_list
+    @cmd_list = nil
+    list.each do |cmd|
+      case cmd
+      when 'command_list_begin', 'command_list_ok_begin'
+        return out(unknown_cmd(cmd))
+      end
+    end
+  end
+
   def mpdcmd_stats
     out("artists: \n" \
         "albums: \n" \
diff --git a/test/test_mpd_emu.rb b/test/test_mpd_emu.rb
index 869bff4..e536459 100644
--- a/test/test_mpd_emu.rb
+++ b/test/test_mpd_emu.rb
@@ -51,6 +51,14 @@ class TestMpdEmu < Testcase
     assert_nil @c.read(1)
   end
 
+  def test_bad_list_states
+    %w(command_list_end).each do |cmd|
+      @c.write "#{cmd}\n"
+      assert_equal %Q![5@0 {} unknown command "#{cmd}"\n!, @c.gets
+      assert_nil IO.select([@c], nil, nil, 0)
+    end
+  end
+
   # to ensure output buffering works:
   module BigOutput
     WAKE = IO.pipe