test_libFLAC/md5.c : Fix the tests.
[flac.git] / test / test_flac.sh
blob05ac06c65e5a11f3425ab03a193e87b3c1f91d07
1 #!/bin/bash -e
3 # FLAC - Free Lossless Audio Codec
4 # Copyright (C) 2001-2009 Josh Coalson
5 # Copyright (C) 2011-2013 Xiph.Org Foundation
7 # This file is part the FLAC project. FLAC is comprised of several
8 # components distributed under different licenses. The codec libraries
9 # are distributed under Xiph.Org's BSD-like license (see the file
10 # COPYING.Xiph in this distribution). All other programs, libraries, and
11 # plugins are distributed under the GPL (see COPYING.GPL). The documentation
12 # is distributed under the Gnu FDL (see COPYING.FDL). Each file in the
13 # FLAC distribution contains at the top the terms under which it may be
14 # distributed.
16 # Since this particular file is relevant to all components of FLAC,
17 # it may be distributed under the Xiph.Org license, which is the least
18 # restrictive of those mentioned above. See the file COPYING.Xiph in this
19 # distribution.
21 source common.sh
23 # we use '.' as decimal separator in --skip/--until tests
24 export LANG=C LC_ALL=C
26 dddie="die ERROR: creating files with dd"
28 PATH=`pwd`/../src/flac:$PATH
29 PATH=`pwd`/../src/metaflac:$PATH
30 PATH=`pwd`/../src/test_streams:$PATH
31 PATH=`pwd`/../objs/$BUILD/bin:$PATH
33 flac${EXE} --help 1>/dev/null 2>/dev/null || die "ERROR can't find flac executable"
35 run_flac ()
37 if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
38 echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 flac $*" >>test_flac.valgrind.log
39 valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 flac${EXE} --no-error-on-compression-fail $* 4>>test_flac.valgrind.log
40 else
41 flac${EXE} --no-error-on-compression-fail $*
45 run_metaflac ()
47 if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
48 echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 metaflac $*" >>test_flac.valgrind.log
49 valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 metaflac${EXE} $* 4>>test_flac.valgrind.log
50 else
51 metaflac${EXE} $*
55 md5cmp ()
57 n=`( [ -f "$1" ] && [ -f "$2" ] && metaflac${EXE} --show-md5sum --no-filename "$1" "$2" 2>/dev/null || exit 1 ) | uniq | wc -l`
58 [ "$n" != "" ] && [ $n = 1 ]
61 if [ `env | grep -ic '^comspec='` != 0 ] ; then
62 is_win=yes
63 else
64 is_win=no
67 echo "Checking for --ogg support in flac..."
68 if flac${EXE} --ogg $SILENT --force-raw-format --endian=little --sign=signed --channels=1 --bps=8 --sample-rate=44100 -c $0 1>/dev/null 2>&1 ; then
69 has_ogg=yes;
70 echo "flac --ogg works"
71 else
72 has_ogg=no;
73 echo "flac --ogg doesn't work"
76 echo "Generating streams..."
77 if [ ! -f wacky1.wav ] ; then
78 test_streams || die "ERROR during test_streams"
81 ############################################################################
82 # test that flac doesn't automatically overwrite files unless -f is used
83 ############################################################################
85 echo "Try encoding to a file that exists; should fail"
86 cp wacky1.wav exist.wav
87 touch exist.flac
88 if run_flac $TOTALLY_SILENT -0 exist.wav ; then
89 die "ERROR: it should have failed but didn't"
90 else
91 echo "OK, it failed as it should"
94 echo "Try encoding with -f to a file that exists; should succeed"
95 if run_flac $TOTALLY_SILENT -0 --force exist.wav ; then
96 echo "OK, it succeeded as it should"
97 else
98 die "ERROR: it should have succeeded but didn't"
101 echo "Try decoding to a file that exists; should fail"
102 if run_flac $TOTALLY_SILENT -d exist.flac ; then
103 die "ERROR: it should have failed but didn't"
104 else
105 echo "OK, it failed as it should"
108 echo "Try decoding with -f to a file that exists; should succeed"
109 if run_flac $TOTALLY_SILENT -d -f exist.flac ; then
110 echo "OK, it succeeded as it should"
111 else
112 die "ERROR: it should have succeeded but didn't"
115 rm -f exist.wav exist.flac
117 ############################################################################
118 # test fractional block sizes
119 ############################################################################
121 test_fractional ()
123 blocksize=$1
124 samples=$2
125 dd if=noise.raw ibs=4 count=$samples of=pbs.raw 2>/dev/null || $dddie
126 echo -n "fractional block size test (blocksize=$blocksize samples=$samples) encode... "
127 run_flac $SILENT --force --verify --force-raw-format --endian=little --sign=signed --sample-rate=44100 --bps=16 --channels=2 --blocksize=$blocksize --no-padding --lax -o pbs.flac pbs.raw || die "ERROR"
128 echo -n "decode... "
129 run_flac $SILENT --force --decode --force-raw-format --endian=little --sign=signed -o pbs.cmp pbs.flac || die "ERROR"
130 echo -n "compare... "
131 cmp pbs.raw pbs.cmp || die "ERROR: file mismatch"
132 echo "OK"
133 rm -f pbs.raw pbs.flac pbs.cmp
136 # The special significance of 2048 is it's the # of samples that flac calls
137 # FLAC__stream_encoder_process() on.
139 # We're trying to make sure the 1-sample overread logic in the stream encoder
140 # (used for last-block checking) works; these values probe around common
141 # multiples of the flac sample chunk size (2048) and the blocksize.
142 for samples in 31 32 33 34 35 2046 2047 2048 2049 2050 ; do
143 test_fractional 33 $samples
144 done
145 for samples in 254 255 256 257 258 510 511 512 513 514 1022 1023 1024 1025 1026 2046 2047 2048 2049 2050 4094 4095 4096 4097 4098 ; do
146 test_fractional 256 $samples
147 done
148 for samples in 1022 1023 1024 1025 1026 2046 2047 2048 2049 2050 4094 4095 4096 4097 4098 ; do
149 test_fractional 2048 $samples
150 done
151 for samples in 1022 1023 1024 1025 1026 2046 2047 2048 2049 2050 4094 4095 4096 4097 4098 4606 4607 4608 4609 4610 8190 8191 8192 8193 8194 16382 16383 16384 16385 16386 ; do
152 test_fractional 4608 $samples
153 done
155 ############################################################################
156 # basic 'round-trip' tests of various kinds of streams
157 ############################################################################
159 rt_test_raw ()
161 f="$1"
162 extra="$2"
163 channels=`echo $f | awk -F- '{print $2}'`
164 bps=`echo $f | awk -F- '{print $3}'`
165 echo -n "round-trip test ($f) encode... "
166 run_flac $SILENT --force --verify --force-raw-format --endian=little --sign=signed --sample-rate=44100 --bps=$bps --channels=$channels --no-padding --lax -o rt.flac $extra $f || die "ERROR"
167 echo -n "decode... "
168 run_flac $SILENT --force --decode --force-raw-format --endian=little --sign=signed -o rt.raw $extra rt.flac || die "ERROR"
169 echo -n "compare... "
170 cmp $f rt.raw || die "ERROR: file mismatch"
171 echo "OK"
172 rm -f rt.flac rt.raw
175 rt_test_wav ()
177 f="$1"
178 extra="$2"
179 echo -n "round-trip test ($f) encode... "
180 run_flac $SILENT --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
181 echo -n "decode... "
182 run_flac $SILENT --force --decode --channel-map=none -o rt.wav $extra rt.flac || die "ERROR"
183 echo -n "compare... "
184 cmp $f rt.wav || die "ERROR: file mismatch"
185 echo "OK"
186 rm -f rt.flac rt.wav
189 rt_test_w64 ()
191 f="$1"
192 extra="$2"
193 echo -n "round-trip test ($f) encode... "
194 run_flac $SILENT --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
195 echo -n "decode... "
196 run_flac $SILENT --force --decode --channel-map=none -o rt.w64 $extra rt.flac || die "ERROR"
197 echo -n "compare... "
198 cmp $f rt.w64 || die "ERROR: file mismatch"
199 echo "OK"
200 rm -f rt.flac rt.w64
203 rt_test_rf64 ()
205 f="$1"
206 extra="$2"
207 echo -n "round-trip test ($f) encode... "
208 run_flac $SILENT --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
209 echo -n "decode... "
210 run_flac $SILENT --force --decode --channel-map=none -o rt.rf64 $extra rt.flac || die "ERROR"
211 echo -n "compare... "
212 cmp $f rt.rf64 || die "ERROR: file mismatch"
213 echo "OK"
214 rm -f rt.flac rt.rf64
217 rt_test_aiff ()
219 f="$1"
220 extra="$2"
221 echo -n "round-trip test ($f) encode... "
222 run_flac $SILENT --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
223 echo -n "decode... "
224 run_flac $SILENT --force --decode --channel-map=none -o rt.aiff $extra rt.flac || die "ERROR"
225 echo -n "compare... "
226 cmp $f rt.aiff || die "ERROR: file mismatch"
227 echo "OK"
228 rm -f rt.flac rt.aiff
231 # assumes input file is WAVE; does not check the metadata-preserving features of flac-to-flac; that is checked later
232 rt_test_flac ()
234 f="$1"
235 extra="$2"
236 echo -n "round-trip test ($f->flac->flac->wav) encode... "
237 run_flac $SILENT --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
238 echo -n "re-encode... "
239 run_flac $SILENT --force --verify --lax -o rt2.flac rt.flac || die "ERROR"
240 echo -n "decode... "
241 run_flac $SILENT --force --decode --channel-map=none -o rt.wav $extra rt2.flac || die "ERROR"
242 echo -n "compare... "
243 cmp $f rt.wav || die "ERROR: file mismatch"
244 echo "OK"
245 rm -f rt.wav rt.flac rt2.flac
248 # assumes input file is WAVE; does not check the metadata-preserving features of flac-to-flac; that is checked later
249 rt_test_ogg_flac ()
251 f="$1"
252 extra="$2"
253 echo -n "round-trip test ($f->oggflac->oggflac->wav) encode... "
254 run_flac $SILENT --force --verify --channel-map=none --no-padding --lax -o rt.oga --ogg $extra $f || die "ERROR"
255 echo -n "re-encode... "
256 run_flac $SILENT --force --verify --lax -o rt2.oga --ogg rt.oga || die "ERROR"
257 echo -n "decode... "
258 run_flac $SILENT --force --decode --channel-map=none -o rt.wav $extra rt2.oga || die "ERROR"
259 echo -n "compare... "
260 cmp $f rt.wav || die "ERROR: file mismatch"
261 echo "OK"
262 rm -f rt.wav rt.oga rt2.oga
265 for f in rt-*.raw ; do
266 rt_test_raw $f
267 done
268 for f in rt-*.wav ; do
269 rt_test_wav $f
270 done
271 for f in rt-*.w64 ; do
272 rt_test_w64 $f
273 done
274 for f in rt-*.rf64 ; do
275 rt_test_rf64 $f
276 done
277 for f in rt-*.aiff ; do
278 rt_test_aiff $f
279 done
280 for f in rt-*.wav ; do
281 rt_test_flac $f
282 done
283 if [ $has_ogg = yes ] ; then
284 for f in rt-*.wav ; do
285 rt_test_ogg_flac $f
286 done
289 ############################################################################
290 # test --skip and --until
291 ############################################################################
294 # first make some chopped-up raw files
296 echo "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMN" > master.raw
297 dd if=master.raw ibs=1 count=50 of=50c.raw 2>/dev/null || $dddie
298 dd if=master.raw ibs=1 skip=10 count=40 of=50c.skip10.raw 2>/dev/null || $dddie
299 dd if=master.raw ibs=1 skip=11 count=39 of=50c.skip11.raw 2>/dev/null || $dddie
300 dd if=master.raw ibs=1 skip=20 count=30 of=50c.skip20.raw 2>/dev/null || $dddie
301 dd if=master.raw ibs=1 skip=30 count=20 of=50c.skip30.raw 2>/dev/null || $dddie
302 dd if=master.raw ibs=1 skip=40 count=10 of=50c.skip40.raw 2>/dev/null || $dddie
303 dd if=master.raw ibs=1 count=10 of=50c.until10.raw 2>/dev/null || $dddie
304 dd if=master.raw ibs=1 count=20 of=50c.until20.raw 2>/dev/null || $dddie
305 dd if=master.raw ibs=1 count=30 of=50c.until30.raw 2>/dev/null || $dddie
306 dd if=master.raw ibs=1 count=39 of=50c.until39.raw 2>/dev/null || $dddie
307 dd if=master.raw ibs=1 count=40 of=50c.until40.raw 2>/dev/null || $dddie
308 dd if=master.raw ibs=1 skip=10 count=20 of=50c.skip10.until30.raw 2>/dev/null || $dddie
309 dd if=master.raw ibs=1 skip=10 count=29 of=50c.skip10.until39.raw 2>/dev/null || $dddie
310 dd if=master.raw ibs=1 skip=10 count=30 of=50c.skip10.until40.raw 2>/dev/null || $dddie
311 dd if=master.raw ibs=1 skip=20 count=10 of=50c.skip20.until30.raw 2>/dev/null || $dddie
312 dd if=master.raw ibs=1 skip=20 count=20 of=50c.skip20.until40.raw 2>/dev/null || $dddie
314 wav_eopt="$SILENT --force --verify --no-padding --lax"
315 wav_dopt="$SILENT --force --decode"
317 raw_eopt="$wav_eopt --force-raw-format --endian=big --sign=signed --sample-rate=10 --bps=8 --channels=1"
318 raw_dopt="$wav_dopt --force-raw-format --endian=big --sign=signed"
321 # convert them to WAVE/AIFF/Ogg FLAC files
323 convert_to_wav ()
325 run_flac "$2" $1.raw || die "ERROR converting $1.raw to WAVE"
326 run_flac "$3" $1.flac || die "ERROR converting $1.raw to WAVE"
328 convert_to_wav 50c "$raw_eopt" "$wav_dopt"
329 convert_to_wav 50c.skip10 "$raw_eopt" "$wav_dopt"
330 convert_to_wav 50c.skip11 "$raw_eopt" "$wav_dopt"
331 convert_to_wav 50c.skip20 "$raw_eopt" "$wav_dopt"
332 convert_to_wav 50c.skip30 "$raw_eopt" "$wav_dopt"
333 convert_to_wav 50c.skip40 "$raw_eopt" "$wav_dopt"
334 convert_to_wav 50c.until10 "$raw_eopt" "$wav_dopt"
335 convert_to_wav 50c.until20 "$raw_eopt" "$wav_dopt"
336 convert_to_wav 50c.until30 "$raw_eopt" "$wav_dopt"
337 convert_to_wav 50c.until39 "$raw_eopt" "$wav_dopt"
338 convert_to_wav 50c.until40 "$raw_eopt" "$wav_dopt"
339 convert_to_wav 50c.skip10.until30 "$raw_eopt" "$wav_dopt"
340 convert_to_wav 50c.skip10.until39 "$raw_eopt" "$wav_dopt"
341 convert_to_wav 50c.skip10.until40 "$raw_eopt" "$wav_dopt"
342 convert_to_wav 50c.skip20.until30 "$raw_eopt" "$wav_dopt"
343 convert_to_wav 50c.skip20.until40 "$raw_eopt" "$wav_dopt"
345 convert_to_aiff ()
347 run_flac "$2" $1.raw || die "ERROR converting $1.raw to AIFF"
348 run_flac "$3" $1.flac -o $1.aiff || die "ERROR converting $1.raw to AIFF"
350 convert_to_aiff 50c "$raw_eopt" "$wav_dopt"
351 convert_to_aiff 50c.skip10 "$raw_eopt" "$wav_dopt"
352 convert_to_aiff 50c.skip11 "$raw_eopt" "$wav_dopt"
353 convert_to_aiff 50c.skip20 "$raw_eopt" "$wav_dopt"
354 convert_to_aiff 50c.skip30 "$raw_eopt" "$wav_dopt"
355 convert_to_aiff 50c.skip40 "$raw_eopt" "$wav_dopt"
356 convert_to_aiff 50c.until10 "$raw_eopt" "$wav_dopt"
357 convert_to_aiff 50c.until20 "$raw_eopt" "$wav_dopt"
358 convert_to_aiff 50c.until30 "$raw_eopt" "$wav_dopt"
359 convert_to_aiff 50c.until39 "$raw_eopt" "$wav_dopt"
360 convert_to_aiff 50c.until40 "$raw_eopt" "$wav_dopt"
361 convert_to_aiff 50c.skip10.until30 "$raw_eopt" "$wav_dopt"
362 convert_to_aiff 50c.skip10.until39 "$raw_eopt" "$wav_dopt"
363 convert_to_aiff 50c.skip10.until40 "$raw_eopt" "$wav_dopt"
364 convert_to_aiff 50c.skip20.until30 "$raw_eopt" "$wav_dopt"
365 convert_to_aiff 50c.skip20.until40 "$raw_eopt" "$wav_dopt"
367 convert_to_ogg ()
369 run_flac "$wav_eopt" --ogg $1.wav || die "ERROR converting $1.raw to Ogg FLAC"
371 if [ $has_ogg = yes ] ; then
372 convert_to_ogg 50c
373 convert_to_ogg 50c.skip10
374 convert_to_ogg 50c.skip11
375 convert_to_ogg 50c.skip20
376 convert_to_ogg 50c.skip30
377 convert_to_ogg 50c.skip40
378 convert_to_ogg 50c.until10
379 convert_to_ogg 50c.until20
380 convert_to_ogg 50c.until30
381 convert_to_ogg 50c.until39
382 convert_to_ogg 50c.until40
383 convert_to_ogg 50c.skip10.until30
384 convert_to_ogg 50c.skip10.until39
385 convert_to_ogg 50c.skip10.until40
386 convert_to_ogg 50c.skip20.until30
387 convert_to_ogg 50c.skip20.until40
390 test_skip_until ()
392 in_fmt=$1
393 out_fmt=$2
395 [ "$in_fmt" = wav ] || [ "$in_fmt" = aiff ] || [ "$in_fmt" = raw ] || [ "$in_fmt" = flac ] || [ "$in_fmt" = ogg ] || die "ERROR: internal error, bad 'in' format '$in_fmt'"
397 [ "$out_fmt" = flac ] || [ "$out_fmt" = ogg ] || die "ERROR: internal error, bad 'out' format '$out_fmt'"
399 if [ $in_fmt = raw ] ; then
400 eopt="$raw_eopt"
401 dopt="$raw_dopt"
402 else
403 eopt="$wav_eopt"
404 dopt="$wav_dopt"
407 if ( [ $in_fmt = flac ] || [ $in_fmt = ogg ] ) && ( [ $out_fmt = flac ] || [ $out_fmt = ogg ] ) ; then
408 CMP=md5cmp
409 else
410 CMP=cmp
413 if [ $out_fmt = ogg ] ; then
414 eopt="--ogg $eopt"
418 # test --skip when encoding
421 desc="($in_fmt<->$out_fmt)"
423 echo -n "testing --skip=# (encode) $desc... "
424 run_flac $eopt --skip=10 -o z50c.skip10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
425 [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.$in_fmt z50c.skip10.$out_fmt || die "ERROR decoding FLAC file $desc"
426 $CMP 50c.skip10.$in_fmt z50c.skip10.$in_fmt || die "ERROR: file mismatch for --skip=10 (encode) $desc"
427 rm -f z50c.skip10.$out_fmt z50c.skip10.$in_fmt
428 echo OK
430 echo -n "testing --skip=mm:ss (encode) $desc... "
431 run_flac $eopt --skip=0:01 -o z50c.skip0_01.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
432 [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip0_01.$in_fmt z50c.skip0_01.$out_fmt || die "ERROR decoding FLAC file $desc"
433 $CMP 50c.skip10.$in_fmt z50c.skip0_01.$in_fmt || die "ERROR: file mismatch for --skip=0:01 (encode) $desc"
434 rm -f z50c.skip0_01.$out_fmt z50c.skip0_01.$in_fmt
435 echo OK
437 echo -n "testing --skip=mm:ss.sss (encode) $desc... "
438 run_flac $eopt --skip=0:01.1001 -o z50c.skip0_01.1001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
439 [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip0_01.1001.$in_fmt z50c.skip0_01.1001.$out_fmt || die "ERROR decoding FLAC file $desc"
440 $CMP 50c.skip11.$in_fmt z50c.skip0_01.1001.$in_fmt || die "ERROR: file mismatch for --skip=0:01.1001 (encode) $desc"
441 rm -f z50c.skip0_01.1001.$out_fmt z50c.skip0_01.1001.$in_fmt
442 echo OK
445 # test --skip when decoding
448 if [ $in_fmt != $out_fmt ] ; then run_flac $eopt -o z50c.$out_fmt 50c.$in_fmt ; else cp -f 50c.$in_fmt z50c.$out_fmt ; fi || die "ERROR generating FLAC file $desc"
450 echo -n "testing --skip=# (decode) $desc... "
451 run_flac $dopt --skip=10 -o z50c.skip10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
452 $CMP 50c.skip10.$in_fmt z50c.skip10.$in_fmt || die "ERROR: file mismatch for --skip=10 (decode) $desc"
453 rm -f z50c.skip10.$in_fmt
454 echo OK
456 echo -n "testing --skip=mm:ss (decode) $desc... "
457 run_flac $dopt --skip=0:01 -o z50c.skip0_01.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
458 $CMP 50c.skip10.$in_fmt z50c.skip0_01.$in_fmt || die "ERROR: file mismatch for --skip=0:01 (decode) $desc"
459 rm -f z50c.skip0_01.$in_fmt
460 echo OK
462 echo -n "testing --skip=mm:ss.sss (decode) $desc... "
463 run_flac $dopt --skip=0:01.1001 -o z50c.skip0_01.1001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
464 $CMP 50c.skip11.$in_fmt z50c.skip0_01.1001.$in_fmt || die "ERROR: file mismatch for --skip=0:01.1001 (decode) $desc"
465 rm -f z50c.skip0_01.1001.$in_fmt
466 echo OK
468 rm -f z50c.$out_fmt
471 # test --until when encoding
474 echo -n "testing --until=# (encode) $desc... "
475 run_flac $eopt --until=40 -o z50c.until40.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
476 [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until40.$in_fmt z50c.until40.$out_fmt || die "ERROR decoding FLAC file $desc"
477 $CMP 50c.until40.$in_fmt z50c.until40.$in_fmt || die "ERROR: file mismatch for --until=40 (encode) $desc"
478 rm -f z50c.until40.$out_fmt z50c.until40.$in_fmt
479 echo OK
481 echo -n "testing --until=mm:ss (encode) $desc... "
482 run_flac $eopt --until=0:04 -o z50c.until0_04.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
483 [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until0_04.$in_fmt z50c.until0_04.$out_fmt || die "ERROR decoding FLAC file $desc"
484 $CMP 50c.until40.$in_fmt z50c.until0_04.$in_fmt || die "ERROR: file mismatch for --until=0:04 (encode) $desc"
485 rm -f z50c.until0_04.$out_fmt z50c.until0_04.$in_fmt
486 echo OK
488 echo -n "testing --until=mm:ss.sss (encode) $desc... "
489 run_flac $eopt --until=0:03.9001 -o z50c.until0_03.9001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
490 [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until0_03.9001.$in_fmt z50c.until0_03.9001.$out_fmt || die "ERROR decoding FLAC file $desc"
491 $CMP 50c.until39.$in_fmt z50c.until0_03.9001.$in_fmt || die "ERROR: file mismatch for --until=0:03.9001 (encode) $desc"
492 rm -f z50c.until0_03.9001.$out_fmt z50c.until0_03.9001.$in_fmt
493 echo OK
495 echo -n "testing --until=-# (encode) $desc... "
496 run_flac $eopt --until=-10 -o z50c.until-10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
497 [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until-10.$in_fmt z50c.until-10.$out_fmt || die "ERROR decoding FLAC file $desc"
498 $CMP 50c.until40.$in_fmt z50c.until-10.$in_fmt || die "ERROR: file mismatch for --until=-10 (encode) $desc"
499 rm -f z50c.until-10.$out_fmt z50c.until-10.$in_fmt
500 echo OK
502 echo -n "testing --until=-mm:ss (encode) $desc... "
503 run_flac $eopt --until=-0:01 -o z50c.until-0_01.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
504 [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until-0_01.$in_fmt z50c.until-0_01.$out_fmt || die "ERROR decoding FLAC file $desc"
505 $CMP 50c.until40.$in_fmt z50c.until-0_01.$in_fmt || die "ERROR: file mismatch for --until=-0:01 (encode) $desc"
506 rm -f z50c.until-0_01.$out_fmt z50c.until-0_01.$in_fmt
507 echo OK
509 echo -n "testing --until=-mm:ss.sss (encode) $desc... "
510 run_flac $eopt --until=-0:01.1001 -o z50c.until-0_01.1001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
511 [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until-0_01.1001.$in_fmt z50c.until-0_01.1001.$out_fmt || die "ERROR decoding FLAC file $desc"
512 $CMP 50c.until39.$in_fmt z50c.until-0_01.1001.$in_fmt || die "ERROR: file mismatch for --until=-0:01.1001 (encode) $desc"
513 rm -f z50c.until-0_01.1001.$out_fmt z50c.until-0_01.1001.$in_fmt
514 echo OK
517 # test --until when decoding
520 if [ $in_fmt != $out_fmt ] ; then run_flac $eopt -o z50c.$out_fmt 50c.$in_fmt ; else cp -f 50c.$in_fmt z50c.$out_fmt ; fi || die "ERROR generating FLAC file $desc"
522 echo -n "testing --until=# (decode) $desc... "
523 run_flac $dopt --until=40 -o z50c.until40.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
524 $CMP 50c.until40.$in_fmt z50c.until40.$in_fmt || die "ERROR: file mismatch for --until=40 (decode) $desc"
525 rm -f z50c.until40.$in_fmt
526 echo OK
528 echo -n "testing --until=mm:ss (decode) $desc... "
529 run_flac $dopt --until=0:04 -o z50c.until0_04.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
530 $CMP 50c.until40.$in_fmt z50c.until0_04.$in_fmt || die "ERROR: file mismatch for --until=0:04 (decode) $desc"
531 rm -f z50c.until0_04.$in_fmt
532 echo OK
534 echo -n "testing --until=mm:ss.sss (decode) $desc... "
535 run_flac $dopt --until=0:03.9001 -o z50c.until0_03.9001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
536 $CMP 50c.until39.$in_fmt z50c.until0_03.9001.$in_fmt || die "ERROR: file mismatch for --until=0:03.9001 (decode) $desc"
537 rm -f z50c.until0_03.9001.$in_fmt
538 echo OK
540 echo -n "testing --until=-# (decode) $desc... "
541 run_flac $dopt --until=-10 -o z50c.until-10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
542 $CMP 50c.until40.$in_fmt z50c.until-10.$in_fmt || die "ERROR: file mismatch for --until=-10 (decode) $desc"
543 rm -f z50c.until-10.$in_fmt
544 echo OK
546 echo -n "testing --until=-mm:ss (decode) $desc... "
547 run_flac $dopt --until=-0:01 -o z50c.until-0_01.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
548 $CMP 50c.until40.$in_fmt z50c.until-0_01.$in_fmt || die "ERROR: file mismatch for --until=-0:01 (decode) $desc"
549 rm -f z50c.until-0_01.$in_fmt
550 echo OK
552 echo -n "testing --until=-mm:ss.sss (decode) $desc... "
553 run_flac $dopt --until=-0:01.1001 -o z50c.until-0_01.1001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
554 $CMP 50c.until39.$in_fmt z50c.until-0_01.1001.$in_fmt || die "ERROR: file mismatch for --until=-0:01.1001 (decode) $desc"
555 rm -f z50c.until-0_01.1001.$in_fmt
556 echo OK
558 rm -f z50c.$out_fmt
561 # test --skip and --until when encoding
564 echo -n "testing --skip=10 --until=# (encode) $desc... "
565 run_flac $eopt --skip=10 --until=40 -o z50c.skip10.until40.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
566 [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until40.$in_fmt z50c.skip10.until40.$out_fmt || die "ERROR decoding FLAC file $desc"
567 $CMP 50c.skip10.until40.$in_fmt z50c.skip10.until40.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=40 (encode) $desc"
568 rm -f z50c.skip10.until40.$out_fmt z50c.skip10.until40.$in_fmt
569 echo OK
571 echo -n "testing --skip=10 --until=mm:ss (encode) $desc... "
572 run_flac $eopt --skip=10 --until=0:04 -o z50c.skip10.until0_04.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
573 [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until0_04.$in_fmt z50c.skip10.until0_04.$out_fmt || die "ERROR decoding FLAC file $desc"
574 $CMP 50c.skip10.until40.$in_fmt z50c.skip10.until0_04.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=0:04 (encode) $desc"
575 rm -f z50c.skip10.until0_04.$out_fmt z50c.skip10.until0_04.$in_fmt
576 echo OK
578 echo -n "testing --skip=10 --until=mm:ss.sss (encode) $desc... "
579 run_flac $eopt --skip=10 --until=0:03.9001 -o z50c.skip10.until0_03.9001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
580 [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until0_03.9001.$in_fmt z50c.skip10.until0_03.9001.$out_fmt || die "ERROR decoding FLAC file $desc"
581 $CMP 50c.skip10.until39.$in_fmt z50c.skip10.until0_03.9001.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=0:03.9001 (encode) $desc"
582 rm -f z50c.skip10.until0_03.9001.$out_fmt z50c.skip10.until0_03.9001.$in_fmt
583 echo OK
585 echo -n "testing --skip=10 --until=+# (encode) $desc... "
586 run_flac $eopt --skip=10 --until=+30 -o z50c.skip10.until+30.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
587 [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until+30.$in_fmt z50c.skip10.until+30.$out_fmt || die "ERROR decoding FLAC file $desc"
588 $CMP 50c.skip10.until40.$in_fmt z50c.skip10.until+30.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=+30 (encode) $desc"
589 rm -f z50c.skip10.until+30.$out_fmt z50c.skip10.until+30.$in_fmt
590 echo OK
592 echo -n "testing --skip=10 --until=+mm:ss (encode) $desc... "
593 run_flac $eopt --skip=10 --until=+0:03 -o z50c.skip10.until+0_03.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
594 [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until+0_03.$in_fmt z50c.skip10.until+0_03.$out_fmt || die "ERROR decoding FLAC file $desc"
595 $CMP 50c.skip10.until40.$in_fmt z50c.skip10.until+0_03.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=+0:03 (encode) $desc"
596 rm -f z50c.skip10.until+0_03.$out_fmt z50c.skip10.until+0_03.$in_fmt
597 echo OK
599 echo -n "testing --skip=10 --until=+mm:ss.sss (encode) $desc... "
600 run_flac $eopt --skip=10 --until=+0:02.9001 -o z50c.skip10.until+0_02.9001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
601 [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until+0_02.9001.$in_fmt z50c.skip10.until+0_02.9001.$out_fmt || die "ERROR decoding FLAC file $desc"
602 $CMP 50c.skip10.until39.$in_fmt z50c.skip10.until+0_02.9001.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=+0:02.9001 (encode) $desc"
603 rm -f z50c.skip10.until+0_02.9001.$out_fmt z50c.skip10.until+0_02.9001.$in_fmt
604 echo OK
606 echo -n "testing --skip=10 --until=-# (encode) $desc... "
607 run_flac $eopt --skip=10 --until=-10 -o z50c.skip10.until-10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
608 [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until-10.$in_fmt z50c.skip10.until-10.$out_fmt || die "ERROR decoding FLAC file $desc"
609 $CMP 50c.skip10.until40.$in_fmt z50c.skip10.until-10.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-10 (encode) $desc"
610 rm -f z50c.skip10.until-10.$out_fmt z50c.skip10.until-10.$in_fmt
611 echo OK
613 echo -n "testing --skip=10 --until=-mm:ss (encode) $desc... "
614 run_flac $eopt --skip=10 --until=-0:01 -o z50c.skip10.until-0_01.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
615 [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until-0_01.$in_fmt z50c.skip10.until-0_01.$out_fmt || die "ERROR decoding FLAC file $desc"
616 $CMP 50c.skip10.until40.$in_fmt z50c.skip10.until-0_01.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-0:01 (encode) $desc"
617 rm -f z50c.skip10.until-0_01.$out_fmt z50c.skip10.until-0_01.$in_fmt
618 echo OK
620 echo -n "testing --skip=10 --until=-mm:ss.sss (encode) $desc... "
621 run_flac $eopt --skip=10 --until=-0:01.1001 -o z50c.skip10.until-0_01.1001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
622 [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until-0_01.1001.$in_fmt z50c.skip10.until-0_01.1001.$out_fmt || die "ERROR decoding FLAC file $desc"
623 $CMP 50c.skip10.until39.$in_fmt z50c.skip10.until-0_01.1001.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-0:01.1001 (encode) $desc"
624 rm -f z50c.skip10.until-0_01.1001.$out_fmt z50c.skip10.until-0_01.1001.$in_fmt
625 echo OK
628 # test --skip and --until when decoding
631 if [ $in_fmt != $out_fmt ] ; then run_flac $eopt -o z50c.$out_fmt 50c.$in_fmt ; else cp -f 50c.$in_fmt z50c.$out_fmt ; fi || die "ERROR generating FLAC file $desc"
634 echo -n "testing --skip=10 --until=# (decode) $desc... "
635 run_flac $dopt --skip=10 --until=40 -o z50c.skip10.until40.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
636 $CMP 50c.skip10.until40.$in_fmt z50c.skip10.until40.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=40 (decode) $desc"
637 rm -f z50c.skip10.until40.$in_fmt
638 echo OK
640 echo -n "testing --skip=10 --until=mm:ss (decode) $desc... "
641 run_flac $dopt --skip=10 --until=0:04 -o z50c.skip10.until0_04.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
642 $CMP 50c.skip10.until40.$in_fmt z50c.skip10.until0_04.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=0:04 (decode) $desc"
643 rm -f z50c.skip10.until0_04.$in_fmt
644 echo OK
646 echo -n "testing --skip=10 --until=mm:ss.sss (decode) $desc... "
647 run_flac $dopt --skip=10 --until=0:03.9001 -o z50c.skip10.until0_03.9001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
648 $CMP 50c.skip10.until39.$in_fmt z50c.skip10.until0_03.9001.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=0:03.9001 (decode) $desc"
649 rm -f z50c.skip10.until0_03.9001.$in_fmt
650 echo OK
652 echo -n "testing --skip=10 --until=-# (decode) $desc... "
653 run_flac $dopt --skip=10 --until=-10 -o z50c.skip10.until-10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
654 $CMP 50c.skip10.until40.$in_fmt z50c.skip10.until-10.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-10 (decode) $desc"
655 rm -f z50c.skip10.until-10.$in_fmt
656 echo OK
658 echo -n "testing --skip=10 --until=-mm:ss (decode) $desc... "
659 run_flac $dopt --skip=10 --until=-0:01 -o z50c.skip10.until-0_01.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
660 $CMP 50c.skip10.until40.$in_fmt z50c.skip10.until-0_01.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-0:01 (decode) $desc"
661 rm -f z50c.skip10.until-0_01.$in_fmt
662 echo OK
664 echo -n "testing --skip=10 --until=-mm:ss.sss (decode) $desc... "
665 run_flac $dopt --skip=10 --until=-0:01.1001 -o z50c.skip10.until-0_01.1001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
666 $CMP 50c.skip10.until39.$in_fmt z50c.skip10.until-0_01.1001.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-0:01.1001 (decode) $desc"
667 rm -f z50c.skip10.until-0_01.1001.$in_fmt
668 echo OK
670 rm -f z50c.$out_fmt
673 test_skip_until raw flac
674 test_skip_until wav flac
675 test_skip_until aiff flac
676 test_skip_until flac flac
677 #@@@if [ $has_ogg = yes ] ; then
678 #@@@ #@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
679 #@@@ test_skip_until ogg flac
680 #@@@fi
682 if [ $has_ogg = yes ] ; then
683 test_skip_until raw ogg
684 test_skip_until wav ogg
685 test_skip_until aiff ogg
686 #@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
687 #@@@test_skip_until flac ogg
688 #@@@test_skip_until ogg ogg
691 echo "testing seek extremes:"
693 run_flac --verify --force $SILENT --no-padding --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=16 --channels=2 --blocksize=576 noise.raw || die "ERROR generating FLAC file"
695 if [ $is_win = no ] ; then
696 total_noise_cdda_samples=`run_metaflac --show-total-samples noise.flac`
697 [ $? = 0 ] || die "ERROR getting total sample count from noise.flac"
698 else
699 # some flavors of cygwin don't seem to treat the \x0d as a word
700 # separator, so we hard code it. we'll just have to fix it later
701 # if we change the way noise.flac is made.
702 total_noise_cdda_samples=393216
705 echo -n "testing --skip=0... "
706 run_flac $wav_dopt --skip=0 -o z.wav noise.flac || die "ERROR decoding FLAC file noise.flac"
707 echo OK
709 for delta in 2 1 ; do
710 n=`expr $total_noise_cdda_samples - $delta`
711 echo -n "testing --skip=$n... "
712 run_flac $wav_dopt --skip=$n -o z.wav noise.flac || die "ERROR decoding FLAC file noise.flac"
713 echo OK
714 done
716 rm noise.flac z.wav
719 ############################################################################
720 # test --input-size
721 ############################################################################
723 #@@@ cat will not work on old cygwin, need to fix
724 if [ $is_win = no ] ; then
725 echo -n "testing --input-size=50 --skip=10... "
726 cat 50c.raw | run_flac $raw_eopt --input-size=50 --skip=10 -o z50c.skip10.flac - || die "ERROR generating FLAC file"
727 run_flac $raw_dopt -o z50c.skip10.raw z50c.skip10.flac || die "ERROR decoding FLAC file"
728 cmp 50c.skip10.raw z50c.skip10.raw || die "ERROR: file mismatch for --input-size=50 --skip=10"
729 rm -f z50c.skip10.raw z50c.skip10.flac
730 echo OK
734 ############################################################################
735 # test --cue
736 ############################################################################
739 # create the cue sheet
741 cuesheet=cuetest.cue
742 cat > $cuesheet << EOF
743 CATALOG 1234567890123
744 FILE "blah" WAVE
745 TRACK 01 AUDIO
746 INDEX 01 0
747 INDEX 02 10
748 INDEX 03 20
749 TRACK 02 AUDIO
750 INDEX 01 30
751 TRACK 04 AUDIO
752 INDEX 01 40
755 test_cue ()
757 in_fmt=$1
758 out_fmt=$2
760 [ "$in_fmt" = wav ] || [ "$in_fmt" = aiff ] || [ "$in_fmt" = raw ] || [ "$in_fmt" = flac ] || [ "$in_fmt" = ogg ] || die "ERROR: internal error, bad 'in' format '$in_fmt'"
762 [ "$out_fmt" = flac ] || [ "$out_fmt" = ogg ] || die "ERROR: internal error, bad 'out' format '$out_fmt'"
764 if [ $in_fmt = raw ] ; then
765 eopt="$raw_eopt"
766 dopt="$raw_dopt"
767 else
768 eopt="$wav_eopt"
769 dopt="$wav_dopt"
772 if ( [ $in_fmt = flac ] || [ $in_fmt = ogg ] ) && ( [ $out_fmt = flac ] || [ $out_fmt = ogg ] ) ; then
773 CMP=md5cmp
774 else
775 CMP=cmp
778 if [ $out_fmt = ogg ] ; then
779 eopt="--ogg $eopt"
782 desc="($in_fmt<->$out_fmt)"
785 # for this we need just need just one FLAC file; --cue only works while decoding
787 run_flac $eopt --cuesheet=$cuesheet -o z50c.cue.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
789 # To make it easy to translate from cue point to sample numbers, the
790 # file has a sample rate of 10 Hz and a cuesheet like so:
792 # TRACK 01, INDEX 01 : 0:00.00 -> sample 0
793 # TRACK 01, INDEX 02 : 0:01.00 -> sample 10
794 # TRACK 01, INDEX 03 : 0:02.00 -> sample 20
795 # TRACK 02, INDEX 01 : 0:03.00 -> sample 30
796 # TRACK 04, INDEX 01 : 0:04.00 -> sample 40
798 echo -n "testing --cue=- $desc... "
799 run_flac $dopt -o z50c.cued.$in_fmt --cue=- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
800 $CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=- $desc"
801 rm -f z50c.cued.$in_fmt
802 echo OK
804 echo -n "testing --cue=1.0 $desc... "
805 run_flac $dopt -o z50c.cued.$in_fmt --cue=1.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
806 $CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.0 $desc"
807 rm -f z50c.cued.$in_fmt
808 echo OK
810 echo -n "testing --cue=1.0- $desc... "
811 run_flac $dopt -o z50c.cued.$in_fmt --cue=1.0- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
812 $CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.0- $desc"
813 rm -f z50c.cued.$in_fmt
814 echo OK
816 echo -n "testing --cue=1.1 $desc... "
817 run_flac $dopt -o z50c.cued.$in_fmt --cue=1.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
818 $CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.1 $desc"
819 rm -f z50c.cued.$in_fmt
820 echo OK
822 echo -n "testing --cue=1.1- $desc... "
823 run_flac $dopt -o z50c.cued.$in_fmt --cue=1.1- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
824 $CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.1- $desc"
825 rm -f z50c.cued.$in_fmt
826 echo OK
828 echo -n "testing --cue=1.2 $desc... "
829 run_flac $dopt -o z50c.cued.$in_fmt --cue=1.2 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
830 $CMP 50c.skip10.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.2 $desc"
831 rm -f z50c.cued.$in_fmt
832 echo OK
834 echo -n "testing --cue=1.2- $desc... "
835 run_flac $dopt -o z50c.cued.$in_fmt --cue=1.2- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
836 $CMP 50c.skip10.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.2- $desc"
837 rm -f z50c.cued.$in_fmt
838 echo OK
840 echo -n "testing --cue=1.4 $desc... "
841 run_flac $dopt -o z50c.cued.$in_fmt --cue=1.4 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
842 $CMP 50c.skip20.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.4 $desc"
843 rm -f z50c.cued.$in_fmt
844 echo OK
846 echo -n "testing --cue=1.4- $desc... "
847 run_flac $dopt -o z50c.cued.$in_fmt --cue=1.4- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
848 $CMP 50c.skip20.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.4- $desc"
849 rm -f z50c.cued.$in_fmt
850 echo OK
852 echo -n "testing --cue=-5.0 $desc... "
853 run_flac $dopt -o z50c.cued.$in_fmt --cue=-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
854 $CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=-5.0 $desc"
855 rm -f z50c.cued.$in_fmt
856 echo OK
858 echo -n "testing --cue=-4.1 $desc... "
859 run_flac $dopt -o z50c.cued.$in_fmt --cue=-4.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
860 $CMP 50c.until40.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=-4.1 $desc"
861 rm -f z50c.cued.$in_fmt
862 echo OK
864 echo -n "testing --cue=-3.1 $desc... "
865 run_flac $dopt -o z50c.cued.$in_fmt --cue=-3.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
866 $CMP 50c.until40.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=-3.1 $desc"
867 rm -f z50c.cued.$in_fmt
868 echo OK
870 echo -n "testing --cue=-1.4 $desc... "
871 run_flac $dopt -o z50c.cued.$in_fmt --cue=-1.4 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
872 $CMP 50c.until30.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=-1.4 $desc"
873 rm -f z50c.cued.$in_fmt
874 echo OK
876 echo -n "testing --cue=1.0-5.0 $desc... "
877 run_flac $dopt -o z50c.cued.$in_fmt --cue=1.0-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
878 $CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.0-5.0 $desc"
879 rm -f z50c.cued.$in_fmt
880 echo OK
882 echo -n "testing --cue=1.1-5.0 $desc... "
883 run_flac $dopt -o z50c.cued.$in_fmt --cue=1.1-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
884 $CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.1-5.0 $desc"
885 rm -f z50c.cued.$in_fmt
886 echo OK
888 echo -n "testing --cue=1.2-4.1 $desc... "
889 run_flac $dopt -o z50c.cued.$in_fmt --cue=1.2-4.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
890 $CMP 50c.skip10.until40.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.2-4.1 $desc"
891 rm -f z50c.cued.$in_fmt
892 echo OK
894 echo -n "testing --cue=1.4-2.0 $desc... "
895 run_flac $dopt -o z50c.cued.$in_fmt --cue=1.4-2.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
896 $CMP 50c.skip20.until30.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.4-2.0 $desc"
897 rm -f z50c.cued.$in_fmt
898 echo OK
900 rm -f z50c.cue.$out_fmt
903 test_cue raw flac
904 test_cue wav flac
905 test_cue aiff flac
906 test_cue flac flac
907 #@@@if [ $has_ogg = yes ] ; then
908 #@@@ #@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
909 #@@@ test_cue ogg flac
910 #@@@fi
912 if [ $has_ogg = yes ] ; then
913 test_cue raw ogg
914 test_cue wav ogg
915 test_cue aiff ogg
916 #@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
917 #@@@test_cue flac ogg
918 #@@@test_cue ogg ogg
921 ############################################################################
922 # test 'fixup' code that happens when a FLAC file with total_samples == 0
923 # in the STREAMINFO block is converted to WAVE or AIFF, requiring the
924 # decoder go back and fix up the chunk headers
925 ############################################################################
927 echo -n "WAVE fixup test... "
929 echo -n "prepare... "
930 convert_to_wav noise "$raw_eopt" "$wav_dopt" || die "ERROR creating reference WAVE"
932 echo -n "encode... "
933 # the pipe from 'cat' to 'flac' does not work on cygwin because of the EOF/
934 # binary-mode stdin problem, so we use an undocumented option to metaflac to
935 # set the total sample count to 0
936 if [ $is_win = yes ] ; then
937 run_flac $raw_eopt noise.raw -o fixup.flac || die "ERROR generating FLAC file"
938 run_metaflac --set-total-samples=0 fixup.flac 2> /dev/null
939 else
940 cat noise.raw | run_flac $raw_eopt - -c > fixup.flac || die "ERROR generating FLAC file"
943 echo -n "decode... "
944 run_flac $wav_dopt fixup.flac -o fixup.wav || die "ERROR decoding FLAC file"
946 echo -n "compare... "
947 cmp noise.wav fixup.wav || die "ERROR: file mismatch"
949 echo OK
950 rm -f noise.wav fixup.wav fixup.flac
952 echo -n "AIFF fixup test... "
954 echo -n "prepare... "
955 convert_to_aiff noise "$raw_eopt" "$wav_dopt" || die "ERROR creating reference AIFF"
957 echo -n "encode... "
958 # the pipe from 'cat' to 'flac' does not work on cygwin because of the EOF/
959 # binary-mode stdin problem, so we use an undocumented option to metaflac to
960 # set the total sample count to 0
961 if [ $is_win = yes ] ; then
962 run_flac $raw_eopt noise.raw -o fixup.flac || die "ERROR generating FLAC file"
963 run_metaflac --set-total-samples=0 fixup.flac 2> /dev/null
964 else
965 cat noise.raw | run_flac $raw_eopt - -c > fixup.flac || die "ERROR generating FLAC file"
968 echo -n "decode... "
969 run_flac $wav_dopt fixup.flac -o fixup.aiff || die "ERROR decoding FLAC file"
971 echo -n "compare... "
972 cmp noise.aiff fixup.aiff || die "ERROR: file mismatch"
974 echo OK
975 rm -f noise.aiff fixup.aiff fixup.flac
978 ############################################################################
979 # multi-file tests
980 ############################################################################
982 echo "Generating multiple input files from noise..."
983 multifile_format_decode="--endian=big --sign=signed"
984 multifile_format_encode="$multifile_format_decode --sample-rate=44100 --bps=16 --channels=2 --no-padding"
985 short_noise_cdda_samples=`expr $total_noise_cdda_samples / 8`
986 run_flac --verify --force $SILENT --force-raw-format $multifile_format_encode --until=$short_noise_cdda_samples -o shortnoise.flac noise.raw || die "ERROR generating FLAC file"
987 run_flac --decode --force $SILENT shortnoise.flac -o shortnoise.raw --force-raw-format $multifile_format_decode || die "ERROR generating RAW file"
988 run_flac --decode --force $SILENT shortnoise.flac || die "ERROR generating WAVE file"
989 run_flac --decode --force $SILENT shortnoise.flac -o shortnoise.aiff || die "ERROR generating AIFF file"
990 cp shortnoise.flac file0.flac
991 cp shortnoise.flac file1.flac
992 cp shortnoise.flac file2.flac
993 rm -f shortnoise.flac
994 cp shortnoise.wav file0.wav
995 cp shortnoise.wav file1.wav
996 cp shortnoise.wav file2.wav
997 rm -f shortnoise.wav
998 cp shortnoise.aiff file0.aiff
999 cp shortnoise.aiff file1.aiff
1000 cp shortnoise.aiff file2.aiff
1001 rm -f shortnoise.aiff
1002 cp shortnoise.raw file0.raw
1003 cp shortnoise.raw file1.raw
1004 cp shortnoise.raw file2.raw
1005 rm -f shortnoise.raw
1006 # create authoritative sector-aligned files for comparison
1007 file0_samples=`expr \( $short_noise_cdda_samples / 588 \) \* 588`
1008 file0_remainder=`expr $short_noise_cdda_samples - $file0_samples`
1009 file1_samples=`expr \( \( $file0_remainder + $short_noise_cdda_samples \) / 588 \) \* 588`
1010 file1_remainder=`expr $file0_remainder + $short_noise_cdda_samples - $file1_samples`
1011 file1_samples=`expr $file1_samples - $file0_remainder`
1012 file2_samples=`expr \( \( $file1_remainder + $short_noise_cdda_samples \) / 588 \) \* 588`
1013 file2_remainder=`expr $file1_remainder + $short_noise_cdda_samples - $file2_samples`
1014 file2_samples=`expr $file2_samples - $file1_remainder`
1015 if [ $file2_remainder != '0' ] ; then
1016 file2_samples=`expr $file2_samples + $file2_remainder`
1017 file2_remainder=`expr 588 - $file2_remainder`
1020 dd if=file0.raw ibs=4 count=$file0_samples of=file0s.raw 2>/dev/null || $dddie
1021 dd if=file0.raw ibs=4 count=$file0_remainder of=file1s.raw skip=$file0_samples 2>/dev/null || $dddie
1022 dd if=file1.raw ibs=4 count=$file1_samples of=z.raw 2>/dev/null || $dddie
1023 cat z.raw >> file1s.raw || die "ERROR: cat-ing sector-aligned files"
1024 dd if=file1.raw ibs=4 count=$file1_remainder of=file2s.raw skip=$file1_samples 2>/dev/null || $dddie
1025 dd if=file2.raw ibs=4 count=$file2_samples of=z.raw 2>/dev/null || $dddie
1026 cat z.raw >> file2s.raw || die "ERROR: cat-ing sector-aligned files"
1027 dd if=/dev/zero ibs=4 count=$file2_remainder of=z.raw 2>/dev/null || $dddie
1028 cat z.raw >> file2s.raw || die "ERROR: cat-ing sector-aligned files"
1029 rm -f z.raw
1031 convert_to_wav file0s "$multifile_format_encode --force" "$SILENT --force --decode" || die "ERROR creating authoritative sector-aligned WAVE"
1032 convert_to_wav file1s "$multifile_format_encode --force" "$SILENT --force --decode" || die "ERROR creating authoritative sector-aligned WAVE"
1033 convert_to_wav file2s "$multifile_format_encode --force" "$SILENT --force --decode" || die "ERROR creating authoritative sector-aligned WAVE"
1035 convert_to_aiff file0s "$multifile_format_encode --force" "$SILENT --force --decode" || die "ERROR creating authoritative sector-aligned AIFF"
1036 convert_to_aiff file1s "$multifile_format_encode --force" "$SILENT --force --decode" || die "ERROR creating authoritative sector-aligned AIFF"
1037 convert_to_aiff file2s "$multifile_format_encode --force" "$SILENT --force --decode" || die "ERROR creating authoritative sector-aligned AIFF"
1039 test_multifile ()
1041 input_type=$1
1042 streamtype=$2
1043 sector_align=$3
1044 encode_options="$4"
1046 extra_encode_options=""
1047 extra_decode_options=""
1048 if [ $input_type = "raw" ] ; then
1049 extra_encode_options="--force-raw-format $multifile_format_encode"
1050 extra_decode_options="--force-raw-format $multifile_format_decode"
1051 else
1052 if [ $input_type = "aiff" ] ; then
1053 extra_decode_options="--force-aiff-format"
1057 if [ $streamtype = ogg ] ; then
1058 suffix=oga
1059 encode_options="$encode_options --ogg"
1060 else
1061 suffix=flac
1064 if [ $sector_align = sector_align ] ; then
1065 encode_options="$encode_options --sector-align"
1068 if [ $input_type = flac ] || [ $input_type = ogg ] ; then
1069 CMP=md5cmp
1070 else
1071 CMP=cmp
1074 for n in 0 1 2 ; do
1075 cp file$n.$input_type file${n}x.$input_type
1076 done
1077 run_flac --force $encode_options $extra_encode_options file0x.$input_type file1x.$input_type file2x.$input_type || die "ERROR"
1078 run_flac --force --decode $extra_decode_options file0x.$suffix file1x.$suffix file2x.$suffix || die "ERROR"
1079 if [ $sector_align != sector_align ] ; then
1080 for n in 0 1 2 ; do
1081 $CMP file$n.$input_type file${n}x.$input_type || die "ERROR: file mismatch on file #$n"
1082 done
1083 else
1084 for n in 0 1 2 ; do
1085 $CMP file${n}s.$input_type file${n}x.$input_type || die "ERROR: file mismatch on file #$n"
1086 done
1088 for n in 0 1 2 ; do
1089 rm -f file${n}x.$suffix file${n}x.$input_type
1090 done
1093 input_types="raw wav aiff flac"
1094 #@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
1095 #@@@if [ $has_ogg = yes ] ; then
1096 #@@@ input_types="$input_types ogg"
1097 #@@@fi
1098 for input_type in $input_types ; do
1099 echo "Testing multiple $input_type files without verify..."
1100 test_multifile $input_type flac no_sector_align ""
1102 echo "Testing multiple $input_type files with verify..."
1103 test_multifile $input_type flac no_sector_align "--verify"
1105 if [ $input_type != flac ] && [ $input_type != ogg ] ; then # --sector-align not supported for FLAC input
1106 echo "Testing multiple $input_type files with --sector-align, without verify..."
1107 test_multifile $input_type flac sector_align ""
1109 echo "Testing multiple $input_type files with --sector-align, with verify..."
1110 test_multifile $input_type flac sector_align "--verify"
1113 if [ $has_ogg = yes ] ; then
1114 echo "Testing multiple $input_type files with --ogg, without verify..."
1115 test_multifile $input_type ogg no_sector_align ""
1117 echo "Testing multiple $input_type files with --ogg, with verify..."
1118 test_multifile $input_type ogg no_sector_align "--verify"
1120 if [ $input_type != flac ] ; then # --sector-align not supported for FLAC input
1121 echo "Testing multiple $input_type files with --ogg and --sector-align, without verify..."
1122 test_multifile $input_type ogg sector_align ""
1124 echo "Testing multiple $input_type files with --ogg and --sector-align, with verify..."
1125 test_multifile $input_type ogg sector_align "--verify"
1128 echo "Testing multiple $input_type files with --ogg and --serial-number, with verify..."
1129 test_multifile $input_type ogg no_sector_align "--serial-number=321 --verify"
1131 done
1134 ############################################################################
1135 # test --keep-foreign-metadata
1136 ############################################################################
1138 echo "Testing --keep-foreign-metadata..."
1140 rt_test_wav wacky1.wav '--keep-foreign-metadata'
1141 rt_test_wav wacky2.wav '--keep-foreign-metadata'
1142 rt_test_w64 wacky1.w64 '--keep-foreign-metadata'
1143 rt_test_w64 wacky2.w64 '--keep-foreign-metadata'
1144 rt_test_rf64 wacky1.rf64 '--keep-foreign-metadata'
1145 rt_test_rf64 wacky2.rf64 '--keep-foreign-metadata'
1148 ############################################################################
1149 # test the metadata-handling properties of flac-to-flac encoding
1150 ############################################################################
1152 echo "Testing the metadata-handling properties of flac-to-flac encoding..."
1154 testdir="flac-to-flac-metadata-test-files"
1155 filter ()
1157 # minor danger, changing vendor strings might change the length of the
1158 # VORBIS_COMMENT block, but if we add "^ length: " to the patterns,
1159 # we lose info about PADDING size that we need
1160 grep -Ev '^ vendor string: |^ m..imum .....size: ' | sed -e 's/, stream_offset.*//'
1162 flac2flac ()
1164 file="$1"
1165 case="$2"
1166 args="$3"
1167 expect="$case-expect.meta"
1168 echo -n "$case... "
1169 run_flac $SILENT -f -o out.flac $args $file || die "ERROR encoding FLAC file"
1170 run_metaflac --list out.flac | filter > out.meta || die "ERROR listing metadata of output FLAC file"
1171 diff -q -w $expect out.meta 2>/dev/null || die "ERROR: metadata does not match expected $expect"
1172 echo OK
1175 #filter=', stream_offset.*|^ vendor string: |^ length: |^ m..imum .....size: '
1176 cd $testdir || die "ERROR changing to directory $testdir"
1178 # case 00a: no alterations on a file with all metadata types, keep all metadata, in same order
1179 flac2flac input-SCVAUP.flac case00a ""
1180 # case 01a: on file with multiple PADDING blocks, they should be aggregated into one at the end
1181 flac2flac input-SCVPAP.flac case01a ""
1182 # case 01b: on file with multiple PADDING blocks and --no-padding specified, they should all be deleted
1183 flac2flac input-SCVPAP.flac case01b "--no-padding"
1184 # case 01c: on file with multiple PADDING blocks and -P specified, they should all be overwritten with -P value
1185 flac2flac input-SCVPAP.flac case01c "-P 1234"
1186 # case 01d: on file with no PADDING blocks, use -P setting
1187 flac2flac input-SCVA.flac case01d "-P 1234"
1188 # case 01e: on file with no PADDING blocks and no -P given, use default padding
1189 flac2flac input-SCVA.flac case01e ""
1190 # case 02a: on file with no VORBIS_COMMENT block, add new VORBIS_COMMENT
1191 flac2flac input-SCPAP.flac case02a ""
1192 # case 02b: on file with no VORBIS_COMMENT block and --tag, add new VORBIS_COMMENT with tags
1193 flac2flac input-SCPAP.flac case02b "--tag=artist=0"
1194 # case 02c: on file with VORBIS_COMMENT block and --tag, replace existing VORBIS_COMMENT with new tags
1195 flac2flac input-SCVAUP.flac case02c "$TOTALLY_SILENT --tag=artist=0"
1196 # case 03a: on file with no CUESHEET block and --cuesheet specified, add it
1197 flac2flac input-SVAUP.flac case03a "--cuesheet=input0.cue"
1198 # case 03b: on file with CUESHEET block and --cuesheet specified, overwrite existing CUESHEET
1199 flac2flac input-SCVAUP.flac case03b "$TOTALLY_SILENT --cuesheet=input0.cue"
1200 # case 03c: on file with CUESHEET block and size-changing option specified, drop existing CUESHEET
1201 flac2flac input-SCVAUP.flac case03c "$TOTALLY_SILENT --skip=1"
1202 # case 04a: on file with no SEEKTABLE block and --no-seektable specified, no SEEKTABLE
1203 flac2flac input-VA.flac case04a "--no-padding --no-seektable"
1204 # case 04b: on file with no SEEKTABLE block and -S specified, new SEEKTABLE
1205 flac2flac input-VA.flac case04b "--no-padding -S 5x"
1206 # case 04c: on file with no SEEKTABLE block and no seektable options specified, new SEEKTABLE with default points
1207 flac2flac input-VA.flac case04c "--no-padding"
1208 # case 04d: on file with SEEKTABLE block and --no-seektable specified, drop existing SEEKTABLE
1209 flac2flac input-SCVA.flac case04d "--no-padding --no-seektable"
1210 # case 04e: on file with SEEKTABLE block and -S specified, overwrite existing SEEKTABLE
1211 flac2flac input-SCVA.flac case04e "$TOTALLY_SILENT --no-padding -S 5x"
1212 # case 04f: on file with SEEKTABLE block and size-changing option specified, drop existing SEEKTABLE, new SEEKTABLE with default points
1213 #(already covered by case03c)
1215 rm -f out.flac out.meta
1217 #@@@ when metaflac handles ogg flac, duplicate flac2flac tests here
1219 cd ..