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