diff options
Diffstat (limited to 'test')
31 files changed, 208 insertions, 86 deletions
diff --git a/test/covshow.rb b/test/covshow.rb index df89037..95f8bfa 100644 --- a/test/covshow.rb +++ b/test/covshow.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2016 all contributors <dtas-all@nongnu.org> +# Copyright (C) 2013-2020 all contributors <dtas-all@nongnu.org> # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt> # frozen_string_literal: true # diff --git a/test/helper.rb b/test/helper.rb index 4031394..0a351e5 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2016 all contributors <dtas-all@nongnu.org> +# Copyright (C) 2013-2020 all contributors <dtas-all@nongnu.org> # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt> # frozen_string_literal: true $stdout.sync = $stderr.sync = Thread.abort_on_exception = true diff --git a/test/player_integration.rb b/test/player_integration.rb index 2e81280..66d1c6e 100644 --- a/test/player_integration.rb +++ b/test/player_integration.rb @@ -1,11 +1,10 @@ -# Copyright (C) 2013-2016 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 8f5d8b5..a47e2d4 100644 --- a/test/test_buffer.rb +++ b/test/test_buffer.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2019 all contributors <dtas-all@nongnu.org> +# Copyright (C) 2013-2020 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' @@ -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 @@ -49,20 +49,20 @@ class TestBuffer < Testcase buf = new_buffer buf.buffer_size = @@max_size assert_equal @@max_size, buf.buffer_size - end if defined?(SleepyPenguin::F_GETPIPE_SZ) + end if defined?(DTAS::Pipe::F_GETPIPE_SZ) def test_buffer_size buf = new_buffer assert_operator buf.buffer_size, :>, 128 buf.buffer_size = @@max_size assert_equal @@max_size, buf.buffer_size - end if defined?(SleepyPenguin::F_GETPIPE_SZ) + end if defined?(DTAS::Pipe::F_GETPIPE_SZ) def test_broadcast_1 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 @@ -108,7 +108,7 @@ class TestBuffer < Testcase assert_equal "HELLO", a[0].read(5) assert_equal "HELLO", b[0].read(5) - return unless defined?(SleepyPenguin::F_GETPIPE_SZ) + return unless defined?(DTAS::Pipe::F_GETPIPE_SZ) b[1].nonblock = true b[1].write('*' * pipe_size(b[1])) @@ -167,7 +167,7 @@ class TestBuffer < Testcase buf.wr.write "HELLO" assert_equal tmp, buf.broadcast(tmp) assert_equal [a[1], b[1]], tmp - end if defined?(SleepyPenguin::F_GETPIPE_SZ) + end if defined?(DTAS::Pipe::F_GETPIPE_SZ) def test_serialize buf = new_buffer @@ -206,6 +206,6 @@ class TestBuffer < Testcase end def pipe_size(io) - io.fcntl(SleepyPenguin::F_GETPIPE_SZ) + io.fcntl(DTAS::Pipe::F_GETPIPE_SZ) end end diff --git a/test/test_encoding.rb b/test/test_encoding.rb index b60ba36..5cd5da7 100644 --- a/test/test_encoding.rb +++ b/test/test_encoding.rb @@ -1,9 +1,8 @@ -# Copyright (C) 2018-2019 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_env.rb b/test/test_env.rb index 4426be3..8520842 100644 --- a/test/test_env.rb +++ b/test/test_env.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2016 all contributors <dtas-all@nongnu.org> +# Copyright (C) 2013-2020 all contributors <dtas-all@nongnu.org> # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt> # frozen_string_literal: true require_relative 'helper' diff --git a/test/test_fadefx.rb b/test/test_fadefx.rb index fb36c21..481a5a5 100644 --- a/test/test_fadefx.rb +++ b/test/test_fadefx.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2016 all contributors <dtas-all@nongnu.org> +# Copyright (C) 2013-2020 all contributors <dtas-all@nongnu.org> # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt> # frozen_string_literal: true require_relative 'helper' diff --git a/test/test_format.rb b/test/test_format.rb index a2118df..81b67bf 100644 --- a/test/test_format.rb +++ b/test/test_format.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2016 all contributors <dtas-all@nongnu.org> +# Copyright (C) 2013-2020 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' diff --git a/test/test_format_change.rb b/test/test_format_change.rb index 73b4403..dc94f02 100644 --- a/test/test_format_change.rb +++ b/test/test_format_change.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2016 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 6957021..983a69e 100644 --- a/test/test_mcache.rb +++ b/test/test_mcache.rb @@ -1,19 +1,29 @@ -# Copyright (C) 2016 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_mlib.rb b/test/test_mlib.rb index b16ea15..75c07f2 100644 --- a/test/test_mlib.rb +++ b/test/test_mlib.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2019 all contributors <dtas-all@nongnu.org> +# Copyright (C) 2013-2020 all contributors <dtas-all@nongnu.org> # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt> # frozen_string_literal: true require_relative 'helper' diff --git a/test/test_parse_freq.rb b/test/test_parse_freq.rb index 7fd5907..b84c131 100644 --- a/test/test_parse_freq.rb +++ b/test/test_parse_freq.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2016 all contributors <dtas-all@nongnu.org> +# Copyright (C) 2015-2020 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' diff --git a/test/test_pipeline.rb b/test/test_pipeline.rb index f235410..19cf2b0 100644 --- a/test/test_pipeline.rb +++ b/test/test_pipeline.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2017-2019 all contributors <dtas-all@nongnu.org> +# Copyright (C) 2017-2020 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' diff --git a/test/test_player.rb b/test/test_player.rb index 0c79b3b..d27bd89 100644 --- a/test/test_player.rb +++ b/test/test_player.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2016 all contributors <dtas-all@nongnu.org> +# Copyright (C) 2013-2020 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' diff --git a/test/test_player_client_handler.rb b/test/test_player_client_handler.rb index d76eaeb..eee5e49 100644 --- a/test/test_player_client_handler.rb +++ b/test/test_player_client_handler.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2016 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 175ed00..09eceee 100644 --- a/test/test_player_integration.rb +++ b/test/test_player_integration.rb @@ -1,10 +1,9 @@ -# Copyright (C) 2013-2016 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_process.rb b/test/test_process.rb index 368d877..94abf20 100644 --- a/test/test_process.rb +++ b/test/test_process.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2016 all contributors <dtas-all@nongnu.org> +# Copyright (C) 2013-2020 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' diff --git a/test/test_rg_integration.rb b/test/test_rg_integration.rb index 29dd29b..f274272 100644 --- a/test/test_rg_integration.rb +++ b/test/test_rg_integration.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2016 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_rg_state.rb b/test/test_rg_state.rb index 59061a2..729e7f7 100644 --- a/test/test_rg_state.rb +++ b/test/test_rg_state.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2016 all contributors <dtas-all@nongnu.org> +# Copyright (C) 2013-2020 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' diff --git a/test/test_sigevent.rb b/test/test_sigevent.rb new file mode 100644 index 0000000..f7e7385 --- /dev/null +++ b/test/test_sigevent.rb @@ -0,0 +1,20 @@ +# Copyright (C) 2019-2020 all contributors <dtas-all@nongnu.org> +# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt> +# frozen_string_literal: true +require_relative 'helper' +require 'dtas' +require 'dtas/sigevent' + +class TestSigevent < Testcase + def test_sigevent + io = DTAS::Sigevent.new + io.signal + assert IO.select([io]), 'IO.select returns' + res = io.readable_iter do |f,arg| + assert_same io, f + assert_nil arg + end + assert_equal :wait_readable, res + assert_nil io.close + end +end diff --git a/test/test_sink.rb b/test/test_sink.rb index 761ccb1..7214da6 100644 --- a/test/test_sink.rb +++ b/test/test_sink.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2016 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_sink_pipe_size.rb b/test/test_sink_pipe_size.rb index 1b6db72..86a7f2c 100644 --- a/test/test_sink_pipe_size.rb +++ b/test/test_sink_pipe_size.rb @@ -1,20 +1,17 @@ -# Copyright (C) 2013-2019 all contributors <dtas-all@nongnu.org> +# Copyright (C) 2013-2020 all contributors <dtas-all@nongnu.org> # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt> # frozen_string_literal: true -begin - require 'sleepy_penguin' - require './test/player_integration' - class TestSinkPipeSizeIntegration < Testcase - include PlayerIntegration +require './test/player_integration' +class TestSinkPipeSizeIntegration < Testcase + include PlayerIntegration - def test_sink_pipe_size_integration - s = client_socket - default_sink_pid(s) - s.req_ok("sink ed default pipe_size=0x1000") - s.req_ok("sink ed default pipe_size=0x10000") - s.req_ok("sink ed default pipe_size=") - s.req_ok("sink ed default pipe_size=4096") - end if SleepyPenguin.const_defined?(:F_SETPIPE_SZ) + def test_sink_pipe_size_integration + s = client_socket + default_sink_pid(s) + s.req_ok("sink ed default pipe_size=0x1000") + s.req_ok("sink ed default pipe_size=0x10000") + s.req_ok("sink ed default pipe_size=") + s.req_ok("sink ed default pipe_size=4096") end -rescue LoadError -end +end if RUBY_PLATFORM =~ /linux/i && + File.readable?('/proc/sys/fs/pipe-max-size') diff --git a/test/test_sink_tee_integration.rb b/test/test_sink_tee_integration.rb index e130f42..3a44e7b 100644 --- a/test/test_sink_tee_integration.rb +++ b/test/test_sink_tee_integration.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2016 all contributors <dtas-all@nongnu.org> +# Copyright (C) 2013-2020 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' diff --git a/test/test_source_av.rb b/test/test_source_av.rb index dddd4a6..3ee115e 100644 --- a/test/test_source_av.rb +++ b/test/test_source_av.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2016 all contributors <dtas-all@nongnu.org> +# Copyright (C) 2013-2020 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' 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_source_sox.rb b/test/test_source_sox.rb index 8c994f1..6e091ee 100644 --- a/test/test_source_sox.rb +++ b/test/test_source_sox.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2016 all contributors <dtas-all@nongnu.org> +# Copyright (C) 2013-2020 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' diff --git a/test/test_splitfx.rb b/test/test_splitfx.rb index d952031..f2e0e09 100644 --- a/test/test_splitfx.rb +++ b/test/test_splitfx.rb @@ -1,14 +1,11 @@ -# Copyright (C) 2013-2016 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 5d77b9d..be68079 100644 --- a/test/test_tfx.rb +++ b/test/test_tfx.rb @@ -1,10 +1,9 @@ -# Copyright (C) 2013-2016 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_tracklist.rb b/test/test_tracklist.rb index e98fa8c..b280390 100644 --- a/test/test_tracklist.rb +++ b/test/test_tracklist.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2016 all contributors <dtas-all@nongnu.org> +# Copyright (C) 2013-2020 all contributors <dtas-all@nongnu.org> # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt> # frozen_string_literal: true require_relative 'helper' diff --git a/test/test_unixserver.rb b/test/test_unixserver.rb index 64f71be..c91354d 100644 --- a/test/test_unixserver.rb +++ b/test/test_unixserver.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2016 all contributors <dtas-all@nongnu.org> +# Copyright (C) 2013-2020 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' @@ -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 diff --git a/test/test_util.rb b/test/test_util.rb index f618511..66194cf 100644 --- a/test/test_util.rb +++ b/test/test_util.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2016 all contributors <dtas-all@nongnu.org> +# Copyright (C) 2013-2020 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' |