instrument for valgrind
[platform/upstream/flac.git] / test / test_metaflac.sh
1 #!/bin/sh
2
3 #  FLAC - Free Lossless Audio Codec
4 #  Copyright (C) 2002  Josh Coalson
5 #
6 #  This program is part of FLAC; you can redistribute it and/or
7 #  modify it under the terms of the GNU General Public License
8 #  as published by the Free Software Foundation; either version 2
9 #  of the License, or (at your option) any later version.
10 #
11 #  This program is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #  GNU General Public License for more details.
15 #
16 #  You should have received a copy of the GNU General Public License
17 #  along with this program; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 LD_LIBRARY_PATH=../src/libFLAC/.libs:../obj/release/lib:../obj/debug/lib:$LD_LIBRARY_PATH
21 export LD_LIBRARY_PATH
22 PATH=../src/flac:../src/metaflac:../obj/release/bin:../obj/debug/bin:$PATH
23
24 flacfile=metaflac.flac
25
26 flac --help 1>/dev/null 2>/dev/null || (echo "ERROR can't find flac executable" 1>&2 && exit 1)
27 if [ $? != 0 ] ; then exit 1 ; fi
28
29 metaflac --help 1>/dev/null 2>/dev/null || (echo "ERROR can't find metaflac executable" 1>&2 && exit 1)
30 if [ $? != 0 ] ; then exit 1 ; fi
31
32 run_flac ()
33 {
34         if [ "$FLAC__VALGRIND" = yes ] ; then
35                 valgrind --leak-check=yes --show-reachable=yes --num-callers=10 --logfile-fd=4 flac $* 4>>valgrind.log
36         else
37                 flac $*
38         fi
39 }
40
41 run_metaflac ()
42 {
43         if [ "$FLAC__VALGRIND" = yes ] ; then
44                 valgrind --leak-check=yes --show-reachable=yes --num-callers=10 --logfile-fd=4 metaflac $* 4>>valgrind.log
45         else
46                 metaflac $*
47         fi
48 }
49
50 echo "Generating stream..."
51 if [ -f /bin/sh.exe ] ; then
52         inputfile=/bin/sh.exe
53 else
54         inputfile=/bin/sh
55 fi
56 if run_flac --verify -0 --output-name=$flacfile --force-raw-format --endian=big --sign=signed --channels=1 --bps=8 --sample-rate=44100 $inputfile ; then
57         chmod +w $flacfile
58 else
59         echo "ERROR during generation" 1>&2
60         exit 1
61 fi
62
63 check_exit ()
64 {
65         exit_code=$?
66         if [ $exit_code != 0 ] ; then
67                 echo "ERROR, exit code = $exit_code" 1>&2
68                 exit 1
69         fi
70 }
71
72 check_flac ()
73 {
74         if run_flac --silent --test $flacfile ; then : ; else
75                 echo "ERROR in $flacfile" 1>&2
76                 exit 1
77         fi
78 }
79
80 check_flac
81
82 (set -x && run_metaflac --list $flacfile)
83 check_exit
84
85 (set -x &&
86 run_metaflac \
87         --show-md5sum \
88         --show-min-blocksize \
89         --show-max-blocksize \
90         --show-min-framesize \
91         --show-max-framesize \
92         --show-sample-rate \
93         --show-channels \
94         --show-bps \
95         --show-total-samples \
96         $flacfile
97 )
98 check_exit
99
100 (set -x && run_metaflac --preserve-modtime --add-padding=12345 $flacfile)
101 check_exit
102 check_flac
103
104 # some flavors of /bin/sh (e.g. Darwin's) won't even handle quoted spaces, so we underscore:
105 (set -x && run_metaflac --set-vc-field="ARTIST=The_artist_formerly_known_as_the_artist..." $flacfile)
106 check_exit
107 check_flac
108
109 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
110 check_exit
111
112 (set -x && run_metaflac --set-vc-field="ARTIST=Chuck_Woolery" $flacfile)
113 check_exit
114 check_flac
115
116 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
117 check_exit
118
119 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
120 check_exit
121
122 (set -x && run_metaflac --set-vc-field="ARTIST=Vern" $flacfile)
123 check_exit
124 check_flac
125
126 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
127 check_exit
128
129 (set -x && run_metaflac --set-vc-field="TITLE=He_who_smelt_it_dealt_it" $flacfile)
130 check_exit
131 check_flac
132
133 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
134 check_exit
135
136 (set -x && run_metaflac --show-vc-vendor --show-vc-field=ARTIST $flacfile)
137 check_exit
138
139 (set -x && run_metaflac --remove-vc-firstfield=ARTIST $flacfile)
140 check_exit
141 check_flac
142
143 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
144 check_exit
145
146 (set -x && run_metaflac --remove-vc-field=ARTIST $flacfile)
147 check_exit
148 check_flac
149
150 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
151 check_exit
152
153 (set -x && run_metaflac --list --block-number=0 $flacfile)
154 check_exit
155
156 (set -x && run_metaflac --list --block-number=1,2,999 $flacfile)
157 check_exit
158
159 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT,PADDING $flacfile)
160 check_exit
161
162 (set -x && run_metaflac --list --except-block-type=SEEKTABLE,VORBIS_COMMENT $flacfile)
163 check_exit
164
165 (set -x && run_metaflac --add-padding=4321 $flacfile $flacfile)
166 check_exit
167 check_flac
168
169 (set -x && run_metaflac --merge-padding $flacfile)
170 check_exit
171 check_flac
172
173 (set -x && run_metaflac --add-padding=0 $flacfile)
174 check_exit
175 check_flac
176
177 (set -x && run_metaflac --sort-padding $flacfile)
178 check_exit
179 check_flac
180
181 (set -x && run_metaflac --add-padding=0 $flacfile)
182 check_exit
183 check_flac
184
185 (set -x && run_metaflac --remove-vc-all $flacfile)
186 check_exit
187 check_flac
188
189 (set -x && run_metaflac --remove --block-number=1,99 --dont-use-padding $flacfile)
190 check_exit
191 check_flac
192
193 (set -x && run_metaflac --remove --block-number=99 --dont-use-padding $flacfile)
194 check_exit
195 check_flac
196
197 (set -x && run_metaflac --remove --block-type=PADDING $flacfile)
198 check_exit
199 check_flac
200
201 (set -x && run_metaflac --remove --block-type=PADDING --dont-use-padding $flacfile)
202 check_exit
203 check_flac
204
205 (set -x && run_metaflac --add-padding=0 $flacfile $flacfile)
206 check_exit
207 check_flac
208
209 (set -x && run_metaflac --remove --except-block-type=PADDING $flacfile)
210 check_exit
211 check_flac
212
213 (set -x && run_metaflac --remove-all $flacfile)
214 check_exit
215 check_flac
216
217 (set -x && run_metaflac --remove-all --dont-use-padding $flacfile)
218 check_exit
219 check_flac
220
221 (set -x && run_metaflac --remove-all --dont-use-padding $flacfile)
222 check_exit
223 check_flac
224
225 (set -x && run_metaflac --set-vc-field="f=0123456789abcdefghij" $flacfile)
226 check_exit
227 check_flac
228 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
229 check_exit
230
231 (set -x && run_metaflac --remove-vc-all --set-vc-field="f=0123456789abcdefghi" $flacfile)
232 check_exit
233 check_flac
234 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
235 check_exit
236
237 (set -x && run_metaflac --remove-vc-all --set-vc-field="f=0123456789abcde" $flacfile)
238 check_exit
239 check_flac
240 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
241 check_exit
242
243 (set -x && run_metaflac --remove-vc-all --set-vc-field="f=0" $flacfile)
244 check_exit
245 check_flac
246 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
247 check_exit
248
249 (set -x && run_metaflac --remove-vc-all --set-vc-field="f=0123456789" $flacfile)
250 check_exit
251 check_flac
252 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
253 check_exit
254
255 (set -x && run_metaflac --remove-vc-all --set-vc-field="f=0123456789abcdefghi" $flacfile)
256 check_exit
257 check_flac
258 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
259 check_exit
260
261 (set -x && run_metaflac --remove-vc-all --set-vc-field="f=0123456789" $flacfile)
262 check_exit
263 check_flac
264 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
265 check_exit
266
267 (set -x && run_metaflac --remove-vc-all --set-vc-field="f=0123456789abcdefghij" $flacfile)
268 check_exit
269 check_flac
270 (set -x && run_metaflac --list --except-block-type=STREAMINFO $flacfile)
271 check_exit
272
273 (set -x && echo "TITLE=Tittle" | run_metaflac --import-vc-from=- $flacfile)
274 check_exit
275 check_flac
276 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
277 check_exit
278
279 cat > vc.txt << EOF
280 artist=Fartist
281 artist=artits
282 EOF
283 (set -x && run_metaflac --import-vc-from=vc.txt $flacfile)
284 check_exit
285 check_flac
286 (set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
287 check_exit
288
289 rm vc.txt
290
291 cs_in=cuesheets/good.000.cue
292 cs_out=metaflac.cue
293 cs_out2=metaflac2.cue
294 (set -x && run_metaflac --import-cuesheet-from="$cs_in" $flacfile)
295 check_exit
296 check_flac
297 (set -x && run_metaflac --export-cuesheet-to=$cs_out $flacfile)
298 check_exit
299 (set -x && run_metaflac --remove --block-type=CUESHEET $flacfile)
300 check_exit
301 check_flac
302 (set -x && run_metaflac --import-cuesheet-from=$cs_out $flacfile)
303 check_exit
304 check_flac
305 (set -x && run_metaflac --export-cuesheet-to=$cs_out2 $flacfile)
306 check_exit
307 echo "comparing cuesheets:"
308 if diff $cs_out $cs_out2 ; then : ; else
309         echo "ERROR, cuesheets should be identical"
310         exit 1
311 fi
312 echo identical
313
314 rm -f $cs_out $cs_out2
315
316 exit 0