add configure options --disable-thorough-tests which breaks up testing into 3 levels...
[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 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__TEST_WITH_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__TEST_WITH_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 elif [ -f /bin/sh ] ; then
72         inputfile=/bin/sh
73 else
74         inputfile="$0"
75 fi
76 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
77         chmod +w $flacfile
78 else
79         die "ERROR during generation"
80 fi
81
82 check_exit ()
83 {
84         exit_code=$?
85         [ $exit_code = 0 ] || die "ERROR, exit code = $exit_code"
86 }
87
88 check_flac ()
89 {
90         run_flac --silent --test $flacfile || die "ERROR in $flacfile" 1>&2
91 }
92
93 check_flac
94
95 (set -x && run_metaflac --list $flacfile)
96 check_exit
97
98 (set -x &&
99 run_metaflac \
100         --show-md5sum \
101         --show-min-blocksize \
102         --show-max-blocksize \
103         --show-min-framesize \
104         --show-max-framesize \
105         --show-sample-rate \
106         --show-channels \
107         --show-bps \
108         --show-total-samples \
109         $flacfile
110 )
111 check_exit
112
113 (set -x && run_metaflac --preserve-modtime --add-padding=12345 $flacfile)
114 check_exit
115 check_flac
116
117 # some flavors of /bin/sh (e.g. Darwin's) won't even handle quoted spaces, so we underscore:
118 (set -x && run_metaflac --set-tag="ARTIST=The_artist_formerly_known_as_the_artist..." $flacfile)
119 check_exit
120 check_flac
121
122 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
123 check_exit
124
125 (set -x && run_metaflac --set-tag="ARTIST=Chuck_Woolery" $flacfile)
126 check_exit
127 check_flac
128
129 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
130 check_exit
131
132 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
133 check_exit
134
135 (set -x && run_metaflac --set-tag="ARTIST=Vern" $flacfile)
136 check_exit
137 check_flac
138
139 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
140 check_exit
141
142 (set -x && run_metaflac --set-tag="TITLE=He_who_smelt_it_dealt_it" $flacfile)
143 check_exit
144 check_flac
145
146 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
147 check_exit
148
149 (set -x && run_metaflac --show-vendor-tag --show-tag=ARTIST $flacfile)
150 check_exit
151
152 (set -x && run_metaflac --remove-first-tag=ARTIST $flacfile)
153 check_exit
154 check_flac
155
156 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
157 check_exit
158
159 (set -x && run_metaflac --remove-tag=ARTIST $flacfile)
160 check_exit
161 check_flac
162
163 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
164 check_exit
165
166 (set -x && run_metaflac --list --block-number=0 $flacfile)
167 check_exit
168
169 (set -x && run_metaflac --list --block-number=1,2,999 $flacfile)
170 check_exit
171
172 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT,PADDING $flacfile)
173 check_exit
174
175 (set -x && run_metaflac --list --except-block-type=SEEKTABLE,VORBIS_COMMENT $flacfile)
176 check_exit
177
178 (set -x && run_metaflac --add-padding=4321 $flacfile $flacfile)
179 check_exit
180 check_flac
181
182 (set -x && run_metaflac --merge-padding $flacfile)
183 check_exit
184 check_flac
185
186 (set -x && run_metaflac --add-padding=0 $flacfile)
187 check_exit
188 check_flac
189
190 (set -x && run_metaflac --sort-padding $flacfile)
191 check_exit
192 check_flac
193
194 (set -x && run_metaflac --add-padding=0 $flacfile)
195 check_exit
196 check_flac
197
198 (set -x && run_metaflac --remove-all-tags $flacfile)
199 check_exit
200 check_flac
201
202 (set -x && run_metaflac --remove --block-number=1,99 --dont-use-padding $flacfile)
203 check_exit
204 check_flac
205
206 (set -x && run_metaflac --remove --block-number=99 --dont-use-padding $flacfile)
207 check_exit
208 check_flac
209
210 (set -x && run_metaflac --remove --block-type=PADDING $flacfile)
211 check_exit
212 check_flac
213
214 (set -x && run_metaflac --remove --block-type=PADDING --dont-use-padding $flacfile)
215 check_exit
216 check_flac
217
218 (set -x && run_metaflac --add-padding=0 $flacfile $flacfile)
219 check_exit
220 check_flac
221
222 (set -x && run_metaflac --remove --except-block-type=PADDING $flacfile)
223 check_exit
224 check_flac
225
226 (set -x && run_metaflac --remove-all $flacfile)
227 check_exit
228 check_flac
229
230 (set -x && run_metaflac --remove-all --dont-use-padding $flacfile)
231 check_exit
232 check_flac
233
234 (set -x && run_metaflac --remove-all --dont-use-padding $flacfile)
235 check_exit
236 check_flac
237
238 (set -x && run_metaflac --set-tag="f=0123456789abcdefghij" $flacfile)
239 check_exit
240 check_flac
241 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
242 check_exit
243
244 (set -x && run_metaflac --remove-all-tags --set-tag="f=0123456789abcdefghi" $flacfile)
245 check_exit
246 check_flac
247 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
248 check_exit
249
250 (set -x && run_metaflac --remove-all-tags --set-tag="f=0123456789abcde" $flacfile)
251 check_exit
252 check_flac
253 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
254 check_exit
255
256 (set -x && run_metaflac --remove-all-tags --set-tag="f=0" $flacfile)
257 check_exit
258 check_flac
259 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
260 check_exit
261
262 (set -x && run_metaflac --remove-all-tags --set-tag="f=0123456789" $flacfile)
263 check_exit
264 check_flac
265 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
266 check_exit
267
268 (set -x && run_metaflac --remove-all-tags --set-tag="f=0123456789abcdefghi" $flacfile)
269 check_exit
270 check_flac
271 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
272 check_exit
273
274 (set -x && run_metaflac --remove-all-tags --set-tag="f=0123456789" $flacfile)
275 check_exit
276 check_flac
277 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
278 check_exit
279
280 (set -x && run_metaflac --remove-all-tags --set-tag="f=0123456789abcdefghij" $flacfile)
281 check_exit
282 check_flac
283 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
284 check_exit
285
286 (set -x && echo "TITLE=Tittle" | run_metaflac --import-tags-from=- $flacfile)
287 check_exit
288 check_flac
289 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
290 check_exit
291
292 cat > vc.txt << EOF
293 artist=Fartist
294 artist=artits
295 EOF
296 (set -x && run_metaflac --import-tags-from=vc.txt $flacfile)
297 check_exit
298 check_flac
299 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
300 check_exit
301
302 rm vc.txt
303
304 cs_in=cuesheets/good.000.cue
305 cs_out=metaflac.cue
306 cs_out2=metaflac2.cue
307 (set -x && run_metaflac --import-cuesheet-from="$cs_in" $flacfile)
308 check_exit
309 check_flac
310 (set -x && run_metaflac --export-cuesheet-to=$cs_out $flacfile)
311 check_exit
312 (set -x && run_metaflac --remove --block-type=CUESHEET $flacfile)
313 check_exit
314 check_flac
315 (set -x && run_metaflac --import-cuesheet-from=$cs_out $flacfile)
316 check_exit
317 check_flac
318 (set -x && run_metaflac --export-cuesheet-to=$cs_out2 $flacfile)
319 check_exit
320 echo "comparing cuesheets:"
321 diff $cs_out $cs_out2 || die "ERROR, cuesheets should be identical"
322 echo identical
323
324 rm -f $cs_out $cs_out2
325
326 (set -x && run_metaflac --add-replay-gain $flacfile)
327 check_exit
328 check_flac
329 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
330 check_exit
331
332 (set -x && run_metaflac --remove-replay-gain $flacfile)
333 check_exit
334 check_flac
335 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
336 check_exit
337
338 echo -n "Testing FLAC file with unknown metadata... "
339 cp -p metaflac.flac.in $flacfile
340 # remove the VORBIS_COMMENT block so vendor string changes don't interfere with the comparison:
341 run_metaflac --remove --block-type=VORBIS_COMMENT --dont-use-padding $flacfile
342 cmp $flacfile metaflac.flac.ok || die "ERROR, $flacfile and metaflac.flac.ok differ"
343 echo OK
344
345 exit 0