test_flac.sh 52.2 KB
Newer Older
1
#!/bin/sh -e
Josh Coalson's avatar
Josh Coalson committed
2
3

#  FLAC - Free Lossless Audio Codec
4
#  Copyright (C) 2001-2009  Josh Coalson
5
#  Copyright (C) 2011-2016  Xiph.Org Foundation
Josh Coalson's avatar
Josh Coalson committed
6
#
Josh Coalson's avatar
Josh Coalson committed
7
#  This file is part the FLAC project.  FLAC is comprised of several
8
#  components distributed under different licenses.  The codec libraries
Josh Coalson's avatar
Josh Coalson committed
9
10
11
12
13
14
#  are distributed under Xiph.Org's BSD-like license (see the file
#  COPYING.Xiph in this distribution).  All other programs, libraries, and
#  plugins are distributed under the GPL (see COPYING.GPL).  The documentation
#  is distributed under the Gnu FDL (see COPYING.FDL).  Each file in the
#  FLAC distribution contains at the top the terms under which it may be
#  distributed.
Josh Coalson's avatar
Josh Coalson committed
15
#
Josh Coalson's avatar
Josh Coalson committed
16
17
18
19
#  Since this particular file is relevant to all components of FLAC,
#  it may be distributed under the Xiph.Org license, which is the least
#  restrictive of those mentioned above.  See the file COPYING.Xiph in this
#  distribution.
Josh Coalson's avatar
Josh Coalson committed
20

21
. ./common.sh
22

23
24
25
# we use '.' as decimal separator in --skip/--until tests
export LANG=C LC_ALL=C

Josh Coalson's avatar
Josh Coalson committed
26
27
dddie="die ERROR: creating files with dd"

28
29
30
PATH=`pwd`/../src/flac:$PATH
PATH=`pwd`/../src/metaflac:$PATH
PATH=`pwd`/../src/test_streams:$PATH
31
PATH=`pwd`/../objs/$BUILD/bin:$PATH
Josh Coalson's avatar
Josh Coalson committed
32

33
flac${EXE} --help 1>/dev/null 2>/dev/null || die "ERROR can't find flac executable"
Josh Coalson's avatar
Josh Coalson committed
34
35
36

run_flac ()
{
37
	if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
38
		echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 flac $*" >>test_flac.valgrind.log
39
		valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 flac${EXE} $TOTALLY_SILENT --no-error-on-compression-fail $* 4>>test_flac.valgrind.log
Josh Coalson's avatar
Josh Coalson committed
40
	else
41
		flac${EXE} $TOTALLY_SILENT --no-error-on-compression-fail $*
Josh Coalson's avatar
Josh Coalson committed
42
43
44
	fi
}

45
46
run_metaflac ()
{
47
	if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
48
		echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 metaflac $*" >>test_flac.valgrind.log
49
		valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 metaflac${EXE} $* 4>>test_flac.valgrind.log
50
	else
51
		metaflac${EXE} $*
52
53
54
	fi
}

55
56
md5cmp ()
{
57
	n=`( [ -f "$1" ] && [ -f "$2" ] && metaflac${EXE} --show-md5sum --no-filename "$1" "$2" 2>/dev/null || exit 1 ) | uniq | wc -l`
58
59
60
	[ "$n" != "" ] && [ $n = 1 ]
}

Josh Coalson's avatar
Josh Coalson committed
61
echo "Checking for --ogg support in flac..."
62
if flac${EXE} --ogg $TOTTALY_SILENT --force-raw-format --endian=little --sign=signed --channels=1 --bps=8 --sample-rate=44100 -c $0 1>/dev/null 2>&1 ; then
Josh Coalson's avatar
Josh Coalson committed
63
64
65
66
67
68
69
	has_ogg=yes;
	echo "flac --ogg works"
else
	has_ogg=no;
	echo "flac --ogg doesn't work"
fi

70
71
72
73
74
echo "Generating streams..."
if [ ! -f wacky1.wav ] ; then
	test_streams || die "ERROR during test_streams"
fi

75
76
77
78
79
80
81
############################################################################
# test that flac doesn't automatically overwrite files unless -f is used
############################################################################

echo "Try encoding to a file that exists; should fail"
cp wacky1.wav exist.wav
touch exist.flac
82
if run_flac -0 exist.wav ; then
83
84
85
86
87
88
	die "ERROR: it should have failed but didn't"
else
	echo "OK, it failed as it should"
fi

echo "Try encoding with -f to a file that exists; should succeed"
89
if run_flac -0 --force exist.wav ; then
90
91
92
93
94
95
	echo "OK, it succeeded as it should"
else
	die "ERROR: it should have succeeded but didn't"
fi

echo "Try decoding to a file that exists; should fail"
96
if run_flac -d exist.flac ; then
97
98
99
100
101
102
	die "ERROR: it should have failed but didn't"
else
	echo "OK, it failed as it should"
fi

echo "Try decoding with -f to a file that exists; should succeed"
103
if run_flac -d -f exist.flac ; then
104
105
106
107
108
109
110
	echo "OK, it succeeded as it should"
else
	die "ERROR: it should have succeeded but didn't"
fi

rm -f exist.wav exist.flac

Josh Coalson's avatar
Josh Coalson committed
111
112
113
114
############################################################################
# test fractional block sizes
############################################################################

115
116
117
118
test_fractional ()
{
	blocksize=$1
	samples=$2
Josh Coalson's avatar
Josh Coalson committed
119
	dd if=noise.raw ibs=4 count=$samples of=pbs.raw 2>/dev/null || $dddie
120
	echo $ECHO_N "fractional block size test (blocksize=$blocksize samples=$samples) encode... " $ECHO_C
121
	run_flac --force --verify --force-raw-format --endian=little --sign=signed --sample-rate=44100 --bps=16 --channels=2 --blocksize=$blocksize --no-padding --lax -o pbs.flac pbs.raw || die "ERROR"
122
	echo $ECHO_N "decode... " $ECHO_C
123
	run_flac --force --decode --force-raw-format --endian=little --sign=signed -o pbs.cmp pbs.flac || die "ERROR"
124
	echo $ECHO_N "compare... " $ECHO_C
Josh Coalson's avatar
Josh Coalson committed
125
126
127
	cmp pbs.raw pbs.cmp || die "ERROR: file mismatch"
	echo "OK"
	rm -f pbs.raw pbs.flac pbs.cmp
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
}

# The special significance of 2048 is it's the # of samples that flac calls
# FLAC__stream_encoder_process() on.
#
# We're trying to make sure the 1-sample overread logic in the stream encoder
# (used for last-block checking) works; these values probe around common
# multiples of the flac sample chunk size (2048) and the blocksize.
for samples in 31 32 33 34 35 2046 2047 2048 2049 2050 ; do
	test_fractional 33 $samples
done
for samples in 254 255 256 257 258 510 511 512 513 514 1022 1023 1024 1025 1026 2046 2047 2048 2049 2050 4094 4095 4096 4097 4098 ; do
	test_fractional 256 $samples
done
for samples in 1022 1023 1024 1025 1026 2046 2047 2048 2049 2050 4094 4095 4096 4097 4098 ; do
	test_fractional 2048 $samples
done
for samples in 1022 1023 1024 1025 1026 2046 2047 2048 2049 2050 4094 4095 4096 4097 4098 4606 4607 4608 4609 4610 8190 8191 8192 8193 8194 16382 16383 16384 16385 16386 ; do
	test_fractional 4608 $samples
Josh Coalson's avatar
Josh Coalson committed
147
148
done

149
150
151
152
153
154
155
############################################################################
# basic 'round-trip' tests of various kinds of streams
############################################################################

rt_test_raw ()
{
	f="$1"
Josh Coalson's avatar
Josh Coalson committed
156
	extra="$2"
157
	channels=`echo $f | awk -F- '{print $2}'`
158
	bps=`echo $f | awk -F- '{print $3}'`
159
160
	sign=`echo $f | awk -F- '{print $4}'`

161
	echo $ECHO_N "round-trip test ($f) encode... " $ECHO_C
162
	run_flac --force --verify --force-raw-format --endian=little --sign=$sign --sample-rate=44100 --bps=$bps --channels=$channels --no-padding --lax -o rt.flac $extra $f || die "ERROR"
163
	echo $ECHO_N "decode... " $ECHO_C
164
	run_flac --force --decode --force-raw-format --endian=little --sign=$sign -o rt.raw $extra rt.flac || die "ERROR"
165
	echo $ECHO_N "compare... " $ECHO_C
166
167
168
169
170
171
172
173
	cmp $f rt.raw || die "ERROR: file mismatch"
	echo "OK"
	rm -f rt.flac rt.raw
}

rt_test_wav ()
{
	f="$1"
Josh Coalson's avatar
Josh Coalson committed
174
	extra="$2"
175
	echo $ECHO_N "round-trip test ($f) encode... " $ECHO_C
176
	run_flac --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
177
	echo $ECHO_N "decode... " $ECHO_C
178
	run_flac --force --decode --channel-map=none -o rt.wav $extra rt.flac || die "ERROR"
179
	echo $ECHO_N "compare... " $ECHO_C
180
181
182
183
184
	cmp $f rt.wav || die "ERROR: file mismatch"
	echo "OK"
	rm -f rt.flac rt.wav
}

185
186
187
188
rt_test_w64 ()
{
	f="$1"
	extra="$2"
189
	echo $ECHO_N "round-trip test ($f) encode... " $ECHO_C
190
	run_flac --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
191
	echo $ECHO_N "decode... " $ECHO_C
192
	run_flac --force --decode --channel-map=none -o rt.w64 $extra rt.flac || die "ERROR"
193
	echo $ECHO_N "compare... " $ECHO_C
194
195
196
197
198
	cmp $f rt.w64 || die "ERROR: file mismatch"
	echo "OK"
	rm -f rt.flac rt.w64
}

Josh Coalson's avatar
Josh Coalson committed
199
200
201
202
rt_test_rf64 ()
{
	f="$1"
	extra="$2"
203
	echo $ECHO_N "round-trip test ($f) encode... " $ECHO_C
204
	run_flac --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
205
	echo $ECHO_N "decode... " $ECHO_C
206
	run_flac --force --decode --channel-map=none -o rt.rf64 $extra rt.flac || die "ERROR"
207
	echo $ECHO_N "compare... " $ECHO_C
Josh Coalson's avatar
Josh Coalson committed
208
209
210
211
212
	cmp $f rt.rf64 || die "ERROR: file mismatch"
	echo "OK"
	rm -f rt.flac rt.rf64
}

213
214
215
rt_test_aiff ()
{
	f="$1"
Josh Coalson's avatar
Josh Coalson committed
216
	extra="$2"
217
	echo $ECHO_N "round-trip test ($f) encode... " $ECHO_C
218
	run_flac --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
219
	echo $ECHO_N "decode... " $ECHO_C
220
	run_flac --force --decode --channel-map=none -o rt.aiff $extra rt.flac || die "ERROR"
221
	echo $ECHO_N "compare... " $ECHO_C
222
223
224
225
226
	cmp $f rt.aiff || die "ERROR: file mismatch"
	echo "OK"
	rm -f rt.flac rt.aiff
}

227
228
229
230
# assumes input file is WAVE; does not check the metadata-preserving features of flac-to-flac; that is checked later
rt_test_flac ()
{
	f="$1"
Josh Coalson's avatar
Josh Coalson committed
231
	extra="$2"
232
	echo $ECHO_N "round-trip test ($f->flac->flac->wav) encode... " $ECHO_C
233
	run_flac --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
234
	echo $ECHO_N "re-encode... " $ECHO_C
235
	run_flac --force --verify --lax -o rt2.flac rt.flac || die "ERROR"
236
	echo $ECHO_N "decode... " $ECHO_C
237
	run_flac --force --decode --channel-map=none -o rt.wav $extra rt2.flac || die "ERROR"
238
	echo $ECHO_N "compare... " $ECHO_C
239
240
241
242
243
	cmp $f rt.wav || die "ERROR: file mismatch"
	echo "OK"
	rm -f rt.wav rt.flac rt2.flac
}

244
245
246
247
# assumes input file is WAVE; does not check the metadata-preserving features of flac-to-flac; that is checked later
rt_test_ogg_flac ()
{
	f="$1"
Josh Coalson's avatar
Josh Coalson committed
248
	extra="$2"
249
	echo $ECHO_N "round-trip test ($f->oggflac->oggflac->wav) encode... " $ECHO_C
250
	run_flac --force --verify --channel-map=none --no-padding --lax -o rt.oga --ogg $extra $f || die "ERROR"
251
	echo $ECHO_N "re-encode... " $ECHO_C
252
	run_flac --force --verify --lax -o rt2.oga --ogg rt.oga || die "ERROR"
253
	echo $ECHO_N "decode... " $ECHO_C
254
	run_flac --force --decode --channel-map=none -o rt.wav $extra rt2.oga || die "ERROR"
255
	echo $ECHO_N "compare... " $ECHO_C
256
257
	cmp $f rt.wav || die "ERROR: file mismatch"
	echo "OK"
258
	rm -f rt.wav rt.oga rt2.oga
259
260
}

261
262
263
264
265
266
for f in rt-*.raw ; do
	rt_test_raw $f
done
for f in rt-*.wav ; do
	rt_test_wav $f
done
267
268
269
for f in rt-*.w64 ; do
	rt_test_w64 $f
done
Josh Coalson's avatar
Josh Coalson committed
270
271
272
for f in rt-*.rf64 ; do
	rt_test_rf64 $f
done
273
274
275
for f in rt-*.aiff ; do
	rt_test_aiff $f
done
276
277
278
for f in rt-*.wav ; do
	rt_test_flac $f
done
279
280
281
282
283
if [ $has_ogg = yes ] ; then
	for f in rt-*.wav ; do
		rt_test_ogg_flac $f
	done
fi
284

285
286
287
288
############################################################################
# test --skip and --until
############################################################################

Josh Coalson's avatar
Josh Coalson committed
289
#
290
# first make some chopped-up raw files
Josh Coalson's avatar
Josh Coalson committed
291
#
292
293
294
295
echo "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMN" > master.raw
dd if=master.raw ibs=1 count=50 of=50c.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=10 count=40 of=50c.skip10.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=11 count=39 of=50c.skip11.raw 2>/dev/null || $dddie
296
297
298
299
300
301
dd if=master.raw ibs=1 skip=20 count=30 of=50c.skip20.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=30 count=20 of=50c.skip30.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=40 count=10 of=50c.skip40.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 count=10 of=50c.until10.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 count=20 of=50c.until20.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 count=30 of=50c.until30.raw 2>/dev/null || $dddie
302
dd if=master.raw ibs=1 count=39 of=50c.until39.raw 2>/dev/null || $dddie
303
304
dd if=master.raw ibs=1 count=40 of=50c.until40.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=10 count=20 of=50c.skip10.until30.raw 2>/dev/null || $dddie
305
dd if=master.raw ibs=1 skip=10 count=29 of=50c.skip10.until39.raw 2>/dev/null || $dddie
306
307
308
dd if=master.raw ibs=1 skip=10 count=30 of=50c.skip10.until40.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=20 count=10 of=50c.skip20.until30.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=20 count=20 of=50c.skip20.until40.raw 2>/dev/null || $dddie
Josh Coalson's avatar
Josh Coalson committed
309

310
311
wav_eopt="--force --verify --no-padding --lax"
wav_dopt="--force --decode"
312

Josh Coalson's avatar
Josh Coalson committed
313
raw_eopt="$wav_eopt --force-raw-format --endian=big --sign=signed --sample-rate=10 --bps=8 --channels=1"
314
raw_dopt="$wav_dopt --force-raw-format --endian=big --sign=signed"
315
316

#
317
# convert them to WAVE/AIFF/Ogg FLAC files
318
#
319
320
convert_to_wav ()
{
321
322
	run_flac "$2" $1.raw || die "ERROR converting $1.raw to WAVE"
	run_flac "$3" $1.flac || die "ERROR converting $1.raw to WAVE"
323
}
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
convert_to_wav 50c "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.skip10 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.skip11 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.skip20 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.skip30 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.skip40 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.until10 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.until20 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.until30 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.until39 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.until40 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.skip10.until30 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.skip10.until39 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.skip10.until40 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.skip20.until30 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.skip20.until40 "$raw_eopt" "$wav_dopt"
340

341
342
convert_to_aiff ()
{
343
344
	run_flac "$2" $1.raw || die "ERROR converting $1.raw to AIFF"
	run_flac "$3" $1.flac -o $1.aiff || die "ERROR converting $1.raw to AIFF"
345
}
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
convert_to_aiff 50c "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.skip10 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.skip11 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.skip20 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.skip30 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.skip40 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.until10 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.until20 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.until30 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.until39 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.until40 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.skip10.until30 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.skip10.until39 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.skip10.until40 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.skip20.until30 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.skip20.until40 "$raw_eopt" "$wav_dopt"
362

363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
convert_to_ogg ()
{
	run_flac "$wav_eopt" --ogg $1.wav || die "ERROR converting $1.raw to Ogg FLAC"
}
if [ $has_ogg = yes ] ; then
	convert_to_ogg 50c
	convert_to_ogg 50c.skip10
	convert_to_ogg 50c.skip11
	convert_to_ogg 50c.skip20
	convert_to_ogg 50c.skip30
	convert_to_ogg 50c.skip40
	convert_to_ogg 50c.until10
	convert_to_ogg 50c.until20
	convert_to_ogg 50c.until30
	convert_to_ogg 50c.until39
	convert_to_ogg 50c.until40
	convert_to_ogg 50c.skip10.until30
	convert_to_ogg 50c.skip10.until39
	convert_to_ogg 50c.skip10.until40
	convert_to_ogg 50c.skip20.until30
	convert_to_ogg 50c.skip20.until40
fi

386
387
test_skip_until ()
{
388
389
	in_fmt=$1
	out_fmt=$2
390

391
	[ "$in_fmt" = wav ] || [ "$in_fmt" = aiff ] || [ "$in_fmt" = raw ] || [ "$in_fmt" = flac ] || [ "$in_fmt" = ogg ] || die "ERROR: internal error, bad 'in' format '$in_fmt'"
392

393
394
395
	[ "$out_fmt" = flac ] || [ "$out_fmt" = ogg ] || die "ERROR: internal error, bad 'out' format '$out_fmt'"

	if [ $in_fmt = raw ] ; then
396
397
398
399
400
401
		eopt="$raw_eopt"
		dopt="$raw_dopt"
	else
		eopt="$wav_eopt"
		dopt="$wav_dopt"
	fi
402

403
	if ( [ $in_fmt = flac ] || [ $in_fmt = ogg ] ) && ( [ $out_fmt = flac ] || [ $out_fmt = ogg ] ) ; then
404
405
406
407
408
		CMP=md5cmp
	else
		CMP=cmp
	fi

409
410
411
412
	if [ $out_fmt = ogg ] ; then
		eopt="--ogg $eopt"
	fi

413
414
415
416
	#
	# test --skip when encoding
	#

417
418
	desc="($in_fmt<->$out_fmt)"

419
	echo $ECHO_N "testing --skip=# (encode) $desc... " $ECHO_C
420
	run_flac $eopt --skip=10 -o z50c.skip10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
421
422
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.$in_fmt z50c.skip10.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.$in_fmt z50c.skip10.$in_fmt || die "ERROR: file mismatch for --skip=10 (encode) $desc"
423
	rm -f z50c.skip10.$out_fmt z50c.skip10.$in_fmt
424
425
	echo OK

426
	echo $ECHO_N "testing --skip=mm:ss (encode) $desc... " $ECHO_C
427
	run_flac $eopt --skip=0:01 -o z50c.skip0_01.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
428

429
430
431
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip0_01.$in_fmt z50c.skip0_01.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.$in_fmt z50c.skip0_01.$in_fmt || die "ERROR: file mismatch for --skip=0:01 (encode) $desc"
	rm -f z50c.skip0_01.$out_fmt z50c.skip0_01.$in_fmt
432
433
	echo OK

434
	echo $ECHO_N "testing --skip=mm:ss.sss (encode) $desc... " $ECHO_C
435
436
437
438
	run_flac $eopt --skip=0:01.1001 -o z50c.skip0_01.1001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip0_01.1001.$in_fmt z50c.skip0_01.1001.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip11.$in_fmt z50c.skip0_01.1001.$in_fmt || die "ERROR: file mismatch for --skip=0:01.1001 (encode) $desc"
	rm -f z50c.skip0_01.1001.$out_fmt z50c.skip0_01.1001.$in_fmt
439
440
441
442
443
444
	echo OK

	#
	# test --skip when decoding
	#

445
446
	if [ $in_fmt != $out_fmt ] ; then run_flac $eopt -o z50c.$out_fmt 50c.$in_fmt ; else cp -f 50c.$in_fmt z50c.$out_fmt ; fi || die "ERROR generating FLAC file $desc"

447
	echo $ECHO_N "testing --skip=# (decode) $desc... " $ECHO_C
448
	run_flac $dopt --skip=10 -o z50c.skip10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
449
	$CMP 50c.skip10.$in_fmt z50c.skip10.$in_fmt || die "ERROR: file mismatch for --skip=10 (decode) $desc"
450
	rm -f z50c.skip10.$in_fmt
451
452
	echo OK

453
	echo $ECHO_N "testing --skip=mm:ss (decode) $desc... " $ECHO_C
454
455
456
	run_flac $dopt --skip=0:01 -o z50c.skip0_01.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.$in_fmt z50c.skip0_01.$in_fmt || die "ERROR: file mismatch for --skip=0:01 (decode) $desc"
	rm -f z50c.skip0_01.$in_fmt
457
458
	echo OK

459
	echo $ECHO_N "testing --skip=mm:ss.sss (decode) $desc... " $ECHO_C
460
461
462
	run_flac $dopt --skip=0:01.1001 -o z50c.skip0_01.1001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip11.$in_fmt z50c.skip0_01.1001.$in_fmt || die "ERROR: file mismatch for --skip=0:01.1001 (decode) $desc"
	rm -f z50c.skip0_01.1001.$in_fmt
463
464
	echo OK

465
	rm -f z50c.$out_fmt
466
467
468
469
470

	#
	# test --until when encoding
	#

471
	echo $ECHO_N "testing --until=# (encode) $desc... " $ECHO_C
472
	run_flac $eopt --until=40 -o z50c.until40.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
473
474
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until40.$in_fmt z50c.until40.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until40.$in_fmt z50c.until40.$in_fmt || die "ERROR: file mismatch for --until=40 (encode) $desc"
475
	rm -f z50c.until40.$out_fmt z50c.until40.$in_fmt
476
477
	echo OK

478
	echo $ECHO_N "testing --until=mm:ss (encode) $desc... " $ECHO_C
479
480
481
482
	run_flac $eopt --until=0:04 -o z50c.until0_04.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until0_04.$in_fmt z50c.until0_04.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until40.$in_fmt z50c.until0_04.$in_fmt || die "ERROR: file mismatch for --until=0:04 (encode) $desc"
	rm -f z50c.until0_04.$out_fmt z50c.until0_04.$in_fmt
483
484
	echo OK

485
	echo $ECHO_N "testing --until=mm:ss.sss (encode) $desc... " $ECHO_C
486
487
488
489
	run_flac $eopt --until=0:03.9001 -o z50c.until0_03.9001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until0_03.9001.$in_fmt z50c.until0_03.9001.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until39.$in_fmt z50c.until0_03.9001.$in_fmt || die "ERROR: file mismatch for --until=0:03.9001 (encode) $desc"
	rm -f z50c.until0_03.9001.$out_fmt z50c.until0_03.9001.$in_fmt
490
491
	echo OK

492
	echo $ECHO_N "testing --until=-# (encode) $desc... " $ECHO_C
493
	run_flac $eopt --until=-10 -o z50c.until-10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
494
495
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until-10.$in_fmt z50c.until-10.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until40.$in_fmt z50c.until-10.$in_fmt || die "ERROR: file mismatch for --until=-10 (encode) $desc"
496
	rm -f z50c.until-10.$out_fmt z50c.until-10.$in_fmt
497
498
	echo OK

499
	echo $ECHO_N "testing --until=-mm:ss (encode) $desc... " $ECHO_C
500
501
502
503
	run_flac $eopt --until=-0:01 -o z50c.until-0_01.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until-0_01.$in_fmt z50c.until-0_01.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until40.$in_fmt z50c.until-0_01.$in_fmt || die "ERROR: file mismatch for --until=-0:01 (encode) $desc"
	rm -f z50c.until-0_01.$out_fmt z50c.until-0_01.$in_fmt
504
505
	echo OK

506
	echo $ECHO_N "testing --until=-mm:ss.sss (encode) $desc... " $ECHO_C
507
508
509
510
	run_flac $eopt --until=-0:01.1001 -o z50c.until-0_01.1001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until-0_01.1001.$in_fmt z50c.until-0_01.1001.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until39.$in_fmt z50c.until-0_01.1001.$in_fmt || die "ERROR: file mismatch for --until=-0:01.1001 (encode) $desc"
	rm -f z50c.until-0_01.1001.$out_fmt z50c.until-0_01.1001.$in_fmt
511
512
513
514
515
516
	echo OK

	#
	# test --until when decoding
	#

517
	if [ $in_fmt != $out_fmt ] ; then run_flac $eopt -o z50c.$out_fmt 50c.$in_fmt ; else cp -f 50c.$in_fmt z50c.$out_fmt ; fi || die "ERROR generating FLAC file $desc"
518

519
	echo $ECHO_N "testing --until=# (decode) $desc... " $ECHO_C
520
	run_flac $dopt --until=40 -o z50c.until40.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
521
	$CMP 50c.until40.$in_fmt z50c.until40.$in_fmt || die "ERROR: file mismatch for --until=40 (decode) $desc"
522
	rm -f z50c.until40.$in_fmt
523
524
	echo OK

525
	echo $ECHO_N "testing --until=mm:ss (decode) $desc... " $ECHO_C
526
527
528
	run_flac $dopt --until=0:04 -o z50c.until0_04.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until40.$in_fmt z50c.until0_04.$in_fmt || die "ERROR: file mismatch for --until=0:04 (decode) $desc"
	rm -f z50c.until0_04.$in_fmt
529
530
	echo OK

531
	echo $ECHO_N "testing --until=mm:ss.sss (decode) $desc... " $ECHO_C
532
533
534
	run_flac $dopt --until=0:03.9001 -o z50c.until0_03.9001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until39.$in_fmt z50c.until0_03.9001.$in_fmt || die "ERROR: file mismatch for --until=0:03.9001 (decode) $desc"
	rm -f z50c.until0_03.9001.$in_fmt
535
536
	echo OK

537
	echo $ECHO_N "testing --until=-# (decode) $desc... " $ECHO_C
538
	run_flac $dopt --until=-10 -o z50c.until-10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
539
	$CMP 50c.until40.$in_fmt z50c.until-10.$in_fmt || die "ERROR: file mismatch for --until=-10 (decode) $desc"
540
	rm -f z50c.until-10.$in_fmt
541
542
	echo OK

543
	echo $ECHO_N "testing --until=-mm:ss (decode) $desc... " $ECHO_C
544
545
546
	run_flac $dopt --until=-0:01 -o z50c.until-0_01.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until40.$in_fmt z50c.until-0_01.$in_fmt || die "ERROR: file mismatch for --until=-0:01 (decode) $desc"
	rm -f z50c.until-0_01.$in_fmt
547
548
	echo OK

549
	echo $ECHO_N "testing --until=-mm:ss.sss (decode) $desc... " $ECHO_C
550
551
552
	run_flac $dopt --until=-0:01.1001 -o z50c.until-0_01.1001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until39.$in_fmt z50c.until-0_01.1001.$in_fmt || die "ERROR: file mismatch for --until=-0:01.1001 (decode) $desc"
	rm -f z50c.until-0_01.1001.$in_fmt
553
554
	echo OK

555
	rm -f z50c.$out_fmt
556
557
558
559
560

	#
	# test --skip and --until when encoding
	#

561
	echo $ECHO_N "testing --skip=10 --until=# (encode) $desc... " $ECHO_C
562
	run_flac $eopt --skip=10 --until=40 -o z50c.skip10.until40.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
563
564
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until40.$in_fmt z50c.skip10.until40.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.until40.$in_fmt z50c.skip10.until40.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=40 (encode) $desc"
565
	rm -f z50c.skip10.until40.$out_fmt z50c.skip10.until40.$in_fmt
566
567
	echo OK

568
	echo $ECHO_N "testing --skip=10 --until=mm:ss (encode) $desc... " $ECHO_C
569
570
571
572
	run_flac $eopt --skip=10 --until=0:04 -o z50c.skip10.until0_04.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until0_04.$in_fmt z50c.skip10.until0_04.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.until40.$in_fmt z50c.skip10.until0_04.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=0:04 (encode) $desc"
	rm -f z50c.skip10.until0_04.$out_fmt z50c.skip10.until0_04.$in_fmt
573
574
	echo OK

575
	echo $ECHO_N "testing --skip=10 --until=mm:ss.sss (encode) $desc... " $ECHO_C
576
577
578
579
	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"
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until0_03.9001.$in_fmt z50c.skip10.until0_03.9001.$out_fmt || die "ERROR decoding FLAC file $desc"
	$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"
	rm -f z50c.skip10.until0_03.9001.$out_fmt z50c.skip10.until0_03.9001.$in_fmt
580
581
	echo OK

582
	echo $ECHO_N "testing --skip=10 --until=+# (encode) $desc... " $ECHO_C
583
	run_flac $eopt --skip=10 --until=+30 -o z50c.skip10.until+30.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
584
585
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until+30.$in_fmt z50c.skip10.until+30.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.until40.$in_fmt z50c.skip10.until+30.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=+30 (encode) $desc"
586
	rm -f z50c.skip10.until+30.$out_fmt z50c.skip10.until+30.$in_fmt
587
588
	echo OK

589
	echo $ECHO_N "testing --skip=10 --until=+mm:ss (encode) $desc... " $ECHO_C
590
591
592
593
	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"
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until+0_03.$in_fmt z50c.skip10.until+0_03.$out_fmt || die "ERROR decoding FLAC file $desc"
	$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"
	rm -f z50c.skip10.until+0_03.$out_fmt z50c.skip10.until+0_03.$in_fmt
594
595
	echo OK

596
	echo $ECHO_N "testing --skip=10 --until=+mm:ss.sss (encode) $desc... " $ECHO_C
597
598
599
600
	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"
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until+0_02.9001.$in_fmt z50c.skip10.until+0_02.9001.$out_fmt || die "ERROR decoding FLAC file $desc"
	$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"
	rm -f z50c.skip10.until+0_02.9001.$out_fmt z50c.skip10.until+0_02.9001.$in_fmt
601
602
	echo OK

603
	echo $ECHO_N "testing --skip=10 --until=-# (encode) $desc... " $ECHO_C
604
	run_flac $eopt --skip=10 --until=-10 -o z50c.skip10.until-10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
605
606
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until-10.$in_fmt z50c.skip10.until-10.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.until40.$in_fmt z50c.skip10.until-10.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-10 (encode) $desc"
607
	rm -f z50c.skip10.until-10.$out_fmt z50c.skip10.until-10.$in_fmt
608
609
	echo OK

610
	echo $ECHO_N "testing --skip=10 --until=-mm:ss (encode) $desc... " $ECHO_C
611
612
613
614
	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"
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until-0_01.$in_fmt z50c.skip10.until-0_01.$out_fmt || die "ERROR decoding FLAC file $desc"
	$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"
	rm -f z50c.skip10.until-0_01.$out_fmt z50c.skip10.until-0_01.$in_fmt
615
616
	echo OK

617
	echo $ECHO_N "testing --skip=10 --until=-mm:ss.sss (encode) $desc... " $ECHO_C
618
619
620
621
	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"
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until-0_01.1001.$in_fmt z50c.skip10.until-0_01.1001.$out_fmt || die "ERROR decoding FLAC file $desc"
	$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"
	rm -f z50c.skip10.until-0_01.1001.$out_fmt z50c.skip10.until-0_01.1001.$in_fmt
622
623
624
625
626
627
	echo OK

	#
	# test --skip and --until when decoding
	#

628
629
	if [ $in_fmt != $out_fmt ] ; then run_flac $eopt -o z50c.$out_fmt 50c.$in_fmt ; else cp -f 50c.$in_fmt z50c.$out_fmt ; fi || die "ERROR generating FLAC file $desc"

630

631
	echo $ECHO_N "testing --skip=10 --until=# (decode) $desc... " $ECHO_C
632
	run_flac $dopt --skip=10 --until=40 -o z50c.skip10.until40.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
633
	$CMP 50c.skip10.until40.$in_fmt z50c.skip10.until40.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=40 (decode) $desc"
634
	rm -f z50c.skip10.until40.$in_fmt
635
636
	echo OK

637
	echo $ECHO_N "testing --skip=10 --until=mm:ss (decode) $desc... " $ECHO_C
638
639
640
	run_flac $dopt --skip=10 --until=0:04 -o z50c.skip10.until0_04.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.until40.$in_fmt z50c.skip10.until0_04.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=0:04 (decode) $desc"
	rm -f z50c.skip10.until0_04.$in_fmt
641
642
	echo OK

643
	echo $ECHO_N "testing --skip=10 --until=mm:ss.sss (decode) $desc... " $ECHO_C
644
645
646
	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"
	$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"
	rm -f z50c.skip10.until0_03.9001.$in_fmt
647
648
	echo OK

649
	echo $ECHO_N "testing --skip=10 --until=-# (decode) $desc... " $ECHO_C
650
	run_flac $dopt --skip=10 --until=-10 -o z50c.skip10.until-10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
651
	$CMP 50c.skip10.until40.$in_fmt z50c.skip10.until-10.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-10 (decode) $desc"
652
	rm -f z50c.skip10.until-10.$in_fmt
653
654
	echo OK

655
	echo $ECHO_N "testing --skip=10 --until=-mm:ss (decode) $desc... " $ECHO_C
656
657
658
	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"
	$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"
	rm -f z50c.skip10.until-0_01.$in_fmt
659
660
	echo OK

661
	echo $ECHO_N "testing --skip=10 --until=-mm:ss.sss (decode) $desc... " $ECHO_C
662
663
664
	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"
	$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"
	rm -f z50c.skip10.until-0_01.1001.$in_fmt
665
666
	echo OK

667
	rm -f z50c.$out_fmt
668
}
669

670
671
672
test_skip_until raw flac
test_skip_until wav flac
test_skip_until aiff flac
673
test_skip_until flac flac
674
675
676
677
#@@@if [ $has_ogg = yes ] ; then
#@@@	#@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
#@@@	test_skip_until ogg flac
#@@@fi
Josh Coalson's avatar
Josh Coalson committed
678

679
if [ $has_ogg = yes ] ; then
680
681
682
	test_skip_until raw ogg
	test_skip_until wav ogg
	test_skip_until aiff ogg
683
	#@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
684
	#@@@test_skip_until flac ogg
685
	#@@@test_skip_until ogg ogg
686
fi
Josh Coalson's avatar
Josh Coalson committed
687

Josh Coalson's avatar
Josh Coalson committed
688
echo "testing seek extremes:"
689

690
run_flac --verify --force --no-padding --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=16 --channels=2 --blocksize=576 noise.raw || die "ERROR generating FLAC file"
691

Josh Coalson's avatar
Josh Coalson committed
692
if [ $is_win = no ] ; then
693
	total_noise_cdda_samples=`run_metaflac --show-total-samples noise.flac`
Josh Coalson's avatar
Josh Coalson committed
694
695
696
697
698
	[ $? = 0 ] || die "ERROR getting total sample count from noise.flac"
else
	# some flavors of cygwin don't seem to treat the \x0d as a word
	# separator, so we hard code it.  we'll just have to fix it later
	# if we change the way noise.flac is made.
699
	total_noise_cdda_samples=393216
Josh Coalson's avatar
Josh Coalson committed
700
fi
701

702
echo $ECHO_N "testing --skip=0... " $ECHO_C
Josh Coalson's avatar
Josh Coalson committed
703
run_flac $wav_dopt --skip=0 -o z.wav noise.flac || die "ERROR decoding FLAC file noise.flac"
704
705
706
echo OK

for delta in 2 1 ; do
707
	n=`expr $total_noise_cdda_samples - $delta`
708
	echo $ECHO_N "testing --skip=$n... " $ECHO_C
Josh Coalson's avatar
Josh Coalson committed
709
	run_flac $wav_dopt --skip=$n -o z.wav noise.flac || die "ERROR decoding FLAC file noise.flac"
710
711
712
713
714
	echo OK
done

rm noise.flac z.wav

715
716
717
718
############################################################################
# test --input-size
############################################################################

Josh Coalson's avatar
Josh Coalson committed
719
#@@@ cat will not work on old cygwin, need to fix
720
if [ $is_win = no ] ; then
721
	echo $ECHO_N "testing --input-size=50 --skip=10... " $ECHO_C
722
723
724
725
726
727
	cat 50c.raw | run_flac $raw_eopt --input-size=50 --skip=10 -o z50c.skip10.flac - || die "ERROR generating FLAC file"
	run_flac $raw_dopt -o z50c.skip10.raw z50c.skip10.flac || die "ERROR decoding FLAC file"
	cmp 50c.skip10.raw z50c.skip10.raw || die "ERROR: file mismatch for --input-size=50 --skip=10"
	rm -f z50c.skip10.raw z50c.skip10.flac
	echo OK
fi
728
729


730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
############################################################################
# test --cue
############################################################################

#
# create the cue sheet
#
cuesheet=cuetest.cue
cat > $cuesheet << EOF
CATALOG 1234567890123
FILE "blah" WAVE
  TRACK 01 AUDIO
    INDEX 01 0
    INDEX 02 10
    INDEX 03 20
  TRACK 02 AUDIO
    INDEX 01 30
  TRACK 04 AUDIO
    INDEX 01 40
EOF

test_cue ()
{
	in_fmt=$1
	out_fmt=$2

756
	[ "$in_fmt" = wav ] || [ "$in_fmt" = aiff ] || [ "$in_fmt" = raw ] || [ "$in_fmt" = flac ] || [ "$in_fmt" = ogg ] || die "ERROR: internal error, bad 'in' format '$in_fmt'"
757
758
759
760
761
762
763
764
765
766
767

	[ "$out_fmt" = flac ] || [ "$out_fmt" = ogg ] || die "ERROR: internal error, bad 'out' format '$out_fmt'"

	if [ $in_fmt = raw ] ; then
		eopt="$raw_eopt"
		dopt="$raw_dopt"
	else
		eopt="$wav_eopt"
		dopt="$wav_dopt"
	fi

768
	if ( [ $in_fmt = flac ] || [ $in_fmt = ogg ] ) && ( [ $out_fmt = flac ] || [ $out_fmt = ogg ] ) ; then
769
770
771
772
773
		CMP=md5cmp
	else
		CMP=cmp
	fi

774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
	if [ $out_fmt = ogg ] ; then
		eopt="--ogg $eopt"
	fi

	desc="($in_fmt<->$out_fmt)"

	#
	# for this we need just need just one FLAC file; --cue only works while decoding
	#
	run_flac $eopt --cuesheet=$cuesheet -o z50c.cue.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"

	# To make it easy to translate from cue point to sample numbers, the
	# file has a sample rate of 10 Hz and a cuesheet like so:
	#
	# TRACK 01, INDEX 01 : 0:00.00 -> sample 0
	# TRACK 01, INDEX 02 : 0:01.00 -> sample 10
	# TRACK 01, INDEX 03 : 0:02.00 -> sample 20
	# TRACK 02, INDEX 01 : 0:03.00 -> sample 30
	# TRACK 04, INDEX 01 : 0:04.00 -> sample 40
	#
794
	echo $ECHO_N "testing --cue=- $desc... " $ECHO_C
795
796
797
	run_flac $dopt -o z50c.cued.$in_fmt --cue=- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=- $desc"
	rm -f z50c.cued.$in_fmt
798
799
	echo OK

800
	echo $ECHO_N "testing --cue=1.0 $desc... " $ECHO_C
801
802
803
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.0 $desc"
	rm -f z50c.cued.$in_fmt
804
805
	echo OK

806
	echo $ECHO_N "testing --cue=1.0- $desc... " $ECHO_C
807
808
809
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.0- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.0- $desc"
	rm -f z50c.cued.$in_fmt
810
811
	echo OK

812
	echo $ECHO_N "testing --cue=1.1 $desc... " $ECHO_C
813
814
815
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.1 $desc"
	rm -f z50c.cued.$in_fmt
816
817
	echo OK

818
	echo $ECHO_N "testing --cue=1.1- $desc... " $ECHO_C
819
820
821
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.1- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.1- $desc"
	rm -f z50c.cued.$in_fmt
822
823
	echo OK

824
	echo $ECHO_N "testing --cue=1.2 $desc... " $ECHO_C
825
826
827
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.2 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.2 $desc"
	rm -f z50c.cued.$in_fmt
828
829
	echo OK

830
	echo $ECHO_N "testing --cue=1.2- $desc... " $ECHO_C
831
832
833
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.2- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.2- $desc"
	rm -f z50c.cued.$in_fmt
834
835
	echo OK

836
	echo $ECHO_N "testing --cue=1.4 $desc... " $ECHO_C
837
838
839
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.4 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip20.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.4 $desc"
	rm -f z50c.cued.$in_fmt
840
841
	echo OK

842
	echo $ECHO_N "testing --cue=1.4- $desc... " $ECHO_C
843
844
845
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.4- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip20.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.4- $desc"
	rm -f z50c.cued.$in_fmt
846
847
	echo OK

848
	echo $ECHO_N "testing --cue=-5.0 $desc... " $ECHO_C
849
850
851
	run_flac $dopt -o z50c.cued.$in_fmt --cue=-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=-5.0 $desc"
	rm -f z50c.cued.$in_fmt
852
853
	echo OK

854
	echo $ECHO_N "testing --cue=-4.1 $desc... " $ECHO_C
855
856
857
	run_flac $dopt -o z50c.cued.$in_fmt --cue=-4.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until40.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=-4.1 $desc"
	rm -f z50c.cued.$in_fmt
858
859
	echo OK

860
	echo $ECHO_N "testing --cue=-3.1 $desc... " $ECHO_C
861
862
863
	run_flac $dopt -o z50c.cued.$in_fmt --cue=-3.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until40.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=-3.1 $desc"
	rm -f z50c.cued.$in_fmt
864
865
	echo OK

866
	echo $ECHO_N "testing --cue=-1.4 $desc... " $ECHO_C
867
868
869
	run_flac $dopt -o z50c.cued.$in_fmt --cue=-1.4 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until30.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=-1.4 $desc"
	rm -f z50c.cued.$in_fmt
870
871
	echo OK

872
	echo $ECHO_N "testing --cue=1.0-5.0 $desc... " $ECHO_C
873
874
875
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.0-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.0-5.0 $desc"
	rm -f z50c.cued.$in_fmt
876
877
	echo OK

878
	echo $ECHO_N "testing --cue=1.1-5.0 $desc... " $ECHO_C
879
880
881
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.1-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.1-5.0 $desc"
	rm -f z50c.cued.$in_fmt
882
883
	echo OK

884
	echo $ECHO_N "testing --cue=1.2-4.1 $desc... " $ECHO_C
885
886
887
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.2-4.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.until40.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.2-4.1 $desc"
	rm -f z50c.cued.$in_fmt
888
889
	echo OK

890
	echo $ECHO_N "testing --cue=1.4-2.0 $desc... " $ECHO_C
891
892
893
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.4-2.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip20.until30.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.4-2.0 $desc"
	rm -f z50c.cued.$in_fmt
894
895
896
897
898
899
900
901
	echo OK

	rm -f z50c.cue.$out_fmt
}

test_cue raw flac
test_cue wav flac
test_cue aiff flac
902
test_cue flac flac
903
904
905
906
#@@@if [ $has_ogg = yes ] ; then
#@@@	#@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
#@@@	test_cue ogg flac
#@@@fi
907

908
if [ $has_ogg = yes ] ; then
909
910
911
	test_cue raw ogg
	test_cue wav ogg
	test_cue aiff ogg
912
	#@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
913
	#@@@test_cue flac ogg
914
	#@@@test_cue ogg ogg
915
916
fi

Josh Coalson's avatar
Josh Coalson committed
917
918
919
920
921
922
############################################################################
# test 'fixup' code that happens when a FLAC file with total_samples == 0
# in the STREAMINFO block is converted to WAVE or AIFF, requiring the
# decoder go back and fix up the chunk headers
############################################################################

923
echo $ECHO_N "WAVE fixup test... " $ECHO_C
Josh Coalson's avatar
Josh Coalson committed
924

925
echo $ECHO_N "prepare... " $ECHO_C
926
convert_to_wav noise "$raw_eopt" "$wav_dopt" || die "ERROR creating reference WAVE"
Josh Coalson's avatar
Josh Coalson committed
927

928
echo $ECHO_N "encode... " $ECHO_C
Josh Coalson's avatar
Josh Coalson committed
929
930
931
932
933
# the pipe from 'cat' to 'flac' does not work on cygwin because of the EOF/
# binary-mode stdin problem, so we use an undocumented option to metaflac to
# set the total sample count to 0
if [ $is_win = yes ] ; then
	run_flac $raw_eopt noise.raw -o fixup.flac || die "ERROR generating FLAC file"
934
	run_metaflac --set-total-samples=0 fixup.flac 2> /dev/null
Josh Coalson's avatar
Josh Coalson committed
935
936
937
938
else
	cat noise.raw | run_flac $raw_eopt - -c > fixup.flac || die "ERROR generating FLAC file"
fi

939
echo $ECHO_N "decode... " $ECHO_C
Josh Coalson's avatar
Josh Coalson committed
940
run_flac $wav_dopt fixup.flac -o fixup.wav || die "ERROR decoding FLAC file"
Josh Coalson's avatar
Josh Coalson committed
941

942
echo $ECHO_N "compare... " $ECHO_C
Josh Coalson's avatar
Josh Coalson committed
943
cmp noise.wav fixup.wav || die "ERROR: file mismatch"
Josh Coalson's avatar
Josh Coalson committed
944

Josh Coalson's avatar
Josh Coalson committed
945
946
947
echo OK
rm -f noise.wav fixup.wav fixup.flac

948
echo $ECHO_N "AIFF fixup test... " $ECHO_C
Josh Coalson's avatar
Josh Coalson committed
949

950
echo $ECHO_N "prepare... " $ECHO_C
951
convert_to_aiff noise "$raw_eopt" "$wav_dopt" || die "ERROR creating reference AIFF"
Josh Coalson's avatar
Josh Coalson committed
952

953
echo $ECHO_N "encode... " $ECHO_C
Josh Coalson's avatar
Josh Coalson committed
954
955
956
957
958
# the pipe from 'cat' to 'flac' does not work on cygwin because of the EOF/
# binary-mode stdin problem, so we use an undocumented option to metaflac to
# set the total sample count to 0
if [ $is_win = yes ] ; then
	run_flac $raw_eopt noise.raw -o fixup.flac || die "ERROR generating FLAC file"
959
	run_metaflac --set-total-samples=0 fixup.flac 2> /dev/null
Josh Coalson's avatar
Josh Coalson committed
960
961
962
963
else
	cat noise.raw | run_flac $raw_eopt - -c > fixup.flac || die "ERROR generating FLAC file"
fi

964
echo $ECHO_N "decode... " $ECHO_C
Josh Coalson's avatar
Josh Coalson committed
965
run_flac $wav_dopt fixup.flac -o fixup.aiff || die "ERROR decoding FLAC file"
Josh Coalson's avatar
Josh Coalson committed
966

967
echo $ECHO_N "compare... " $ECHO_C
Josh Coalson's avatar
Josh Coalson committed
968
cmp noise.aiff fixup.aiff || die "ERROR: file mismatch"
Josh Coalson's avatar
Josh Coalson committed
969

Josh Coalson's avatar
Josh Coalson committed
970
971
972
973
974
echo OK
rm -f noise.aiff fixup.aiff fixup.flac


############################################################################
Josh Coalson's avatar
Josh Coalson committed
975
# multi-file tests
Josh Coalson's avatar
Josh Coalson committed
976
############################################################################
Josh Coalson's avatar
Josh Coalson committed
977
978

echo "Generating multiple input files from noise..."
979
multifile_format_decode="--endian=big --sign=signed"
980
multifile_format_encode="$multifile_format_decode --sample-rate=44100 --bps=16 --channels=2 --no-padding"
981
short_noise_cdda_samples=`expr $total_noise_cdda_samples / 8`
982
983
984
985
run_flac --verify --force --force-raw-format $multifile_format_encode --until=$short_noise_cdda_samples -o shortnoise.flac noise.raw || die "ERROR generating FLAC file"
run_flac --decode --force shor