about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/player_integration.rb3
-rw-r--r--test/test_buffer.rb4
-rw-r--r--test/test_encoding.rb5
-rw-r--r--test/test_format_change.rb4
-rw-r--r--test/test_mcache.rb20
-rw-r--r--test/test_player_client_handler.rb4
-rw-r--r--test/test_player_integration.rb19
-rw-r--r--test/test_rg_integration.rb18
-rw-r--r--test/test_sink.rb4
-rw-r--r--test/test_source_ff.rb102
-rw-r--r--test/test_splitfx.rb7
-rw-r--r--test/test_tfx.rb5
-rw-r--r--test/test_unixserver.rb4
13 files changed, 152 insertions, 47 deletions
diff --git a/test/player_integration.rb b/test/player_integration.rb
index 4ad0e0c..66d1c6e 100644
--- a/test/player_integration.rb
+++ b/test/player_integration.rb
@@ -1,11 +1,10 @@
-# Copyright (C) 2013-2020 all contributors <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 # frozen_string_literal: true
 require './test/helper'
 require 'dtas/player'
 require 'dtas/state_file'
 require 'dtas/unix_client'
-require 'yaml'
 require 'tempfile'
 require 'shellwords'
 require 'timeout'
diff --git a/test/test_buffer.rb b/test/test_buffer.rb
index 54ee584..a47e2d4 100644
--- a/test/test_buffer.rb
+++ b/test/test_buffer.rb
@@ -11,7 +11,7 @@ class TestBuffer < Testcase
   @@max_size = nil if @@max_size == 0
 
   def teardown
-    @to_close.each { |io| io.close unless io.closed? }
+    @to_close.each(&:close)
   end
 
   def setup
@@ -62,7 +62,7 @@ class TestBuffer < Testcase
     buf = new_buffer
     r, w = IO.pipe
     buf.wr.write "HIHI"
-    assert_equal :wait_readable, buf.broadcast([w])
+    assert_equal [w], buf.broadcast([w])
     assert_equal 4, buf.bytes_xfer
     tmp = [w]
     r.close
diff --git a/test/test_encoding.rb b/test/test_encoding.rb
index 9ef6a25..5cd5da7 100644
--- a/test/test_encoding.rb
+++ b/test/test_encoding.rb
@@ -1,9 +1,8 @@
-# Copyright (C) 2018-2020 all contributors <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 # frozen_string_literal: true
 require './test/helper'
 require 'dtas'
-require 'yaml'
 
 class TestEncoding < Testcase
   def test_encoding
@@ -13,7 +12,7 @@ comments:
   ARTIST: !binary |-
     RW5yaXF1ZSBSb2Ryw61ndWV6
 EOD
-    hash = YAML.load(data)
+    hash = DTAS.yaml_load(data)
     artist = DTAS.try_enc(hash['comments']['ARTIST'], Encoding::UTF_8)
     assert_equal 'Enrique Rodríguez', artist
   end
diff --git a/test/test_format_change.rb b/test/test_format_change.rb
index 95bb860..dc94f02 100644
--- a/test/test_format_change.rb
+++ b/test/test_format_change.rb
@@ -1,4 +1,4 @@
-# Copyright (C) 2013-2020 all contributors <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 # frozen_string_literal: true
 require './test/player_integration'
@@ -26,7 +26,7 @@ class TestFormatChange < Testcase
 
       Timeout.timeout(len) do
         begin
-          cur = YAML.load(s.req("current"))
+          cur = DTAS.yaml_load(s.req("current"))
         end while cur["sinks"] && sleep(0.01)
       end
 
diff --git a/test/test_mcache.rb b/test/test_mcache.rb
index 2bf0e98..983a69e 100644
--- a/test/test_mcache.rb
+++ b/test/test_mcache.rb
@@ -1,19 +1,29 @@
-# Copyright (C) 2016-2020 all contributors <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 # frozen_string_literal: true
 require './test/helper'
 require 'dtas/mcache'
+require 'tempfile'
 
 class TestMcache < Testcase
   def test_mcache
+    tmp = Tempfile.new(%W(tmp .sox))
+    fn = tmp.path
+    cmd = %W(sox -r 44100 -b 16 -c 2 -n #{fn} trim 0 1)
+    system(*cmd) or skip
     mc = DTAS::Mcache.new
     exist = nil
-    mc.lookup('hello') { |infile, hash| exist = hash }
+    mc.lookup(fn) { |infile, hash|
+      hash[:ctime] = File.stat(infile).ctime
+      exist = hash
+    }
     assert_kind_of Hash, exist
-    assert_equal 'hello', exist[:infile]
+    assert_equal fn, exist[:infile]
     assert_operator exist[:btime], :<=, DTAS.now
-    assert_same exist, mc.lookup('hello')
+    assert_same exist, mc.lookup(fn)
     assert_nil mc.lookup('HELLO')
-    assert_same exist, mc.lookup('hello'), 'no change after miss'
+    assert_same exist, mc.lookup(fn), 'no change after miss'
+  ensure
+    tmp.close!
   end
 end
diff --git a/test/test_player_client_handler.rb b/test/test_player_client_handler.rb
index 7ea8cc0..eee5e49 100644
--- a/test/test_player_client_handler.rb
+++ b/test/test_player_client_handler.rb
@@ -1,4 +1,4 @@
-# Copyright (C) 2013-2020 all contributors <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 # frozen_string_literal: true
 require './test/helper'
@@ -71,7 +71,7 @@ class TestPlayerClientHandler < Testcase
     @sinks["default"] = sink
     dpc_sink(@io, %W(cat default))
     assert_equal 1, @io.size
-    hsh = YAML.load(@io[0])
+    hsh = DTAS.yaml_load(@io[0])
     assert_kind_of Hash, hsh
     assert_equal "default", hsh["name"]
     assert_match("dither -s", hsh["command"])
diff --git a/test/test_player_integration.rb b/test/test_player_integration.rb
index d2e11cf..09eceee 100644
--- a/test/test_player_integration.rb
+++ b/test/test_player_integration.rb
@@ -1,10 +1,9 @@
-# Copyright (C) 2013-2020 all contributors <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 # frozen_string_literal: true
 require './test/player_integration'
 class TestPlayerIntegration < Testcase
   include PlayerIntegration
-  include DTAS::SpawnFix
 
   def test_cmd_rate
     env = ENV.to_hash.merge(@fmt.to_env)
@@ -140,7 +139,7 @@ class TestPlayerIntegration < Testcase
     Timeout.timeout(5) do
       begin
         yaml = s.req("current")
-        cur = YAML.load(yaml)
+        cur = DTAS.yaml_load(yaml)
       end while cur["sinks"] && sleep(0.01)
     end
 
@@ -167,7 +166,7 @@ class TestPlayerIntegration < Testcase
     Timeout.timeout(len) do
       begin
         yaml = s.req("current")
-        cur = YAML.load(yaml)
+        cur = DTAS.yaml_load(yaml)
       end while cur["sinks"] && sleep(0.01)
     end
     assert(system("cmp", dump.path, expect.path),
@@ -196,13 +195,13 @@ class TestPlayerIntegration < Testcase
     state.close!
     s = client_socket
     s.req_ok(%W(state dump #{state_path}))
-    hash = YAML.load(IO.binread(state_path))
+    hash = DTAS.yaml_load(IO.binread(state_path))
     assert_equal @sock_path, hash["socket"]
     assert_equal "default", hash["sinks"][0]["name"]
 
     assert_equal "", IO.binread(@state_tmp.path)
     s.req_ok(%W(state dump))
-    orig = YAML.load(IO.binread(@state_tmp.path))
+    orig = DTAS.yaml_load(IO.binread(@state_tmp.path))
     assert_equal orig, hash
   ensure
     File.unlink(state_path)
@@ -210,18 +209,18 @@ class TestPlayerIntegration < Testcase
 
   def test_source_ed
     s = client_socket
-    assert_equal "sox av ff splitfx", s.req("source ls")
+    assert_equal "sox ff av splitfx", s.req("source ls")
     s.req_ok("source ed av tryorder=-1")
     assert_equal "av sox ff splitfx", s.req("source ls")
     s.req_ok("source ed av tryorder=")
-    assert_equal "sox av ff splitfx", s.req("source ls")
+    assert_equal "sox ff av splitfx", s.req("source ls")
 
     s.req_ok("source ed sox command=true")
-    sox = YAML.load(s.req("source cat sox"))
+    sox = DTAS.yaml_load(s.req("source cat sox"))
     assert_equal "true", sox["command"]
 
     s.req_ok("source ed sox command=")
-    sox = YAML.load(s.req("source cat sox"))
+    sox = DTAS.yaml_load(s.req("source cat sox"))
     assert_equal DTAS::Source::Sox::SOX_DEFAULTS["command"], sox["command"]
   end
 
diff --git a/test/test_rg_integration.rb b/test/test_rg_integration.rb
index efa0721..f274272 100644
--- a/test/test_rg_integration.rb
+++ b/test/test_rg_integration.rb
@@ -1,4 +1,4 @@
-# Copyright (C) 2013-2020 all contributors <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 # frozen_string_literal: true
 require './test/player_integration'
@@ -39,7 +39,7 @@ class TestRgIntegration < Testcase
     yaml = cur = nil
     Timeout.timeout(5) do
       begin
-        cur = YAML.load(yaml = s.req("current"))
+        cur = DTAS.yaml_load(yaml = s.req("current"))
       end while cur["current_offset"] == 0 && sleep(0.01)
     end
 
@@ -55,7 +55,7 @@ class TestRgIntegration < Testcase
       Timeout.timeout(5) do
         begin
           yaml = s.req("current")
-          cur = YAML.load(yaml)
+          cur = DTAS.yaml_load(yaml)
         end while cur["current"]["env"]["RGFX"] !~ expect && sleep(0.01)
       end
       assert_match expect, cur["current"]["env"]["RGFX"]
@@ -67,27 +67,27 @@ class TestRgIntegration < Testcase
     check_gain.call(%r{gain 2\.5}, "track_peak")
 
     s.req_ok("rg preamp+=1")
-    rg = YAML.load(yaml = s.req("rg"))
+    rg = DTAS.yaml_load(yaml = s.req("rg"))
     assert_equal 1, rg["preamp"]
 
     s.req_ok("rg preamp-=1")
-    rg = YAML.load(yaml = s.req("rg"))
+    rg = DTAS.yaml_load(yaml = s.req("rg"))
     assert_nil rg["preamp"]
 
     s.req_ok("rg preamp=2")
-    rg = YAML.load(yaml = s.req("rg"))
+    rg = DTAS.yaml_load(yaml = s.req("rg"))
     assert_equal 2, rg["preamp"]
 
     s.req_ok("rg preamp-=0.3")
-    rg = YAML.load(yaml = s.req("rg"))
+    rg = DTAS.yaml_load(yaml = s.req("rg"))
     assert_equal 1.7, rg["preamp"]
 
     s.req_ok("rg preamp-=-0.3")
-    rg = YAML.load(yaml = s.req("rg"))
+    rg = DTAS.yaml_load(yaml = s.req("rg"))
     assert_equal 2.0, rg["preamp"]
 
     s.req_ok("rg preamp-=+0.3")
-    rg = YAML.load(yaml = s.req("rg"))
+    rg = DTAS.yaml_load(yaml = s.req("rg"))
     assert_equal 1.7, rg["preamp"]
 
     dethrottle_decoder(s)
diff --git a/test/test_sink.rb b/test/test_sink.rb
index 873fb3a..7214da6 100644
--- a/test/test_sink.rb
+++ b/test/test_sink.rb
@@ -1,4 +1,4 @@
-# Copyright (C) 2013-2020 all contributors <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 # frozen_string_literal: true
 require './test/helper'
@@ -27,6 +27,6 @@ class TestSink < Testcase
   def test_inactive_load
     orig = { "active" => false }.freeze
     tmp = orig.to_yaml
-    assert_equal orig, YAML.load(tmp)
+    assert_equal orig, DTAS.yaml_load(tmp)
   end
 end
diff --git a/test/test_source_ff.rb b/test/test_source_ff.rb
new file mode 100644
index 0000000..e53e72e
--- /dev/null
+++ b/test/test_source_ff.rb
@@ -0,0 +1,102 @@
+# Copyright (C) all contributors <dtas-all@nongnu.org>
+# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
+# frozen_string_literal: true
+require './test/helper'
+require 'dtas/source/ff'
+require 'tempfile'
+
+class TestSourceFf < Testcase
+  def teardown
+    @tempfiles.each(&:close!)
+  end
+
+  def setup
+    @tempfiles = []
+  end
+
+  def x(cmd)
+    system(*cmd)
+    assert $?.success?, cmd.inspect
+  end
+
+  def new_file(suffix)
+    tmp = Tempfile.new(%W(tmp .#{suffix}))
+    @tempfiles << tmp
+    cmd = %W(sox -r 44100 -b 16 -c 2 -n #{tmp.path} trim 0 1)
+    return tmp if system(*cmd)
+    nil
+  end
+
+  def test_flac
+    return if `which metaflac`.strip.size == 0
+    tmp = new_file('flac') or return
+
+    x(%W(metaflac --set-tag=FOO=BAR #{tmp.path}))
+    x(%W(metaflac --add-replay-gain #{tmp.path}))
+    source = DTAS::Source::Ff.new.try(tmp.path)
+    assert_equal source.comments["FOO"], "BAR", source.inspect
+    rg = source.replaygain('track_gain')
+    assert_kind_of DTAS::ReplayGain, rg
+    assert_in_delta 0.0, rg.track_peak.to_f, 0.00000001
+    assert_in_delta 0.0, rg.album_peak.to_f, 0.00000001
+    assert_operator rg.album_gain.to_f, :>, 1
+    assert_operator rg.track_gain.to_f, :>, 1
+  end
+
+  def test_mp3gain
+    return if `which mp3gain`.strip.size == 0
+    a = new_file('mp3') or return
+    b = new_file('mp3') or return
+
+    # redirect stdout to /dev/null temporarily, mp3gain is noisy
+    File.open("/dev/null", "w") do |null|
+      old_out = $stdout.dup
+      $stdout.reopen(null)
+      begin
+        x(%W(mp3gain -q #{a.path} #{b.path}))
+      ensure
+        $stdout.reopen(old_out)
+        old_out.close
+      end
+    end
+
+    source = DTAS::Source::Ff.new.try(a.path)
+    rg = source.replaygain('track_gain')
+    assert_kind_of DTAS::ReplayGain, rg
+    assert_in_delta 0.0, rg.track_peak.to_f, 0.00000001
+    assert_in_delta 0.0, rg.album_peak.to_f, 0.00000001
+    assert_operator rg.album_gain.to_f, :>, 1
+    assert_operator rg.track_gain.to_f, :>, 1
+  end
+
+  def test_offset
+    tmp = new_file('flac') or return
+    source = DTAS::Source::Ff.new.try(*%W(#{tmp.path} 5s))
+    assert_equal 5, source.offset_samples
+
+    source = DTAS::Source::Ff.new.try(*%W(#{tmp.path} 1:00:00.5))
+    expect = 1 * 60 * 60 * 44100 + (44100/2)
+    assert_equal expect, source.offset_samples
+
+    source = DTAS::Source::Ff.new.try(*%W(#{tmp.path} 1:10.5))
+    expect = 1 * 60 * 44100 + (10 * 44100) + (44100/2)
+    assert_equal expect, source.offset_samples
+
+    source = DTAS::Source::Ff.new.try(*%W(#{tmp.path} 10.03))
+    expect = (10 * 44100) + (44100 * 3/100.0)
+    assert_equal expect, source.offset_samples
+  end
+
+  def test_offset_us
+    tmp = new_file('flac') or return
+    source = DTAS::Source::Ff.new.try(*%W(#{tmp.path} 441s))
+    assert_equal 10000.0, source.offset_us
+
+    source = DTAS::Source::Ff.new.try(*%W(#{tmp.path} 22050s))
+    assert_equal 500000.0, source.offset_us
+
+    source = DTAS::Source::Ff.new.try(tmp.path, '1')
+    assert_equal 1000000.0, source.offset_us
+  end
+end if `which ffprobe 2>/dev/null` =~ /ffprobe/ &&
+       `which ffmpeg 2>/dev/null` =~ /ffmpeg/
diff --git a/test/test_splitfx.rb b/test/test_splitfx.rb
index b6ae01f..f2e0e09 100644
--- a/test/test_splitfx.rb
+++ b/test/test_splitfx.rb
@@ -1,14 +1,11 @@
-# Copyright (C) 2013-2020 all contributors <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 # frozen_string_literal: true
-require 'yaml'
 require 'dtas/splitfx'
 require 'thread'
 require_relative 'helper'
 
 class TestSplitfx < Testcase
-  include DTAS::SpawnFix
-
   def tmp_err(path)
     err = $stderr.dup
     $stderr.reopen(path, 'a')
@@ -41,7 +38,7 @@ class TestSplitfx < Testcase
   end
 
   def test_example
-    hash = YAML.load(File.read("examples/splitfx.sample.yml"))
+    hash = DTAS.yaml_load(File.read("examples/splitfx.sample.yml"))
     sfx = DTAS::SplitFX.new
     Dir.mktmpdir do |dir|
       Dir.chdir(dir) do
diff --git a/test/test_tfx.rb b/test/test_tfx.rb
index fa77ca5..be68079 100644
--- a/test/test_tfx.rb
+++ b/test/test_tfx.rb
@@ -1,10 +1,9 @@
-# Copyright (C) 2013-2020 all contributors <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 # frozen_string_literal: true
 require './test/helper'
 require 'dtas/tfx'
 require 'dtas/format'
-require 'yaml'
 
 class TestTFX < Testcase
   def rate
@@ -12,7 +11,7 @@ class TestTFX < Testcase
   end
 
   def test_example
-    ex = YAML.load(File.read("examples/tfx.sample.yml"))
+    ex = DTAS.yaml_load(File.read("examples/tfx.sample.yml"))
     effects = []
     ex["effects"].each do |line|
       words = Shellwords.split(line)
diff --git a/test/test_unixserver.rb b/test/test_unixserver.rb
index b061af0..c91354d 100644
--- a/test/test_unixserver.rb
+++ b/test/test_unixserver.rb
@@ -21,7 +21,7 @@ class TestUNIXServer < Testcase
   end
 
   def teardown
-    @clients.each { |io| io.close unless io.closed? }
+    @clients.each(&:close)
     if File.exist?(@tmp.path)
       @tmp.close!
     else
@@ -41,7 +41,7 @@ class TestUNIXServer < Testcase
     @srv.run_once # nothing
     msgs = []
     clients = []
-    client.send("HELLO", Socket::MSG_EOR)
+    client.send("HELLO", 0)
     @srv.run_once do |c, msg|
       clients << c
       msgs << msg