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