minor wording
[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 --totally-silent -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 --totally-silent -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 --totally-silent -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 --totally-silent -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 echo "Testing seek extremes:"
513
514 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"
515
516 total_samples=`metaflac --show-total-samples noise.flac`
517 [ $? = 0 ] || die "ERROR getting total sample count from noise.flac"
518
519 echo -n "Testing --skip=0... "
520 run_flac $wav_dopt --skip=0 -o z.wav noise.flac || die "ERROR decoding FLAC file noise.flac"
521 echo OK
522
523 for delta in 2 1 ; do
524         n=`expr $total_samples - $delta`
525         echo -n "Testing --skip=$n... "
526         run_flac $wav_dopt --skip=$n -o z.wav noise.flac || die "ERROR decoding FLAC file noise.flac"
527         echo OK
528 done
529
530 rm noise.flac z.wav
531
532
533 ############################################################################
534 # test --cue
535 ############################################################################
536
537 #
538 # create the cue sheet
539 #
540 cuesheet=cuetest.cue
541 cat > $cuesheet << EOF
542 CATALOG 1234567890123
543 FILE "blah" WAVE
544   TRACK 01 AUDIO
545     INDEX 01 0
546     INDEX 02 10
547     INDEX 03 20
548   TRACK 02 AUDIO
549     INDEX 01 30
550   TRACK 04 AUDIO
551     INDEX 01 40
552 EOF
553
554 test_cue ()
555 {
556         in_fmt=$1
557         out_fmt=$2
558
559         [ "$in_fmt" = wav ] || [ "$in_fmt" = aiff ] || [ "$in_fmt" = raw ] || die "ERROR: internal error, bad 'in' format '$in_fmt'"
560
561         [ "$out_fmt" = flac ] || [ "$out_fmt" = ogg ] || die "ERROR: internal error, bad 'out' format '$out_fmt'"
562
563         if [ $in_fmt = raw ] ; then
564                 eopt="$raw_eopt"
565                 dopt="$raw_dopt"
566         else
567                 eopt="$wav_eopt"
568                 dopt="$wav_dopt"
569         fi
570
571         if [ $out_fmt = ogg ] ; then
572                 eopt="--ogg $eopt"
573         fi
574
575         desc="($in_fmt<->$out_fmt)"
576
577         #
578         # for this we need just need just one FLAC file; --cue only works while decoding
579         #
580         run_flac $eopt --cuesheet=$cuesheet -o z50c.cue.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
581
582         # To make it easy to translate from cue point to sample numbers, the
583         # file has a sample rate of 10 Hz and a cuesheet like so:
584         #
585         # TRACK 01, INDEX 01 : 0:00.00 -> sample 0
586         # TRACK 01, INDEX 02 : 0:01.00 -> sample 10
587         # TRACK 01, INDEX 03 : 0:02.00 -> sample 20
588         # TRACK 02, INDEX 01 : 0:03.00 -> sample 30
589         # TRACK 04, INDEX 01 : 0:04.00 -> sample 40
590         #
591         echo -n "testing --cue=- $desc... "
592         run_flac $dopt -o z50c.cue.$in_fmt --cue=- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
593         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=- $desc"
594         rm -f z50c.cue.$in_fmt
595         echo OK
596
597         echo -n "testing --cue=1.0 $desc... "
598         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
599         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.0 $desc"
600         rm -f z50c.cue.$in_fmt
601         echo OK
602
603         echo -n "testing --cue=1.0- $desc... "
604         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.0- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
605         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.0- $desc"
606         rm -f z50c.cue.$in_fmt
607         echo OK
608
609         echo -n "testing --cue=1.1 $desc... "
610         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
611         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.1 $desc"
612         rm -f z50c.cue.$in_fmt
613         echo OK
614
615         echo -n "testing --cue=1.1- $desc... "
616         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.1- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
617         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.1- $desc"
618         rm -f z50c.cue.$in_fmt
619         echo OK
620
621         echo -n "testing --cue=1.2 $desc... "
622         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.2 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
623         cmp 50c.skip10.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.2 $desc"
624         rm -f z50c.cue.$in_fmt
625         echo OK
626
627         echo -n "testing --cue=1.2- $desc... "
628         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.2- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
629         cmp 50c.skip10.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.2- $desc"
630         rm -f z50c.cue.$in_fmt
631         echo OK
632
633         echo -n "testing --cue=1.4 $desc... "
634         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.4 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
635         cmp 50c.skip20.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.4 $desc"
636         rm -f z50c.cue.$in_fmt
637         echo OK
638
639         echo -n "testing --cue=1.4- $desc... "
640         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.4- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
641         cmp 50c.skip20.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.4- $desc"
642         rm -f z50c.cue.$in_fmt
643         echo OK
644
645         echo -n "testing --cue=-5.0 $desc... "
646         run_flac $dopt -o z50c.cue.$in_fmt --cue=-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
647         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=-5.0 $desc"
648         rm -f z50c.cue.$in_fmt
649         echo OK
650
651         echo -n "testing --cue=-4.1 $desc... "
652         run_flac $dopt -o z50c.cue.$in_fmt --cue=-4.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
653         cmp 50c.until40.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=-4.1 $desc"
654         rm -f z50c.cue.$in_fmt
655         echo OK
656
657         echo -n "testing --cue=-3.1 $desc... "
658         run_flac $dopt -o z50c.cue.$in_fmt --cue=-3.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
659         cmp 50c.until40.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=-3.1 $desc"
660         rm -f z50c.cue.$in_fmt
661         echo OK
662
663         echo -n "testing --cue=-1.4 $desc... "
664         run_flac $dopt -o z50c.cue.$in_fmt --cue=-1.4 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
665         cmp 50c.until30.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=-1.4 $desc"
666         rm -f z50c.cue.$in_fmt
667         echo OK
668
669         echo -n "testing --cue=1.0-5.0 $desc... "
670         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.0-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
671         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.0-5.0 $desc"
672         rm -f z50c.cue.$in_fmt
673         echo OK
674
675         echo -n "testing --cue=1.1-5.0 $desc... "
676         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.1-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
677         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.1-5.0 $desc"
678         rm -f z50c.cue.$in_fmt
679         echo OK
680
681         echo -n "testing --cue=1.2-4.1 $desc... "
682         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.2-4.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
683         cmp 50c.skip10.until40.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.2-4.1 $desc"
684         rm -f z50c.cue.$in_fmt
685         echo OK
686
687         echo -n "testing --cue=1.4-2.0 $desc... "
688         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.4-2.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
689         cmp 50c.skip20.until30.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.4-2.0 $desc"
690         rm -f z50c.cue.$in_fmt
691         echo OK
692
693         rm -f z50c.cue.$out_fmt
694 }
695
696 test_cue raw flac
697 test_cue wav flac
698 test_cue aiff flac
699
700 if [ $has_ogg = "yes" ] ; then
701         test_cue raw ogg
702         test_cue wav ogg
703         test_cue aiff ogg
704 fi
705
706 ############################################################################
707 # test 'fixup' code that happens when a FLAC file with total_samples == 0
708 # in the STREAMINFO block is converted to WAVE or AIFF, requiring the
709 # decoder go back and fix up the chunk headers
710 ############################################################################
711
712 echo -n "WAVE fixup test... "
713 echo -n "prepare... "
714 convert_to_wav noise || die "ERROR creating reference WAVE"
715 echo -n "encode... "
716 cat noise.raw | run_flac $raw_eopt - -c > fixup.flac || die "ERROR generating FLAC file"
717 echo -n "decode... "
718 run_flac $wav_dopt fixup.flac -o fixup.wav || die "ERROR decoding FLAC file"
719 echo -n "compare... "
720 cmp noise.wav fixup.wav || die "ERROR: file mismatch"
721 echo OK
722 rm -f noise.wav fixup.wav fixup.flac
723
724 echo -n "AIFF fixup test... "
725 echo -n "prepare... "
726 convert_to_aiff noise || die "ERROR creating reference AIFF"
727 echo -n "encode... "
728 cat noise.raw | run_flac $raw_eopt - -c > fixup.flac || die "ERROR generating FLAC file"
729 echo -n "decode... "
730 run_flac $wav_dopt fixup.flac -o fixup.aiff || die "ERROR decoding FLAC file"
731 echo -n "compare... "
732 cmp noise.aiff fixup.aiff || die "ERROR: file mismatch"
733 echo OK
734 rm -f noise.aiff fixup.aiff fixup.flac
735
736
737 ############################################################################
738 # multi-file tests
739 ############################################################################
740
741 echo "Generating multiple input files from noise..."
742 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"
743 run_flac --decode --force --silent noise.flac || die "ERROR generating WAVE file"
744 rm -f noise.flac
745 mv noise.wav file0.wav
746 cp file0.wav file1.wav
747 cp file1.wav file2.wav
748
749 test_multifile ()
750 {
751         streamtype=$1
752         sector_align=$2
753         encode_options="$3"
754
755         if [ $streamtype = ogg ] ; then
756                 suffix=ogg
757                 encode_options="$encode_options --ogg"
758         else
759                 suffix=flac
760         fi
761
762         if [ $sector_align = sector_align ] ; then
763                 encode_options="$encode_options --sector-align"
764         fi
765
766         run_flac --force $encode_options file0.wav file1.wav file2.wav || die "ERROR"
767         for n in 0 1 2 ; do
768                 mv file$n.$suffix file${n}x.$suffix
769         done
770         run_flac --force --decode file0x.$suffix file1x.$suffix file2x.$suffix || die "ERROR"
771         if [ $sector_align != sector_align ] ; then
772                 for n in 0 1 2 ; do
773                         cmp file$n.wav file${n}x.wav || die "ERROR: file mismatch on file #$n"
774                 done
775         fi
776         for n in 0 1 2 ; do
777                 rm -f file${n}x.$suffix file${n}x.wav
778         done
779 }
780
781 echo "Testing multiple files without verify..."
782 test_multifile flac no_sector_align ""
783
784 echo "Testing multiple files with verify..."
785 test_multifile flac no_sector_align "--verify"
786
787 echo "Testing multiple files with --sector-align, without verify..."
788 test_multifile flac sector_align ""
789
790 echo "Testing multiple files with --sector-align, with verify..."
791 test_multifile flac sector_align "--verify"
792
793 if [ $has_ogg = "yes" ] ; then
794         echo "Testing multiple files with --ogg, without verify..."
795         test_multifile ogg no_sector_align ""
796
797         echo "Testing multiple files with --ogg, with verify..."
798         test_multifile ogg no_sector_align "--verify"
799
800         echo "Testing multiple files with --ogg and --sector-align, without verify..."
801         test_multifile ogg sector_align ""
802
803         echo "Testing multiple files with --ogg and --sector-align, with verify..."
804         test_multifile sector_align ogg "--verify"
805
806         echo "Testing multiple files with --ogg and --serial-number, with verify..."
807         test_multifile ogg no_sector_align "--serial-number=321 --verify"
808 fi