fix script invocation in valgrind mode
[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  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 LD_LIBRARY_PATH=../src/libFLAC/.libs:$LD_LIBRARY_PATH
33 LD_LIBRARY_PATH=../src/libOggFLAC/.libs:$LD_LIBRARY_PATH
34 LD_LIBRARY_PATH=../src/share/grabbag/.libs:$LD_LIBRARY_PATH
35 LD_LIBRARY_PATH=../src/share/getopt/.libs:$LD_LIBRARY_PATH
36 LD_LIBRARY_PATH=../src/share/replaygain_analysis/.libs:$LD_LIBRARY_PATH
37 LD_LIBRARY_PATH=../src/share/replaygain_synthesis/.libs:$LD_LIBRARY_PATH
38 LD_LIBRARY_PATH=../src/share/utf8/.libs:$LD_LIBRARY_PATH
39 LD_LIBRARY_PATH=../obj/$BUILD/lib:$LD_LIBRARY_PATH
40 export LD_LIBRARY_PATH
41 PATH=../src/flac:$PATH
42 PATH=../src/metaflac:$PATH
43 PATH=../obj/$BUILD/bin:$PATH
44
45 flacfile=metaflac.flac
46
47 flac --help 1>/dev/null 2>/dev/null || die "ERROR can't find flac executable"
48 metaflac --help 1>/dev/null 2>/dev/null || die "ERROR can't find metaflac executable"
49
50 run_flac ()
51 {
52         if [ x"$FLAC__VALGRIND" = xyes ] ; then
53                 valgrind --leak-check=yes --show-reachable=yes --num-callers=100 --logfile-fd=4 flac $* 4>>test_metaflac.valgrind.log
54         else
55                 flac $*
56         fi
57 }
58
59 run_metaflac ()
60 {
61         if [ x"$FLAC__VALGRIND" = xyes ] ; then
62                 valgrind --leak-check=yes --show-reachable=yes --num-callers=100 --logfile-fd=4 metaflac $* 4>>test_metaflac.valgrind.log
63         else
64                 metaflac $*
65         fi
66 }
67
68 echo "Generating stream..."
69 if [ -f /bin/sh.exe ] ; then
70         inputfile=/bin/sh.exe
71 else
72         inputfile=/bin/sh
73 fi
74 if run_flac --force --verify -0 --output-name=$flacfile --force-raw-format --endian=big --sign=signed --channels=1 --bps=8 --sample-rate=44100 $inputfile ; then
75         chmod +w $flacfile
76 else
77         die "ERROR during generation"
78 fi
79
80 check_exit ()
81 {
82         exit_code=$?
83         [ $exit_code = 0 ] || die "ERROR, exit code = $exit_code"
84 }
85
86 check_flac ()
87 {
88         run_flac --silent --test $flacfile || die "ERROR in $flacfile" 1>&2
89 }
90
91 check_flac
92
93 (set -x && run_metaflac --list $flacfile)
94 check_exit
95
96 (set -x &&
97 run_metaflac \
98         --show-md5sum \
99         --show-min-blocksize \
100         --show-max-blocksize \
101         --show-min-framesize \
102         --show-max-framesize \
103         --show-sample-rate \
104         --show-channels \
105         --show-bps \
106         --show-total-samples \
107         $flacfile
108 )
109 check_exit
110
111 (set -x && run_metaflac --preserve-modtime --add-padding=12345 $flacfile)
112 check_exit
113 check_flac
114
115 # some flavors of /bin/sh (e.g. Darwin's) won't even handle quoted spaces, so we underscore:
116 (set -x && run_metaflac --set-tag="ARTIST=The_artist_formerly_known_as_the_artist..." $flacfile)
117 check_exit
118 check_flac
119
120 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
121 check_exit
122
123 (set -x && run_metaflac --set-tag="ARTIST=Chuck_Woolery" $flacfile)
124 check_exit
125 check_flac
126
127 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
128 check_exit
129
130 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
131 check_exit
132
133 (set -x && run_metaflac --set-tag="ARTIST=Vern" $flacfile)
134 check_exit
135 check_flac
136
137 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
138 check_exit
139
140 (set -x && run_metaflac --set-tag="TITLE=He_who_smelt_it_dealt_it" $flacfile)
141 check_exit
142 check_flac
143
144 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
145 check_exit
146
147 (set -x && run_metaflac --show-vendor-tag --show-tag=ARTIST $flacfile)
148 check_exit
149
150 (set -x && run_metaflac --remove-first-tag=ARTIST $flacfile)
151 check_exit
152 check_flac
153
154 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
155 check_exit
156
157 (set -x && run_metaflac --remove-tag=ARTIST $flacfile)
158 check_exit
159 check_flac
160
161 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
162 check_exit
163
164 (set -x && run_metaflac --list --block-number=0 $flacfile)
165 check_exit
166
167 (set -x && run_metaflac --list --block-number=1,2,999 $flacfile)
168 check_exit
169
170 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT,PADDING $flacfile)
171 check_exit
172
173 (set -x && run_metaflac --list --except-block-type=SEEKTABLE,VORBIS_COMMENT $flacfile)
174 check_exit
175
176 (set -x && run_metaflac --add-padding=4321 $flacfile $flacfile)
177 check_exit
178 check_flac
179
180 (set -x && run_metaflac --merge-padding $flacfile)
181 check_exit
182 check_flac
183
184 (set -x && run_metaflac --add-padding=0 $flacfile)
185 check_exit
186 check_flac
187
188 (set -x && run_metaflac --sort-padding $flacfile)
189 check_exit
190 check_flac
191
192 (set -x && run_metaflac --add-padding=0 $flacfile)
193 check_exit
194 check_flac
195
196 (set -x && run_metaflac --remove-all-tags $flacfile)
197 check_exit
198 check_flac
199
200 (set -x && run_metaflac --remove --block-number=1,99 --dont-use-padding $flacfile)
201 check_exit
202 check_flac
203
204 (set -x && run_metaflac --remove --block-number=99 --dont-use-padding $flacfile)
205 check_exit
206 check_flac
207
208 (set -x && run_metaflac --remove --block-type=PADDING $flacfile)
209 check_exit
210 check_flac
211
212 (set -x && run_metaflac --remove --block-type=PADDING --dont-use-padding $flacfile)
213 check_exit
214 check_flac
215
216 (set -x && run_metaflac --add-padding=0 $flacfile $flacfile)
217 check_exit
218 check_flac
219
220 (set -x && run_metaflac --remove --except-block-type=PADDING $flacfile)
221 check_exit
222 check_flac
223
224 (set -x && run_metaflac --remove-all $flacfile)
225 check_exit
226 check_flac
227
228 (set -x && run_metaflac --remove-all --dont-use-padding $flacfile)
229 check_exit
230 check_flac
231
232 (set -x && run_metaflac --remove-all --dont-use-padding $flacfile)
233 check_exit
234 check_flac
235
236 (set -x && run_metaflac --set-tag="f=0123456789abcdefghij" $flacfile)
237 check_exit
238 check_flac
239 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
240 check_exit
241
242 (set -x && run_metaflac --remove-all-tags --set-tag="f=0123456789abcdefghi" $flacfile)
243 check_exit
244 check_flac
245 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
246 check_exit
247
248 (set -x && run_metaflac --remove-all-tags --set-tag="f=0123456789abcde" $flacfile)
249 check_exit
250 check_flac
251 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
252 check_exit
253
254 (set -x && run_metaflac --remove-all-tags --set-tag="f=0" $flacfile)
255 check_exit
256 check_flac
257 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
258 check_exit
259
260 (set -x && run_metaflac --remove-all-tags --set-tag="f=0123456789" $flacfile)
261 check_exit
262 check_flac
263 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
264 check_exit
265
266 (set -x && run_metaflac --remove-all-tags --set-tag="f=0123456789abcdefghi" $flacfile)
267 check_exit
268 check_flac
269 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
270 check_exit
271
272 (set -x && run_metaflac --remove-all-tags --set-tag="f=0123456789" $flacfile)
273 check_exit
274 check_flac
275 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
276 check_exit
277
278 (set -x && run_metaflac --remove-all-tags --set-tag="f=0123456789abcdefghij" $flacfile)
279 check_exit
280 check_flac
281 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
282 check_exit
283
284 (set -x && echo "TITLE=Tittle" | run_metaflac --import-tags-from=- $flacfile)
285 check_exit
286 check_flac
287 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
288 check_exit
289
290 cat > vc.txt << EOF
291 artist=Fartist
292 artist=artits
293 EOF
294 (set -x && run_metaflac --import-tags-from=vc.txt $flacfile)
295 check_exit
296 check_flac
297 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
298 check_exit
299
300 rm vc.txt
301
302 cs_in=cuesheets/good.000.cue
303 cs_out=metaflac.cue
304 cs_out2=metaflac2.cue
305 (set -x && run_metaflac --import-cuesheet-from="$cs_in" $flacfile)
306 check_exit
307 check_flac
308 (set -x && run_metaflac --export-cuesheet-to=$cs_out $flacfile)
309 check_exit
310 (set -x && run_metaflac --remove --block-type=CUESHEET $flacfile)
311 check_exit
312 check_flac
313 (set -x && run_metaflac --import-cuesheet-from=$cs_out $flacfile)
314 check_exit
315 check_flac
316 (set -x && run_metaflac --export-cuesheet-to=$cs_out2 $flacfile)
317 check_exit
318 echo "comparing cuesheets:"
319 diff $cs_out $cs_out2 || die "ERROR, cuesheets should be identical"
320 echo identical
321
322 rm -f $cs_out $cs_out2
323
324 (set -x && run_metaflac --add-replay-gain $flacfile)
325 check_exit
326 check_flac
327
328 echo -n "Testing FLAC file with unknown metadata... "
329 cp -p metaflac.flac.in $flacfile
330 # remove the VORBIS_COMMENT block so vendor string changes don't interfere with the comparison:
331 run_metaflac --remove --block-type=VORBIS_COMMENT --dont-use-padding $flacfile
332 cmp $flacfile metaflac.flac.ok || die "ERROR, $flacfile and metaflac.flac.ok differ"
333 echo OK
334
335 exit 0