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