about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2014-12-28 23:07:17 +0000
committerEric Wong <e@80x24.org>2014-12-28 23:54:15 +0000
commit20aa6c4baa00d7c7673f2efd30d83f7fee1566a9 (patch)
tree81e5b14a5097b420107be340b8a85b00d6caa8a9 /test
parent97a390057c473c515aba7b7fb371a7c9569a87cb (diff)
downloaddtas-20aa6c4baa00d7c7673f2efd30d83f7fee1566a9.tar.gz
While we're at it, document the splitfx manpage and
make the example suitable for tests.
Diffstat (limited to 'test')
-rw-r--r--test/test_splitfx.rb53
1 files changed, 41 insertions, 12 deletions
diff --git a/test/test_splitfx.rb b/test/test_splitfx.rb
index ab0dcd2..ea170ce 100644
--- a/test/test_splitfx.rb
+++ b/test/test_splitfx.rb
@@ -6,6 +6,18 @@ require 'thread'
 require_relative 'helper'
 
 class TestSplitfx < Testcase
+
+  def tmp_err(path)
+    err = $stderr.dup
+    $stderr.reopen(path, 'a')
+    begin
+      yield
+    ensure
+      $stderr.reopen(err)
+      err.close
+    end
+  end
+
   def test_t2s
     sfx = DTAS::SplitFX.new
     sfx.instance_eval do
@@ -15,6 +27,17 @@ class TestSplitfx < Testcase
     assert_equal 118554030, sfx.t2s('44:48.3')
   end
 
+  def assert_contains_stats(file)
+    buf = File.read(file)
+    [ 'DC offset', 'Min level', 'Max level', 'Pk lev dB',
+      'RMS lev dB', 'RMS Pk dB', 'RMS Tr dB', 'Crest factor', 'Flat factor',
+      'Pk count', 'Bit-depth', 'Num samples',
+      'Length s', 'Scale max', 'Window s'
+    ].each do |re|
+      assert_match(/^#{re}/, buf, buf)
+    end
+  end
+
   def test_example
     hash = YAML.load(File.read("examples/splitfx.sample.yml"))
     sfx = DTAS::SplitFX.new
@@ -25,19 +48,25 @@ class TestSplitfx < Testcase
         opts = { jobs: nil, silent: true }
 
         # ensure default FLAC target works
-        WAIT_ALL_MTX.synchronize { sfx.run("flac", opts) }
+        WAIT_ALL_MTX.synchronize do
+          tmp_err('err.txt') { sfx.run("flac", opts) }
+        end
         expect = %w(1.flac 2.flac foo.flac)
         assert_equal expect, Dir["*.flac"].sort
 
         # compare results with expected output
-        res_cmd = "sox 1.flac 2.flac -ts32 -c2 -r44100 result.s32"
-        res_pid = Process.spawn(res_cmd)
-        exp_cmd = "sox foo.flac -ts32 -c2 -r44100 expect.s32 trim 4"
-        exp_pid = Process.spawn(exp_cmd)
+        res_cmd = "sox 1.flac 2.flac -ts32 -c2 -r44100 result.s32 stats"
+        res_pid = Process.spawn(res_cmd, err: 'b.txt')
+        exp_cmd = "sox foo.flac -ts32 -c2 -r44100 expect.s32 trim 4 stats"
+        exp_pid = Process.spawn(exp_cmd, err: 'a.txt')
         _, s = Process.waitpid2(res_pid)
         assert s.success?, "#{res_cmd}: #{s.inspect}"
         _, s = Process.waitpid2(exp_pid)
         assert s.success?, "#{exp_cmd}: #{s.inspect}"
+        assert_equal File.read('a.txt'), File.read('b.txt')
+
+        assert_contains_stats('err.txt')
+
         cmp = "cmp result.s32 expect.s32"
         assert system(cmp), cmp
 
@@ -46,13 +75,10 @@ class TestSplitfx < Testcase
         # hasn't made it into Debian, yet)
         if `which opusenc 2>/dev/null`.size > 0 &&
            `which opusdec 2>/dev/null`.size > 0
-          err = $stderr.dup
-          begin
-            $stderr.reopen("/dev/null", "a")
-            WAIT_ALL_MTX.synchronize { sfx.run("opusenc", opts) }
-          ensure
-            $stderr.reopen(err)
+          WAIT_ALL_MTX.synchronize do
+            tmp_err('opus.err.txt') { sfx.run("opusenc", opts) }
           end
+          assert_contains_stats('opus.err.txt')
 
           # ensure opus lengths match flac ones, we decode using opusdec
           # since sox does not yet have opus support in Debian 7.0
@@ -64,7 +90,10 @@ class TestSplitfx < Testcase
 
           # ensure 16/44.1kHz FLAC works (CDDA-like)
           File.unlink('1.flac', '2.flac')
-          WAIT_ALL_MTX.synchronize { sfx.run("flac-cdda", opts) }
+          WAIT_ALL_MTX.synchronize do
+            tmp_err('flac-cdda.err.txt') { sfx.run("flac-cdda", opts) }
+          end
+          assert_contains_stats('flac-cdda.err.txt')
           %w(1 2).each do |nr|
             assert_equal `soxi -D #{nr}.flac`, `soxi -D #{nr}.wav`
           end