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