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