• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh -e
2
3#  FLAC - Free Lossless Audio Codec
4#  Copyright (C) 2002-2009  Josh Coalson
5#  Copyright (C) 2011-2016  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
23PATH=`pwd`/../src/flac:$PATH
24PATH=`pwd`/../src/metaflac:$PATH
25PATH=`pwd`/../objs/$BUILD/bin:$PATH
26
27if echo a | (grep -E '(a|b)') >/dev/null 2>&1
28	then EGREP='grep -E'
29	else EGREP='egrep'
30fi
31
32testdir="metaflac-test-files"
33flacfile="metaflac.flac"
34
35flac${EXE} --help 1>/dev/null 2>/dev/null || die "ERROR can't find flac executable"
36metaflac${EXE} --help 1>/dev/null 2>/dev/null || die "ERROR can't find metaflac executable"
37
38run_flac ()
39{
40	if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
41		echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 flac $*" >>test_metaflac.valgrind.log
42		valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 flac${EXE} ${TOTALLY_SILENT} --no-error-on-compression-fail $* 4>>test_metaflac.valgrind.log
43	else
44		flac${EXE} ${TOTALLY_SILENT} --no-error-on-compression-fail $*
45	fi
46}
47
48run_metaflac ()
49{
50	if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
51		echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 metaflac $*" >>test_metaflac.valgrind.log
52		valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 metaflac${EXE} $* 4>>test_metaflac.valgrind.log
53	else
54		metaflac${EXE} $*
55	fi
56}
57
58run_metaflac_silent ()
59{
60	if [ -z "$SILENT" ] ; then
61		run_metaflac $*
62	else
63		if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
64			echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 metaflac $*" >>test_metaflac.valgrind.log
65			valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 metaflac${EXE} $* 2>/dev/null 4>>test_metaflac.valgrind.log
66		else
67			metaflac${EXE} $* 2>/dev/null
68		fi
69	fi
70}
71
72check_flac ()
73{
74	run_flac --silent --test $flacfile || die "ERROR in $flacfile" 1>&2
75}
76
77echo "Generating stream..."
78bytes=80000
79if dd if=/dev/zero ibs=1 count=$bytes 2>/dev/null | flac${EXE} ${TOTALLY_SILENT} --force --verify -0 --input-size=$bytes --output-name=$flacfile --force-raw-format --endian=big --sign=signed --channels=1 --bps=8 --sample-rate=8000 - ; then
80	chmod +w $flacfile
81else
82	die "ERROR during generation"
83fi
84
85check_flac
86
87testdatadir=${top_srcdir}/test/metaflac-test-files
88
89filter ()
90{
91	# minor danger, changing vendor strings will change the length of the
92	# VORBIS_COMMENT block, but if we add "^  length: " to the patterns,
93	# we lose info about PADDING size that we need
94	# grep pattern 1: remove vendor string
95	# grep pattern 2: remove minimum/maximum frame and block size from STREAMINFO
96	# grep pattern 3: remove hexdump data from PICTURE metadata blocks
97	# sed pattern 1: remove stream offset values from SEEKTABLE points
98	$EGREP -v '^  vendor string: |^  m..imum .....size: |^    0000[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]: ' \
99		| sed -e 's/, stream_offset.*//'
100}
101metaflac_test ()
102{
103	case="$testdatadir/$1"
104	desc="$2"
105	args="$3"
106	expect="$case-expect.meta"
107	echo $ECHO_N "test $1: $desc... " $ECHO_C
108	run_metaflac $args $flacfile | filter > $testdir/out1.meta || die "ERROR running metaflac"
109	# Ignore lengths which can be affected by the version string.
110	sed "s/length:.*/length: XXX/" $testdir/out1.meta > $testdir/out.meta
111	diff -w $expect $testdir/out.meta > /dev/null 2>&1 || die "ERROR: metadata does not match expected $expect"
112	# To blindly accept (and check later): cp -f $testdir/out.meta $expect
113	echo OK
114}
115
116metaflac_test case00 "--list" "--list"
117
118metaflac_test case01 "STREAMINFO --show-* shortcuts" "
119	--show-md5sum
120	--show-min-blocksize
121	--show-max-blocksize
122	--show-min-framesize
123	--show-max-framesize
124	--show-sample-rate
125	--show-channels
126	--show-bps
127	--show-total-samples"
128
129run_metaflac --preserve-modtime --add-padding=12345 $flacfile
130check_flac
131metaflac_test case02 "--add-padding" "--list"
132
133# some flavors of /bin/sh (e.g. Darwin's) won't even handle quoted spaces, so we underscore:
134run_metaflac --set-tag="ARTIST=The_artist_formerly_known_as_the_artist..." $flacfile
135check_flac
136metaflac_test case03 "--set-tag=ARTIST" "--list"
137
138run_metaflac --set-tag="ARTIST=Chuck_Woolery" $flacfile
139check_flac
140metaflac_test case04 "--set-tag=ARTIST" "--list"
141
142run_metaflac --set-tag="ARTIST=Vern" $flacfile
143check_flac
144metaflac_test case05 "--set-tag=ARTIST" "--list"
145
146run_metaflac --set-tag="TITLE=He_who_smelt_it_dealt_it" $flacfile
147check_flac
148metaflac_test case06 "--set-tag=TITLE" "--list"
149
150metaflac_test case07 "--show-vendor-tag --show-tag=ARTIST" "--show-vendor-tag --show-tag=ARTIST"
151
152run_metaflac --remove-first-tag=ARTIST $flacfile
153check_flac
154metaflac_test case08 "--remove-first-tag=ARTIST" "--list"
155
156run_metaflac --remove-tag=ARTIST $flacfile
157check_flac
158metaflac_test case09 "--remove-tag=ARTIST" "--list"
159
160metaflac_test case10 "--list --block-type=VORBIS_COMMENT" "--list --block-type=VORBIS_COMMENT"
161metaflac_test case11 "--list --block-number=0" "--list --block-number=0"
162metaflac_test case12 "--list --block-number=1,2,999" "--list --block-number=1,2,999"
163metaflac_test case13 "--list --block-type=VORBIS_COMMENT,PADDING" "--list --block-type=VORBIS_COMMENT,PADDING"
164metaflac_test case14 "--list --except-block-type=SEEKTABLE,VORBIS_COMMENT" "--list --except-block-type=SEEKTABLE,VORBIS_COMMENT"
165metaflac_test case15 "--list --except-block-type=STREAMINFO" "--list --except-block-type=STREAMINFO"
166
167run_metaflac --add-padding=4321 $flacfile $flacfile
168check_flac
169metaflac_test case16 "--add-padding=4321 * 2" "--list"
170
171run_metaflac --merge-padding $flacfile
172check_flac
173metaflac_test case17 "--merge-padding" "--list"
174
175run_metaflac --add-padding=0 $flacfile
176check_flac
177metaflac_test case18 "--add-padding=0" "--list"
178
179run_metaflac --sort-padding $flacfile
180check_flac
181metaflac_test case19 "--sort-padding" "--list"
182
183run_metaflac --add-padding=0 $flacfile
184check_flac
185metaflac_test case20 "--add-padding=0" "--list"
186
187run_metaflac --remove-all-tags $flacfile
188check_flac
189metaflac_test case21 "--remove-all-tags" "--list"
190
191run_metaflac --remove --block-number=1,99 --dont-use-padding $flacfile
192check_flac
193metaflac_test case22 "--remove --block-number=1,99 --dont-use-padding" "--list"
194
195run_metaflac --remove --block-number=99 --dont-use-padding $flacfile
196check_flac
197metaflac_test case23 "--remove --block-number=99 --dont-use-padding" "--list"
198
199run_metaflac --remove --block-type=PADDING $flacfile
200check_flac
201metaflac_test case24 "--remove --block-type=PADDING" "--list"
202
203run_metaflac --remove --block-type=PADDING --dont-use-padding $flacfile
204check_flac
205metaflac_test case25 "--remove --block-type=PADDING --dont-use-padding" "--list"
206
207run_metaflac --add-padding=0 $flacfile $flacfile
208check_flac
209metaflac_test case26 "--add-padding=0 * 2" "--list"
210
211run_metaflac --remove --except-block-type=PADDING $flacfile
212check_flac
213metaflac_test case27 "--remove --except-block-type=PADDING" "--list"
214
215run_metaflac --remove-all $flacfile
216check_flac
217metaflac_test case28 "--remove-all" "--list"
218
219run_metaflac --remove-all --dont-use-padding $flacfile
220check_flac
221metaflac_test case29 "--remove-all --dont-use-padding" "--list"
222
223run_metaflac --remove-all --dont-use-padding $flacfile
224check_flac
225metaflac_test case30 "--remove-all --dont-use-padding" "--list"
226
227run_metaflac --set-tag="f=0123456789abcdefghij" $flacfile
228check_flac
229metaflac_test case31 "--set-tag=..." "--list"
230
231run_metaflac --remove-all-tags --set-tag="f=0123456789abcdefghi" $flacfile
232check_flac
233metaflac_test case32 "--remove-all-tags --set-tag=..." "--list"
234
235run_metaflac --remove-all-tags --set-tag="f=0123456789abcde" $flacfile
236check_flac
237metaflac_test case33 "--remove-all-tags --set-tag=..." "--list"
238
239run_metaflac --remove-all-tags --set-tag="f=0" $flacfile
240check_flac
241metaflac_test case34 "--remove-all-tags --set-tag=..." "--list"
242
243run_metaflac --remove-all-tags --set-tag="f=0123456789" $flacfile
244check_flac
245metaflac_test case35 "--remove-all-tags --set-tag=..." "--list"
246
247run_metaflac --remove-all-tags --set-tag="f=0123456789abcdefghi" $flacfile
248check_flac
249metaflac_test case36 "--remove-all-tags --set-tag=..." "--list"
250
251run_metaflac --remove-all-tags --set-tag="f=0123456789" $flacfile
252check_flac
253metaflac_test case37 "--remove-all-tags --set-tag=..." "--list"
254
255run_metaflac --remove-all-tags --set-tag="f=0123456789abcdefghij" $flacfile
256check_flac
257metaflac_test case38 "--remove-all-tags --set-tag=..." "--list"
258
259echo "TITLE=Tittle" | run_metaflac --import-tags-from=- $flacfile
260check_flac
261metaflac_test case39 "--import-tags-from=-" "--list"
262
263cat > vc.txt << EOF
264artist=Fartist
265artist=artits
266EOF
267run_metaflac --import-tags-from=vc.txt $flacfile
268check_flac
269metaflac_test case40 "--import-tags-from=[FILE]" "--list"
270
271rm vc.txt
272
273run_metaflac --add-replay-gain $flacfile
274check_flac
275metaflac_test case41 "--add-replay-gain" "--list"
276
277run_metaflac --remove-replay-gain $flacfile
278check_flac
279metaflac_test case42 "--remove-replay-gain" "--list"
280
281run_metaflac --scan-replay-gain $flacfile
282check_flac
283metaflac_test case42 "--scan-replay-gain" "--list"
284
285# CUESHEET blocks
286cs_in=${top_srcdir}/test/cuesheets/good.000.cue
287cs_out=metaflac.cue
288cs_out2=metaflac2.cue
289run_metaflac --import-cuesheet-from="$cs_in" $flacfile
290check_flac
291metaflac_test case43 "--import-cuesheet-from" "--list"
292run_metaflac --export-cuesheet-to=$cs_out $flacfile
293run_metaflac --remove --block-type=CUESHEET $flacfile
294check_flac
295metaflac_test case44 "--remove --block-type=CUESHEET" "--list"
296run_metaflac --import-cuesheet-from=$cs_out $flacfile
297check_flac
298metaflac_test case45 "--import-cuesheet-from" "--list"
299run_metaflac --export-cuesheet-to=$cs_out2 $flacfile
300echo "comparing cuesheets:"
301diff $cs_out $cs_out2 || die "ERROR, cuesheets should be identical"
302echo identical
303
304rm -f $cs_out $cs_out2
305
306# PICTURE blocks
307ncase=46
308for f in \
309	0.gif \
310	1.gif \
311	2.gif \
312; do
313	run_metaflac --import-picture-from="|image/gif|$f||${top_srcdir}/test/pictures/$f" $flacfile
314	check_flac
315	metaflac_test "case$ncase" "--import-picture-from" "--list"
316	ncase=`expr $ncase + 1`
317done
318for f in \
319	0.jpg \
320	4.jpg \
321; do
322	run_metaflac --import-picture-from="4|image/jpeg|$f||${top_srcdir}/test/pictures/$f" $flacfile
323	check_flac
324	metaflac_test "case$ncase" "--import-picture-from" "--list"
325	ncase=`expr $ncase + 1`
326done
327for f in \
328	0.png \
329	1.png \
330	2.png \
331	3.png \
332	4.png \
333	5.png \
334	6.png \
335	7.png \
336	8.png \
337; do
338	run_metaflac --import-picture-from="5|image/png|$f||${top_srcdir}/test/pictures/$f" $flacfile
339	check_flac
340	metaflac_test "case$ncase" "--import-picture-from" "--list"
341	ncase=`expr $ncase + 1`
342done
343[ $ncase = 60 ] || die "expected case# to be 60"
344
345fn=export-picture-check
346echo $ECHO_N "Testing --export-picture-to... " $ECHO_C
347run_metaflac --export-picture-to=$fn $flacfile
348check_flac
349cmp $fn ${top_srcdir}/test/pictures/0.gif || die "ERROR, exported picture file and original differ"
350echo OK
351rm -f $fn
352echo $ECHO_N "Testing --block-number --export-picture-to... " $ECHO_C
353run_metaflac --block-number=9 --export-picture-to=$fn $flacfile
354check_flac
355cmp $fn ${top_srcdir}/test/pictures/0.png || die "ERROR, exported picture file and original differ"
356echo OK
357rm -f $fn
358
359run_metaflac --remove --block-type=PICTURE $flacfile
360check_flac
361metaflac_test case60 "--remove --block-type=PICTURE" "--list"
362run_metaflac --import-picture-from="1|image/png|standard_icon|32x32x24|${top_srcdir}/test/pictures/0.png" $flacfile
363check_flac
364metaflac_test case61 "--import-picture-from" "--list"
365run_metaflac --import-picture-from="2|image/png|icon|64x64x24|${top_srcdir}/test/pictures/1.png" $flacfile
366check_flac
367metaflac_test case62 "--import-picture-from" "--list"
368
369# UNKNOWN blocks
370echo $ECHO_N "Testing FLAC file with unknown metadata... " $ECHO_C
371cp -p ${top_srcdir}/test/metaflac.flac.in $flacfile
372# remove the VORBIS_COMMENT block so vendor string changes don't interfere with the comparison:
373run_metaflac --remove --block-type=VORBIS_COMMENT --dont-use-padding $flacfile
374cmp $flacfile ${top_srcdir}/test/metaflac.flac.ok || die "ERROR, $flacfile and metaflac.flac.ok differ"
375echo OK
376
377rm -f metaflac-test-files/out.meta  metaflac-test-files/out1.meta
378