libFLAC/fixed_intrin_sse2.c : Fix comments.
[flac.git] / test / test_metaflac.sh
blobaff59482cd135e87f527e62d22fdc4fc49d8eab9
1 #!/bin/bash -e
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
14 # distributed.
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.
21 source common.sh
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
28 then EGREP='grep -E'
29 else EGREP='egrep'
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"
38 run_flac ()
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
43 else
44 flac${EXE} --no-error-on-compression-fail $*
48 run_metaflac ()
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} $*
58 run_metaflac_silent ()
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
72 check_flac ()
74 run_flac --silent --test $flacfile || die "ERROR in $flacfile" 1>&2
77 echo "Generating stream..."
78 bytes=80000
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
80 chmod +w $flacfile
81 else
82 die "ERROR during generation"
85 check_flac
87 echo
89 filter ()
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.*//'
100 metaflac_test ()
102 case="$1"
103 desc="$2"
104 args="$3"
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"
109 echo OK
112 metaflac_test case00 "--list" "--list"
114 metaflac_test case01 "STREAMINFO --show-* shortcuts" "
115 --show-md5sum
116 --show-min-blocksize
117 --show-max-blocksize
118 --show-min-framesize
119 --show-max-framesize
120 --show-sample-rate
121 --show-channels
122 --show-bps
123 --show-total-samples"
125 run_metaflac --preserve-modtime --add-padding=12345 $flacfile
126 check_flac
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
131 check_flac
132 metaflac_test case03 "--set-tag=ARTIST" "--list"
134 run_metaflac --set-tag="ARTIST=Chuck_Woolery" $flacfile
135 check_flac
136 metaflac_test case04 "--set-tag=ARTIST" "--list"
138 run_metaflac --set-tag="ARTIST=Vern" $flacfile
139 check_flac
140 metaflac_test case05 "--set-tag=ARTIST" "--list"
142 run_metaflac --set-tag="TITLE=He_who_smelt_it_dealt_it" $flacfile
143 check_flac
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
149 check_flac
150 metaflac_test case08 "--remove-first-tag=ARTIST" "--list"
152 run_metaflac --remove-tag=ARTIST $flacfile
153 check_flac
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
164 check_flac
165 metaflac_test case16 "--add-padding=4321 * 2" "--list"
167 run_metaflac --merge-padding $flacfile
168 check_flac
169 metaflac_test case17 "--merge-padding" "--list"
171 run_metaflac --add-padding=0 $flacfile
172 check_flac
173 metaflac_test case18 "--add-padding=0" "--list"
175 run_metaflac --sort-padding $flacfile
176 check_flac
177 metaflac_test case19 "--sort-padding" "--list"
179 run_metaflac --add-padding=0 $flacfile
180 check_flac
181 metaflac_test case20 "--add-padding=0" "--list"
183 run_metaflac --remove-all-tags $flacfile
184 check_flac
185 metaflac_test case21 "--remove-all-tags" "--list"
187 run_metaflac --remove --block-number=1,99 --dont-use-padding $flacfile
188 check_flac
189 metaflac_test case22 "--remove --block-number=1,99 --dont-use-padding" "--list"
191 run_metaflac --remove --block-number=99 --dont-use-padding $flacfile
192 check_flac
193 metaflac_test case23 "--remove --block-number=99 --dont-use-padding" "--list"
195 run_metaflac --remove --block-type=PADDING $flacfile
196 check_flac
197 metaflac_test case24 "--remove --block-type=PADDING" "--list"
199 run_metaflac --remove --block-type=PADDING --dont-use-padding $flacfile
200 check_flac
201 metaflac_test case25 "--remove --block-type=PADDING --dont-use-padding" "--list"
203 run_metaflac --add-padding=0 $flacfile $flacfile
204 check_flac
205 metaflac_test case26 "--add-padding=0 * 2" "--list"
207 run_metaflac --remove --except-block-type=PADDING $flacfile
208 check_flac
209 metaflac_test case27 "--remove --except-block-type=PADDING" "--list"
211 run_metaflac --remove-all $flacfile
212 check_flac
213 metaflac_test case28 "--remove-all" "--list"
215 run_metaflac --remove-all --dont-use-padding $flacfile
216 check_flac
217 metaflac_test case29 "--remove-all --dont-use-padding" "--list"
219 run_metaflac --remove-all --dont-use-padding $flacfile
220 check_flac
221 metaflac_test case30 "--remove-all --dont-use-padding" "--list"
223 run_metaflac --set-tag="f=0123456789abcdefghij" $flacfile
224 check_flac
225 metaflac_test case31 "--set-tag=..." "--list"
227 run_metaflac --remove-all-tags --set-tag="f=0123456789abcdefghi" $flacfile
228 check_flac
229 metaflac_test case32 "--remove-all-tags --set-tag=..." "--list"
231 run_metaflac --remove-all-tags --set-tag="f=0123456789abcde" $flacfile
232 check_flac
233 metaflac_test case33 "--remove-all-tags --set-tag=..." "--list"
235 run_metaflac --remove-all-tags --set-tag="f=0" $flacfile
236 check_flac
237 metaflac_test case34 "--remove-all-tags --set-tag=..." "--list"
239 run_metaflac --remove-all-tags --set-tag="f=0123456789" $flacfile
240 check_flac
241 metaflac_test case35 "--remove-all-tags --set-tag=..." "--list"
243 run_metaflac --remove-all-tags --set-tag="f=0123456789abcdefghi" $flacfile
244 check_flac
245 metaflac_test case36 "--remove-all-tags --set-tag=..." "--list"
247 run_metaflac --remove-all-tags --set-tag="f=0123456789" $flacfile
248 check_flac
249 metaflac_test case37 "--remove-all-tags --set-tag=..." "--list"
251 run_metaflac --remove-all-tags --set-tag="f=0123456789abcdefghij" $flacfile
252 check_flac
253 metaflac_test case38 "--remove-all-tags --set-tag=..." "--list"
255 echo "TITLE=Tittle" | run_metaflac --import-tags-from=- $flacfile
256 check_flac
257 metaflac_test case39 "--import-tags-from=-" "--list"
259 cat > vc.txt << EOF
260 artist=Fartist
261 artist=artits
263 run_metaflac --import-tags-from=vc.txt $flacfile
264 check_flac
265 metaflac_test case40 "--import-tags-from=[FILE]" "--list"
267 rm vc.txt
269 run_metaflac --add-replay-gain $flacfile
270 check_flac
271 metaflac_test case41 "--add-replay-gain" "--list"
273 run_metaflac --remove-replay-gain $flacfile
274 check_flac
275 metaflac_test case42 "--remove-replay-gain" "--list"
277 # CUESHEET blocks
278 cs_in=cuesheets/good.000.cue
279 cs_out=metaflac.cue
280 cs_out2=metaflac2.cue
281 run_metaflac --import-cuesheet-from="$cs_in" $flacfile
282 check_flac
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
286 check_flac
287 metaflac_test case44 "--remove --block-type=CUESHEET" "--list"
288 run_metaflac --import-cuesheet-from=$cs_out $flacfile
289 check_flac
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"
294 echo identical
296 rm -f $cs_out $cs_out2
298 # PICTURE blocks
299 ncase=46
300 for f in \
301 0.gif \
302 1.gif \
303 2.gif \
304 ; do
305 run_metaflac --import-picture-from="|image/gif|$f||pictures/$f" $flacfile
306 check_flac
307 metaflac_test "case$ncase" "--import-picture-from" "--list"
308 ncase=`expr $ncase + 1`
309 done
310 for f in \
311 0.jpg \
312 4.jpg \
313 ; do
314 run_metaflac --import-picture-from="4|image/jpeg|$f||pictures/$f" $flacfile
315 check_flac
316 metaflac_test "case$ncase" "--import-picture-from" "--list"
317 ncase=`expr $ncase + 1`
318 done
319 for f in \
320 0.png \
321 1.png \
322 2.png \
323 3.png \
324 4.png \
325 5.png \
326 6.png \
327 7.png \
328 8.png \
329 ; do
330 run_metaflac --import-picture-from="5|image/png|$f||pictures/$f" $flacfile
331 check_flac
332 metaflac_test "case$ncase" "--import-picture-from" "--list"
333 ncase=`expr $ncase + 1`
334 done
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
340 check_flac
341 cmp $fn pictures/0.gif || die "ERROR, exported picture file and original differ"
342 echo OK
343 rm -f $fn
344 echo -n "Testing --block-number --export-picture-to... "
345 run_metaflac --block-number=9 --export-picture-to=$fn $flacfile
346 check_flac
347 cmp $fn pictures/0.png || die "ERROR, exported picture file and original differ"
348 echo OK
349 rm -f $fn
351 run_metaflac --remove --block-type=PICTURE $flacfile
352 check_flac
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
355 check_flac
356 metaflac_test case61 "--import-picture-from" "--list"
357 run_metaflac --import-picture-from="2|image/png|icon|64x64x24|pictures/1.png" $flacfile
358 check_flac
359 metaflac_test case62 "--import-picture-from" "--list"
361 # UNKNOWN blocks
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"
367 echo OK