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