about summary refs log tree commit homepage
path: root/test/test_format_change.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-08-24 09:54:45 +0000
committerEric Wong <normalperson@yhbt.net>2013-08-24 09:54:45 +0000
commit3e09ac0c10c95bb24a08af62393b4f761e2743d0 (patch)
tree778dffa2ba8798503fc047db0feef6d65426ea22 /test/test_format_change.rb
downloaddtas-3e09ac0c10c95bb24a08af62393b4f761e2743d0.tar.gz
Diffstat (limited to 'test/test_format_change.rb')
-rw-r--r--test/test_format_change.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/test_format_change.rb b/test/test_format_change.rb
new file mode 100644
index 0000000..ed0e7a2
--- /dev/null
+++ b/test/test_format_change.rb
@@ -0,0 +1,49 @@
+# -*- encoding: binary -*-
+# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net>
+# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
+require './test/player_integration'
+require 'tmpdir'
+class TestFormatChange < Minitest::Unit::TestCase
+  include PlayerIntegration
+
+  def test_format_change
+    s = client_socket
+    default_pid = default_sink_pid(s)
+    Dir.mktmpdir do |dir|
+      d = "#{dir}/dump.$CHANNELS.$RATE"
+      f44100 = File.open("#{dir}/dump.2.44100", IO::RDWR|IO::CREAT)
+      f88200 = File.open("#{dir}/dump.2.88200", IO::RDWR|IO::CREAT)
+      s.preq("sink ed dump active=true command='cat > #{d}'")
+      assert_equal "OK", s.readpartial(666)
+      noise, len = tmp_noise
+      s.preq(%W(enq #{noise.path}))
+      assert_equal "OK", s.readpartial(666)
+      wait_files_not_empty(default_pid, f44100)
+
+      s.preq("format rate=88200")
+      assert_equal "OK", s.readpartial(666)
+
+      wait_files_not_empty(f88200)
+
+      dethrottle_decoder(s)
+
+      Timeout.timeout(len) do
+        begin
+          s.preq("current")
+          cur = YAML.load(s.readpartial(6666))
+        end while cur["sinks"] && sleep(0.01)
+      end
+
+      c = "sox -R -ts32 -c2 -r88200 #{dir}/dump.2.88200 " \
+          "-ts32 -c2 -r44100 #{dir}/part2"
+      assert(system(c), c)
+
+      c = "sox -R -ts32 -c2 -r44100 #{dir}/dump.2.44100 " \
+          "-ts32 -c2 -r44100 #{dir}/part2 #{dir}/res.sox"
+      assert(system(c), c)
+
+      assert_equal `soxi -s #{dir}/res.sox`, `soxi -s #{noise.path}`
+      File.unlink(*Dir["#{dir}/*"].to_a)
+    end
+  end
+end