From 3e09ac0c10c95bb24a08af62393b4f761e2743d0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 24 Aug 2013 09:54:45 +0000 Subject: initial commit --- test/test_format.rb | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 test/test_format.rb (limited to 'test/test_format.rb') diff --git a/test/test_format.rb b/test/test_format.rb new file mode 100644 index 0000000..ba039a7 --- /dev/null +++ b/test/test_format.rb @@ -0,0 +1,61 @@ +# -*- encoding: binary -*- +# Copyright (C) 2013, Eric Wong +# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +require './test/helper' +require 'tempfile' +require 'dtas/format' + +class TestFormat < Minitest::Unit::TestCase + def test_initialize + fmt = DTAS::Format.new + assert_equal %w(-ts32 -c2 -r44100), fmt.to_sox_arg + hash = fmt.to_hsh + assert_equal({}, hash) + end + + def test_nonstandard + fmt = DTAS::Format.new + fmt.type = "s16" + fmt.rate = 48000 + fmt.channels = 4 + hash = fmt.to_hsh + assert_kind_of Hash, hash + assert_equal %w(channels rate type), hash.keys.sort + assert_equal "s16", hash["type"] + assert_equal 48000, hash["rate"] + assert_equal 4, hash["channels"] + + # back to stereo + fmt.channels = 2 + hash = fmt.to_hsh + assert_equal %w(rate type), hash.keys.sort + assert_equal "s16", hash["type"] + assert_equal 48000, hash["rate"] + assert_nil hash["channels"] + end + + def test_from_file + Tempfile.open(%w(tmp .wav)) do |tmp| + # generate an empty file with 1s of audio + cmd = %W(sox -r 96000 -b 24 -c 2 -n #{tmp.path} trim 0 1) + system(*cmd) + assert $?.success?, "#{cmd.inspect} failed: #$?" + fmt = DTAS::Format.new + fmt.from_file tmp.path + assert_equal 96000, fmt.rate + assert_equal 2, fmt.channels + tmp.unlink + end + end + + def test_bytes_per_sample + fmt = DTAS::Format.new + assert_equal 4, fmt.bytes_per_sample + fmt.type = "f64" + assert_equal 8, fmt.bytes_per_sample + fmt.type = "f32" + assert_equal 4, fmt.bytes_per_sample + fmt.type = "s16" + assert_equal 2, fmt.bytes_per_sample + end +end -- cgit v1.2.3-24-ge0c7