xref: /aosp_15_r20/external/flac/test/test_flac.sh (revision 600f14f40d737144c998e2ec7a483122d3776fbc)
1#!/bin/sh -e
2
3#  FLAC - Free Lossless Audio Codec
4#  Copyright (C) 2001-2009  Josh Coalson
5#  Copyright (C) 2011-2023  Xiph.Org Foundation
6#
7#  This file is part the FLAC project.  FLAC is comprised of several
8#  components distributed under different licenses.  The codec libraries
9#  are distributed under Xiph.Org's BSD-like license (see the file
10#  COPYING.Xiph in this distribution).  All other programs, libraries, and
11#  plugins are distributed under the GPL (see COPYING.GPL).  The documentation
12#  is distributed under the Gnu FDL (see COPYING.FDL).  Each file in the
13#  FLAC distribution contains at the top the terms under which it may be
14#  distributed.
15#
16#  Since this particular file is relevant to all components of FLAC,
17#  it may be distributed under the Xiph.Org license, which is the least
18#  restrictive of those mentioned above.  See the file COPYING.Xiph in this
19#  distribution.
20
21. ./common.sh
22
23# we use '.' as decimal separator in --skip/--until tests
24export LANG=C LC_ALL=C
25
26dddie="die ERROR: creating files with dd"
27
28PATH="$(pwd)/../src/flac:$PATH"
29PATH="$(pwd)/../src/metaflac:$PATH"
30PATH="$(pwd)/../src/test_streams:$PATH"
31PATH="$(pwd)/../objs/$BUILD/bin:$PATH"
32
33flac${EXE} --help 1>/dev/null 2>/dev/null || die "ERROR can't find flac executable"
34
35run_flac ()
36{
37	if [ "$FLAC__TEST_WITH_VALGRIND" = yes ] ; 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
40	else
41		flac${EXE} $TOTALLY_SILENT --no-error-on-compression-fail $*
42	fi
43}
44
45run_metaflac ()
46{
47	if [ "$FLAC__TEST_WITH_VALGRIND" = yes ] ; 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	fi
53}
54
55md5cmp ()
56{
57	n=$( ( [ -f "$1" ] && [ -f "$2" ] && metaflac${EXE} --show-md5sum --no-filename "$1" "$2" 2>/dev/null || exit 1 ) | uniq | wc -l)
58	[ "$n" != "" ] && [ $n = 1 ]
59}
60
61echo "Checking for --ogg support in flac..."
62if 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
63	has_ogg=yes;
64	echo "flac --ogg works"
65else
66	has_ogg=no;
67	echo "flac --ogg doesn't work"
68fi
69
70echo "Generating streams..."
71if [ ! -f wacky1.wav ] ; then
72	test_streams || die "ERROR during test_streams"
73fi
74
75############################################################################
76# test that flac doesn't automatically overwrite files unless -f is used
77############################################################################
78
79echo "Try encoding to a file that exists; should fail"
80cp wacky1.wav exist.wav
81touch exist.flac
82if run_flac -0 exist.wav ; then
83	die "ERROR: it should have failed but didn't"
84else
85	echo "OK, it failed as it should"
86fi
87
88echo "Try encoding with -f to a file that exists; should succeed"
89if run_flac -0 --force exist.wav ; then
90	echo "OK, it succeeded as it should"
91else
92	die "ERROR: it should have succeeded but didn't"
93fi
94
95echo "Try decoding to a file that exists; should fail"
96if run_flac -d exist.flac ; then
97	die "ERROR: it should have failed but didn't"
98else
99	echo "OK, it failed as it should"
100fi
101
102echo "Try decoding with -f to a file that exists; should succeed"
103if run_flac -d -f exist.flac ; then
104	echo "OK, it succeeded as it should"
105else
106	die "ERROR: it should have succeeded but didn't"
107fi
108
109rm -f exist.wav exist.flac
110
111############################################################################
112# test fractional block sizes
113############################################################################
114
115test_fractional ()
116{
117	blocksize=$1
118	samples=$2
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
125	cmp pbs.raw pbs.cmp || die "ERROR: file mismatch"
126	echo "OK"
127	rm -f pbs.raw pbs.flac pbs.cmp
128}
129
130# The special significance of 2048 is it's the # of samples that flac calls
131# FLAC__stream_encoder_process() on.
132#
133# We're trying to make sure the 1-sample overread logic in the stream encoder
134# (used for last-block checking) works; these values probe around common
135# multiples of the flac sample chunk size (2048) and the blocksize.
136for samples in 31 32 33 34 35 2046 2047 2048 2049 2050 ; do
137	test_fractional 33 $samples
138done
139for 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
140	test_fractional 256 $samples
141done
142for samples in 1022 1023 1024 1025 1026 2046 2047 2048 2049 2050 4094 4095 4096 4097 4098 ; do
143	test_fractional 2048 $samples
144done
145for 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
146	test_fractional 4608 $samples
147done
148
149############################################################################
150# basic 'round-trip' tests of various kinds of streams
151############################################################################
152
153rt_test_raw ()
154{
155	f="$1"
156	extra="$2"
157	channels="$(echo $f | awk -F- '{print $2}')"
158	bps="$(echo $f | awk -F- '{print $3}')"
159	sign="$(echo $f | awk -F- '{print $4}')"
160
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	cmp $f rt.raw || die "ERROR: file mismatch"
167	echo "OK"
168	rm -f rt.flac rt.raw
169}
170
171rt_test_wav ()
172{
173	f="$1"
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	cmp $f rt.wav || die "ERROR: file mismatch"
181	echo "OK"
182	rm -f rt.flac rt.wav
183}
184
185rt_test_wav_autokf ()
186{
187	f="$1"
188	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 $extra rt.flac || die "ERROR"
193	echo $ECHO_N "compare... " $ECHO_C
194	cmp $f rt.wav || die "ERROR: file mismatch"
195	echo "OK"
196	rm -f rt.flac rt.wav
197}
198
199rt_test_w64 ()
200{
201	f="$1"
202	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.w64 $extra rt.flac || die "ERROR"
207	echo $ECHO_N "compare... " $ECHO_C
208	cmp $f rt.w64 || die "ERROR: file mismatch"
209	echo "OK"
210	rm -f rt.flac rt.w64
211}
212
213rt_test_w64_autokf ()
214{
215	f="$1"
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 $extra rt.flac || die "ERROR"
221	echo $ECHO_N "compare... " $ECHO_C
222	cmp $f rt.w64 || die "ERROR: file mismatch"
223	echo "OK"
224	rm -f rt.flac rt.w64
225}
226
227rt_test_rf64 ()
228{
229	f="$1"
230	extra="$2"
231	echo $ECHO_N "round-trip test ($f) encode... " $ECHO_C
232	run_flac --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
233	echo $ECHO_N "decode... " $ECHO_C
234	run_flac --force --decode --channel-map=none -o rt.rf64 $extra rt.flac || die "ERROR"
235	echo $ECHO_N "compare... " $ECHO_C
236	cmp $f rt.rf64 || die "ERROR: file mismatch"
237	echo "OK"
238	rm -f rt.flac rt.rf64
239}
240
241rt_test_rf64_autokf ()
242{
243	f="$1"
244	extra="$2"
245	echo $ECHO_N "round-trip test ($f) encode... " $ECHO_C
246	run_flac --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
247	echo $ECHO_N "decode... " $ECHO_C
248	run_flac --force --decode --channel-map=none $extra rt.flac || die "ERROR"
249	echo $ECHO_N "compare... " $ECHO_C
250	cmp $f rt.rf64 || die "ERROR: file mismatch"
251	echo "OK"
252	rm -f rt.flac rt.rf64
253}
254
255rt_test_aiff ()
256{
257	f="$1"
258	extra="$2"
259	echo $ECHO_N "round-trip test ($f) encode... " $ECHO_C
260	run_flac --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
261	echo $ECHO_N "decode... " $ECHO_C
262	run_flac --force --decode --channel-map=none -o rt.aiff $extra rt.flac || die "ERROR"
263	echo $ECHO_N "compare... " $ECHO_C
264	cmp $f rt.aiff || die "ERROR: file mismatch"
265	echo "OK"
266	rm -f rt.flac rt.aiff
267}
268
269rt_test_autokf ()
270{
271	f="$1"
272	extra="$2"
273	echo $ECHO_N "round-trip test ($f) encode... " $ECHO_C
274	run_flac --force --verify --no-padding --lax -o rt.flac $extra $f || die "ERROR"
275	echo $ECHO_N "decode... " $ECHO_C
276	run_flac --force --decode $extra rt.flac || die "ERROR"
277	echo $ECHO_N "compare... " $ECHO_C
278	cmp $f $3 || die "ERROR: file mismatch"
279	echo "OK"
280	rm -f rt.flac $3
281}
282
283# assumes input file is WAVE; does not check the metadata-preserving features of flac-to-flac; that is checked later
284rt_test_flac ()
285{
286	f="$1"
287	extra="$2"
288	echo $ECHO_N "round-trip test ($f->flac->flac->wav) encode... " $ECHO_C
289	run_flac --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
290	echo $ECHO_N "re-encode... " $ECHO_C
291	run_flac --force --verify --lax -o rt2.flac rt.flac || die "ERROR"
292	echo $ECHO_N "decode... " $ECHO_C
293	run_flac --force --decode --channel-map=none -o rt.wav $extra rt2.flac || die "ERROR"
294	echo $ECHO_N "compare... " $ECHO_C
295	cmp $f rt.wav || die "ERROR: file mismatch"
296	echo "OK"
297	rm -f rt.wav rt.flac rt2.flac
298}
299
300# assumes input file is WAVE; does not check the metadata-preserving features of flac-to-flac; that is checked later
301rt_test_ogg_flac ()
302{
303	f="$1"
304	extra="$2"
305	echo $ECHO_N "round-trip test ($f->oggflac->oggflac->wav) encode... " $ECHO_C
306	run_flac --force --verify --channel-map=none --no-padding --lax -o rt.oga --ogg $extra $f || die "ERROR"
307	echo $ECHO_N "re-encode... " $ECHO_C
308	run_flac --force --verify --lax -o rt2.oga --ogg rt.oga || die "ERROR"
309	echo $ECHO_N "decode... " $ECHO_C
310	run_flac --force --decode --channel-map=none -o rt.wav $extra rt2.oga || die "ERROR"
311	echo $ECHO_N "compare... " $ECHO_C
312	cmp $f rt.wav || die "ERROR: file mismatch"
313	echo "OK"
314	rm -f rt.wav rt.oga rt2.oga
315}
316
317for f in rt-*.raw ; do
318	rt_test_raw $f
319done
320for f in rt-*.wav ; do
321	rt_test_wav $f
322done
323for f in rt-*.w64 ; do
324	rt_test_w64 $f
325done
326for f in rt-*.rf64 ; do
327	rt_test_rf64 $f
328done
329for f in rt-*.aiff ; do
330	rt_test_aiff $f
331done
332for f in rt-*.wav ; do
333	rt_test_flac $f
334done
335if [ $has_ogg = yes ] ; then
336	for f in rt-*.wav ; do
337		rt_test_ogg_flac $f
338	done
339fi
340
341############################################################################
342# test --skip and --until
343############################################################################
344
345#
346# first make some chopped-up raw files
347#
348echo "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMN" > master.raw
349dd if=master.raw ibs=1 count=50 of=50c.raw 2>/dev/null || $dddie
350dd if=master.raw ibs=1 skip=10 count=40 of=50c.skip10.raw 2>/dev/null || $dddie
351dd if=master.raw ibs=1 skip=11 count=39 of=50c.skip11.raw 2>/dev/null || $dddie
352dd if=master.raw ibs=1 skip=20 count=30 of=50c.skip20.raw 2>/dev/null || $dddie
353dd if=master.raw ibs=1 skip=30 count=20 of=50c.skip30.raw 2>/dev/null || $dddie
354dd if=master.raw ibs=1 skip=40 count=10 of=50c.skip40.raw 2>/dev/null || $dddie
355dd if=master.raw ibs=1 count=10 of=50c.until10.raw 2>/dev/null || $dddie
356dd if=master.raw ibs=1 count=20 of=50c.until20.raw 2>/dev/null || $dddie
357dd if=master.raw ibs=1 count=30 of=50c.until30.raw 2>/dev/null || $dddie
358dd if=master.raw ibs=1 count=39 of=50c.until39.raw 2>/dev/null || $dddie
359dd if=master.raw ibs=1 count=40 of=50c.until40.raw 2>/dev/null || $dddie
360dd if=master.raw ibs=1 skip=10 count=20 of=50c.skip10.until30.raw 2>/dev/null || $dddie
361dd if=master.raw ibs=1 skip=10 count=29 of=50c.skip10.until39.raw 2>/dev/null || $dddie
362dd if=master.raw ibs=1 skip=10 count=30 of=50c.skip10.until40.raw 2>/dev/null || $dddie
363dd if=master.raw ibs=1 skip=20 count=10 of=50c.skip20.until30.raw 2>/dev/null || $dddie
364dd if=master.raw ibs=1 skip=20 count=20 of=50c.skip20.until40.raw 2>/dev/null || $dddie
365
366wav_eopt="--force --verify --no-padding --lax"
367wav_dopt="--force --decode"
368
369raw_eopt="$wav_eopt --force-raw-format --endian=big --sign=signed --sample-rate=10 --bps=8 --channels=1"
370raw_dopt="$wav_dopt --force-raw-format --endian=big --sign=signed"
371
372#
373# convert them to WAVE/AIFF/Ogg FLAC files
374#
375convert_to_wav ()
376{
377	run_flac "$2" $1.raw || die "ERROR converting $1.raw to WAVE"
378	run_flac "$3" $1.flac || die "ERROR converting $1.raw to WAVE"
379}
380convert_to_wav 50c "$raw_eopt" "$wav_dopt"
381convert_to_wav 50c.skip10 "$raw_eopt" "$wav_dopt"
382convert_to_wav 50c.skip11 "$raw_eopt" "$wav_dopt"
383convert_to_wav 50c.skip20 "$raw_eopt" "$wav_dopt"
384convert_to_wav 50c.skip30 "$raw_eopt" "$wav_dopt"
385convert_to_wav 50c.skip40 "$raw_eopt" "$wav_dopt"
386convert_to_wav 50c.until10 "$raw_eopt" "$wav_dopt"
387convert_to_wav 50c.until20 "$raw_eopt" "$wav_dopt"
388convert_to_wav 50c.until30 "$raw_eopt" "$wav_dopt"
389convert_to_wav 50c.until39 "$raw_eopt" "$wav_dopt"
390convert_to_wav 50c.until40 "$raw_eopt" "$wav_dopt"
391convert_to_wav 50c.skip10.until30 "$raw_eopt" "$wav_dopt"
392convert_to_wav 50c.skip10.until39 "$raw_eopt" "$wav_dopt"
393convert_to_wav 50c.skip10.until40 "$raw_eopt" "$wav_dopt"
394convert_to_wav 50c.skip20.until30 "$raw_eopt" "$wav_dopt"
395convert_to_wav 50c.skip20.until40 "$raw_eopt" "$wav_dopt"
396
397convert_to_aiff ()
398{
399	run_flac "$2" $1.raw || die "ERROR converting $1.raw to AIFF"
400	run_flac "$3" $1.flac -o $1.aiff || die "ERROR converting $1.raw to AIFF"
401}
402convert_to_aiff 50c "$raw_eopt" "$wav_dopt"
403convert_to_aiff 50c.skip10 "$raw_eopt" "$wav_dopt"
404convert_to_aiff 50c.skip11 "$raw_eopt" "$wav_dopt"
405convert_to_aiff 50c.skip20 "$raw_eopt" "$wav_dopt"
406convert_to_aiff 50c.skip30 "$raw_eopt" "$wav_dopt"
407convert_to_aiff 50c.skip40 "$raw_eopt" "$wav_dopt"
408convert_to_aiff 50c.until10 "$raw_eopt" "$wav_dopt"
409convert_to_aiff 50c.until20 "$raw_eopt" "$wav_dopt"
410convert_to_aiff 50c.until30 "$raw_eopt" "$wav_dopt"
411convert_to_aiff 50c.until39 "$raw_eopt" "$wav_dopt"
412convert_to_aiff 50c.until40 "$raw_eopt" "$wav_dopt"
413convert_to_aiff 50c.skip10.until30 "$raw_eopt" "$wav_dopt"
414convert_to_aiff 50c.skip10.until39 "$raw_eopt" "$wav_dopt"
415convert_to_aiff 50c.skip10.until40 "$raw_eopt" "$wav_dopt"
416convert_to_aiff 50c.skip20.until30 "$raw_eopt" "$wav_dopt"
417convert_to_aiff 50c.skip20.until40 "$raw_eopt" "$wav_dopt"
418
419convert_to_ogg ()
420{
421	run_flac "$wav_eopt" --ogg $1.wav || die "ERROR converting $1.raw to Ogg FLAC"
422}
423if [ $has_ogg = yes ] ; then
424	convert_to_ogg 50c
425	convert_to_ogg 50c.skip10
426	convert_to_ogg 50c.skip11
427	convert_to_ogg 50c.skip20
428	convert_to_ogg 50c.skip30
429	convert_to_ogg 50c.skip40
430	convert_to_ogg 50c.until10
431	convert_to_ogg 50c.until20
432	convert_to_ogg 50c.until30
433	convert_to_ogg 50c.until39
434	convert_to_ogg 50c.until40
435	convert_to_ogg 50c.skip10.until30
436	convert_to_ogg 50c.skip10.until39
437	convert_to_ogg 50c.skip10.until40
438	convert_to_ogg 50c.skip20.until30
439	convert_to_ogg 50c.skip20.until40
440fi
441
442test_skip_until ()
443{
444	in_fmt=$1
445	out_fmt=$2
446
447	[ "$in_fmt" = wav ] || [ "$in_fmt" = aiff ] || [ "$in_fmt" = raw ] || [ "$in_fmt" = flac ] || [ "$in_fmt" = ogg ] || die "ERROR: internal error, bad 'in' format '$in_fmt'"
448
449	[ "$out_fmt" = flac ] || [ "$out_fmt" = ogg ] || die "ERROR: internal error, bad 'out' format '$out_fmt'"
450
451	if [ $in_fmt = raw ] ; then
452		eopt="$raw_eopt"
453		dopt="$raw_dopt"
454	else
455		eopt="$wav_eopt"
456		dopt="$wav_dopt"
457	fi
458
459	if [ $in_fmt = flac -o $in_fmt = ogg ] && [ $out_fmt = flac -o $out_fmt = ogg ]; then
460		CMP=md5cmp
461	else
462		CMP=cmp
463	fi
464
465	if [ $out_fmt = ogg ] ; then
466		eopt="--ogg $eopt"
467	fi
468
469	#
470	# test --skip when encoding
471	#
472
473	desc="($in_fmt<->$out_fmt)"
474
475	echo $ECHO_N "testing --skip=# (encode) $desc... " $ECHO_C
476	run_flac $eopt --skip=10 -o z50c.skip10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
477	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.$in_fmt z50c.skip10.$out_fmt || die "ERROR decoding FLAC file $desc"
478	$CMP 50c.skip10.$in_fmt z50c.skip10.$in_fmt || die "ERROR: file mismatch for --skip=10 (encode) $desc"
479	rm -f z50c.skip10.$out_fmt z50c.skip10.$in_fmt
480	echo OK
481
482	echo $ECHO_N "testing --skip=mm:ss (encode) $desc... " $ECHO_C
483	run_flac $eopt --skip=0:01 -o z50c.skip0_01.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
484
485	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip0_01.$in_fmt z50c.skip0_01.$out_fmt || die "ERROR decoding FLAC file $desc"
486	$CMP 50c.skip10.$in_fmt z50c.skip0_01.$in_fmt || die "ERROR: file mismatch for --skip=0:01 (encode) $desc"
487	rm -f z50c.skip0_01.$out_fmt z50c.skip0_01.$in_fmt
488	echo OK
489
490	echo $ECHO_N "testing --skip=mm:ss.sss (encode) $desc... " $ECHO_C
491	run_flac $eopt --skip=0:01.1001 -o z50c.skip0_01.1001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
492	[ $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"
493	$CMP 50c.skip11.$in_fmt z50c.skip0_01.1001.$in_fmt || die "ERROR: file mismatch for --skip=0:01.1001 (encode) $desc"
494	rm -f z50c.skip0_01.1001.$out_fmt z50c.skip0_01.1001.$in_fmt
495	echo OK
496
497	#
498	# test --skip when decoding
499	#
500
501	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"
502
503	echo $ECHO_N "testing --skip=# (decode) $desc... " $ECHO_C
504	run_flac $dopt --skip=10 -o z50c.skip10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
505	$CMP 50c.skip10.$in_fmt z50c.skip10.$in_fmt || die "ERROR: file mismatch for --skip=10 (decode) $desc"
506	rm -f z50c.skip10.$in_fmt
507	echo OK
508
509	echo $ECHO_N "testing --skip=mm:ss (decode) $desc... " $ECHO_C
510	run_flac $dopt --skip=0:01 -o z50c.skip0_01.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
511	$CMP 50c.skip10.$in_fmt z50c.skip0_01.$in_fmt || die "ERROR: file mismatch for --skip=0:01 (decode) $desc"
512	rm -f z50c.skip0_01.$in_fmt
513	echo OK
514
515	echo $ECHO_N "testing --skip=mm:ss.sss (decode) $desc... " $ECHO_C
516	run_flac $dopt --skip=0:01.1001 -o z50c.skip0_01.1001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
517	$CMP 50c.skip11.$in_fmt z50c.skip0_01.1001.$in_fmt || die "ERROR: file mismatch for --skip=0:01.1001 (decode) $desc"
518	rm -f z50c.skip0_01.1001.$in_fmt
519	echo OK
520
521	rm -f z50c.$out_fmt
522
523	#
524	# test --until when encoding
525	#
526
527	echo $ECHO_N "testing --until=# (encode) $desc... " $ECHO_C
528	run_flac $eopt --until=40 -o z50c.until40.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
529	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until40.$in_fmt z50c.until40.$out_fmt || die "ERROR decoding FLAC file $desc"
530	$CMP 50c.until40.$in_fmt z50c.until40.$in_fmt || die "ERROR: file mismatch for --until=40 (encode) $desc"
531	rm -f z50c.until40.$out_fmt z50c.until40.$in_fmt
532	echo OK
533
534	echo $ECHO_N "testing --until=mm:ss (encode) $desc... " $ECHO_C
535	run_flac $eopt --until=0:04 -o z50c.until0_04.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
536	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until0_04.$in_fmt z50c.until0_04.$out_fmt || die "ERROR decoding FLAC file $desc"
537	$CMP 50c.until40.$in_fmt z50c.until0_04.$in_fmt || die "ERROR: file mismatch for --until=0:04 (encode) $desc"
538	rm -f z50c.until0_04.$out_fmt z50c.until0_04.$in_fmt
539	echo OK
540
541	echo $ECHO_N "testing --until=mm:ss.sss (encode) $desc... " $ECHO_C
542	run_flac $eopt --until=0:03.9001 -o z50c.until0_03.9001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
543	[ $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"
544	$CMP 50c.until39.$in_fmt z50c.until0_03.9001.$in_fmt || die "ERROR: file mismatch for --until=0:03.9001 (encode) $desc"
545	rm -f z50c.until0_03.9001.$out_fmt z50c.until0_03.9001.$in_fmt
546	echo OK
547
548	echo $ECHO_N "testing --until=-# (encode) $desc... " $ECHO_C
549	run_flac $eopt --until=-10 -o z50c.until-10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
550	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until-10.$in_fmt z50c.until-10.$out_fmt || die "ERROR decoding FLAC file $desc"
551	$CMP 50c.until40.$in_fmt z50c.until-10.$in_fmt || die "ERROR: file mismatch for --until=-10 (encode) $desc"
552	rm -f z50c.until-10.$out_fmt z50c.until-10.$in_fmt
553	echo OK
554
555	echo $ECHO_N "testing --until=-mm:ss (encode) $desc... " $ECHO_C
556	run_flac $eopt --until=-0:01 -o z50c.until-0_01.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
557	[ $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"
558	$CMP 50c.until40.$in_fmt z50c.until-0_01.$in_fmt || die "ERROR: file mismatch for --until=-0:01 (encode) $desc"
559	rm -f z50c.until-0_01.$out_fmt z50c.until-0_01.$in_fmt
560	echo OK
561
562	echo $ECHO_N "testing --until=-mm:ss.sss (encode) $desc... " $ECHO_C
563	run_flac $eopt --until=-0:01.1001 -o z50c.until-0_01.1001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
564	[ $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"
565	$CMP 50c.until39.$in_fmt z50c.until-0_01.1001.$in_fmt || die "ERROR: file mismatch for --until=-0:01.1001 (encode) $desc"
566	rm -f z50c.until-0_01.1001.$out_fmt z50c.until-0_01.1001.$in_fmt
567	echo OK
568
569	#
570	# test --until when decoding
571	#
572
573	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"
574
575	echo $ECHO_N "testing --until=# (decode) $desc... " $ECHO_C
576	run_flac $dopt --until=40 -o z50c.until40.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
577	$CMP 50c.until40.$in_fmt z50c.until40.$in_fmt || die "ERROR: file mismatch for --until=40 (decode) $desc"
578	rm -f z50c.until40.$in_fmt
579	echo OK
580
581	echo $ECHO_N "testing --until=mm:ss (decode) $desc... " $ECHO_C
582	run_flac $dopt --until=0:04 -o z50c.until0_04.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
583	$CMP 50c.until40.$in_fmt z50c.until0_04.$in_fmt || die "ERROR: file mismatch for --until=0:04 (decode) $desc"
584	rm -f z50c.until0_04.$in_fmt
585	echo OK
586
587	echo $ECHO_N "testing --until=mm:ss.sss (decode) $desc... " $ECHO_C
588	run_flac $dopt --until=0:03.9001 -o z50c.until0_03.9001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
589	$CMP 50c.until39.$in_fmt z50c.until0_03.9001.$in_fmt || die "ERROR: file mismatch for --until=0:03.9001 (decode) $desc"
590	rm -f z50c.until0_03.9001.$in_fmt
591	echo OK
592
593	echo $ECHO_N "testing --until=-# (decode) $desc... " $ECHO_C
594	run_flac $dopt --until=-10 -o z50c.until-10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
595	$CMP 50c.until40.$in_fmt z50c.until-10.$in_fmt || die "ERROR: file mismatch for --until=-10 (decode) $desc"
596	rm -f z50c.until-10.$in_fmt
597	echo OK
598
599	echo $ECHO_N "testing --until=-mm:ss (decode) $desc... " $ECHO_C
600	run_flac $dopt --until=-0:01 -o z50c.until-0_01.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
601	$CMP 50c.until40.$in_fmt z50c.until-0_01.$in_fmt || die "ERROR: file mismatch for --until=-0:01 (decode) $desc"
602	rm -f z50c.until-0_01.$in_fmt
603	echo OK
604
605	echo $ECHO_N "testing --until=-mm:ss.sss (decode) $desc... " $ECHO_C
606	run_flac $dopt --until=-0:01.1001 -o z50c.until-0_01.1001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
607	$CMP 50c.until39.$in_fmt z50c.until-0_01.1001.$in_fmt || die "ERROR: file mismatch for --until=-0:01.1001 (decode) $desc"
608	rm -f z50c.until-0_01.1001.$in_fmt
609	echo OK
610
611	rm -f z50c.$out_fmt
612
613	#
614	# test --skip and --until when encoding
615	#
616
617	echo $ECHO_N "testing --skip=10 --until=# (encode) $desc... " $ECHO_C
618	run_flac $eopt --skip=10 --until=40 -o z50c.skip10.until40.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
619	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until40.$in_fmt z50c.skip10.until40.$out_fmt || die "ERROR decoding FLAC file $desc"
620	$CMP 50c.skip10.until40.$in_fmt z50c.skip10.until40.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=40 (encode) $desc"
621	rm -f z50c.skip10.until40.$out_fmt z50c.skip10.until40.$in_fmt
622	echo OK
623
624	echo $ECHO_N "testing --skip=10 --until=mm:ss (encode) $desc... " $ECHO_C
625	run_flac $eopt --skip=10 --until=0:04 -o z50c.skip10.until0_04.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
626	[ $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"
627	$CMP 50c.skip10.until40.$in_fmt z50c.skip10.until0_04.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=0:04 (encode) $desc"
628	rm -f z50c.skip10.until0_04.$out_fmt z50c.skip10.until0_04.$in_fmt
629	echo OK
630
631	echo $ECHO_N "testing --skip=10 --until=mm:ss.sss (encode) $desc... " $ECHO_C
632	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"
633	[ $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"
634	$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"
635	rm -f z50c.skip10.until0_03.9001.$out_fmt z50c.skip10.until0_03.9001.$in_fmt
636	echo OK
637
638	echo $ECHO_N "testing --skip=10 --until=+# (encode) $desc... " $ECHO_C
639	run_flac $eopt --skip=10 --until=+30 -o z50c.skip10.until+30.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
640	[ $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"
641	$CMP 50c.skip10.until40.$in_fmt z50c.skip10.until+30.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=+30 (encode) $desc"
642	rm -f z50c.skip10.until+30.$out_fmt z50c.skip10.until+30.$in_fmt
643	echo OK
644
645	echo $ECHO_N "testing --skip=10 --until=+mm:ss (encode) $desc... " $ECHO_C
646	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"
647	[ $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"
648	$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"
649	rm -f z50c.skip10.until+0_03.$out_fmt z50c.skip10.until+0_03.$in_fmt
650	echo OK
651
652	echo $ECHO_N "testing --skip=10 --until=+mm:ss.sss (encode) $desc... " $ECHO_C
653	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"
654	[ $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"
655	$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"
656	rm -f z50c.skip10.until+0_02.9001.$out_fmt z50c.skip10.until+0_02.9001.$in_fmt
657	echo OK
658
659	echo $ECHO_N "testing --skip=10 --until=-# (encode) $desc... " $ECHO_C
660	run_flac $eopt --skip=10 --until=-10 -o z50c.skip10.until-10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
661	[ $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"
662	$CMP 50c.skip10.until40.$in_fmt z50c.skip10.until-10.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-10 (encode) $desc"
663	rm -f z50c.skip10.until-10.$out_fmt z50c.skip10.until-10.$in_fmt
664	echo OK
665
666	echo $ECHO_N "testing --skip=10 --until=-mm:ss (encode) $desc... " $ECHO_C
667	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"
668	[ $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"
669	$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"
670	rm -f z50c.skip10.until-0_01.$out_fmt z50c.skip10.until-0_01.$in_fmt
671	echo OK
672
673	echo $ECHO_N "testing --skip=10 --until=-mm:ss.sss (encode) $desc... " $ECHO_C
674	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"
675	[ $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"
676	$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"
677	rm -f z50c.skip10.until-0_01.1001.$out_fmt z50c.skip10.until-0_01.1001.$in_fmt
678	echo OK
679
680	#
681	# test --skip and --until when decoding
682	#
683
684	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"
685
686
687	echo $ECHO_N "testing --skip=10 --until=# (decode) $desc... " $ECHO_C
688	run_flac $dopt --skip=10 --until=40 -o z50c.skip10.until40.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
689	$CMP 50c.skip10.until40.$in_fmt z50c.skip10.until40.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=40 (decode) $desc"
690	rm -f z50c.skip10.until40.$in_fmt
691	echo OK
692
693	echo $ECHO_N "testing --skip=10 --until=mm:ss (decode) $desc... " $ECHO_C
694	run_flac $dopt --skip=10 --until=0:04 -o z50c.skip10.until0_04.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
695	$CMP 50c.skip10.until40.$in_fmt z50c.skip10.until0_04.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=0:04 (decode) $desc"
696	rm -f z50c.skip10.until0_04.$in_fmt
697	echo OK
698
699	echo $ECHO_N "testing --skip=10 --until=mm:ss.sss (decode) $desc... " $ECHO_C
700	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"
701	$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"
702	rm -f z50c.skip10.until0_03.9001.$in_fmt
703	echo OK
704
705	echo $ECHO_N "testing --skip=10 --until=-# (decode) $desc... " $ECHO_C
706	run_flac $dopt --skip=10 --until=-10 -o z50c.skip10.until-10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
707	$CMP 50c.skip10.until40.$in_fmt z50c.skip10.until-10.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-10 (decode) $desc"
708	rm -f z50c.skip10.until-10.$in_fmt
709	echo OK
710
711	echo $ECHO_N "testing --skip=10 --until=-mm:ss (decode) $desc... " $ECHO_C
712	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"
713	$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"
714	rm -f z50c.skip10.until-0_01.$in_fmt
715	echo OK
716
717	echo $ECHO_N "testing --skip=10 --until=-mm:ss.sss (decode) $desc... " $ECHO_C
718	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"
719	$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"
720	rm -f z50c.skip10.until-0_01.1001.$in_fmt
721	echo OK
722
723	rm -f z50c.$out_fmt
724}
725
726test_skip_until raw flac
727test_skip_until wav flac
728test_skip_until aiff flac
729test_skip_until flac flac
730#@@@if [ $has_ogg = yes ] ; then
731#@@@	#@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
732#@@@	test_skip_until ogg flac
733#@@@fi
734
735if [ $has_ogg = yes ] ; then
736	test_skip_until raw ogg
737	test_skip_until wav ogg
738	test_skip_until aiff ogg
739	#@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
740	#@@@test_skip_until flac ogg
741	#@@@test_skip_until ogg ogg
742fi
743
744echo "testing seek extremes:"
745
746run_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"
747
748if [ $is_win = no ] ; then
749	total_noise_cdda_samples="$(run_metaflac --show-total-samples noise.flac)"
750	[ $? = 0 ] || die "ERROR getting total sample count from noise.flac"
751else
752	# some flavors of cygwin don't seem to treat the \x0d as a word
753	# separator, so we hard code it.  we'll just have to fix it later
754	# if we change the way noise.flac is made.
755	total_noise_cdda_samples=393216
756fi
757
758echo $ECHO_N "testing --skip=0... " $ECHO_C
759run_flac $wav_dopt --skip=0 -o z.wav noise.flac || die "ERROR decoding FLAC file noise.flac"
760echo OK
761
762for delta in 2 1 ; do
763	n=$((total_noise_cdda_samples - delta))
764	echo $ECHO_N "testing --skip=$n... " $ECHO_C
765	run_flac $wav_dopt --skip=$n -o z.wav noise.flac || die "ERROR decoding FLAC file noise.flac"
766	echo OK
767done
768
769rm noise.flac z.wav
770
771############################################################################
772# test --input-size
773############################################################################
774
775#@@@ cat will not work on old cygwin, need to fix
776if [ $is_win = no ] ; then
777	echo $ECHO_N "testing --input-size=50 --skip=10... " $ECHO_C
778	run_flac $raw_eopt --input-size=50 --skip=10 -o z50c.skip10.flac - < 50c.raw || die "ERROR generating FLAC file"
779	run_flac $raw_dopt -o z50c.skip10.raw z50c.skip10.flac || die "ERROR decoding FLAC file"
780	cmp 50c.skip10.raw z50c.skip10.raw || die "ERROR: file mismatch for --input-size=50 --skip=10"
781	rm -f z50c.skip10.raw z50c.skip10.flac
782	echo OK
783fi
784
785############################################################################
786# test --output-prefix
787############################################################################
788
789in_dir=./tmp_in
790out_dir=./tmp_out
791mkdir $in_dir $out_dir || die "ERROR failed to create temp directories"
792
793cp 50c.raw 50c.flac $in_dir
794
795#
796# test --output-prefix when encoding
797#
798
799echo $ECHO_N "testing --output-prefix=$out_dir/ (encode)... " $ECHO_C
800run_flac $raw_eopt --output-prefix=$out_dir/ $in_dir/50c.raw || die "ERROR generating FLAC file in $out_dir (encode)"
801[ -f $out_dir/50c.flac ] || die "ERROR FLAC file not in $out_dir (encode)"
802run_flac $raw_dopt $out_dir/50c.flac || die "ERROR decoding FLAC file (encode)"
803[ -f $out_dir/50c.raw ] || die "ERROR RAW file not in $out_dir (encode)"
804cmp 50c.raw $out_dir/50c.raw || die "ERROR: file mismatch for --output-prefix=$out_dir (encode)"
805rm -f $out_dir/50c.flac $out_dir/50c.raw
806echo OK
807
808#
809# test --ouput-prefix when decoding
810#
811
812echo $ECHO_N "testing --output-prefix=$out_dir/ (decode)... " $ECHO_C
813run_flac $raw_dopt --output-prefix=$out_dir/ $in_dir/50c.flac || die "ERROR deocding FLAC file in $out_dir (decode)"
814[ -f $out_dir/50c.raw ] || die "ERROR RAW file not in $out_dir (decode)"
815run_flac $raw_eopt $out_dir/50c.raw || die "ERROR generating FLAC file (decode)"
816[ -f $out_dir/50c.flac ] || die "ERROR FLAC file not in $out_dir (decode)"
817cmp 50c.flac $out_dir/50c.flac || die "ERROR: file mismatch for --output-prefix=$out_dir (decode)"
818rm -f $out_dir/50c.flac $out_dir/50c.raw
819echo OK
820
821rm -rf $in_dir $out_dir
822
823############################################################################
824# test --cue
825############################################################################
826
827#
828# create the cue sheet
829#
830cuesheet=cuetest.cue
831cat > $cuesheet << EOF
832CATALOG 1234567890123
833FILE "blah" WAVE
834  TRACK 01 AUDIO
835    INDEX 01 0
836    INDEX 02 10
837    INDEX 03 20
838  TRACK 02 AUDIO
839    INDEX 01 30
840  TRACK 04 AUDIO
841    INDEX 01 40
842EOF
843
844test_cue ()
845{
846	in_fmt=$1
847	out_fmt=$2
848
849	[ "$in_fmt" = wav ] || [ "$in_fmt" = aiff ] || [ "$in_fmt" = raw ] || [ "$in_fmt" = flac ] || [ "$in_fmt" = ogg ] || die "ERROR: internal error, bad 'in' format '$in_fmt'"
850
851	[ "$out_fmt" = flac ] || [ "$out_fmt" = ogg ] || die "ERROR: internal error, bad 'out' format '$out_fmt'"
852
853	if [ $in_fmt = raw ] ; then
854		eopt="$raw_eopt"
855		dopt="$raw_dopt"
856	else
857		eopt="$wav_eopt"
858		dopt="$wav_dopt"
859	fi
860
861	if [ $in_fmt = flac -o $in_fmt = ogg ] && [ $out_fmt = flac -o $out_fmt = ogg ]; then
862		CMP=md5cmp
863	else
864		CMP=cmp
865	fi
866
867	if [ $out_fmt = ogg ] ; then
868		eopt="--ogg $eopt"
869	fi
870
871	desc="($in_fmt<->$out_fmt)"
872
873	#
874	# for this we need just need just one FLAC file; --cue only works while decoding
875	#
876	run_flac $eopt --cuesheet=$cuesheet -o z50c.cue.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
877
878	# To make it easy to translate from cue point to sample numbers, the
879	# file has a sample rate of 10 Hz and a cuesheet like so:
880	#
881	# TRACK 01, INDEX 01 : 0:00.00 -> sample 0
882	# TRACK 01, INDEX 02 : 0:01.00 -> sample 10
883	# TRACK 01, INDEX 03 : 0:02.00 -> sample 20
884	# TRACK 02, INDEX 01 : 0:03.00 -> sample 30
885	# TRACK 04, INDEX 01 : 0:04.00 -> sample 40
886	#
887	echo $ECHO_N "testing --cue=- $desc... " $ECHO_C
888	run_flac $dopt -o z50c.cued.$in_fmt --cue=- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
889	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=- $desc"
890	rm -f z50c.cued.$in_fmt
891	echo OK
892
893	echo $ECHO_N "testing --cue=1.0 $desc... " $ECHO_C
894	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
895	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.0 $desc"
896	rm -f z50c.cued.$in_fmt
897	echo OK
898
899	echo $ECHO_N "testing --cue=1.0- $desc... " $ECHO_C
900	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.0- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
901	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.0- $desc"
902	rm -f z50c.cued.$in_fmt
903	echo OK
904
905	echo $ECHO_N "testing --cue=1.1 $desc... " $ECHO_C
906	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
907	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.1 $desc"
908	rm -f z50c.cued.$in_fmt
909	echo OK
910
911	echo $ECHO_N "testing --cue=1.1- $desc... " $ECHO_C
912	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.1- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
913	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.1- $desc"
914	rm -f z50c.cued.$in_fmt
915	echo OK
916
917	echo $ECHO_N "testing --cue=1.2 $desc... " $ECHO_C
918	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.2 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
919	$CMP 50c.skip10.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.2 $desc"
920	rm -f z50c.cued.$in_fmt
921	echo OK
922
923	echo $ECHO_N "testing --cue=1.2- $desc... " $ECHO_C
924	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.2- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
925	$CMP 50c.skip10.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.2- $desc"
926	rm -f z50c.cued.$in_fmt
927	echo OK
928
929	echo $ECHO_N "testing --cue=1.4 $desc... " $ECHO_C
930	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.4 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
931	$CMP 50c.skip20.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.4 $desc"
932	rm -f z50c.cued.$in_fmt
933	echo OK
934
935	echo $ECHO_N "testing --cue=1.4- $desc... " $ECHO_C
936	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.4- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
937	$CMP 50c.skip20.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.4- $desc"
938	rm -f z50c.cued.$in_fmt
939	echo OK
940
941	echo $ECHO_N "testing --cue=-5.0 $desc... " $ECHO_C
942	run_flac $dopt -o z50c.cued.$in_fmt --cue=-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
943	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=-5.0 $desc"
944	rm -f z50c.cued.$in_fmt
945	echo OK
946
947	echo $ECHO_N "testing --cue=-4.1 $desc... " $ECHO_C
948	run_flac $dopt -o z50c.cued.$in_fmt --cue=-4.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
949	$CMP 50c.until40.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=-4.1 $desc"
950	rm -f z50c.cued.$in_fmt
951	echo OK
952
953	echo $ECHO_N "testing --cue=-3.1 $desc... " $ECHO_C
954	run_flac $dopt -o z50c.cued.$in_fmt --cue=-3.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
955	$CMP 50c.until40.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=-3.1 $desc"
956	rm -f z50c.cued.$in_fmt
957	echo OK
958
959	echo $ECHO_N "testing --cue=-1.4 $desc... " $ECHO_C
960	run_flac $dopt -o z50c.cued.$in_fmt --cue=-1.4 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
961	$CMP 50c.until30.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=-1.4 $desc"
962	rm -f z50c.cued.$in_fmt
963	echo OK
964
965	echo $ECHO_N "testing --cue=1.0-5.0 $desc... " $ECHO_C
966	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.0-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
967	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.0-5.0 $desc"
968	rm -f z50c.cued.$in_fmt
969	echo OK
970
971	echo $ECHO_N "testing --cue=1.1-5.0 $desc... " $ECHO_C
972	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.1-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
973	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.1-5.0 $desc"
974	rm -f z50c.cued.$in_fmt
975	echo OK
976
977	echo $ECHO_N "testing --cue=1.2-4.1 $desc... " $ECHO_C
978	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.2-4.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
979	$CMP 50c.skip10.until40.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.2-4.1 $desc"
980	rm -f z50c.cued.$in_fmt
981	echo OK
982
983	echo $ECHO_N "testing --cue=1.4-2.0 $desc... " $ECHO_C
984	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.4-2.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
985	$CMP 50c.skip20.until30.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.4-2.0 $desc"
986	rm -f z50c.cued.$in_fmt
987	echo OK
988
989	rm -f z50c.cue.$out_fmt
990}
991
992test_cue raw flac
993test_cue wav flac
994test_cue aiff flac
995test_cue flac flac
996#@@@if [ $has_ogg = yes ] ; then
997#@@@	#@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
998#@@@	test_cue ogg flac
999#@@@fi
1000
1001if [ $has_ogg = yes ] ; then
1002	test_cue raw ogg
1003	test_cue wav ogg
1004	test_cue aiff ogg
1005	#@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
1006	#@@@test_cue flac ogg
1007	#@@@test_cue ogg ogg
1008fi
1009
1010############################################################################
1011# test 'fixup' code that happens when a FLAC file with total_samples == 0
1012# in the STREAMINFO block is converted to WAVE or AIFF, requiring the
1013# decoder go back and fix up the chunk headers
1014############################################################################
1015
1016echo $ECHO_N "WAVE fixup test... " $ECHO_C
1017
1018echo $ECHO_N "prepare... " $ECHO_C
1019convert_to_wav noise "$raw_eopt" "$wav_dopt" || die "ERROR creating reference WAVE"
1020
1021echo $ECHO_N "encode... " $ECHO_C
1022# the pipe from 'cat' to 'flac' does not work on cygwin because of the EOF/
1023# binary-mode stdin problem, so we use an undocumented option to metaflac to
1024# set the total sample count to 0
1025if [ $is_win = yes ] ; then
1026	run_flac $raw_eopt noise.raw -o fixup.flac || die "ERROR generating FLAC file"
1027	run_metaflac --set-total-samples=0 fixup.flac 2> /dev/null
1028else
1029	run_flac $raw_eopt - -c < noise.raw > fixup.flac || die "ERROR generating FLAC file"
1030fi
1031
1032echo $ECHO_N "decode... " $ECHO_C
1033run_flac $wav_dopt fixup.flac -o fixup.wav || die "ERROR decoding FLAC file"
1034
1035echo $ECHO_N "compare... " $ECHO_C
1036cmp noise.wav fixup.wav || die "ERROR: file mismatch"
1037
1038echo OK
1039rm -f noise.wav fixup.wav fixup.flac
1040
1041echo $ECHO_N "AIFF fixup test... " $ECHO_C
1042
1043echo $ECHO_N "prepare... " $ECHO_C
1044convert_to_aiff noise "$raw_eopt" "$wav_dopt" || die "ERROR creating reference AIFF"
1045
1046echo $ECHO_N "encode... " $ECHO_C
1047# the pipe from 'cat' to 'flac' does not work on cygwin because of the EOF/
1048# binary-mode stdin problem, so we use an undocumented option to metaflac to
1049# set the total sample count to 0
1050if [ $is_win = yes ] ; then
1051	run_flac $raw_eopt noise.raw -o fixup.flac || die "ERROR generating FLAC file"
1052	run_metaflac --set-total-samples=0 fixup.flac 2> /dev/null
1053else
1054	run_flac $raw_eopt - -c < noise.raw > fixup.flac || die "ERROR generating FLAC file"
1055fi
1056
1057echo $ECHO_N "decode... " $ECHO_C
1058run_flac $wav_dopt fixup.flac -o fixup.aiff || die "ERROR decoding FLAC file"
1059
1060echo $ECHO_N "compare... " $ECHO_C
1061cmp noise.aiff fixup.aiff || die "ERROR: file mismatch"
1062
1063echo OK
1064rm -f noise.aiff fixup.aiff fixup.flac
1065
1066
1067############################################################################
1068# multi-file tests
1069############################################################################
1070
1071echo "Generating multiple input files from noise..."
1072multifile_format_decode="--endian=big --sign=signed"
1073multifile_format_encode="$multifile_format_decode --sample-rate=44100 --bps=16 --channels=2 --no-padding"
1074short_noise_cdda_samples=$((total_noise_cdda_samples / 8))
1075run_flac --verify --force --force-raw-format $multifile_format_encode --until=$short_noise_cdda_samples -o shortnoise.flac noise.raw || die "ERROR generating FLAC file"
1076run_flac --decode --force shortnoise.flac -o shortnoise.raw --force-raw-format $multifile_format_decode || die "ERROR generating RAW file"
1077run_flac --decode --force shortnoise.flac || die "ERROR generating WAVE file"
1078run_flac --decode --force shortnoise.flac -o shortnoise.aiff || die "ERROR generating AIFF file"
1079cp shortnoise.flac file0.flac
1080cp shortnoise.flac file1.flac
1081cp shortnoise.flac file2.flac
1082rm -f shortnoise.flac
1083cp shortnoise.wav file0.wav
1084cp shortnoise.wav file1.wav
1085cp shortnoise.wav file2.wav
1086rm -f shortnoise.wav
1087cp shortnoise.aiff file0.aiff
1088cp shortnoise.aiff file1.aiff
1089cp shortnoise.aiff file2.aiff
1090rm -f shortnoise.aiff
1091cp shortnoise.raw file0.raw
1092cp shortnoise.raw file1.raw
1093cp shortnoise.raw file2.raw
1094rm -f shortnoise.raw
1095
1096test_multifile ()
1097{
1098	input_type=$1
1099	streamtype=$2
1100	encode_options="$3"
1101
1102	extra_encode_options=""
1103	extra_decode_options=""
1104	if [ $input_type = "raw" ] ; then
1105		extra_encode_options="--force-raw-format $multifile_format_encode"
1106		extra_decode_options="--force-raw-format $multifile_format_decode"
1107	else
1108		if [ $input_type = "aiff" ] ; then
1109			extra_decode_options="--force-aiff-format"
1110		fi
1111	fi
1112
1113	if [ $streamtype = ogg ] ; then
1114		suffix=oga
1115		encode_options="$encode_options --ogg"
1116	else
1117		suffix=flac
1118	fi
1119
1120	if [ $input_type = flac ] || [ $input_type = ogg ] ; then
1121		CMP=md5cmp
1122	else
1123		CMP=cmp
1124	fi
1125
1126	for n in 0 1 2 ; do
1127		cp file$n.$input_type file${n}x.$input_type
1128	done
1129	run_flac --force $encode_options $extra_encode_options file0x.$input_type file1x.$input_type file2x.$input_type || die "ERROR"
1130	run_flac --force --decode $extra_decode_options file0x.$suffix file1x.$suffix file2x.$suffix || die "ERROR"
1131	for n in 0 1 2 ; do
1132		$CMP file$n.$input_type file${n}x.$input_type || die "ERROR: file mismatch on file #$n"
1133	done
1134	for n in 0 1 2 ; do
1135		rm -f file${n}x.$suffix file${n}x.$input_type
1136	done
1137}
1138
1139input_types="raw wav aiff flac"
1140#@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
1141#@@@if [ $has_ogg = yes ] ; then
1142#@@@	input_types="$input_types ogg"
1143#@@@fi
1144for input_type in $input_types ; do
1145	echo "Testing multiple $input_type files without verify..."
1146	test_multifile $input_type flac ""
1147
1148	echo "Testing multiple $input_type files with verify..."
1149	test_multifile $input_type flac "--verify"
1150
1151	if [ $has_ogg = yes ] ; then
1152		echo "Testing multiple $input_type files with --ogg, without verify..."
1153		test_multifile $input_type ogg ""
1154
1155		echo "Testing multiple $input_type files with --ogg, with verify..."
1156		test_multifile $input_type ogg "--verify"
1157
1158		echo "Testing multiple $input_type files with --ogg and --serial-number, with verify..."
1159		test_multifile $input_type ogg "--serial-number=321 --verify"
1160	fi
1161done
1162
1163
1164############################################################################
1165# test --keep-foreign-metadata
1166############################################################################
1167
1168echo "Testing --keep-foreign-metadata..."
1169
1170rt_test_wav wacky1.wav '--keep-foreign-metadata'
1171rt_test_wav wacky2.wav '--keep-foreign-metadata'
1172rt_test_w64 wacky1.w64 '--keep-foreign-metadata'
1173rt_test_w64 wacky2.w64 '--keep-foreign-metadata'
1174rt_test_rf64 wacky1.rf64 '--keep-foreign-metadata'
1175rt_test_rf64 wacky2.rf64 '--keep-foreign-metadata'
1176
1177rt_test_wav_autokf wacky1.wav '--keep-foreign-metadata'
1178rt_test_wav_autokf wacky2.wav '--keep-foreign-metadata'
1179rt_test_w64_autokf wacky1.w64 '--keep-foreign-metadata'
1180rt_test_w64_autokf wacky2.w64 '--keep-foreign-metadata'
1181rt_test_rf64_autokf wacky1.rf64 '--keep-foreign-metadata'
1182rt_test_rf64_autokf wacky2.rf64 '--keep-foreign-metadata'
1183
1184testdatadir=${top_srcdir}/test/foreign-metadata-test-files
1185
1186rt_test_autokf "$testdatadir/BWF-WaveFmtEx.wav" '--keep-foreign-metadata' 'rt.wav'
1187rt_test_autokf "$testdatadir/AIFF-ID3.aiff" '--keep-foreign-metadata' 'rt.aiff'
1188rt_test_autokf "$testdatadir/AIFF-C-sowt-tag.aifc" '--keep-foreign-metadata' 'rt.aifc'
1189rt_test_autokf "$testdatadir/AIFF-C-sowt-compression-type-name.aifc" '--keep-foreign-metadata' 'rt.aifc'
1190rt_test_autokf "$testdatadir/24bit-WaveFmtPCM.wav" '--keep-foreign-metadata' 'rt.wav'
1191
1192############################################################################
1193# test the metadata-handling properties of flac-to-flac encoding
1194############################################################################
1195
1196echo "Testing the metadata-handling properties of flac-to-flac encoding..."
1197
1198testdatadir=${top_srcdir}/test/flac-to-flac-metadata-test-files
1199
1200filter ()
1201{
1202	# minor danger, changing vendor strings might change the length of the
1203	# VORBIS_COMMENT block, but if we add "^  length: " to the patterns,
1204	# we lose info about PADDING size that we need
1205	grep -Ev '^  vendor string: |^  m..imum .....size: ' | sed -e 's/, stream_offset.*//'
1206}
1207flac2flac ()
1208{
1209	file="$testdatadir/$1"
1210	case="$testdatadir/$2"
1211	args="$3"
1212	expect="$case-expect.meta"
1213	echo $ECHO_N "$2... " $ECHO_C
1214	# The 'make distcheck' target needs this.
1215	chmod u+w $file
1216	run_flac -f -o out.flac $args $file || die "ERROR encoding FLAC file"
1217	run_metaflac --list out.flac | filter > out1.meta || die "ERROR listing metadata of output FLAC file"
1218    # Ignore lengths which can be affected by the version string.
1219    sed "s/length:.*/length: XXX/" out1.meta > out.meta
1220	diff -q -w $expect out.meta 2>/dev/null || die "ERROR: metadata does not match expected $expect"
1221	echo OK
1222}
1223
1224#filter=', stream_offset.*|^  vendor string: |^  length: |^  m..imum .....size: '
1225
1226# case 00a: no alterations on a file with all metadata types, keep all metadata, in same order
1227flac2flac input-SCVAUP.flac case00a ""
1228# case 01a: on file with multiple PADDING blocks, they should be aggregated into one at the end
1229flac2flac input-SCVPAP.flac case01a ""
1230# case 01b: on file with multiple PADDING blocks and --no-padding specified, they should all be deleted
1231flac2flac input-SCVPAP.flac case01b "--no-padding"
1232# case 01c: on file with multiple PADDING blocks and -P specified, they should all be overwritten with -P value
1233flac2flac input-SCVPAP.flac case01c "-P 1234"
1234# case 01d: on file with no PADDING blocks, use -P setting
1235flac2flac input-SCVA.flac case01d "-P 1234"
1236# case 01e: on file with no PADDING blocks and no -P given, use default padding
1237flac2flac input-SCVA.flac case01e ""
1238# case 02a: on file with no VORBIS_COMMENT block, add new VORBIS_COMMENT
1239flac2flac input-SCPAP.flac case02a ""
1240# case 02b: on file with no VORBIS_COMMENT block and --tag, add new VORBIS_COMMENT with tags
1241flac2flac input-SCPAP.flac case02b "--tag=artist=0"
1242# case 02c: on file with VORBIS_COMMENT block and --tag, replace existing VORBIS_COMMENT with new tags
1243flac2flac input-SCVAUP.flac case02c "--tag=artist=0"
1244# case 03a: on file with no CUESHEET block and --cuesheet specified, add it
1245flac2flac input-SVAUP.flac case03a "--cuesheet=$testdatadir/input0.cue"
1246# case 03b: on file with CUESHEET block and --cuesheet specified, overwrite existing CUESHEET
1247flac2flac input-SCVAUP.flac case03b "--cuesheet=$testdatadir/input0.cue"
1248# case 03c: on file with CUESHEET block and size-changing option specified, drop existing CUESHEET
1249flac2flac input-SCVAUP.flac case03c "--skip=1"
1250# case 04a: on file with no SEEKTABLE block and --no-seektable specified, no SEEKTABLE
1251flac2flac input-VA.flac case04a "--no-padding --no-seektable"
1252# case 04b: on file with no SEEKTABLE block and -S specified, new SEEKTABLE
1253flac2flac input-VA.flac case04b "--no-padding -S 5x"
1254# case 04c: on file with no SEEKTABLE block and no seektable options specified, new SEEKTABLE with default points
1255flac2flac input-VA.flac case04c "--no-padding"
1256# case 04d: on file with SEEKTABLE block and --no-seektable specified, drop existing SEEKTABLE
1257flac2flac input-SCVA.flac case04d "--no-padding --no-seektable"
1258# case 04e: on file with SEEKTABLE block and -S specified, overwrite existing SEEKTABLE
1259flac2flac input-SCVA.flac case04e "--no-padding -S 5x"
1260# case 04f: on file with SEEKTABLE block and size-changing option specified, drop existing SEEKTABLE, new SEEKTABLE with default points
1261#(already covered by case03c)
1262
1263############################################################################
1264# test limiting minimum bitrate
1265############################################################################
1266
1267echo $ECHO_N "Testing --limit-min-bitrate" $ECHO_C
1268
1269run_flac -f -o out.flac --no-padding --no-seektable --limit-min-bitrate "$testdatadir/input-VA.flac"
1270size=$(wc -c < out.flac)
1271
1272if [ "$size" -lt "1022" ]; then
1273    die "ERROR: filesize of flac file encoded with --limit-min-bitrate is smaller than expected"
1274fi
1275
1276echo OK
1277
1278############################################################################
1279# test overflow of total samples field in STREAMINFO
1280############################################################################
1281
1282test_total_samples_overflow ()
1283{
1284	total_samples=$1
1285	expected_stored_total_samples=$2
1286	echo $ECHO_N "total_samples overflow test (samples=$total_samples) encode... " $ECHO_C
1287	head -c $total_samples /dev/zero | run_flac --force --verify --sign=signed --sample-rate=96000 -b 16384 --channels=1 --endian=little --bps=8 -o big-$total_samples.flac - || die "ERROR"
1288	echo $ECHO_N "decode... " $ECHO_C
1289	run_flac -t big-$total_samples.flac || die "ERROR"
1290	echo $ECHO_N "check... " $ECHO_C
1291	run_metaflac --show-total-samples big-$total_samples.flac > big-$total_samples.cmp1
1292	echo $expected_stored_total_samples >  big-$total_samples.cmp2
1293	diff -q -w big-$total_samples.cmp1 big-$total_samples.cmp2  || die "ERROR"
1294	echo "OK"
1295	rm -f big-$total_samples.flac big-$total_samples.cmp1 big-$total_samples.cmp2
1296}
1297
1298if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
1299	test_total_samples_overflow 68719476735 68719476735
1300	test_total_samples_overflow 68719476736 0
1301	test_total_samples_overflow 68719476737 0
1302fi
1303
1304############################################################################
1305# test handling of UTF-8 filenames
1306############################################################################
1307
1308
1309test_utf8_handling ()
1310{
1311	echo $ECHO_N "Test decoding from $1... " $ECHO_C
1312	run_flac -d $testdatadir/$1 -o out.wav
1313	if [ -f out.wav ] ; then
1314		echo "OK"
1315	else
1316		die "Decoding failed"
1317	fi
1318	echo $ECHO_N "Test encoding to $1... " $ECHO_C
1319	run_flac out.wav -o $1
1320	if [ -f $1 ] ; then
1321		echo "OK"
1322	else
1323		die "Encoding failed"
1324	fi
1325	rm -f $1 out.wav
1326}
1327
1328if [ "$WIN32BUSYBOX" != "yes" ]; then
1329	test_utf8_handling שלום.flac
1330	test_utf8_handling ��.flac
1331	test_utf8_handling Prøve.flac
1332fi
1333
1334rm -f out.flac out.meta out1.meta
1335
1336#@@@ when metaflac handles ogg flac, duplicate flac2flac tests here
1337
1338cd ..
1339