Declare UTF-8 encoding for changelog
[platform/upstream/flac.git] / test / test_flac.sh
1 #!/bin/sh
2
3 #  FLAC - Free Lossless Audio Codec
4 #  Copyright (C) 2001-2009  Josh Coalson
5 #  Copyright (C) 2011-2013  Xiph.Org Foundation
6 #
7 #  This file is part the FLAC project.  FLAC is comprised of several
8 #  components distributed under difference 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.
15 #
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.
20
21 # we use '.' as decimal separator in --skip/--until tests
22 export LANG=C LC_ALL=C
23
24 die ()
25 {
26         echo $* 1>&2
27         exit 1
28 }
29
30 dddie="die ERROR: creating files with dd"
31
32 if [ x = x"$1" ] ; then
33         BUILD=debug
34 else
35         BUILD="$1"
36 fi
37
38 # change to 'false' to show flac output (useful for debugging)
39 if true ; then
40         SILENT='--silent'
41         TOTALLY_SILENT='--totally-silent'
42 else
43         SILENT=''
44         TOTALLY_SILENT=''
45 fi
46
47 LD_LIBRARY_PATH=`pwd`/../src/libFLAC/.libs:$LD_LIBRARY_PATH
48 LD_LIBRARY_PATH=`pwd`/../src/share/grabbag/.libs:$LD_LIBRARY_PATH
49 LD_LIBRARY_PATH=`pwd`/../src/share/getopt/.libs:$LD_LIBRARY_PATH
50 LD_LIBRARY_PATH=`pwd`/../src/share/replaygain_analysis/.libs:$LD_LIBRARY_PATH
51 LD_LIBRARY_PATH=`pwd`/../src/share/replaygain_synthesis/.libs:$LD_LIBRARY_PATH
52 LD_LIBRARY_PATH=`pwd`/../src/share/utf8/.libs:$LD_LIBRARY_PATH
53 LD_LIBRARY_PATH=`pwd`/../objs/$BUILD/lib:$LD_LIBRARY_PATH
54 export LD_LIBRARY_PATH
55 export MALLOC_CHECK_=3
56 export MALLOC_PERTURB_=$((1$(date +%N) % 255 + 1))
57 PATH=`pwd`/../src/flac:$PATH
58 PATH=`pwd`/../src/metaflac:$PATH
59 PATH=`pwd`/../src/test_streams:$PATH
60 PATH=`pwd`/../objs/$BUILD/bin:$PATH
61
62 flac --help 1>/dev/null 2>/dev/null || die "ERROR can't find flac executable"
63
64 run_flac ()
65 {
66         if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
67                 echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 flac $*" >>test_flac.valgrind.log
68                 valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 flac $* 4>>test_flac.valgrind.log
69         else
70                 flac $*
71         fi
72 }
73
74 run_metaflac ()
75 {
76         if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
77                 echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 metaflac $*" >>test_flac.valgrind.log
78                 valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 metaflac $* 4>>test_flac.valgrind.log
79         else
80                 metaflac $*
81         fi
82 }
83
84 md5cmp ()
85 {
86         #n=`( [ -f "$1" ] && [ -f "$2" ] && metaflac --show-md5sum --no-filename "$1" "$2" 2>/dev/null || die "ERROR: comparing FLAC files $1 and $2 by MD5 sum" ) | uniq | wc -l`
87         n=`( [ -f "$1" ] && [ -f "$2" ] && metaflac --show-md5sum --no-filename "$1" "$2" 2>/dev/null || exit 1 ) | uniq | wc -l`
88         [ "$n" != "" ] && [ $n = 1 ]
89 }
90
91 if [ `env | grep -ic '^comspec='` != 0 ] ; then
92         is_win=yes
93 else
94         is_win=no
95 fi
96
97 echo "Checking for --ogg support in flac..."
98 if flac --ogg $SILENT --force-raw-format --endian=little --sign=signed --channels=1 --bps=8 --sample-rate=44100 -c $0 1>/dev/null 2>&1 ; then
99         has_ogg=yes;
100         echo "flac --ogg works"
101 else
102         has_ogg=no;
103         echo "flac --ogg doesn't work"
104 fi
105
106 echo "Generating streams..."
107 if [ ! -f wacky1.wav ] ; then
108         test_streams || die "ERROR during test_streams"
109 fi
110
111 ############################################################################
112 # test that flac doesn't automatically overwrite files unless -f is used
113 ############################################################################
114
115 echo "Try encoding to a file that exists; should fail"
116 cp wacky1.wav exist.wav
117 touch exist.flac
118 if run_flac $TOTALLY_SILENT -0 exist.wav ; then
119         die "ERROR: it should have failed but didn't"
120 else
121         echo "OK, it failed as it should"
122 fi
123
124 echo "Try encoding with -f to a file that exists; should succeed"
125 if run_flac $TOTALLY_SILENT -0 --force exist.wav ; then
126         echo "OK, it succeeded as it should"
127 else
128         die "ERROR: it should have succeeded but didn't"
129 fi
130
131 echo "Try decoding to a file that exists; should fail"
132 if run_flac $TOTALLY_SILENT -d exist.flac ; then
133         die "ERROR: it should have failed but didn't"
134 else
135         echo "OK, it failed as it should"
136 fi
137
138 echo "Try decoding with -f to a file that exists; should succeed"
139 if run_flac $TOTALLY_SILENT -d -f exist.flac ; then
140         echo "OK, it succeeded as it should"
141 else
142         die "ERROR: it should have succeeded but didn't"
143 fi
144
145 rm -f exist.wav exist.flac
146
147 ############################################################################
148 # test fractional block sizes
149 ############################################################################
150
151 test_fractional ()
152 {
153         blocksize=$1
154         samples=$2
155         dd if=noise.raw ibs=4 count=$samples of=pbs.raw 2>/dev/null || $dddie
156         echo -n "fractional block size test (blocksize=$blocksize samples=$samples) encode... "
157         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"
158         echo -n "decode... "
159         run_flac $SILENT --force --decode --force-raw-format --endian=little --sign=signed -o pbs.cmp pbs.flac || die "ERROR"
160         echo -n "compare... "
161         cmp pbs.raw pbs.cmp || die "ERROR: file mismatch"
162         echo "OK"
163         rm -f pbs.raw pbs.flac pbs.cmp
164 }
165
166 # The special significance of 2048 is it's the # of samples that flac calls
167 # FLAC__stream_encoder_process() on.
168 #
169 # We're trying to make sure the 1-sample overread logic in the stream encoder
170 # (used for last-block checking) works; these values probe around common
171 # multiples of the flac sample chunk size (2048) and the blocksize.
172 for samples in 31 32 33 34 35 2046 2047 2048 2049 2050 ; do
173         test_fractional 33 $samples
174 done
175 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
176         test_fractional 256 $samples
177 done
178 for samples in 1022 1023 1024 1025 1026 2046 2047 2048 2049 2050 4094 4095 4096 4097 4098 ; do
179         test_fractional 2048 $samples
180 done
181 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
182         test_fractional 4608 $samples
183 done
184
185 ############################################################################
186 # basic 'round-trip' tests of various kinds of streams
187 ############################################################################
188
189 rt_test_raw ()
190 {
191         f="$1"
192         extra="$2"
193         channels=`echo $f | awk -F- '{print $2}'`
194         bps=`echo $f | awk -F- '{print $3}'`
195         echo -n "round-trip test ($f) encode... "
196         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"
197         echo -n "decode... "
198         run_flac $SILENT --force --decode --force-raw-format --endian=little --sign=signed -o rt.raw $extra rt.flac || die "ERROR"
199         echo -n "compare... "
200         cmp $f rt.raw || die "ERROR: file mismatch"
201         echo "OK"
202         rm -f rt.flac rt.raw
203 }
204
205 rt_test_wav ()
206 {
207         f="$1"
208         extra="$2"
209         echo -n "round-trip test ($f) encode... "
210         run_flac $SILENT --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
211         echo -n "decode... "
212         run_flac $SILENT --force --decode --channel-map=none -o rt.wav $extra rt.flac || die "ERROR"
213         echo -n "compare... "
214         cmp $f rt.wav || die "ERROR: file mismatch"
215         echo "OK"
216         rm -f rt.flac rt.wav
217 }
218
219 rt_test_w64 ()
220 {
221         f="$1"
222         extra="$2"
223         echo -n "round-trip test ($f) encode... "
224         run_flac $SILENT --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
225         echo -n "decode... "
226         run_flac $SILENT --force --decode --channel-map=none -o rt.w64 $extra rt.flac || die "ERROR"
227         echo -n "compare... "
228         cmp $f rt.w64 || die "ERROR: file mismatch"
229         echo "OK"
230         rm -f rt.flac rt.w64
231 }
232
233 rt_test_rf64 ()
234 {
235         f="$1"
236         extra="$2"
237         echo -n "round-trip test ($f) encode... "
238         run_flac $SILENT --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
239         echo -n "decode... "
240         run_flac $SILENT --force --decode --channel-map=none -o rt.rf64 $extra rt.flac || die "ERROR"
241         echo -n "compare... "
242         cmp $f rt.rf64 || die "ERROR: file mismatch"
243         echo "OK"
244         rm -f rt.flac rt.rf64
245 }
246
247 rt_test_aiff ()
248 {
249         f="$1"
250         extra="$2"
251         echo -n "round-trip test ($f) encode... "
252         run_flac $SILENT --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
253         echo -n "decode... "
254         run_flac $SILENT --force --decode --channel-map=none -o rt.aiff $extra rt.flac || die "ERROR"
255         echo -n "compare... "
256         cmp $f rt.aiff || die "ERROR: file mismatch"
257         echo "OK"
258         rm -f rt.flac rt.aiff
259 }
260
261 # assumes input file is WAVE; does not check the metadata-preserving features of flac-to-flac; that is checked later
262 rt_test_flac ()
263 {
264         f="$1"
265         extra="$2"
266         echo -n "round-trip test ($f->flac->flac->wav) encode... "
267         run_flac $SILENT --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
268         echo -n "re-encode... "
269         run_flac $SILENT --force --verify --lax -o rt2.flac rt.flac || die "ERROR"
270         echo -n "decode... "
271         run_flac $SILENT --force --decode --channel-map=none -o rt.wav $extra rt2.flac || die "ERROR"
272         echo -n "compare... "
273         cmp $f rt.wav || die "ERROR: file mismatch"
274         echo "OK"
275         rm -f rt.wav rt.flac rt2.flac
276 }
277
278 # assumes input file is WAVE; does not check the metadata-preserving features of flac-to-flac; that is checked later
279 rt_test_ogg_flac ()
280 {
281         f="$1"
282         extra="$2"
283         echo -n "round-trip test ($f->oggflac->oggflac->wav) encode... "
284         run_flac $SILENT --force --verify --channel-map=none --no-padding --lax -o rt.oga --ogg $extra $f || die "ERROR"
285         echo -n "re-encode... "
286         run_flac $SILENT --force --verify --lax -o rt2.oga --ogg rt.oga || die "ERROR"
287         echo -n "decode... "
288         run_flac $SILENT --force --decode --channel-map=none -o rt.wav $extra rt2.oga || die "ERROR"
289         echo -n "compare... "
290         cmp $f rt.wav || die "ERROR: file mismatch"
291         echo "OK"
292         rm -f rt.wav rt.oga rt2.oga
293 }
294
295 for f in rt-*.raw ; do
296         rt_test_raw $f
297 done
298 for f in rt-*.wav ; do
299         rt_test_wav $f
300 done
301 for f in rt-*.w64 ; do
302         rt_test_w64 $f
303 done
304 for f in rt-*.rf64 ; do
305         rt_test_rf64 $f
306 done
307 for f in rt-*.aiff ; do
308         rt_test_aiff $f
309 done
310 for f in rt-*.wav ; do
311         rt_test_flac $f
312 done
313 if [ $has_ogg = yes ] ; then
314         for f in rt-*.wav ; do
315                 rt_test_ogg_flac $f
316         done
317 fi
318
319 ############################################################################
320 # test --skip and --until
321 ############################################################################
322
323 #
324 # first make some chopped-up raw files
325 #
326 echo "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMN" > master.raw
327 dd if=master.raw ibs=1 count=50 of=50c.raw 2>/dev/null || $dddie
328 dd if=master.raw ibs=1 skip=10 count=40 of=50c.skip10.raw 2>/dev/null || $dddie
329 dd if=master.raw ibs=1 skip=11 count=39 of=50c.skip11.raw 2>/dev/null || $dddie
330 dd if=master.raw ibs=1 skip=20 count=30 of=50c.skip20.raw 2>/dev/null || $dddie
331 dd if=master.raw ibs=1 skip=30 count=20 of=50c.skip30.raw 2>/dev/null || $dddie
332 dd if=master.raw ibs=1 skip=40 count=10 of=50c.skip40.raw 2>/dev/null || $dddie
333 dd if=master.raw ibs=1 count=10 of=50c.until10.raw 2>/dev/null || $dddie
334 dd if=master.raw ibs=1 count=20 of=50c.until20.raw 2>/dev/null || $dddie
335 dd if=master.raw ibs=1 count=30 of=50c.until30.raw 2>/dev/null || $dddie
336 dd if=master.raw ibs=1 count=39 of=50c.until39.raw 2>/dev/null || $dddie
337 dd if=master.raw ibs=1 count=40 of=50c.until40.raw 2>/dev/null || $dddie
338 dd if=master.raw ibs=1 skip=10 count=20 of=50c.skip10.until30.raw 2>/dev/null || $dddie
339 dd if=master.raw ibs=1 skip=10 count=29 of=50c.skip10.until39.raw 2>/dev/null || $dddie
340 dd if=master.raw ibs=1 skip=10 count=30 of=50c.skip10.until40.raw 2>/dev/null || $dddie
341 dd if=master.raw ibs=1 skip=20 count=10 of=50c.skip20.until30.raw 2>/dev/null || $dddie
342 dd if=master.raw ibs=1 skip=20 count=20 of=50c.skip20.until40.raw 2>/dev/null || $dddie
343
344 wav_eopt="$SILENT --force --verify --no-padding --lax"
345 wav_dopt="$SILENT --force --decode"
346
347 raw_eopt="$wav_eopt --force-raw-format --endian=big --sign=signed --sample-rate=10 --bps=8 --channels=1"
348 raw_dopt="$wav_dopt --force-raw-format --endian=big --sign=signed"
349
350 #
351 # convert them to WAVE/AIFF/Ogg FLAC files
352 #
353 convert_to_wav ()
354 {
355         run_flac "$2" $1.raw || die "ERROR converting $1.raw to WAVE"
356         run_flac "$3" $1.flac || die "ERROR converting $1.raw to WAVE"
357 }
358 convert_to_wav 50c "$raw_eopt" "$wav_dopt"
359 convert_to_wav 50c.skip10 "$raw_eopt" "$wav_dopt"
360 convert_to_wav 50c.skip11 "$raw_eopt" "$wav_dopt"
361 convert_to_wav 50c.skip20 "$raw_eopt" "$wav_dopt"
362 convert_to_wav 50c.skip30 "$raw_eopt" "$wav_dopt"
363 convert_to_wav 50c.skip40 "$raw_eopt" "$wav_dopt"
364 convert_to_wav 50c.until10 "$raw_eopt" "$wav_dopt"
365 convert_to_wav 50c.until20 "$raw_eopt" "$wav_dopt"
366 convert_to_wav 50c.until30 "$raw_eopt" "$wav_dopt"
367 convert_to_wav 50c.until39 "$raw_eopt" "$wav_dopt"
368 convert_to_wav 50c.until40 "$raw_eopt" "$wav_dopt"
369 convert_to_wav 50c.skip10.until30 "$raw_eopt" "$wav_dopt"
370 convert_to_wav 50c.skip10.until39 "$raw_eopt" "$wav_dopt"
371 convert_to_wav 50c.skip10.until40 "$raw_eopt" "$wav_dopt"
372 convert_to_wav 50c.skip20.until30 "$raw_eopt" "$wav_dopt"
373 convert_to_wav 50c.skip20.until40 "$raw_eopt" "$wav_dopt"
374
375 convert_to_aiff ()
376 {
377         run_flac "$2" $1.raw || die "ERROR converting $1.raw to AIFF"
378         run_flac "$3" $1.flac -o $1.aiff || die "ERROR converting $1.raw to AIFF"
379 }
380 convert_to_aiff 50c "$raw_eopt" "$wav_dopt"
381 convert_to_aiff 50c.skip10 "$raw_eopt" "$wav_dopt"
382 convert_to_aiff 50c.skip11 "$raw_eopt" "$wav_dopt"
383 convert_to_aiff 50c.skip20 "$raw_eopt" "$wav_dopt"
384 convert_to_aiff 50c.skip30 "$raw_eopt" "$wav_dopt"
385 convert_to_aiff 50c.skip40 "$raw_eopt" "$wav_dopt"
386 convert_to_aiff 50c.until10 "$raw_eopt" "$wav_dopt"
387 convert_to_aiff 50c.until20 "$raw_eopt" "$wav_dopt"
388 convert_to_aiff 50c.until30 "$raw_eopt" "$wav_dopt"
389 convert_to_aiff 50c.until39 "$raw_eopt" "$wav_dopt"
390 convert_to_aiff 50c.until40 "$raw_eopt" "$wav_dopt"
391 convert_to_aiff 50c.skip10.until30 "$raw_eopt" "$wav_dopt"
392 convert_to_aiff 50c.skip10.until39 "$raw_eopt" "$wav_dopt"
393 convert_to_aiff 50c.skip10.until40 "$raw_eopt" "$wav_dopt"
394 convert_to_aiff 50c.skip20.until30 "$raw_eopt" "$wav_dopt"
395 convert_to_aiff 50c.skip20.until40 "$raw_eopt" "$wav_dopt"
396
397 convert_to_ogg ()
398 {
399         run_flac "$wav_eopt" --ogg $1.wav || die "ERROR converting $1.raw to Ogg FLAC"
400 }
401 if [ $has_ogg = yes ] ; then
402         convert_to_ogg 50c
403         convert_to_ogg 50c.skip10
404         convert_to_ogg 50c.skip11
405         convert_to_ogg 50c.skip20
406         convert_to_ogg 50c.skip30
407         convert_to_ogg 50c.skip40
408         convert_to_ogg 50c.until10
409         convert_to_ogg 50c.until20
410         convert_to_ogg 50c.until30
411         convert_to_ogg 50c.until39
412         convert_to_ogg 50c.until40
413         convert_to_ogg 50c.skip10.until30
414         convert_to_ogg 50c.skip10.until39
415         convert_to_ogg 50c.skip10.until40
416         convert_to_ogg 50c.skip20.until30
417         convert_to_ogg 50c.skip20.until40
418 fi
419
420 test_skip_until ()
421 {
422         in_fmt=$1
423         out_fmt=$2
424
425         [ "$in_fmt" = wav ] || [ "$in_fmt" = aiff ] || [ "$in_fmt" = raw ] || [ "$in_fmt" = flac ] || [ "$in_fmt" = ogg ] || die "ERROR: internal error, bad 'in' format '$in_fmt'"
426
427         [ "$out_fmt" = flac ] || [ "$out_fmt" = ogg ] || die "ERROR: internal error, bad 'out' format '$out_fmt'"
428
429         if [ $in_fmt = raw ] ; then
430                 eopt="$raw_eopt"
431                 dopt="$raw_dopt"
432         else
433                 eopt="$wav_eopt"
434                 dopt="$wav_dopt"
435         fi
436
437         if ( [ $in_fmt = flac ] || [ $in_fmt = ogg ] ) && ( [ $out_fmt = flac ] || [ $out_fmt = ogg ] ) ; then
438                 CMP=md5cmp
439         else
440                 CMP=cmp
441         fi
442
443         if [ $out_fmt = ogg ] ; then
444                 eopt="--ogg $eopt"
445         fi
446
447         #
448         # test --skip when encoding
449         #
450
451         desc="($in_fmt<->$out_fmt)"
452
453         echo -n "testing --skip=# (encode) $desc... "
454         run_flac $eopt --skip=10 -o z50c.skip10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
455         [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.$in_fmt z50c.skip10.$out_fmt || die "ERROR decoding FLAC file $desc"
456         $CMP 50c.skip10.$in_fmt z50c.skip10.$in_fmt || die "ERROR: file mismatch for --skip=10 (encode) $desc"
457         rm -f z50c.skip10.$out_fmt z50c.skip10.$in_fmt
458         echo OK
459
460         echo -n "testing --skip=mm:ss (encode) $desc... "
461         run_flac $eopt --skip=0:01 -o z50c.skip0_01.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
462         [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip0_01.$in_fmt z50c.skip0_01.$out_fmt || die "ERROR decoding FLAC file $desc"
463         $CMP 50c.skip10.$in_fmt z50c.skip0_01.$in_fmt || die "ERROR: file mismatch for --skip=0:01 (encode) $desc"
464         rm -f z50c.skip0_01.$out_fmt z50c.skip0_01.$in_fmt
465         echo OK
466
467         echo -n "testing --skip=mm:ss.sss (encode) $desc... "
468         run_flac $eopt --skip=0:01.1001 -o z50c.skip0_01.1001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
469         [ $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"
470         $CMP 50c.skip11.$in_fmt z50c.skip0_01.1001.$in_fmt || die "ERROR: file mismatch for --skip=0:01.1001 (encode) $desc"
471         rm -f z50c.skip0_01.1001.$out_fmt z50c.skip0_01.1001.$in_fmt
472         echo OK
473
474         #
475         # test --skip when decoding
476         #
477
478         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"
479
480         echo -n "testing --skip=# (decode) $desc... "
481         run_flac $dopt --skip=10 -o z50c.skip10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
482         $CMP 50c.skip10.$in_fmt z50c.skip10.$in_fmt || die "ERROR: file mismatch for --skip=10 (decode) $desc"
483         rm -f z50c.skip10.$in_fmt
484         echo OK
485
486         echo -n "testing --skip=mm:ss (decode) $desc... "
487         run_flac $dopt --skip=0:01 -o z50c.skip0_01.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
488         $CMP 50c.skip10.$in_fmt z50c.skip0_01.$in_fmt || die "ERROR: file mismatch for --skip=0:01 (decode) $desc"
489         rm -f z50c.skip0_01.$in_fmt
490         echo OK
491
492         echo -n "testing --skip=mm:ss.sss (decode) $desc... "
493         run_flac $dopt --skip=0:01.1001 -o z50c.skip0_01.1001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
494         $CMP 50c.skip11.$in_fmt z50c.skip0_01.1001.$in_fmt || die "ERROR: file mismatch for --skip=0:01.1001 (decode) $desc"
495         rm -f z50c.skip0_01.1001.$in_fmt
496         echo OK
497
498         rm -f z50c.$out_fmt
499
500         #
501         # test --until when encoding
502         #
503
504         echo -n "testing --until=# (encode) $desc... "
505         run_flac $eopt --until=40 -o z50c.until40.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
506         [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until40.$in_fmt z50c.until40.$out_fmt || die "ERROR decoding FLAC file $desc"
507         $CMP 50c.until40.$in_fmt z50c.until40.$in_fmt || die "ERROR: file mismatch for --until=40 (encode) $desc"
508         rm -f z50c.until40.$out_fmt z50c.until40.$in_fmt
509         echo OK
510
511         echo -n "testing --until=mm:ss (encode) $desc... "
512         run_flac $eopt --until=0:04 -o z50c.until0_04.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
513         [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until0_04.$in_fmt z50c.until0_04.$out_fmt || die "ERROR decoding FLAC file $desc"
514         $CMP 50c.until40.$in_fmt z50c.until0_04.$in_fmt || die "ERROR: file mismatch for --until=0:04 (encode) $desc"
515         rm -f z50c.until0_04.$out_fmt z50c.until0_04.$in_fmt
516         echo OK
517
518         echo -n "testing --until=mm:ss.sss (encode) $desc... "
519         run_flac $eopt --until=0:03.9001 -o z50c.until0_03.9001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
520         [ $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"
521         $CMP 50c.until39.$in_fmt z50c.until0_03.9001.$in_fmt || die "ERROR: file mismatch for --until=0:03.9001 (encode) $desc"
522         rm -f z50c.until0_03.9001.$out_fmt z50c.until0_03.9001.$in_fmt
523         echo OK
524
525         echo -n "testing --until=-# (encode) $desc... "
526         run_flac $eopt --until=-10 -o z50c.until-10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
527         [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until-10.$in_fmt z50c.until-10.$out_fmt || die "ERROR decoding FLAC file $desc"
528         $CMP 50c.until40.$in_fmt z50c.until-10.$in_fmt || die "ERROR: file mismatch for --until=-10 (encode) $desc"
529         rm -f z50c.until-10.$out_fmt z50c.until-10.$in_fmt
530         echo OK
531
532         echo -n "testing --until=-mm:ss (encode) $desc... "
533         run_flac $eopt --until=-0:01 -o z50c.until-0_01.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
534         [ $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"
535         $CMP 50c.until40.$in_fmt z50c.until-0_01.$in_fmt || die "ERROR: file mismatch for --until=-0:01 (encode) $desc"
536         rm -f z50c.until-0_01.$out_fmt z50c.until-0_01.$in_fmt
537         echo OK
538
539         echo -n "testing --until=-mm:ss.sss (encode) $desc... "
540         run_flac $eopt --until=-0:01.1001 -o z50c.until-0_01.1001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
541         [ $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"
542         $CMP 50c.until39.$in_fmt z50c.until-0_01.1001.$in_fmt || die "ERROR: file mismatch for --until=-0:01.1001 (encode) $desc"
543         rm -f z50c.until-0_01.1001.$out_fmt z50c.until-0_01.1001.$in_fmt
544         echo OK
545
546         #
547         # test --until when decoding
548         #
549
550         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"
551
552         echo -n "testing --until=# (decode) $desc... "
553         run_flac $dopt --until=40 -o z50c.until40.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
554         $CMP 50c.until40.$in_fmt z50c.until40.$in_fmt || die "ERROR: file mismatch for --until=40 (decode) $desc"
555         rm -f z50c.until40.$in_fmt
556         echo OK
557
558         echo -n "testing --until=mm:ss (decode) $desc... "
559         run_flac $dopt --until=0:04 -o z50c.until0_04.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
560         $CMP 50c.until40.$in_fmt z50c.until0_04.$in_fmt || die "ERROR: file mismatch for --until=0:04 (decode) $desc"
561         rm -f z50c.until0_04.$in_fmt
562         echo OK
563
564         echo -n "testing --until=mm:ss.sss (decode) $desc... "
565         run_flac $dopt --until=0:03.9001 -o z50c.until0_03.9001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
566         $CMP 50c.until39.$in_fmt z50c.until0_03.9001.$in_fmt || die "ERROR: file mismatch for --until=0:03.9001 (decode) $desc"
567         rm -f z50c.until0_03.9001.$in_fmt
568         echo OK
569
570         echo -n "testing --until=-# (decode) $desc... "
571         run_flac $dopt --until=-10 -o z50c.until-10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
572         $CMP 50c.until40.$in_fmt z50c.until-10.$in_fmt || die "ERROR: file mismatch for --until=-10 (decode) $desc"
573         rm -f z50c.until-10.$in_fmt
574         echo OK
575
576         echo -n "testing --until=-mm:ss (decode) $desc... "
577         run_flac $dopt --until=-0:01 -o z50c.until-0_01.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
578         $CMP 50c.until40.$in_fmt z50c.until-0_01.$in_fmt || die "ERROR: file mismatch for --until=-0:01 (decode) $desc"
579         rm -f z50c.until-0_01.$in_fmt
580         echo OK
581
582         echo -n "testing --until=-mm:ss.sss (decode) $desc... "
583         run_flac $dopt --until=-0:01.1001 -o z50c.until-0_01.1001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
584         $CMP 50c.until39.$in_fmt z50c.until-0_01.1001.$in_fmt || die "ERROR: file mismatch for --until=-0:01.1001 (decode) $desc"
585         rm -f z50c.until-0_01.1001.$in_fmt
586         echo OK
587
588         rm -f z50c.$out_fmt
589
590         #
591         # test --skip and --until when encoding
592         #
593
594         echo -n "testing --skip=10 --until=# (encode) $desc... "
595         run_flac $eopt --skip=10 --until=40 -o z50c.skip10.until40.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
596         [ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until40.$in_fmt z50c.skip10.until40.$out_fmt || die "ERROR decoding FLAC file $desc"
597         $CMP 50c.skip10.until40.$in_fmt z50c.skip10.until40.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=40 (encode) $desc"
598         rm -f z50c.skip10.until40.$out_fmt z50c.skip10.until40.$in_fmt
599         echo OK
600
601         echo -n "testing --skip=10 --until=mm:ss (encode) $desc... "
602         run_flac $eopt --skip=10 --until=0:04 -o z50c.skip10.until0_04.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
603         [ $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"
604         $CMP 50c.skip10.until40.$in_fmt z50c.skip10.until0_04.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=0:04 (encode) $desc"
605         rm -f z50c.skip10.until0_04.$out_fmt z50c.skip10.until0_04.$in_fmt
606         echo OK
607
608         echo -n "testing --skip=10 --until=mm:ss.sss (encode) $desc... "
609         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"
610         [ $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"
611         $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"
612         rm -f z50c.skip10.until0_03.9001.$out_fmt z50c.skip10.until0_03.9001.$in_fmt
613         echo OK
614
615         echo -n "testing --skip=10 --until=+# (encode) $desc... "
616         run_flac $eopt --skip=10 --until=+30 -o z50c.skip10.until+30.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
617         [ $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"
618         $CMP 50c.skip10.until40.$in_fmt z50c.skip10.until+30.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=+30 (encode) $desc"
619         rm -f z50c.skip10.until+30.$out_fmt z50c.skip10.until+30.$in_fmt
620         echo OK
621
622         echo -n "testing --skip=10 --until=+mm:ss (encode) $desc... "
623         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"
624         [ $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"
625         $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"
626         rm -f z50c.skip10.until+0_03.$out_fmt z50c.skip10.until+0_03.$in_fmt
627         echo OK
628
629         echo -n "testing --skip=10 --until=+mm:ss.sss (encode) $desc... "
630         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"
631         [ $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"
632         $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"
633         rm -f z50c.skip10.until+0_02.9001.$out_fmt z50c.skip10.until+0_02.9001.$in_fmt
634         echo OK
635
636         echo -n "testing --skip=10 --until=-# (encode) $desc... "
637         run_flac $eopt --skip=10 --until=-10 -o z50c.skip10.until-10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
638         [ $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"
639         $CMP 50c.skip10.until40.$in_fmt z50c.skip10.until-10.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-10 (encode) $desc"
640         rm -f z50c.skip10.until-10.$out_fmt z50c.skip10.until-10.$in_fmt
641         echo OK
642
643         echo -n "testing --skip=10 --until=-mm:ss (encode) $desc... "
644         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"
645         [ $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"
646         $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"
647         rm -f z50c.skip10.until-0_01.$out_fmt z50c.skip10.until-0_01.$in_fmt
648         echo OK
649
650         echo -n "testing --skip=10 --until=-mm:ss.sss (encode) $desc... "
651         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"
652         [ $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"
653         $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"
654         rm -f z50c.skip10.until-0_01.1001.$out_fmt z50c.skip10.until-0_01.1001.$in_fmt
655         echo OK
656
657         #
658         # test --skip and --until when decoding
659         #
660
661         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"
662
663
664         echo -n "testing --skip=10 --until=# (decode) $desc... "
665         run_flac $dopt --skip=10 --until=40 -o z50c.skip10.until40.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
666         $CMP 50c.skip10.until40.$in_fmt z50c.skip10.until40.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=40 (decode) $desc"
667         rm -f z50c.skip10.until40.$in_fmt
668         echo OK
669
670         echo -n "testing --skip=10 --until=mm:ss (decode) $desc... "
671         run_flac $dopt --skip=10 --until=0:04 -o z50c.skip10.until0_04.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
672         $CMP 50c.skip10.until40.$in_fmt z50c.skip10.until0_04.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=0:04 (decode) $desc"
673         rm -f z50c.skip10.until0_04.$in_fmt
674         echo OK
675
676         echo -n "testing --skip=10 --until=mm:ss.sss (decode) $desc... "
677         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"
678         $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"
679         rm -f z50c.skip10.until0_03.9001.$in_fmt
680         echo OK
681
682         echo -n "testing --skip=10 --until=-# (decode) $desc... "
683         run_flac $dopt --skip=10 --until=-10 -o z50c.skip10.until-10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
684         $CMP 50c.skip10.until40.$in_fmt z50c.skip10.until-10.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-10 (decode) $desc"
685         rm -f z50c.skip10.until-10.$in_fmt
686         echo OK
687
688         echo -n "testing --skip=10 --until=-mm:ss (decode) $desc... "
689         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"
690         $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"
691         rm -f z50c.skip10.until-0_01.$in_fmt
692         echo OK
693
694         echo -n "testing --skip=10 --until=-mm:ss.sss (decode) $desc... "
695         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"
696         $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"
697         rm -f z50c.skip10.until-0_01.1001.$in_fmt
698         echo OK
699
700         rm -f z50c.$out_fmt
701 }
702
703 test_skip_until raw flac
704 test_skip_until wav flac
705 test_skip_until aiff flac
706 test_skip_until flac flac
707 #@@@if [ $has_ogg = yes ] ; then
708 #@@@    #@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
709 #@@@    test_skip_until ogg flac
710 #@@@fi
711
712 if [ $has_ogg = yes ] ; then
713         test_skip_until raw ogg
714         test_skip_until wav ogg
715         test_skip_until aiff ogg
716         #@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
717         #@@@test_skip_until flac ogg
718         #@@@test_skip_until ogg ogg
719 fi
720
721 echo "testing seek extremes:"
722
723 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"
724
725 if [ $is_win = no ] ; then
726         total_noise_cdda_samples=`run_metaflac --show-total-samples noise.flac`
727         [ $? = 0 ] || die "ERROR getting total sample count from noise.flac"
728 else
729         # some flavors of cygwin don't seem to treat the \x0d as a word
730         # separator, so we hard code it.  we'll just have to fix it later
731         # if we change the way noise.flac is made.
732         total_noise_cdda_samples=393216
733 fi
734
735 echo -n "testing --skip=0... "
736 run_flac $wav_dopt --skip=0 -o z.wav noise.flac || die "ERROR decoding FLAC file noise.flac"
737 echo OK
738
739 for delta in 2 1 ; do
740         n=`expr $total_noise_cdda_samples - $delta`
741         echo -n "testing --skip=$n... "
742         run_flac $wav_dopt --skip=$n -o z.wav noise.flac || die "ERROR decoding FLAC file noise.flac"
743         echo OK
744 done
745
746 rm noise.flac z.wav
747
748
749 ############################################################################
750 # test --input-size
751 ############################################################################
752
753 #@@@ cat will not work on old cygwin, need to fix
754 if [ $is_win = no ] ; then
755         echo -n "testing --input-size=50 --skip=10... "
756         cat 50c.raw | run_flac $raw_eopt --input-size=50 --skip=10 -o z50c.skip10.flac - || die "ERROR generating FLAC file"
757         run_flac $raw_dopt -o z50c.skip10.raw z50c.skip10.flac || die "ERROR decoding FLAC file"
758         cmp 50c.skip10.raw z50c.skip10.raw || die "ERROR: file mismatch for --input-size=50 --skip=10"
759         rm -f z50c.skip10.raw z50c.skip10.flac
760         echo OK
761 fi
762
763
764 ############################################################################
765 # test --cue
766 ############################################################################
767
768 #
769 # create the cue sheet
770 #
771 cuesheet=cuetest.cue
772 cat > $cuesheet << EOF
773 CATALOG 1234567890123
774 FILE "blah" WAVE
775   TRACK 01 AUDIO
776     INDEX 01 0
777     INDEX 02 10
778     INDEX 03 20
779   TRACK 02 AUDIO
780     INDEX 01 30
781   TRACK 04 AUDIO
782     INDEX 01 40
783 EOF
784
785 test_cue ()
786 {
787         in_fmt=$1
788         out_fmt=$2
789
790         [ "$in_fmt" = wav ] || [ "$in_fmt" = aiff ] || [ "$in_fmt" = raw ] || [ "$in_fmt" = flac ] || [ "$in_fmt" = ogg ] || die "ERROR: internal error, bad 'in' format '$in_fmt'"
791
792         [ "$out_fmt" = flac ] || [ "$out_fmt" = ogg ] || die "ERROR: internal error, bad 'out' format '$out_fmt'"
793
794         if [ $in_fmt = raw ] ; then
795                 eopt="$raw_eopt"
796                 dopt="$raw_dopt"
797         else
798                 eopt="$wav_eopt"
799                 dopt="$wav_dopt"
800         fi
801
802         if ( [ $in_fmt = flac ] || [ $in_fmt = ogg ] ) && ( [ $out_fmt = flac ] || [ $out_fmt = ogg ] ) ; then
803                 CMP=md5cmp
804         else
805                 CMP=cmp
806         fi
807
808         if [ $out_fmt = ogg ] ; then
809                 eopt="--ogg $eopt"
810         fi
811
812         desc="($in_fmt<->$out_fmt)"
813
814         #
815         # for this we need just need just one FLAC file; --cue only works while decoding
816         #
817         run_flac $eopt --cuesheet=$cuesheet -o z50c.cue.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
818
819         # To make it easy to translate from cue point to sample numbers, the
820         # file has a sample rate of 10 Hz and a cuesheet like so:
821         #
822         # TRACK 01, INDEX 01 : 0:00.00 -> sample 0
823         # TRACK 01, INDEX 02 : 0:01.00 -> sample 10
824         # TRACK 01, INDEX 03 : 0:02.00 -> sample 20
825         # TRACK 02, INDEX 01 : 0:03.00 -> sample 30
826         # TRACK 04, INDEX 01 : 0:04.00 -> sample 40
827         #
828         echo -n "testing --cue=- $desc... "
829         run_flac $dopt -o z50c.cued.$in_fmt --cue=- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
830         $CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=- $desc"
831         rm -f z50c.cued.$in_fmt
832         echo OK
833
834         echo -n "testing --cue=1.0 $desc... "
835         run_flac $dopt -o z50c.cued.$in_fmt --cue=1.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
836         $CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.0 $desc"
837         rm -f z50c.cued.$in_fmt
838         echo OK
839
840         echo -n "testing --cue=1.0- $desc... "
841         run_flac $dopt -o z50c.cued.$in_fmt --cue=1.0- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
842         $CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.0- $desc"
843         rm -f z50c.cued.$in_fmt
844         echo OK
845
846         echo -n "testing --cue=1.1 $desc... "
847         run_flac $dopt -o z50c.cued.$in_fmt --cue=1.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
848         $CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.1 $desc"
849         rm -f z50c.cued.$in_fmt
850         echo OK
851
852         echo -n "testing --cue=1.1- $desc... "
853         run_flac $dopt -o z50c.cued.$in_fmt --cue=1.1- 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=1.1- $desc"
855         rm -f z50c.cued.$in_fmt
856         echo OK
857
858         echo -n "testing --cue=1.2 $desc... "
859         run_flac $dopt -o z50c.cued.$in_fmt --cue=1.2 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
860         $CMP 50c.skip10.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.2 $desc"
861         rm -f z50c.cued.$in_fmt
862         echo OK
863
864         echo -n "testing --cue=1.2- $desc... "
865         run_flac $dopt -o z50c.cued.$in_fmt --cue=1.2- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
866         $CMP 50c.skip10.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.2- $desc"
867         rm -f z50c.cued.$in_fmt
868         echo OK
869
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.skip20.$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
875
876         echo -n "testing --cue=1.4- $desc... "
877         run_flac $dopt -o z50c.cued.$in_fmt --cue=1.4- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
878         $CMP 50c.skip20.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.4- $desc"
879         rm -f z50c.cued.$in_fmt
880         echo OK
881
882         echo -n "testing --cue=-5.0 $desc... "
883         run_flac $dopt -o z50c.cued.$in_fmt --cue=-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=-5.0 $desc"
885         rm -f z50c.cued.$in_fmt
886         echo OK
887
888         echo -n "testing --cue=-4.1 $desc... "
889         run_flac $dopt -o z50c.cued.$in_fmt --cue=-4.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
890         $CMP 50c.until40.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=-4.1 $desc"
891         rm -f z50c.cued.$in_fmt
892         echo OK
893
894         echo -n "testing --cue=-3.1 $desc... "
895         run_flac $dopt -o z50c.cued.$in_fmt --cue=-3.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
896         $CMP 50c.until40.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=-3.1 $desc"
897         rm -f z50c.cued.$in_fmt
898         echo OK
899
900         echo -n "testing --cue=-1.4 $desc... "
901         run_flac $dopt -o z50c.cued.$in_fmt --cue=-1.4 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
902         $CMP 50c.until30.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=-1.4 $desc"
903         rm -f z50c.cued.$in_fmt
904         echo OK
905
906         echo -n "testing --cue=1.0-5.0 $desc... "
907         run_flac $dopt -o z50c.cued.$in_fmt --cue=1.0-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
908         $CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.0-5.0 $desc"
909         rm -f z50c.cued.$in_fmt
910         echo OK
911
912         echo -n "testing --cue=1.1-5.0 $desc... "
913         run_flac $dopt -o z50c.cued.$in_fmt --cue=1.1-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
914         $CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.1-5.0 $desc"
915         rm -f z50c.cued.$in_fmt
916         echo OK
917
918         echo -n "testing --cue=1.2-4.1 $desc... "
919         run_flac $dopt -o z50c.cued.$in_fmt --cue=1.2-4.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
920         $CMP 50c.skip10.until40.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.2-4.1 $desc"
921         rm -f z50c.cued.$in_fmt
922         echo OK
923
924         echo -n "testing --cue=1.4-2.0 $desc... "
925         run_flac $dopt -o z50c.cued.$in_fmt --cue=1.4-2.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
926         $CMP 50c.skip20.until30.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.4-2.0 $desc"
927         rm -f z50c.cued.$in_fmt
928         echo OK
929
930         rm -f z50c.cue.$out_fmt
931 }
932
933 test_cue raw flac
934 test_cue wav flac
935 test_cue aiff flac
936 test_cue flac flac
937 #@@@if [ $has_ogg = yes ] ; then
938 #@@@    #@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
939 #@@@    test_cue ogg flac
940 #@@@fi
941
942 if [ $has_ogg = yes ] ; then
943         test_cue raw ogg
944         test_cue wav ogg
945         test_cue aiff ogg
946         #@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
947         #@@@test_cue flac ogg
948         #@@@test_cue ogg ogg
949 fi
950
951 ############################################################################
952 # test 'fixup' code that happens when a FLAC file with total_samples == 0
953 # in the STREAMINFO block is converted to WAVE or AIFF, requiring the
954 # decoder go back and fix up the chunk headers
955 ############################################################################
956
957 echo -n "WAVE fixup test... "
958
959 echo -n "prepare... "
960 convert_to_wav noise "$raw_eopt" "$wav_dopt" || die "ERROR creating reference WAVE"
961
962 echo -n "encode... "
963 # the pipe from 'cat' to 'flac' does not work on cygwin because of the EOF/
964 # binary-mode stdin problem, so we use an undocumented option to metaflac to
965 # set the total sample count to 0
966 if [ $is_win = yes ] ; then
967         run_flac $raw_eopt noise.raw -o fixup.flac || die "ERROR generating FLAC file"
968         run_metaflac --set-total-samples=0 fixup.flac 2> /dev/null
969 else
970         cat noise.raw | run_flac $raw_eopt - -c > fixup.flac || die "ERROR generating FLAC file"
971 fi
972
973 echo -n "decode... "
974 run_flac $wav_dopt fixup.flac -o fixup.wav || die "ERROR decoding FLAC file"
975
976 echo -n "compare... "
977 cmp noise.wav fixup.wav || die "ERROR: file mismatch"
978
979 echo OK
980 rm -f noise.wav fixup.wav fixup.flac
981
982 echo -n "AIFF fixup test... "
983
984 echo -n "prepare... "
985 convert_to_aiff noise "$raw_eopt" "$wav_dopt" || die "ERROR creating reference AIFF"
986
987 echo -n "encode... "
988 # the pipe from 'cat' to 'flac' does not work on cygwin because of the EOF/
989 # binary-mode stdin problem, so we use an undocumented option to metaflac to
990 # set the total sample count to 0
991 if [ $is_win = yes ] ; then
992         run_flac $raw_eopt noise.raw -o fixup.flac || die "ERROR generating FLAC file"
993         run_metaflac --set-total-samples=0 fixup.flac 2> /dev/null
994 else
995         cat noise.raw | run_flac $raw_eopt - -c > fixup.flac || die "ERROR generating FLAC file"
996 fi
997
998 echo -n "decode... "
999 run_flac $wav_dopt fixup.flac -o fixup.aiff || die "ERROR decoding FLAC file"
1000
1001 echo -n "compare... "
1002 cmp noise.aiff fixup.aiff || die "ERROR: file mismatch"
1003
1004 echo OK
1005 rm -f noise.aiff fixup.aiff fixup.flac
1006
1007
1008 ############################################################################
1009 # multi-file tests
1010 ############################################################################
1011
1012 echo "Generating multiple input files from noise..."
1013 multifile_format_decode="--endian=big --sign=signed"
1014 multifile_format_encode="$multifile_format_decode --sample-rate=44100 --bps=16 --channels=2 --no-padding"
1015 short_noise_cdda_samples=`expr $total_noise_cdda_samples / 8`
1016 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"
1017 run_flac --decode --force $SILENT shortnoise.flac -o shortnoise.raw --force-raw-format $multifile_format_decode || die "ERROR generating RAW file"
1018 run_flac --decode --force $SILENT shortnoise.flac || die "ERROR generating WAVE file"
1019 run_flac --decode --force $SILENT shortnoise.flac -o shortnoise.aiff || die "ERROR generating AIFF file"
1020 cp shortnoise.flac file0.flac
1021 cp shortnoise.flac file1.flac
1022 cp shortnoise.flac file2.flac
1023 rm -f shortnoise.flac
1024 cp shortnoise.wav file0.wav
1025 cp shortnoise.wav file1.wav
1026 cp shortnoise.wav file2.wav
1027 rm -f shortnoise.wav
1028 cp shortnoise.aiff file0.aiff
1029 cp shortnoise.aiff file1.aiff
1030 cp shortnoise.aiff file2.aiff
1031 rm -f shortnoise.aiff
1032 cp shortnoise.raw file0.raw
1033 cp shortnoise.raw file1.raw
1034 cp shortnoise.raw file2.raw
1035 rm -f shortnoise.raw
1036 # create authoritative sector-aligned files for comparison
1037 file0_samples=`expr \( $short_noise_cdda_samples / 588 \) \* 588`
1038 file0_remainder=`expr $short_noise_cdda_samples - $file0_samples`
1039 file1_samples=`expr \( \( $file0_remainder + $short_noise_cdda_samples \) / 588 \) \* 588`
1040 file1_remainder=`expr $file0_remainder + $short_noise_cdda_samples - $file1_samples`
1041 file1_samples=`expr $file1_samples - $file0_remainder`
1042 file2_samples=`expr \( \( $file1_remainder + $short_noise_cdda_samples \) / 588 \) \* 588`
1043 file2_remainder=`expr $file1_remainder + $short_noise_cdda_samples - $file2_samples`
1044 file2_samples=`expr $file2_samples - $file1_remainder`
1045 if [ $file2_remainder != '0' ] ; then
1046         file2_samples=`expr $file2_samples + $file2_remainder`
1047         file2_remainder=`expr 588 - $file2_remainder`
1048 fi
1049
1050 dd if=file0.raw ibs=4 count=$file0_samples of=file0s.raw 2>/dev/null || $dddie
1051 dd if=file0.raw ibs=4 count=$file0_remainder of=file1s.raw skip=$file0_samples 2>/dev/null || $dddie
1052 dd if=file1.raw ibs=4 count=$file1_samples of=z.raw 2>/dev/null || $dddie
1053 cat z.raw >> file1s.raw || die "ERROR: cat-ing sector-aligned files"
1054 dd if=file1.raw ibs=4 count=$file1_remainder of=file2s.raw skip=$file1_samples 2>/dev/null || $dddie
1055 dd if=file2.raw ibs=4 count=$file2_samples of=z.raw 2>/dev/null || $dddie
1056 cat z.raw >> file2s.raw || die "ERROR: cat-ing sector-aligned files"
1057 dd if=/dev/zero ibs=4 count=$file2_remainder of=z.raw 2>/dev/null || $dddie
1058 cat z.raw >> file2s.raw || die "ERROR: cat-ing sector-aligned files"
1059 rm -f z.raw
1060
1061 convert_to_wav file0s "$multifile_format_encode --force" "$SILENT --force --decode" || die "ERROR creating authoritative sector-aligned WAVE"
1062 convert_to_wav file1s "$multifile_format_encode --force" "$SILENT --force --decode" || die "ERROR creating authoritative sector-aligned WAVE"
1063 convert_to_wav file2s "$multifile_format_encode --force" "$SILENT --force --decode" || die "ERROR creating authoritative sector-aligned WAVE"
1064
1065 convert_to_aiff file0s "$multifile_format_encode --force" "$SILENT --force --decode" || die "ERROR creating authoritative sector-aligned AIFF"
1066 convert_to_aiff file1s "$multifile_format_encode --force" "$SILENT --force --decode" || die "ERROR creating authoritative sector-aligned AIFF"
1067 convert_to_aiff file2s "$multifile_format_encode --force" "$SILENT --force --decode" || die "ERROR creating authoritative sector-aligned AIFF"
1068
1069 test_multifile ()
1070 {
1071         input_type=$1
1072         streamtype=$2
1073         sector_align=$3
1074         encode_options="$4"
1075
1076         extra_encode_options=""
1077         extra_decode_options=""
1078         if [ $input_type = "raw" ] ; then
1079                 extra_encode_options="--force-raw-format $multifile_format_encode"
1080                 extra_decode_options="--force-raw-format $multifile_format_decode"
1081         else
1082                 if [ $input_type = "aiff" ] ; then
1083                         extra_decode_options="--force-aiff-format"
1084                 fi
1085         fi
1086
1087         if [ $streamtype = ogg ] ; then
1088                 suffix=oga
1089                 encode_options="$encode_options --ogg"
1090         else
1091                 suffix=flac
1092         fi
1093
1094         if [ $sector_align = sector_align ] ; then
1095                 encode_options="$encode_options --sector-align"
1096         fi
1097
1098         if [ $input_type = flac ] || [ $input_type = ogg ] ; then
1099                 CMP=md5cmp
1100         else
1101                 CMP=cmp
1102         fi
1103
1104         for n in 0 1 2 ; do
1105                 cp file$n.$input_type file${n}x.$input_type
1106         done
1107         run_flac --force $encode_options $extra_encode_options file0x.$input_type file1x.$input_type file2x.$input_type || die "ERROR"
1108         run_flac --force --decode $extra_decode_options file0x.$suffix file1x.$suffix file2x.$suffix || die "ERROR"
1109         if [ $sector_align != sector_align ] ; then
1110                 for n in 0 1 2 ; do
1111                         $CMP file$n.$input_type file${n}x.$input_type || die "ERROR: file mismatch on file #$n"
1112                 done
1113         else
1114                 for n in 0 1 2 ; do
1115                         $CMP file${n}s.$input_type file${n}x.$input_type || die "ERROR: file mismatch on file #$n"
1116                 done
1117         fi
1118         for n in 0 1 2 ; do
1119                 rm -f file${n}x.$suffix file${n}x.$input_type
1120         done
1121 }
1122
1123 input_types="raw wav aiff flac"
1124 #@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
1125 #@@@if [ $has_ogg = yes ] ; then
1126 #@@@    input_types="$input_types ogg"
1127 #@@@fi
1128 for input_type in $input_types ; do
1129         echo "Testing multiple $input_type files without verify..."
1130         test_multifile $input_type flac no_sector_align ""
1131
1132         echo "Testing multiple $input_type files with verify..."
1133         test_multifile $input_type flac no_sector_align "--verify"
1134
1135         if [ $input_type != flac ] && [ $input_type != ogg ] ; then # --sector-align not supported for FLAC input
1136                 echo "Testing multiple $input_type files with --sector-align, without verify..."
1137                 test_multifile $input_type flac sector_align ""
1138
1139                 echo "Testing multiple $input_type files with --sector-align, with verify..."
1140                 test_multifile $input_type flac sector_align "--verify"
1141         fi
1142
1143         if [ $has_ogg = yes ] ; then
1144                 echo "Testing multiple $input_type files with --ogg, without verify..."
1145                 test_multifile $input_type ogg no_sector_align ""
1146
1147                 echo "Testing multiple $input_type files with --ogg, with verify..."
1148                 test_multifile $input_type ogg no_sector_align "--verify"
1149
1150                 if [ $input_type != flac ] ; then # --sector-align not supported for FLAC input
1151                         echo "Testing multiple $input_type files with --ogg and --sector-align, without verify..."
1152                         test_multifile $input_type ogg sector_align ""
1153
1154                         echo "Testing multiple $input_type files with --ogg and --sector-align, with verify..."
1155                         test_multifile $input_type ogg sector_align "--verify"
1156                 fi
1157
1158                 echo "Testing multiple $input_type files with --ogg and --serial-number, with verify..."
1159                 test_multifile $input_type ogg no_sector_align "--serial-number=321 --verify"
1160         fi
1161 done
1162
1163
1164 ############################################################################
1165 # test --keep-foreign-metadata
1166 ############################################################################
1167
1168 echo "Testing --keep-foreign-metadata..."
1169
1170 rt_test_wav wacky1.wav '--keep-foreign-metadata'
1171 rt_test_wav wacky2.wav '--keep-foreign-metadata'
1172 rt_test_w64 wacky1.w64 '--keep-foreign-metadata'
1173 rt_test_w64 wacky2.w64 '--keep-foreign-metadata'
1174 rt_test_rf64 wacky1.rf64 '--keep-foreign-metadata'
1175 rt_test_rf64 wacky2.rf64 '--keep-foreign-metadata'
1176
1177
1178 ############################################################################
1179 # test the metadata-handling properties of flac-to-flac encoding
1180 ############################################################################
1181
1182 echo "Testing the metadata-handling properties of flac-to-flac encoding..."
1183
1184 testdir="flac-to-flac-metadata-test-files"
1185 filter ()
1186 {
1187         # minor danger, changing vendor strings might change the length of the
1188         # VORBIS_COMMENT block, but if we add "^  length: " to the patterns,
1189         # we lose info about PADDING size that we need
1190         grep -Ev '^  vendor string: |^  m..imum .....size: ' | sed -e 's/, stream_offset.*//'
1191 }
1192 flac2flac ()
1193 {
1194         file="$1"
1195         case="$2"
1196         args="$3"
1197         expect="$case-expect.meta"
1198         echo -n "$case... "
1199         run_flac $SILENT -f -o out.flac $args $file || die "ERROR encoding FLAC file"
1200         run_metaflac --list out.flac | filter > out.meta || die "ERROR listing metadata of output FLAC file"
1201         diff -q -w $expect out.meta 2>/dev/null || die "ERROR: metadata does not match expected $expect"
1202         echo OK
1203 }
1204
1205 #filter=', stream_offset.*|^  vendor string: |^  length: |^  m..imum .....size: '
1206 cd $testdir || die "ERROR changing to directory $testdir"
1207
1208 # case 00a: no alterations on a file with all metadata types, keep all metadata, in same order
1209 flac2flac input-SCVAUP.flac case00a ""
1210 # case 01a: on file with multiple PADDING blocks, they should be aggregated into one at the end
1211 flac2flac input-SCVPAP.flac case01a ""
1212 # case 01b: on file with multiple PADDING blocks and --no-padding specified, they should all be deleted
1213 flac2flac input-SCVPAP.flac case01b "--no-padding"
1214 # case 01c: on file with multiple PADDING blocks and -P specified, they should all be overwritten with -P value
1215 flac2flac input-SCVPAP.flac case01c "-P 1234"
1216 # case 01d: on file with no PADDING blocks, use -P setting
1217 flac2flac input-SCVA.flac case01d "-P 1234"
1218 # case 01e: on file with no PADDING blocks and no -P given, use default padding
1219 flac2flac input-SCVA.flac case01e ""
1220 # case 02a: on file with no VORBIS_COMMENT block, add new VORBIS_COMMENT
1221 flac2flac input-SCPAP.flac case02a ""
1222 # case 02b: on file with no VORBIS_COMMENT block and --tag, add new VORBIS_COMMENT with tags
1223 flac2flac input-SCPAP.flac case02b "--tag=artist=0"
1224 # case 02c: on file with VORBIS_COMMENT block and --tag, replace existing VORBIS_COMMENT with new tags
1225 flac2flac input-SCVAUP.flac case02c "$TOTALLY_SILENT --tag=artist=0"
1226 # case 03a: on file with no CUESHEET block and --cuesheet specified, add it
1227 flac2flac input-SVAUP.flac case03a "--cuesheet=input0.cue"
1228 # case 03b: on file with CUESHEET block and --cuesheet specified, overwrite existing CUESHEET
1229 flac2flac input-SCVAUP.flac case03b "$TOTALLY_SILENT --cuesheet=input0.cue"
1230 # case 03c: on file with CUESHEET block and size-changing option specified, drop existing CUESHEET
1231 flac2flac input-SCVAUP.flac case03c "$TOTALLY_SILENT --skip=1"
1232 # case 04a: on file with no SEEKTABLE block and --no-seektable specified, no SEEKTABLE
1233 flac2flac input-VA.flac case04a "--no-padding --no-seektable"
1234 # case 04b: on file with no SEEKTABLE block and -S specified, new SEEKTABLE
1235 flac2flac input-VA.flac case04b "--no-padding -S 5x"
1236 # case 04c: on file with no SEEKTABLE block and no seektable options specified, new SEEKTABLE with default points
1237 flac2flac input-VA.flac case04c "--no-padding"
1238 # case 04d: on file with SEEKTABLE block and --no-seektable specified, drop existing SEEKTABLE
1239 flac2flac input-SCVA.flac case04d "--no-padding --no-seektable"
1240 # case 04e: on file with SEEKTABLE block and -S specified, overwrite existing SEEKTABLE
1241 flac2flac input-SCVA.flac case04e "$TOTALLY_SILENT --no-padding -S 5x"
1242 # case 04f: on file with SEEKTABLE block and size-changing option specified, drop existing SEEKTABLE, new SEEKTABLE with default points
1243 #(already covered by case03c)
1244
1245 rm -f out.flac out.meta
1246
1247 #@@@ when metaflac handles ogg flac, duplicate flac2flac tests here
1248
1249 cd ..