3 # FLAC - Free Lossless Audio Codec
4 # Copyright (C) 2002-2009 Josh Coalson
5 # Copyright (C) 2011-2013 Xiph.Org Foundation
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
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
23 PATH
=`pwd`/..
/src
/flac
:$PATH
24 PATH
=`pwd`/..
/src
/metaflac
:$PATH
25 PATH
=`pwd`/..
/objs
/$BUILD/bin
:$PATH
27 if echo a |
(grep -E '(a|b)') >/dev
/null
2>&1
32 testdir
="metaflac-test-files"
33 flacfile
="metaflac.flac"
35 flac
${EXE} --help 1>/dev
/null
2>/dev
/null || die
"ERROR can't find flac executable"
36 metaflac
${EXE} --help 1>/dev
/null
2>/dev
/null || die
"ERROR can't find metaflac executable"
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} --no-error-on-compression-fail $
* 4>>test_metaflac.valgrind.log
44 flac
${EXE} --no-error-on-compression-fail $
*
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
58 run_metaflac_silent
()
60 if [ -z "$SILENT" ] ; then
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
67 metaflac
${EXE} $
* 2>/dev
/null
74 run_flac
--silent --test $flacfile || die
"ERROR in $flacfile" 1>&2
77 echo "Generating stream..."
79 if dd if=/dev
/zero ibs
=1 count
=$bytes | flac
${EXE} --force --verify -0 --input-size=$bytes --output-name=$flacfile --force-raw-format --endian=big
--sign=signed
--channels=1 --bps=8 --sample-rate=8000 - ; then
82 die
"ERROR during generation"
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]: ' |
sed -e 's/, stream_offset.*//'
105 expect
="$testdir/$case-expect.meta"
106 echo -n "test $case: $desc... "
107 run_metaflac
$args $flacfile | filter
> $testdir/out.meta || die
"ERROR running metaflac"
108 diff -w $expect $testdir/out.meta
> /dev
/null
2>&1 || die
"ERROR: metadata does not match expected $expect"
112 metaflac_test case00
"--list" "--list"
114 metaflac_test case01
"STREAMINFO --show-* shortcuts" "
123 --show-total-samples"
125 run_metaflac
--preserve-modtime --add-padding=12345 $flacfile
127 metaflac_test case02
"--add-padding" "--list"
129 # some flavors of /bin/sh (e.g. Darwin's) won't even handle quoted spaces, so we underscore:
130 run_metaflac
--set-tag="ARTIST=The_artist_formerly_known_as_the_artist..." $flacfile
132 metaflac_test case03
"--set-tag=ARTIST" "--list"
134 run_metaflac
--set-tag="ARTIST=Chuck_Woolery" $flacfile
136 metaflac_test case04
"--set-tag=ARTIST" "--list"
138 run_metaflac
--set-tag="ARTIST=Vern" $flacfile
140 metaflac_test case05
"--set-tag=ARTIST" "--list"
142 run_metaflac
--set-tag="TITLE=He_who_smelt_it_dealt_it" $flacfile
144 metaflac_test case06
"--set-tag=TITLE" "--list"
146 metaflac_test case07
"--show-vendor-tag --show-tag=ARTIST" "--show-vendor-tag --show-tag=ARTIST"
148 run_metaflac
--remove-first-tag=ARTIST
$flacfile
150 metaflac_test case08
"--remove-first-tag=ARTIST" "--list"
152 run_metaflac
--remove-tag=ARTIST
$flacfile
154 metaflac_test case09
"--remove-tag=ARTIST" "--list"
156 metaflac_test case10
"--list --block-type=VORBIS_COMMENT" "--list --block-type=VORBIS_COMMENT"
157 metaflac_test case11
"--list --block-number=0" "--list --block-number=0"
158 metaflac_test case12
"--list --block-number=1,2,999" "--list --block-number=1,2,999"
159 metaflac_test case13
"--list --block-type=VORBIS_COMMENT,PADDING" "--list --block-type=VORBIS_COMMENT,PADDING"
160 metaflac_test case14
"--list --except-block-type=SEEKTABLE,VORBIS_COMMENT" "--list --except-block-type=SEEKTABLE,VORBIS_COMMENT"
161 metaflac_test case15
"--list --except-block-type=STREAMINFO" "--list --except-block-type=STREAMINFO"
163 run_metaflac
--add-padding=4321 $flacfile $flacfile
165 metaflac_test case16
"--add-padding=4321 * 2" "--list"
167 run_metaflac
--merge-padding $flacfile
169 metaflac_test case17
"--merge-padding" "--list"
171 run_metaflac
--add-padding=0 $flacfile
173 metaflac_test case18
"--add-padding=0" "--list"
175 run_metaflac
--sort-padding $flacfile
177 metaflac_test case19
"--sort-padding" "--list"
179 run_metaflac
--add-padding=0 $flacfile
181 metaflac_test case20
"--add-padding=0" "--list"
183 run_metaflac
--remove-all-tags $flacfile
185 metaflac_test case21
"--remove-all-tags" "--list"
187 run_metaflac
--remove --block-number=1,99 --dont-use-padding $flacfile
189 metaflac_test case22
"--remove --block-number=1,99 --dont-use-padding" "--list"
191 run_metaflac
--remove --block-number=99 --dont-use-padding $flacfile
193 metaflac_test case23
"--remove --block-number=99 --dont-use-padding" "--list"
195 run_metaflac
--remove --block-type=PADDING
$flacfile
197 metaflac_test case24
"--remove --block-type=PADDING" "--list"
199 run_metaflac
--remove --block-type=PADDING
--dont-use-padding $flacfile
201 metaflac_test case25
"--remove --block-type=PADDING --dont-use-padding" "--list"
203 run_metaflac
--add-padding=0 $flacfile $flacfile
205 metaflac_test case26
"--add-padding=0 * 2" "--list"
207 run_metaflac
--remove --except-block-type=PADDING
$flacfile
209 metaflac_test case27
"--remove --except-block-type=PADDING" "--list"
211 run_metaflac
--remove-all $flacfile
213 metaflac_test case28
"--remove-all" "--list"
215 run_metaflac
--remove-all --dont-use-padding $flacfile
217 metaflac_test case29
"--remove-all --dont-use-padding" "--list"
219 run_metaflac
--remove-all --dont-use-padding $flacfile
221 metaflac_test case30
"--remove-all --dont-use-padding" "--list"
223 run_metaflac
--set-tag="f=0123456789abcdefghij" $flacfile
225 metaflac_test case31
"--set-tag=..." "--list"
227 run_metaflac
--remove-all-tags --set-tag="f=0123456789abcdefghi" $flacfile
229 metaflac_test case32
"--remove-all-tags --set-tag=..." "--list"
231 run_metaflac
--remove-all-tags --set-tag="f=0123456789abcde" $flacfile
233 metaflac_test case33
"--remove-all-tags --set-tag=..." "--list"
235 run_metaflac
--remove-all-tags --set-tag="f=0" $flacfile
237 metaflac_test case34
"--remove-all-tags --set-tag=..." "--list"
239 run_metaflac
--remove-all-tags --set-tag="f=0123456789" $flacfile
241 metaflac_test case35
"--remove-all-tags --set-tag=..." "--list"
243 run_metaflac
--remove-all-tags --set-tag="f=0123456789abcdefghi" $flacfile
245 metaflac_test case36
"--remove-all-tags --set-tag=..." "--list"
247 run_metaflac
--remove-all-tags --set-tag="f=0123456789" $flacfile
249 metaflac_test case37
"--remove-all-tags --set-tag=..." "--list"
251 run_metaflac
--remove-all-tags --set-tag="f=0123456789abcdefghij" $flacfile
253 metaflac_test case38
"--remove-all-tags --set-tag=..." "--list"
255 echo "TITLE=Tittle" | run_metaflac
--import-tags-from=- $flacfile
257 metaflac_test case39
"--import-tags-from=-" "--list"
263 run_metaflac
--import-tags-from=vc.txt
$flacfile
265 metaflac_test case40
"--import-tags-from=[FILE]" "--list"
269 run_metaflac
--add-replay-gain $flacfile
271 metaflac_test case41
"--add-replay-gain" "--list"
273 run_metaflac
--remove-replay-gain $flacfile
275 metaflac_test case42
"--remove-replay-gain" "--list"
278 cs_in
=cuesheets
/good
.000.cue
280 cs_out2
=metaflac2.cue
281 run_metaflac
--import-cuesheet-from="$cs_in" $flacfile
283 metaflac_test case43
"--import-cuesheet-from" "--list"
284 run_metaflac
--export-cuesheet-to=$cs_out $flacfile
285 run_metaflac
--remove --block-type=CUESHEET
$flacfile
287 metaflac_test case44
"--remove --block-type=CUESHEET" "--list"
288 run_metaflac
--import-cuesheet-from=$cs_out $flacfile
290 metaflac_test case45
"--import-cuesheet-from" "--list"
291 run_metaflac
--export-cuesheet-to=$cs_out2 $flacfile
292 echo "comparing cuesheets:"
293 diff $cs_out $cs_out2 || die
"ERROR, cuesheets should be identical"
296 rm -f $cs_out $cs_out2
305 run_metaflac
--import-picture-from="|image/gif|$f||pictures/$f" $flacfile
307 metaflac_test
"case$ncase" "--import-picture-from" "--list"
308 ncase
=`expr $ncase + 1`
314 run_metaflac
--import-picture-from="4|image/jpeg|$f||pictures/$f" $flacfile
316 metaflac_test
"case$ncase" "--import-picture-from" "--list"
317 ncase
=`expr $ncase + 1`
330 run_metaflac
--import-picture-from="5|image/png|$f||pictures/$f" $flacfile
332 metaflac_test
"case$ncase" "--import-picture-from" "--list"
333 ncase
=`expr $ncase + 1`
335 [ $ncase = 60 ] || die
"expected case# to be 60"
337 fn
=export-picture-check
338 echo -n "Testing --export-picture-to... "
339 run_metaflac
--export-picture-to=$fn $flacfile
341 cmp $fn pictures
/0.gif || die
"ERROR, exported picture file and original differ"
344 echo -n "Testing --block-number --export-picture-to... "
345 run_metaflac
--block-number=9 --export-picture-to=$fn $flacfile
347 cmp $fn pictures
/0.png || die
"ERROR, exported picture file and original differ"
351 run_metaflac
--remove --block-type=PICTURE
$flacfile
353 metaflac_test case60
"--remove --block-type=PICTURE" "--list"
354 run_metaflac
--import-picture-from="1|image/png|standard_icon|32x32x24|pictures/0.png" $flacfile
356 metaflac_test case61
"--import-picture-from" "--list"
357 run_metaflac
--import-picture-from="2|image/png|icon|64x64x24|pictures/1.png" $flacfile
359 metaflac_test case62
"--import-picture-from" "--list"
362 echo -n "Testing FLAC file with unknown metadata... "
363 cp -p metaflac.flac.
in $flacfile
364 # remove the VORBIS_COMMENT block so vendor string changes don't interfere with the comparison:
365 run_metaflac
--remove --block-type=VORBIS_COMMENT
--dont-use-padding $flacfile
366 cmp $flacfile metaflac.flac.ok || die
"ERROR, $flacfile and metaflac.flac.ok differ"