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