add --cue option to flac, and tests and documentation
[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  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 LD_LIBRARY_PATH=../src/libFLAC/.libs:../obj/release/lib:../obj/debug/lib:$LD_LIBRARY_PATH
27 export LD_LIBRARY_PATH
28 PATH=../src/flac:../src/test_streams:../obj/release/bin:../obj/debug/bin:$PATH
29
30 flac --help 1>/dev/null 2>/dev/null || die "ERROR can't find flac executable"
31
32 run_flac ()
33 {
34         if [ x"$FLAC__VALGRIND" = xyes ] ; then
35                 valgrind --leak-check=yes --show-reachable=yes --num-callers=100 --logfile-fd=4 flac $* 4>>test_flac.valgrind.log
36         else
37                 flac $*
38         fi
39 }
40
41 echo "Checking for --ogg support in flac..."
42 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
43         has_ogg=yes;
44         echo "flac --ogg works"
45 else
46         has_ogg=no;
47         echo "flac --ogg doesn't work"
48 fi
49
50
51 echo "Generating streams..."
52 if [ ! -f wacky1.wav ] ; then
53         test_streams || die "ERROR during test_streams"
54 fi
55
56 ############################################################################
57 # test that flac doesn't automatically overwrite files unless -f is used
58 ############################################################################
59
60 echo "Try encoding to a file that exists; should fail"
61 cp wacky1.wav exist.wav
62 touch exist.flac
63 if run_flac -s -0 exist.wav ; then
64         die "ERROR: it should have failed but didn't"
65 else
66         echo "OK, it failed as it should"
67 fi
68
69 echo "Try encoding with -f to a file that exists; should succeed"
70 if run_flac -s -0 --force exist.wav ; then
71         echo "OK, it succeeded as it should"
72 else
73         die "ERROR: it should have succeeded but didn't"
74 fi
75
76 echo "Try decoding to a file that exists; should fail"
77 if run_flac -s -d exist.flac ; then
78         die "ERROR: it should have failed but didn't"
79 else
80         echo "OK, it failed as it should"
81 fi
82
83 echo "Try decoding with -f to a file that exists; should succeed"
84 if run_flac -s -d -f exist.flac ; then
85         echo "OK, it succeeded as it should"
86 else
87         die "ERROR: it should have succeeded but didn't"
88 fi
89
90 rm -f exist.wav exist.flac
91
92 ############################################################################
93 # basic 'round-trip' tests of various kinds of streams
94 ############################################################################
95
96 rt_test_raw ()
97 {
98         f="$1"
99         channels=`echo $f | awk -F- '{print $2}'`
100         bytes_per_sample=`echo $f | awk -F- '{print $3}'`
101         bps=`expr $bytes_per_sample '*' 8`
102         echo -n "round-trip test ($f) encode... "
103         run_flac --silent --force --verify --force-raw-format --endian=little --sign=signed --sample-rate=44100 --bps=$bps --channels=$channels $f -o rt.flac || die "ERROR"
104         echo -n "decode... "
105         run_flac --silent --force --decode --force-raw-format --endian=little --sign=signed -o rt.raw rt.flac || die "ERROR"
106         echo -n "compare... "
107         cmp $f rt.raw || die "ERROR: file mismatch"
108         echo "OK"
109         rm -f rt.flac rt.raw
110 }
111
112 rt_test_wav ()
113 {
114         f="$1"
115         echo -n "round-trip test ($f) encode... "
116         run_flac --silent --force --verify $f -o rt.flac || die "ERROR"
117         echo -n "decode... "
118         run_flac --silent --force --decode -o rt.wav rt.flac || die "ERROR"
119         echo -n "compare... "
120         cmp $f rt.wav || die "ERROR: file mismatch"
121         echo "OK"
122         rm -f rt.flac rt.wav
123 }
124
125 rt_test_aiff ()
126 {
127         f="$1"
128         echo -n "round-trip test ($f) encode... "
129         run_flac --silent --force --verify $f -o rt.flac || die "ERROR"
130         echo -n "decode... "
131         run_flac --silent --force --decode -o rt.aiff rt.flac || die "ERROR"
132         echo -n "compare... "
133         cmp $f rt.aiff || die "ERROR: file mismatch"
134         echo "OK"
135         rm -f rt.flac rt.aiff
136 }
137
138 for f in rt-*.raw ; do
139         rt_test_raw $f
140 done
141 for f in rt-*.wav ; do
142         rt_test_wav $f
143 done
144 for f in rt-*.aiff ; do
145         rt_test_aiff $f
146 done
147
148 ############################################################################
149 # test --skip and --until
150 ############################################################################
151
152 #
153 # first make some chopped-up raw files
154 #
155 echo "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMN" > master.raw
156 dddie="die ERROR: creating files for --skip/--until tests"
157 dd if=master.raw ibs=1 count=50 of=50c.raw 2>/dev/null || $dddie
158 dd if=master.raw ibs=1 skip=10 count=40 of=50c.skip10.raw 2>/dev/null || $dddie
159 dd if=master.raw ibs=1 skip=11 count=39 of=50c.skip11.raw 2>/dev/null || $dddie
160 dd if=master.raw ibs=1 skip=20 count=30 of=50c.skip20.raw 2>/dev/null || $dddie
161 dd if=master.raw ibs=1 skip=30 count=20 of=50c.skip30.raw 2>/dev/null || $dddie
162 dd if=master.raw ibs=1 skip=40 count=10 of=50c.skip40.raw 2>/dev/null || $dddie
163 dd if=master.raw ibs=1 count=10 of=50c.until10.raw 2>/dev/null || $dddie
164 dd if=master.raw ibs=1 count=20 of=50c.until20.raw 2>/dev/null || $dddie
165 dd if=master.raw ibs=1 count=30 of=50c.until30.raw 2>/dev/null || $dddie
166 dd if=master.raw ibs=1 count=39 of=50c.until39.raw 2>/dev/null || $dddie
167 dd if=master.raw ibs=1 count=40 of=50c.until40.raw 2>/dev/null || $dddie
168 dd if=master.raw ibs=1 skip=10 count=20 of=50c.skip10.until30.raw 2>/dev/null || $dddie
169 dd if=master.raw ibs=1 skip=10 count=29 of=50c.skip10.until39.raw 2>/dev/null || $dddie
170 dd if=master.raw ibs=1 skip=10 count=30 of=50c.skip10.until40.raw 2>/dev/null || $dddie
171 dd if=master.raw ibs=1 skip=20 count=10 of=50c.skip20.until30.raw 2>/dev/null || $dddie
172 dd if=master.raw ibs=1 skip=20 count=20 of=50c.skip20.until40.raw 2>/dev/null || $dddie
173
174 wav_eopt="--silent --force --verify --lax"
175 wav_dopt="--silent --force --decode"
176
177 raw_eopt="$wav_eopt --force-raw-format --endian=big --sign=signed --sample-rate=10 --bps=8 --channels=1"
178 raw_dopt="$wav_dopt --force-raw-format --endian=big --sign=signed"
179
180 #
181 # convert them to WAVE and AIFF files
182 #
183 convert_to_wav ()
184 {
185         run_flac $raw_eopt $1.raw || die "ERROR converting $1.raw to WAVE"
186         run_flac $wav_dopt $1.flac || die "ERROR converting $1.raw to WAVE"
187 }
188 convert_to_wav 50c
189 convert_to_wav 50c.skip10
190 convert_to_wav 50c.skip11
191 convert_to_wav 50c.skip20
192 convert_to_wav 50c.skip30
193 convert_to_wav 50c.skip40
194 convert_to_wav 50c.until10
195 convert_to_wav 50c.until20
196 convert_to_wav 50c.until30
197 convert_to_wav 50c.until39
198 convert_to_wav 50c.until40
199 convert_to_wav 50c.skip10.until30
200 convert_to_wav 50c.skip10.until39
201 convert_to_wav 50c.skip10.until40
202 convert_to_wav 50c.skip20.until30
203 convert_to_wav 50c.skip20.until40
204
205 convert_to_aiff ()
206 {
207         run_flac $raw_eopt $1.raw || die "ERROR converting $1.raw to AIFF"
208         run_flac $wav_dopt $1.flac -o $1.aiff || die "ERROR converting $1.raw to AIFF"
209 }
210 convert_to_aiff 50c
211 convert_to_aiff 50c.skip10
212 convert_to_aiff 50c.skip11
213 convert_to_aiff 50c.skip20
214 convert_to_aiff 50c.skip30
215 convert_to_aiff 50c.skip40
216 convert_to_aiff 50c.until10
217 convert_to_aiff 50c.until20
218 convert_to_aiff 50c.until30
219 convert_to_aiff 50c.until39
220 convert_to_aiff 50c.until40
221 convert_to_aiff 50c.skip10.until30
222 convert_to_aiff 50c.skip10.until39
223 convert_to_aiff 50c.skip10.until40
224 convert_to_aiff 50c.skip20.until30
225 convert_to_aiff 50c.skip20.until40
226
227 test_skip_until ()
228 {
229         in_fmt=$1
230         out_fmt=$2
231
232         [ "$in_fmt" = wav ] || [ "$in_fmt" = aiff ] || [ "$in_fmt" = raw ] || die "ERROR: internal error, bad 'in' format '$in_fmt'"
233
234         [ "$out_fmt" = flac ] || [ "$out_fmt" = ogg ] || die "ERROR: internal error, bad 'out' format '$out_fmt'"
235
236         if [ $in_fmt = raw ] ; then
237                 eopt="$raw_eopt"
238                 dopt="$raw_dopt"
239         else
240                 eopt="$wav_eopt"
241                 dopt="$wav_dopt"
242         fi
243
244         if [ $out_fmt = ogg ] ; then
245                 eopt="--ogg $eopt"
246         fi
247
248         #
249         # test --skip when encoding
250         #
251
252         desc="($in_fmt<->$out_fmt)"
253
254         echo -n "testing --skip=# (encode) $desc... "
255         run_flac $eopt --skip=10 -o z50c.skip10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
256         run_flac $dopt -o z50c.skip10.$in_fmt z50c.skip10.$out_fmt || die "ERROR decoding FLAC file $desc"
257         cmp 50c.skip10.$in_fmt z50c.skip10.$in_fmt || die "ERROR: file mismatch for --skip=10 (encode) $desc"
258         rm -f z50c.skip10.$out_fmt z50c.skip10.$in_fmt
259         echo OK
260
261         echo -n "testing --skip=mm:ss (encode) $desc... "
262         run_flac $eopt --skip=0:01 -o z50c.skip0:01.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
263         run_flac $dopt -o z50c.skip0:01.$in_fmt z50c.skip0:01.$out_fmt || die "ERROR decoding FLAC file $desc"
264         cmp 50c.skip10.$in_fmt z50c.skip0:01.$in_fmt || die "ERROR: file mismatch for --skip=0:01 (encode) $desc"
265         rm -f z50c.skip0:01.$out_fmt z50c.skip0:01.$in_fmt
266         echo OK
267
268         echo -n "testing --skip=mm:ss.sss (encode) $desc... "
269         run_flac $eopt --skip=0:01.1001 -o z50c.skip0:01.1001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
270         run_flac $dopt -o z50c.skip0:01.1001.$in_fmt z50c.skip0:01.1001.$out_fmt || die "ERROR decoding FLAC file $desc"
271         cmp 50c.skip11.$in_fmt z50c.skip0:01.1001.$in_fmt || die "ERROR: file mismatch for --skip=0:01.1001 (encode) $desc"
272         rm -f z50c.skip0:01.1001.$out_fmt z50c.skip0:01.1001.$in_fmt
273         echo OK
274
275         #
276         # test --skip when decoding
277         #
278
279         echo -n "testing --skip=# (decode) $desc... "
280         run_flac $eopt -o z50c.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
281         run_flac $dopt --skip=10 -o z50c.skip10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
282         cmp 50c.skip10.$in_fmt z50c.skip10.$in_fmt || die "ERROR: file mismatch for --skip=10 (decode) $desc"
283         rm -f z50c.skip10.$in_fmt
284         echo OK
285
286         echo -n "testing --skip=mm:ss (decode) $desc... "
287         run_flac $dopt --skip=0:01 -o z50c.skip0:01.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
288         cmp 50c.skip10.$in_fmt z50c.skip0:01.$in_fmt || die "ERROR: file mismatch for --skip=0:01 (decode) $desc"
289         rm -f z50c.skip0:01.$in_fmt
290         echo OK
291
292         echo -n "testing --skip=mm:ss.sss (decode) $desc... "
293         run_flac $dopt --skip=0:01.1001 -o z50c.skip0:01.1001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
294         cmp 50c.skip11.$in_fmt z50c.skip0:01.1001.$in_fmt || die "ERROR: file mismatch for --skip=0:01.1001 (decode) $desc"
295         rm -f z50c.skip0:01.1001.$in_fmt
296         echo OK
297
298         rm -f z50c.$out_fmt
299
300         #
301         # test --until when encoding
302         #
303
304         echo -n "testing --until=# (encode) $desc... "
305         run_flac $eopt --until=40 -o z50c.until40.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
306         run_flac $dopt -o z50c.until40.$in_fmt z50c.until40.$out_fmt || die "ERROR decoding FLAC file $desc"
307         cmp 50c.until40.$in_fmt z50c.until40.$in_fmt || die "ERROR: file mismatch for --until=40 (encode) $desc"
308         rm -f z50c.until40.$out_fmt z50c.until40.$in_fmt
309         echo OK
310
311         echo -n "testing --until=mm:ss (encode) $desc... "
312         run_flac $eopt --until=0:04 -o z50c.until0:04.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
313         run_flac $dopt -o z50c.until0:04.$in_fmt z50c.until0:04.$out_fmt || die "ERROR decoding FLAC file $desc"
314         cmp 50c.until40.$in_fmt z50c.until0:04.$in_fmt || die "ERROR: file mismatch for --until=0:04 (encode) $desc"
315         rm -f z50c.until0:04.$out_fmt z50c.until0:04.$in_fmt
316         echo OK
317
318         echo -n "testing --until=mm:ss.sss (encode) $desc... "
319         run_flac $eopt --until=0:03.9001 -o z50c.until0:03.9001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
320         run_flac $dopt -o z50c.until0:03.9001.$in_fmt z50c.until0:03.9001.$out_fmt || die "ERROR decoding FLAC file $desc"
321         cmp 50c.until39.$in_fmt z50c.until0:03.9001.$in_fmt || die "ERROR: file mismatch for --until=0:03.9001 (encode) $desc"
322         rm -f z50c.until0:03.9001.$out_fmt z50c.until0:03.9001.$in_fmt
323         echo OK
324
325         echo -n "testing --until=-# (encode) $desc... "
326         run_flac $eopt --until=-10 -o z50c.until-10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
327         run_flac $dopt -o z50c.until-10.$in_fmt z50c.until-10.$out_fmt || die "ERROR decoding FLAC file $desc"
328         cmp 50c.until40.$in_fmt z50c.until-10.$in_fmt || die "ERROR: file mismatch for --until=-10 (encode) $desc"
329         rm -f z50c.until-10.$out_fmt z50c.until-10.$in_fmt
330         echo OK
331
332         echo -n "testing --until=-mm:ss (encode) $desc... "
333         run_flac $eopt --until=-0:01 -o z50c.until-0:01.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
334         run_flac $dopt -o z50c.until-0:01.$in_fmt z50c.until-0:01.$out_fmt || die "ERROR decoding FLAC file $desc"
335         cmp 50c.until40.$in_fmt z50c.until-0:01.$in_fmt || die "ERROR: file mismatch for --until=-0:01 (encode) $desc"
336         rm -f z50c.until-0:01.$out_fmt z50c.until-0:01.$in_fmt
337         echo OK
338
339         echo -n "testing --until=-mm:ss.sss (encode) $desc... "
340         run_flac $eopt --until=-0:01.1001 -o z50c.until-0:01.1001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
341         run_flac $dopt -o z50c.until-0:01.1001.$in_fmt z50c.until-0:01.1001.$out_fmt || die "ERROR decoding FLAC file $desc"
342         cmp 50c.until39.$in_fmt z50c.until-0:01.1001.$in_fmt || die "ERROR: file mismatch for --until=-0:01.1001 (encode) $desc"
343         rm -f z50c.until-0:01.1001.$out_fmt z50c.until-0:01.1001.$in_fmt
344         echo OK
345
346         #
347         # test --until when decoding
348         #
349
350         run_flac $eopt -o z50c.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
351
352         echo -n "testing --until=# (decode) $desc... "
353         run_flac $dopt --until=40 -o z50c.until40.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
354         cmp 50c.until40.$in_fmt z50c.until40.$in_fmt || die "ERROR: file mismatch for --until=40 (decode) $desc"
355         rm -f z50c.until40.$in_fmt
356         echo OK
357
358         echo -n "testing --until=mm:ss (decode) $desc... "
359         run_flac $dopt --until=0:04 -o z50c.until0:04.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
360         cmp 50c.until40.$in_fmt z50c.until0:04.$in_fmt || die "ERROR: file mismatch for --until=0:04 (decode) $desc"
361         rm -f z50c.until0:04.$in_fmt
362         echo OK
363
364         echo -n "testing --until=mm:ss.sss (decode) $desc... "
365         run_flac $dopt --until=0:03.9001 -o z50c.until0:03.9001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
366         cmp 50c.until39.$in_fmt z50c.until0:03.9001.$in_fmt || die "ERROR: file mismatch for --until=0:03.9001 (decode) $desc"
367         rm -f z50c.until0:03.9001.$in_fmt
368         echo OK
369
370         echo -n "testing --until=-# (decode) $desc... "
371         run_flac $dopt --until=-10 -o z50c.until-10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
372         cmp 50c.until40.$in_fmt z50c.until-10.$in_fmt || die "ERROR: file mismatch for --until=-10 (decode) $desc"
373         rm -f z50c.until-10.$in_fmt
374         echo OK
375
376         echo -n "testing --until=-mm:ss (decode) $desc... "
377         run_flac $dopt --until=-0:01 -o z50c.until-0:01.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
378         cmp 50c.until40.$in_fmt z50c.until-0:01.$in_fmt || die "ERROR: file mismatch for --until=-0:01 (decode) $desc"
379         rm -f z50c.until-0:01.$in_fmt
380         echo OK
381
382         echo -n "testing --until=-mm:ss.sss (decode) $desc... "
383         run_flac $dopt --until=-0:01.1001 -o z50c.until-0:01.1001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
384         cmp 50c.until39.$in_fmt z50c.until-0:01.1001.$in_fmt || die "ERROR: file mismatch for --until=-0:01.1001 (decode) $desc"
385         rm -f z50c.until-0:01.1001.$in_fmt
386         echo OK
387
388         rm -f z50c.$out_fmt
389
390         #
391         # test --skip and --until when encoding
392         #
393
394         echo -n "testing --skip=10 --until=# (encode) $desc... "
395         run_flac $eopt --skip=10 --until=40 -o z50c.skip10.until40.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
396         run_flac $dopt -o z50c.skip10.until40.$in_fmt z50c.skip10.until40.$out_fmt || die "ERROR decoding FLAC file $desc"
397         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until40.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=40 (encode) $desc"
398         rm -f z50c.skip10.until40.$out_fmt z50c.skip10.until40.$in_fmt
399         echo OK
400
401         echo -n "testing --skip=10 --until=mm:ss (encode) $desc... "
402         run_flac $eopt --skip=10 --until=0:04 -o z50c.skip10.until0:04.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
403         run_flac $dopt -o z50c.skip10.until0:04.$in_fmt z50c.skip10.until0:04.$out_fmt || die "ERROR decoding FLAC file $desc"
404         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until0:04.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=0:04 (encode) $desc"
405         rm -f z50c.skip10.until0:04.$out_fmt z50c.skip10.until0:04.$in_fmt
406         echo OK
407
408         echo -n "testing --skip=10 --until=mm:ss.sss (encode) $desc... "
409         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"
410         run_flac $dopt -o z50c.skip10.until0:03.9001.$in_fmt z50c.skip10.until0:03.9001.$out_fmt || die "ERROR decoding FLAC file $desc"
411         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"
412         rm -f z50c.skip10.until0:03.9001.$out_fmt z50c.skip10.until0:03.9001.$in_fmt
413         echo OK
414
415         echo -n "testing --skip=10 --until=+# (encode) $desc... "
416         run_flac $eopt --skip=10 --until=+30 -o z50c.skip10.until+30.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
417         run_flac $dopt -o z50c.skip10.until+30.$in_fmt z50c.skip10.until+30.$out_fmt || die "ERROR decoding FLAC file $desc"
418         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until+30.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=+30 (encode) $desc"
419         rm -f z50c.skip10.until+30.$out_fmt z50c.skip10.until+30.$in_fmt
420         echo OK
421
422         echo -n "testing --skip=10 --until=+mm:ss (encode) $desc... "
423         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"
424         run_flac $dopt -o z50c.skip10.until+0:03.$in_fmt z50c.skip10.until+0:03.$out_fmt || die "ERROR decoding FLAC file $desc"
425         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"
426         rm -f z50c.skip10.until+0:03.$out_fmt z50c.skip10.until+0:03.$in_fmt
427         echo OK
428
429         echo -n "testing --skip=10 --until=+mm:ss.sss (encode) $desc... "
430         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"
431         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"
432         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"
433         rm -f z50c.skip10.until+0:02.9001.$out_fmt z50c.skip10.until+0:02.9001.$in_fmt
434         echo OK
435
436         echo -n "testing --skip=10 --until=-# (encode) $desc... "
437         run_flac $eopt --skip=10 --until=-10 -o z50c.skip10.until-10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
438         run_flac $dopt -o z50c.skip10.until-10.$in_fmt z50c.skip10.until-10.$out_fmt || die "ERROR decoding FLAC file $desc"
439         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until-10.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-10 (encode) $desc"
440         rm -f z50c.skip10.until-10.$out_fmt z50c.skip10.until-10.$in_fmt
441         echo OK
442
443         echo -n "testing --skip=10 --until=-mm:ss (encode) $desc... "
444         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"
445         run_flac $dopt -o z50c.skip10.until-0:01.$in_fmt z50c.skip10.until-0:01.$out_fmt || die "ERROR decoding FLAC file $desc"
446         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"
447         rm -f z50c.skip10.until-0:01.$out_fmt z50c.skip10.until-0:01.$in_fmt
448         echo OK
449
450         echo -n "testing --skip=10 --until=-mm:ss.sss (encode) $desc... "
451         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"
452         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"
453         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"
454         rm -f z50c.skip10.until-0:01.1001.$out_fmt z50c.skip10.until-0:01.1001.$in_fmt
455         echo OK
456
457         #
458         # test --skip and --until when decoding
459         #
460
461         run_flac $eopt -o z50c.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
462
463         echo -n "testing --skip=10 --until=# (decode) $desc... "
464         run_flac $dopt --skip=10 --until=40 -o z50c.skip10.until40.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
465         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until40.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=40 (decode) $desc"
466         rm -f z50c.skip10.until40.$in_fmt
467         echo OK
468
469         echo -n "testing --skip=10 --until=mm:ss (decode) $desc... "
470         run_flac $dopt --skip=10 --until=0:04 -o z50c.skip10.until0:04.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
471         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until0:04.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=0:04 (decode) $desc"
472         rm -f z50c.skip10.until0:04.$in_fmt
473         echo OK
474
475         echo -n "testing --skip=10 --until=mm:ss.sss (decode) $desc... "
476         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"
477         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"
478         rm -f z50c.skip10.until0:03.9001.$in_fmt
479         echo OK
480
481         echo -n "testing --skip=10 --until=-# (decode) $desc... "
482         run_flac $dopt --skip=10 --until=-10 -o z50c.skip10.until-10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
483         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until-10.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-10 (decode) $desc"
484         rm -f z50c.skip10.until-10.$in_fmt
485         echo OK
486
487         echo -n "testing --skip=10 --until=-mm:ss (decode) $desc... "
488         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"
489         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"
490         rm -f z50c.skip10.until-0:01.$in_fmt
491         echo OK
492
493         echo -n "testing --skip=10 --until=-mm:ss.sss (decode) $desc... "
494         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"
495         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"
496         rm -f z50c.skip10.until-0:01.1001.$in_fmt
497         echo OK
498
499         rm -f z50c.$out_fmt
500 }
501
502 test_skip_until raw flac
503 test_skip_until wav flac
504 test_skip_until aiff flac
505
506 if [ $has_ogg = "yes" ] ; then
507         test_skip_until raw ogg
508         test_skip_until wav ogg
509         test_skip_until aiff ogg
510 fi
511
512 ############################################################################
513 # test --cue
514 ############################################################################
515
516 #
517 # create the cue sheet
518 #
519 cuesheet=cuetest.cue
520 cat > $cuesheet << EOF
521 CATALOG 1234567890123
522 FILE "blah" WAVE
523   TRACK 01 AUDIO
524     INDEX 01 0
525     INDEX 02 10
526     INDEX 03 20
527   TRACK 02 AUDIO
528     INDEX 01 30
529   TRACK 04 AUDIO
530     INDEX 01 40
531 EOF
532
533 test_cue ()
534 {
535         in_fmt=$1
536         out_fmt=$2
537
538         [ "$in_fmt" = wav ] || [ "$in_fmt" = aiff ] || [ "$in_fmt" = raw ] || die "ERROR: internal error, bad 'in' format '$in_fmt'"
539
540         [ "$out_fmt" = flac ] || [ "$out_fmt" = ogg ] || die "ERROR: internal error, bad 'out' format '$out_fmt'"
541
542         if [ $in_fmt = raw ] ; then
543                 eopt="$raw_eopt"
544                 dopt="$raw_dopt"
545         else
546                 eopt="$wav_eopt"
547                 dopt="$wav_dopt"
548         fi
549
550         if [ $out_fmt = ogg ] ; then
551                 eopt="--ogg $eopt"
552         fi
553
554         desc="($in_fmt<->$out_fmt)"
555
556         #
557         # for this we need just need just one FLAC file; --cue only works while decoding
558         #
559         run_flac $eopt --cuesheet=$cuesheet -o z50c.cue.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
560
561         # To make it easy to translate from cue point to sample numbers, the
562         # file has a sample rate of 10 Hz and a cuesheet like so:
563         #
564         # TRACK 01, INDEX 01 : 0:00.00 -> sample 0
565         # TRACK 01, INDEX 02 : 0:01.00 -> sample 10
566         # TRACK 01, INDEX 03 : 0:02.00 -> sample 20
567         # TRACK 02, INDEX 01 : 0:03.00 -> sample 30
568         # TRACK 04, INDEX 01 : 0:04.00 -> sample 40
569         #
570         echo -n "testing --cue=- $desc... "
571         run_flac $dopt -o z50c.cue.$in_fmt --cue=- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
572         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=- $desc"
573         rm -f z50c.cue.$in_fmt
574         echo OK
575
576         echo -n "testing --cue=1.0 $desc... "
577         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
578         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.0 $desc"
579         rm -f z50c.cue.$in_fmt
580         echo OK
581
582         echo -n "testing --cue=1.0- $desc... "
583         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.0- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
584         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.0- $desc"
585         rm -f z50c.cue.$in_fmt
586         echo OK
587
588         echo -n "testing --cue=1.1 $desc... "
589         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
590         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.1 $desc"
591         rm -f z50c.cue.$in_fmt
592         echo OK
593
594         echo -n "testing --cue=1.1- $desc... "
595         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.1- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
596         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.1- $desc"
597         rm -f z50c.cue.$in_fmt
598         echo OK
599
600         echo -n "testing --cue=1.2 $desc... "
601         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.2 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
602         cmp 50c.skip10.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.2 $desc"
603         rm -f z50c.cue.$in_fmt
604         echo OK
605
606         echo -n "testing --cue=1.2- $desc... "
607         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.2- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
608         cmp 50c.skip10.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.2- $desc"
609         rm -f z50c.cue.$in_fmt
610         echo OK
611
612         echo -n "testing --cue=1.4 $desc... "
613         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.4 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
614         cmp 50c.skip20.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.4 $desc"
615         rm -f z50c.cue.$in_fmt
616         echo OK
617
618         echo -n "testing --cue=1.4- $desc... "
619         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.4- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
620         cmp 50c.skip20.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.4- $desc"
621         rm -f z50c.cue.$in_fmt
622         echo OK
623
624         echo -n "testing --cue=-5.0 $desc... "
625         run_flac $dopt -o z50c.cue.$in_fmt --cue=-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
626         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=-5.0 $desc"
627         rm -f z50c.cue.$in_fmt
628         echo OK
629
630         echo -n "testing --cue=-4.1 $desc... "
631         run_flac $dopt -o z50c.cue.$in_fmt --cue=-4.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
632         cmp 50c.until40.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=-4.1 $desc"
633         rm -f z50c.cue.$in_fmt
634         echo OK
635
636         echo -n "testing --cue=-3.1 $desc... "
637         run_flac $dopt -o z50c.cue.$in_fmt --cue=-3.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
638         cmp 50c.until40.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=-3.1 $desc"
639         rm -f z50c.cue.$in_fmt
640         echo OK
641
642         echo -n "testing --cue=-1.4 $desc... "
643         run_flac $dopt -o z50c.cue.$in_fmt --cue=-1.4 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
644         cmp 50c.until30.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=-1.4 $desc"
645         rm -f z50c.cue.$in_fmt
646         echo OK
647
648         echo -n "testing --cue=1.0-5.0 $desc... "
649         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.0-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
650         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.0-5.0 $desc"
651         rm -f z50c.cue.$in_fmt
652         echo OK
653
654         echo -n "testing --cue=1.1-5.0 $desc... "
655         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.1-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
656         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.1-5.0 $desc"
657         rm -f z50c.cue.$in_fmt
658         echo OK
659
660         echo -n "testing --cue=1.2-4.1 $desc... "
661         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.2-4.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
662         cmp 50c.skip10.until40.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.2-4.1 $desc"
663         rm -f z50c.cue.$in_fmt
664         echo OK
665
666         echo -n "testing --cue=1.4-2.0 $desc... "
667         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.4-2.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
668         cmp 50c.skip20.until30.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.4-2.0 $desc"
669         rm -f z50c.cue.$in_fmt
670         echo OK
671
672         rm -f z50c.cue.$out_fmt
673 }
674
675 test_cue raw flac
676 test_cue wav flac
677 test_cue aiff flac
678
679 if [ $has_ogg = "yes" ] ; then
680         test_cue raw ogg
681         test_cue wav ogg
682         test_cue aiff ogg
683 fi
684
685 ############################################################################
686 # test 'fixup' code that happens when a FLAC file with total_samples == 0
687 # in the STREAMINFO block is converted to WAVE or AIFF, requiring the
688 # decoder go back and fix up the chunk headers
689 ############################################################################
690
691 echo -n "WAVE fixup test... "
692 echo -n "prepare... "
693 convert_to_wav noise || die "ERROR creating reference WAVE"
694 echo -n "encode... "
695 cat noise.raw | run_flac $raw_eopt - -c > fixup.flac || die "ERROR generating FLAC file"
696 echo -n "decode... "
697 run_flac $wav_dopt fixup.flac -o fixup.wav || die "ERROR decoding FLAC file"
698 echo -n "compare... "
699 cmp noise.wav fixup.wav || die "ERROR: file mismatch"
700 echo OK
701 rm -f noise.wav fixup.wav fixup.flac
702
703 echo -n "AIFF fixup test... "
704 echo -n "prepare... "
705 convert_to_aiff noise || die "ERROR creating reference AIFF"
706 echo -n "encode... "
707 cat noise.raw | run_flac $raw_eopt - -c > fixup.flac || die "ERROR generating FLAC file"
708 echo -n "decode... "
709 run_flac $wav_dopt fixup.flac -o fixup.aiff || die "ERROR decoding FLAC file"
710 echo -n "compare... "
711 cmp noise.aiff fixup.aiff || die "ERROR: file mismatch"
712 echo OK
713 rm -f noise.aiff fixup.aiff fixup.flac
714
715
716 ############################################################################
717 # multi-file tests
718 ############################################################################
719
720 echo "Generating multiple input files from noise..."
721 run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=16 --channels=2 noise.raw || die "ERROR generating FLAC file"
722 run_flac --decode --force --silent noise.flac || die "ERROR generating WAVE file"
723 rm -f noise.flac
724 mv noise.wav file0.wav
725 cp file0.wav file1.wav
726 cp file1.wav file2.wav
727
728 test_multifile ()
729 {
730         streamtype=$1
731         sector_align=$2
732         encode_options="$3"
733
734         if [ $streamtype = ogg ] ; then
735                 suffix=ogg
736                 encode_options="$encode_options --ogg"
737         else
738                 suffix=flac
739         fi
740
741         if [ $sector_align = sector_align ] ; then
742                 encode_options="$encode_options --sector-align"
743         fi
744
745         run_flac --force $encode_options file0.wav file1.wav file2.wav || die "ERROR"
746         for n in 0 1 2 ; do
747                 mv file$n.$suffix file${n}x.$suffix
748         done
749         run_flac --force --decode file0x.$suffix file1x.$suffix file2x.$suffix || die "ERROR"
750         if [ $sector_align != sector_align ] ; then
751                 for n in 0 1 2 ; do
752                         cmp file$n.wav file${n}x.wav || die "ERROR: file mismatch on file #$n"
753                 done
754         fi
755         for n in 0 1 2 ; do
756                 rm -f file${n}x.$suffix file${n}x.wav
757         done
758 }
759
760 echo "Testing multiple files without verify..."
761 test_multifile flac no_sector_align ""
762
763 echo "Testing multiple files with verify..."
764 test_multifile flac no_sector_align "--verify"
765
766 echo "Testing multiple files with --sector-align, without verify..."
767 test_multifile flac sector_align ""
768
769 echo "Testing multiple files with --sector-align, with verify..."
770 test_multifile flac sector_align "--verify"
771
772 if [ $has_ogg = "yes" ] ; then
773         echo "Testing multiple files with --ogg, without verify..."
774         test_multifile ogg no_sector_align ""
775
776         echo "Testing multiple files with --ogg, with verify..."
777         test_multifile ogg no_sector_align "--verify"
778
779         echo "Testing multiple files with --ogg and --sector-align, without verify..."
780         test_multifile ogg sector_align ""
781
782         echo "Testing multiple files with --ogg and --sector-align, with verify..."
783         test_multifile sector_align ogg "--verify"
784
785         echo "Testing multiple files with --ogg and --serial-number, with verify..."
786         test_multifile ogg no_sector_align "--serial-number=321 --verify"
787 fi