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