run --skip and --until tests in Ogg FLAC mode also
[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 # basic 'round-trip' tests of various kinds of streams
58 ############################################################################
59
60 rt_test_raw ()
61 {
62         f="$1"
63         channels=`echo $f | awk -F- '{print $2}'`
64         bytes_per_sample=`echo $f | awk -F- '{print $3}'`
65         bps=`expr $bytes_per_sample '*' 8`
66         echo -n "round-trip test ($f) encode... "
67         run_flac --silent --verify --force-raw-format --endian=little --sign=signed --sample-rate=44100 --bps=$bps --channels=$channels $f -o rt.flac || die "ERROR"
68         echo -n "decode... "
69         run_flac --silent --decode --force-raw-format --endian=little --sign=signed -o rt.raw rt.flac || die "ERROR"
70         echo -n "compare... "
71         cmp $f rt.raw || die "ERROR: file mismatch"
72         echo "OK"
73         rm -f rt.flac rt.raw
74 }
75
76 rt_test_wav ()
77 {
78         f="$1"
79         echo -n "round-trip test ($f) encode... "
80         run_flac --silent --verify $f -o rt.flac || die "ERROR"
81         echo -n "decode... "
82         run_flac --silent --decode -o rt.wav rt.flac || die "ERROR"
83         echo -n "compare... "
84         cmp $f rt.wav || die "ERROR: file mismatch"
85         echo "OK"
86         rm -f rt.flac rt.wav
87 }
88
89 rt_test_aiff ()
90 {
91         f="$1"
92         echo -n "round-trip test ($f) encode... "
93         run_flac --silent --verify $f -o rt.flac || die "ERROR"
94         echo -n "decode... "
95         run_flac --silent --decode -o rt.aiff rt.flac || die "ERROR"
96         echo -n "compare... "
97         cmp $f rt.aiff || die "ERROR: file mismatch"
98         echo "OK"
99         rm -f rt.flac rt.aiff
100 }
101
102 for f in rt-*.raw ; do
103         rt_test_raw $f
104 done
105 for f in rt-*.wav ; do
106         rt_test_wav $f
107 done
108 for f in rt-*.aiff ; do
109         rt_test_aiff $f
110 done
111
112 ############################################################################
113 # test --skip and --until
114 ############################################################################
115
116 #
117 # first make some chopped-up raw files
118 #
119 echo "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMN" > master.raw
120 dddie="die ERROR: creating files for --skip/--until tests"
121 dd if=master.raw ibs=1 count=50 of=50c.raw 2>/dev/null || $dddie
122 dd if=master.raw ibs=1 skip=10 count=40 of=50c.skip10.raw 2>/dev/null || $dddie
123 dd if=master.raw ibs=1 skip=11 count=39 of=50c.skip11.raw 2>/dev/null || $dddie
124 dd if=master.raw ibs=1 count=40 of=50c.until40.raw 2>/dev/null || $dddie
125 dd if=master.raw ibs=1 count=39 of=50c.until39.raw 2>/dev/null || $dddie
126 dd if=master.raw ibs=1 skip=10 count=30 of=50c.skip10.until40.raw 2>/dev/null || $dddie
127 dd if=master.raw ibs=1 skip=10 count=29 of=50c.skip10.until39.raw 2>/dev/null || $dddie
128
129 wav_eopt="--silent --verify --lax"
130 wav_dopt="--silent --decode"
131
132 raw_eopt="$wav_eopt --force-raw-format --endian=big --sign=signed --sample-rate=10 --bps=8 --channels=1"
133 raw_dopt="$wav_dopt --force-raw-format --endian=big --sign=signed"
134
135 #
136 # convert them to WAVE and AIFF files
137 #
138 convert_to_wav ()
139 {
140         run_flac $raw_eopt $1.raw || die "ERROR converting $1.raw to WAVE"
141         run_flac $wav_dopt $1.flac || die "ERROR converting $1.raw to WAVE"
142 }
143 convert_to_wav 50c
144 convert_to_wav 50c.skip10
145 convert_to_wav 50c.skip11
146 convert_to_wav 50c.until40
147 convert_to_wav 50c.until39
148 convert_to_wav 50c.skip10.until40
149 convert_to_wav 50c.skip10.until39
150
151 convert_to_aiff ()
152 {
153         run_flac $raw_eopt $1.raw || die "ERROR converting $1.raw to AIFF"
154         run_flac $wav_dopt $1.flac -o $1.aiff || die "ERROR converting $1.raw to AIFF"
155 }
156 convert_to_aiff 50c
157 convert_to_aiff 50c.skip10
158 convert_to_aiff 50c.skip11
159 convert_to_aiff 50c.until40
160 convert_to_aiff 50c.until39
161 convert_to_aiff 50c.skip10.until40
162 convert_to_aiff 50c.skip10.until39
163
164 test_skip_until ()
165 {
166         in_fmt=$1
167         out_fmt=$2
168
169         [ "$in_fmt" = wav ] || [ "$in_fmt" = aiff ] || [ "$in_fmt" = raw ] || die "ERROR: internal error, bad 'in' format '$in_fmt'"
170
171         [ "$out_fmt" = flac ] || [ "$out_fmt" = ogg ] || die "ERROR: internal error, bad 'out' format '$out_fmt'"
172
173         if [ $in_fmt = raw ] ; then
174                 eopt="$raw_eopt"
175                 dopt="$raw_dopt"
176         else
177                 eopt="$wav_eopt"
178                 dopt="$wav_dopt"
179         fi
180
181         if [ $out_fmt = ogg ] ; then
182                 eopt="--ogg $eopt"
183         fi
184
185         #
186         # test --skip when encoding
187         #
188
189         desc="($in_fmt<->$out_fmt)"
190
191         echo -n "testing --skip=# (encode) $desc... "
192         run_flac $eopt --skip=10 -o z50c.skip10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
193         run_flac $dopt -o z50c.skip10.$in_fmt z50c.skip10.$out_fmt || die "ERROR decoding FLAC file $desc"
194         cmp 50c.skip10.$in_fmt z50c.skip10.$in_fmt || die "ERROR: file mismatch for --skip=10 (encode) $desc"
195         rm -f z50c.skip10.$out_fmt z50c.skip10.$in_fmt
196         echo OK
197
198         echo -n "testing --skip=mm:ss (encode) $desc... "
199         run_flac $eopt --skip=0:01 -o z50c.skip0:01.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
200         run_flac $dopt -o z50c.skip0:01.$in_fmt z50c.skip0:01.$out_fmt || die "ERROR decoding FLAC file $desc"
201         cmp 50c.skip10.$in_fmt z50c.skip0:01.$in_fmt || die "ERROR: file mismatch for --skip=0:01 (encode) $desc"
202         rm -f z50c.skip0:01.$out_fmt z50c.skip0:01.$in_fmt
203         echo OK
204
205         echo -n "testing --skip=mm:ss.sss (encode) $desc... "
206         run_flac $eopt --skip=0:01.1001 -o z50c.skip0:01.1001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
207         run_flac $dopt -o z50c.skip0:01.1001.$in_fmt z50c.skip0:01.1001.$out_fmt || die "ERROR decoding FLAC file $desc"
208         cmp 50c.skip11.$in_fmt z50c.skip0:01.1001.$in_fmt || die "ERROR: file mismatch for --skip=0:01.1001 (encode) $desc"
209         rm -f z50c.skip0:01.1001.$out_fmt z50c.skip0:01.1001.$in_fmt
210         echo OK
211
212         #
213         # test --skip when decoding
214         #
215
216         echo -n "testing --skip=# (decode) $desc... "
217         run_flac $eopt -o z50c.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
218         run_flac $dopt --skip=10 -o z50c.skip10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
219         cmp 50c.skip10.$in_fmt z50c.skip10.$in_fmt || die "ERROR: file mismatch for --skip=10 (decode) $desc"
220         rm -f z50c.skip10.$in_fmt
221         echo OK
222
223         echo -n "testing --skip=mm:ss (decode) $desc... "
224         run_flac $dopt --skip=0:01 -o z50c.skip0:01.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
225         cmp 50c.skip10.$in_fmt z50c.skip0:01.$in_fmt || die "ERROR: file mismatch for --skip=0:01 (decode) $desc"
226         rm -f z50c.skip0:01.$in_fmt
227         echo OK
228
229         echo -n "testing --skip=mm:ss.sss (decode) $desc... "
230         run_flac $dopt --skip=0:01.1001 -o z50c.skip0:01.1001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
231         cmp 50c.skip11.$in_fmt z50c.skip0:01.1001.$in_fmt || die "ERROR: file mismatch for --skip=0:01.1001 (decode) $desc"
232         rm -f z50c.skip0:01.1001.$in_fmt
233         echo OK
234
235         rm -f z50c.$out_fmt
236
237         #
238         # test --until when encoding
239         #
240
241         echo -n "testing --until=# (encode) $desc... "
242         run_flac $eopt --until=40 -o z50c.until40.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
243         run_flac $dopt -o z50c.until40.$in_fmt z50c.until40.$out_fmt || die "ERROR decoding FLAC file $desc"
244         cmp 50c.until40.$in_fmt z50c.until40.$in_fmt || die "ERROR: file mismatch for --until=40 (encode) $desc"
245         rm -f z50c.until40.$out_fmt z50c.until40.$in_fmt
246         echo OK
247
248         echo -n "testing --until=mm:ss (encode) $desc... "
249         run_flac $eopt --until=0:04 -o z50c.until0:04.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
250         run_flac $dopt -o z50c.until0:04.$in_fmt z50c.until0:04.$out_fmt || die "ERROR decoding FLAC file $desc"
251         cmp 50c.until40.$in_fmt z50c.until0:04.$in_fmt || die "ERROR: file mismatch for --until=0:04 (encode) $desc"
252         rm -f z50c.until0:04.$out_fmt z50c.until0:04.$in_fmt
253         echo OK
254
255         echo -n "testing --until=mm:ss.sss (encode) $desc... "
256         run_flac $eopt --until=0:03.9001 -o z50c.until0:03.9001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
257         run_flac $dopt -o z50c.until0:03.9001.$in_fmt z50c.until0:03.9001.$out_fmt || die "ERROR decoding FLAC file $desc"
258         cmp 50c.until39.$in_fmt z50c.until0:03.9001.$in_fmt || die "ERROR: file mismatch for --until=0:03.9001 (encode) $desc"
259         rm -f z50c.until0:03.9001.$out_fmt z50c.until0:03.9001.$in_fmt
260         echo OK
261
262         echo -n "testing --until=-# (encode) $desc... "
263         run_flac $eopt --until=-10 -o z50c.until-10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
264         run_flac $dopt -o z50c.until-10.$in_fmt z50c.until-10.$out_fmt || die "ERROR decoding FLAC file $desc"
265         cmp 50c.until40.$in_fmt z50c.until-10.$in_fmt || die "ERROR: file mismatch for --until=-10 (encode) $desc"
266         rm -f z50c.until-10.$out_fmt z50c.until-10.$in_fmt
267         echo OK
268
269         echo -n "testing --until=-mm:ss (encode) $desc... "
270         run_flac $eopt --until=-0:01 -o z50c.until-0:01.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
271         run_flac $dopt -o z50c.until-0:01.$in_fmt z50c.until-0:01.$out_fmt || die "ERROR decoding FLAC file $desc"
272         cmp 50c.until40.$in_fmt z50c.until-0:01.$in_fmt || die "ERROR: file mismatch for --until=-0:01 (encode) $desc"
273         rm -f z50c.until-0:01.$out_fmt z50c.until-0:01.$in_fmt
274         echo OK
275
276         echo -n "testing --until=-mm:ss.sss (encode) $desc... "
277         run_flac $eopt --until=-0:01.1001 -o z50c.until-0:01.1001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
278         run_flac $dopt -o z50c.until-0:01.1001.$in_fmt z50c.until-0:01.1001.$out_fmt || die "ERROR decoding FLAC file $desc"
279         cmp 50c.until39.$in_fmt z50c.until-0:01.1001.$in_fmt || die "ERROR: file mismatch for --until=-0:01.1001 (encode) $desc"
280         rm -f z50c.until-0:01.1001.$out_fmt z50c.until-0:01.1001.$in_fmt
281         echo OK
282
283         #
284         # test --until when decoding
285         #
286
287         run_flac $eopt -o z50c.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
288
289         echo -n "testing --until=# (decode) $desc... "
290         run_flac $dopt --until=40 -o z50c.until40.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
291         cmp 50c.until40.$in_fmt z50c.until40.$in_fmt || die "ERROR: file mismatch for --until=40 (decode) $desc"
292         rm -f z50c.until40.$in_fmt
293         echo OK
294
295         echo -n "testing --until=mm:ss (decode) $desc... "
296         run_flac $dopt --until=0:04 -o z50c.until0:04.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
297         cmp 50c.until40.$in_fmt z50c.until0:04.$in_fmt || die "ERROR: file mismatch for --until=0:04 (decode) $desc"
298         rm -f z50c.until0:04.$in_fmt
299         echo OK
300
301         echo -n "testing --until=mm:ss.sss (decode) $desc... "
302         run_flac $dopt --until=0:03.9001 -o z50c.until0:03.9001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
303         cmp 50c.until39.$in_fmt z50c.until0:03.9001.$in_fmt || die "ERROR: file mismatch for --until=0:03.9001 (decode) $desc"
304         rm -f z50c.until0:03.9001.$in_fmt
305         echo OK
306
307         echo -n "testing --until=-# (decode) $desc... "
308         run_flac $dopt --until=-10 -o z50c.until-10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
309         cmp 50c.until40.$in_fmt z50c.until-10.$in_fmt || die "ERROR: file mismatch for --until=-10 (decode) $desc"
310         rm -f z50c.until-10.$in_fmt
311         echo OK
312
313         echo -n "testing --until=-mm:ss (decode) $desc... "
314         run_flac $dopt --until=-0:01 -o z50c.until-0:01.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
315         cmp 50c.until40.$in_fmt z50c.until-0:01.$in_fmt || die "ERROR: file mismatch for --until=-0:01 (decode) $desc"
316         rm -f z50c.until-0:01.$in_fmt
317         echo OK
318
319         echo -n "testing --until=-mm:ss.sss (decode) $desc... "
320         run_flac $dopt --until=-0:01.1001 -o z50c.until-0:01.1001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
321         cmp 50c.until39.$in_fmt z50c.until-0:01.1001.$in_fmt || die "ERROR: file mismatch for --until=-0:01.1001 (decode) $desc"
322         rm -f z50c.until-0:01.1001.$in_fmt
323         echo OK
324
325         rm -f z50c.$out_fmt
326
327         #
328         # test --skip and --until when encoding
329         #
330
331         echo -n "testing --skip=10 --until=# (encode) $desc... "
332         run_flac $eopt --skip=10 --until=40 -o z50c.skip10.until40.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
333         run_flac $dopt -o z50c.skip10.until40.$in_fmt z50c.skip10.until40.$out_fmt || die "ERROR decoding FLAC file $desc"
334         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until40.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=40 (encode) $desc"
335         rm -f z50c.skip10.until40.$out_fmt z50c.skip10.until40.$in_fmt
336         echo OK
337
338         echo -n "testing --skip=10 --until=mm:ss (encode) $desc... "
339         run_flac $eopt --skip=10 --until=0:04 -o z50c.skip10.until0:04.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
340         run_flac $dopt -o z50c.skip10.until0:04.$in_fmt z50c.skip10.until0:04.$out_fmt || die "ERROR decoding FLAC file $desc"
341         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until0:04.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=0:04 (encode) $desc"
342         rm -f z50c.skip10.until0:04.$out_fmt z50c.skip10.until0:04.$in_fmt
343         echo OK
344
345         echo -n "testing --skip=10 --until=mm:ss.sss (encode) $desc... "
346         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"
347         run_flac $dopt -o z50c.skip10.until0:03.9001.$in_fmt z50c.skip10.until0:03.9001.$out_fmt || die "ERROR decoding FLAC file $desc"
348         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"
349         rm -f z50c.skip10.until0:03.9001.$out_fmt z50c.skip10.until0:03.9001.$in_fmt
350         echo OK
351
352         echo -n "testing --skip=10 --until=+# (encode) $desc... "
353         run_flac $eopt --skip=10 --until=+30 -o z50c.skip10.until+30.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
354         run_flac $dopt -o z50c.skip10.until+30.$in_fmt z50c.skip10.until+30.$out_fmt || die "ERROR decoding FLAC file $desc"
355         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until+30.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=+30 (encode) $desc"
356         rm -f z50c.skip10.until+30.$out_fmt z50c.skip10.until+30.$in_fmt
357         echo OK
358
359         echo -n "testing --skip=10 --until=+mm:ss (encode) $desc... "
360         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"
361         run_flac $dopt -o z50c.skip10.until+0:03.$in_fmt z50c.skip10.until+0:03.$out_fmt || die "ERROR decoding FLAC file $desc"
362         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"
363         rm -f z50c.skip10.until+0:03.$out_fmt z50c.skip10.until+0:03.$in_fmt
364         echo OK
365
366         echo -n "testing --skip=10 --until=+mm:ss.sss (encode) $desc... "
367         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"
368         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"
369         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"
370         rm -f z50c.skip10.until+0:02.9001.$out_fmt z50c.skip10.until+0:02.9001.$in_fmt
371         echo OK
372
373         echo -n "testing --skip=10 --until=-# (encode) $desc... "
374         run_flac $eopt --skip=10 --until=-10 -o z50c.skip10.until-10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
375         run_flac $dopt -o z50c.skip10.until-10.$in_fmt z50c.skip10.until-10.$out_fmt || die "ERROR decoding FLAC file $desc"
376         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until-10.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-10 (encode) $desc"
377         rm -f z50c.skip10.until-10.$out_fmt z50c.skip10.until-10.$in_fmt
378         echo OK
379
380         echo -n "testing --skip=10 --until=-mm:ss (encode) $desc... "
381         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"
382         run_flac $dopt -o z50c.skip10.until-0:01.$in_fmt z50c.skip10.until-0:01.$out_fmt || die "ERROR decoding FLAC file $desc"
383         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"
384         rm -f z50c.skip10.until-0:01.$out_fmt z50c.skip10.until-0:01.$in_fmt
385         echo OK
386
387         echo -n "testing --skip=10 --until=-mm:ss.sss (encode) $desc... "
388         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"
389         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"
390         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"
391         rm -f z50c.skip10.until-0:01.1001.$out_fmt z50c.skip10.until-0:01.1001.$in_fmt
392         echo OK
393
394         #
395         # test --skip and --until when decoding
396         #
397
398         run_flac $eopt -o z50c.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
399
400         echo -n "testing --skip=10 --until=# (decode) $desc... "
401         run_flac $dopt --skip=10 --until=40 -o z50c.skip10.until40.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
402         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until40.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=40 (decode) $desc"
403         rm -f z50c.skip10.until40.$in_fmt
404         echo OK
405
406         echo -n "testing --skip=10 --until=mm:ss (decode) $desc... "
407         run_flac $dopt --skip=10 --until=0:04 -o z50c.skip10.until0:04.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
408         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until0:04.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=0:04 (decode) $desc"
409         rm -f z50c.skip10.until0:04.$in_fmt
410         echo OK
411
412         echo -n "testing --skip=10 --until=mm:ss.sss (decode) $desc... "
413         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"
414         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"
415         rm -f z50c.skip10.until0:03.9001.$in_fmt
416         echo OK
417
418         echo -n "testing --skip=10 --until=-# (decode) $desc... "
419         run_flac $dopt --skip=10 --until=-10 -o z50c.skip10.until-10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
420         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until-10.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-10 (decode) $desc"
421         rm -f z50c.skip10.until-10.$in_fmt
422         echo OK
423
424         echo -n "testing --skip=10 --until=-mm:ss (decode) $desc... "
425         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"
426         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"
427         rm -f z50c.skip10.until-0:01.$in_fmt
428         echo OK
429
430         echo -n "testing --skip=10 --until=-mm:ss.sss (decode) $desc... "
431         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"
432         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"
433         rm -f z50c.skip10.until-0:01.1001.$in_fmt
434         echo OK
435
436         rm -f z50c.$out_fmt
437 }
438
439 test_skip_until raw flac
440 test_skip_until wav flac
441 test_skip_until aiff flac
442
443 if [ $has_ogg = "yes" ] ; then
444         test_skip_until raw ogg
445         test_skip_until wav ogg
446         test_skip_until aiff ogg
447 fi
448
449 ############################################################################
450 # test 'fixup' code that happens when a FLAC file with total_samples == 0
451 # in the STREAMINFO block is converted to WAVE or AIFF, requiring the
452 # decoder go back and fix up the chunk headers
453 ############################################################################
454
455 echo -n "WAVE fixup test... "
456 echo -n "prepare... "
457 convert_to_wav noise || die "ERROR creating reference WAVE"
458 echo -n "encode... "
459 cat noise.raw | run_flac $raw_eopt - -c > fixup.flac || die "ERROR generating FLAC file"
460 echo -n "decode... "
461 run_flac $wav_dopt fixup.flac -o fixup.wav || die "ERROR decoding FLAC file"
462 echo -n "compare... "
463 cmp noise.wav fixup.wav || die "ERROR: file mismatch"
464 echo OK
465 rm -f noise.wav fixup.wav fixup.flac
466
467 echo -n "AIFF fixup test... "
468 echo -n "prepare... "
469 convert_to_aiff noise || die "ERROR creating reference AIFF"
470 echo -n "encode... "
471 cat noise.raw | run_flac $raw_eopt - -c > fixup.flac || die "ERROR generating FLAC file"
472 echo -n "decode... "
473 run_flac $wav_dopt fixup.flac -o fixup.aiff || die "ERROR decoding FLAC file"
474 echo -n "compare... "
475 cmp noise.aiff fixup.aiff || die "ERROR: file mismatch"
476 echo OK
477 rm -f noise.aiff fixup.aiff fixup.flac
478
479
480 ############################################################################
481 # multi-file tests
482 ############################################################################
483
484 echo "Generating multiple input files from noise..."
485 run_flac --verify --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=16 --channels=2 noise.raw || die "ERROR generating FLAC file"
486 run_flac --decode --silent noise.flac || die "ERROR generating WAVE file"
487 rm -f noise.flac
488 mv noise.wav file0.wav
489 cp file0.wav file1.wav
490 cp file1.wav file2.wav
491
492 test_multifile ()
493 {
494         streamtype=$1
495         sector_align=$2
496         encode_options="$3"
497
498         if [ $streamtype = ogg ] ; then
499                 suffix=ogg
500                 encode_options="$encode_options --ogg"
501         else
502                 suffix=flac
503         fi
504
505         if [ $sector_align = sector_align ] ; then
506                 encode_options="$encode_options --sector-align"
507         fi
508
509         run_flac $encode_options file0.wav file1.wav file2.wav || die "ERROR"
510         for n in 0 1 2 ; do
511                 mv file$n.$suffix file${n}x.$suffix
512         done
513         run_flac --decode file0x.$suffix file1x.$suffix file2x.$suffix || die "ERROR"
514         if [ $sector_align != sector_align ] ; then
515                 for n in 0 1 2 ; do
516                         cmp file$n.wav file${n}x.wav || die "ERROR: file mismatch on file #$n"
517                 done
518         fi
519         for n in 0 1 2 ; do
520                 rm -f file${n}x.$suffix file${n}x.wav
521         done
522 }
523
524 echo "Testing multiple files without verify..."
525 test_multifile flac no_sector_align ""
526
527 echo "Testing multiple files with verify..."
528 test_multifile flac no_sector_align "--verify"
529
530 echo "Testing multiple files with --sector-align, without verify..."
531 test_multifile flac sector_align ""
532
533 echo "Testing multiple files with --sector-align, with verify..."
534 test_multifile flac sector_align "--verify"
535
536 if [ $has_ogg = "yes" ] ; then
537         echo "Testing multiple files with --ogg, without verify..."
538         test_multifile ogg no_sector_align ""
539
540         echo "Testing multiple files with --ogg, with verify..."
541         test_multifile ogg no_sector_align "--verify"
542
543         echo "Testing multiple files with --ogg and --sector-align, without verify..."
544         test_multifile ogg sector_align ""
545
546         echo "Testing multiple files with --ogg and --sector-align, with verify..."
547         test_multifile sector_align ogg "--verify"
548
549         echo "Testing multiple files with --ogg and --serial-number, with verify..."
550         test_multifile ogg no_sector_align "--serial-number=321 --verify"
551 fi