add a few more tests
[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/lib:$LD_LIBRARY_PATH
21 export LD_LIBRARY_PATH
22 PATH=../src/flac:../src/metaflac:../obj/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 #FLAC="valgrind --leak-check=yes --show-reachable=yes flac"
33 FLAC=flac
34 #METAFLAC="valgrind --leak-check=yes --show-reachable=yes metaflac"
35 METAFLAC=metaflac
36
37 echo "Generating stream..."
38 if [ -f /bin/sh.exe ] ; then
39         inputfile=/bin/sh.exe
40 else
41         inputfile=/bin/sh
42 fi
43 if $FLAC --verify -0 --output-name=$flacfile --force-raw-format --endian=big --sign=signed --channels=1 --bps=8 --sample-rate=44100 $inputfile ; then
44         chmod +w $flacfile
45 else
46         echo "ERROR during generation" 1>&2
47         exit 1
48 fi
49
50 check_exit ()
51 {
52         exit_code=$?
53         if [ $exit_code != 0 ] ; then
54                 echo "ERROR, exit code = $exit_code" 1>&2
55                 exit 1
56         fi
57 }
58
59 check_flac ()
60 {
61         if $FLAC --silent --test $flacfile ; then : ; else
62                 echo "ERROR in $flacfile" 1>&2
63                 exit 1
64         fi
65 }
66
67 check_flac
68
69 (set -x && $METAFLAC --list $flacfile)
70 check_exit
71
72 (set -x &&
73 $METAFLAC \
74         --show-md5sum \
75         --show-min-blocksize \
76         --show-max-blocksize \
77         --show-min-framesize \
78         --show-max-framesize \
79         --show-sample-rate \
80         --show-channels \
81         --show-bps \
82         --show-total-samples \
83         $flacfile
84 )
85 check_exit
86
87 (set -x && $METAFLAC --preserve-modtime --add-padding=12345 $flacfile)
88 check_exit
89 check_flac
90
91 # some flavors of /bin/sh (e.g. Darwin's) won't even handle quoted spaces, so we underscore:
92 (set -x && $METAFLAC --set-vc-field="ARTIST=The_artist_formerly_known_as_the_artist..." $flacfile)
93 check_exit
94 check_flac
95
96 (set -x && $METAFLAC --list --block-type=VORBIS_COMMENT $flacfile)
97 check_exit
98
99 (set -x && $METAFLAC --set-vc-field="ARTIST=Chuck_Woolery" $flacfile)
100 check_exit
101 check_flac
102
103 (set -x && $METAFLAC --list --block-type=VORBIS_COMMENT $flacfile)
104 check_exit
105
106 (set -x && $METAFLAC --list --block-type=VORBIS_COMMENT $flacfile)
107 check_exit
108
109 (set -x && $METAFLAC --set-vc-field="ARTIST=Vern" $flacfile)
110 check_exit
111 check_flac
112
113 (set -x && $METAFLAC --list --block-type=VORBIS_COMMENT $flacfile)
114 check_exit
115
116 (set -x && $METAFLAC --set-vc-field="TITLE=He_who_smelt_it_dealt_it" $flacfile)
117 check_exit
118 check_flac
119
120 (set -x && $METAFLAC --list --block-type=VORBIS_COMMENT $flacfile)
121 check_exit
122
123 (set -x && $METAFLAC --show-vc-vendor --show-vc-field=ARTIST $flacfile)
124 check_exit
125
126 (set -x && $METAFLAC --remove-vc-firstfield=ARTIST $flacfile)
127 check_exit
128 check_flac
129
130 (set -x && $METAFLAC --list --block-type=VORBIS_COMMENT $flacfile)
131 check_exit
132
133 (set -x && $METAFLAC --remove-vc-field=ARTIST $flacfile)
134 check_exit
135 check_flac
136
137 (set -x && $METAFLAC --list --block-type=VORBIS_COMMENT $flacfile)
138 check_exit
139
140 (set -x && $METAFLAC --list --block-number=0 $flacfile)
141 check_exit
142
143 (set -x && $METAFLAC --list --block-number=1,2,999 $flacfile)
144 check_exit
145
146 (set -x && $METAFLAC --list --block-type=VORBIS_COMMENT,PADDING $flacfile)
147 check_exit
148
149 (set -x && $METAFLAC --list --except-block-type=SEEKTABLE,VORBIS_COMMENT $flacfile)
150 check_exit
151
152 (set -x && $METAFLAC --add-padding=4321 $flacfile $flacfile)
153 check_exit
154 check_flac
155
156 (set -x && $METAFLAC --merge-padding $flacfile)
157 check_exit
158 check_flac
159
160 (set -x && $METAFLAC --add-padding=0 $flacfile)
161 check_exit
162 check_flac
163
164 (set -x && $METAFLAC --sort-padding $flacfile)
165 check_exit
166 check_flac
167
168 (set -x && $METAFLAC --add-padding=0 $flacfile)
169 check_exit
170 check_flac
171
172 (set -x && $METAFLAC --remove-vc-all $flacfile)
173 check_exit
174 check_flac
175
176 (set -x && $METAFLAC --remove --block-number=1,99 --dont-use-padding $flacfile)
177 check_exit
178 check_flac
179
180 (set -x && $METAFLAC --remove --block-number=99 --dont-use-padding $flacfile)
181 check_exit
182 check_flac
183
184 (set -x && $METAFLAC --remove --block-type=PADDING $flacfile)
185 check_exit
186 check_flac
187
188 (set -x && $METAFLAC --remove --block-type=PADDING --dont-use-padding $flacfile)
189 check_exit
190 check_flac
191
192 (set -x && $METAFLAC --add-padding=0 $flacfile $flacfile)
193 check_exit
194 check_flac
195
196 (set -x && $METAFLAC --remove --except-block-type=PADDING $flacfile)
197 check_exit
198 check_flac
199
200 (set -x && $METAFLAC --remove-all $flacfile)
201 check_exit
202 check_flac
203
204 (set -x && $METAFLAC --remove-all --dont-use-padding $flacfile)
205 check_exit
206 check_flac
207
208 (set -x && $METAFLAC --remove-all --dont-use-padding $flacfile)
209 check_exit
210 check_flac
211
212 (set -x && $METAFLAC --set-vc-field="f=0123456789abcdefghij" $flacfile)
213 check_exit
214 check_flac
215 (set -x && $METAFLAC --list --except-block-type=STREAMINFO $flacfile)
216 check_exit
217
218 (set -x && $METAFLAC --remove-vc-all --set-vc-field="f=0123456789abcdefghi" $flacfile)
219 check_exit
220 check_flac
221 (set -x && $METAFLAC --list --except-block-type=STREAMINFO $flacfile)
222 check_exit
223
224 (set -x && $METAFLAC --remove-vc-all --set-vc-field="f=0123456789abcde" $flacfile)
225 check_exit
226 check_flac
227 (set -x && $METAFLAC --list --except-block-type=STREAMINFO $flacfile)
228 check_exit
229
230 (set -x && $METAFLAC --remove-vc-all --set-vc-field="f=0" $flacfile)
231 check_exit
232 check_flac
233 (set -x && $METAFLAC --list --except-block-type=STREAMINFO $flacfile)
234 check_exit
235
236 (set -x && $METAFLAC --remove-vc-all --set-vc-field="f=0123456789" $flacfile)
237 check_exit
238 check_flac
239 (set -x && $METAFLAC --list --except-block-type=STREAMINFO $flacfile)
240 check_exit
241
242 (set -x && $METAFLAC --remove-vc-all --set-vc-field="f=0123456789abcdefghi" $flacfile)
243 check_exit
244 check_flac
245 (set -x && $METAFLAC --list --except-block-type=STREAMINFO $flacfile)
246 check_exit
247
248 (set -x && $METAFLAC --remove-vc-all --set-vc-field="f=0123456789" $flacfile)
249 check_exit
250 check_flac
251 (set -x && $METAFLAC --list --except-block-type=STREAMINFO $flacfile)
252 check_exit
253
254 (set -x && $METAFLAC --remove-vc-all --set-vc-field="f=0123456789abcdefghij" $flacfile)
255 check_exit
256 check_flac
257 (set -x && $METAFLAC --list --except-block-type=STREAMINFO $flacfile)
258 check_exit
259
260 (set -x && echo "TITLE=Tittle" | $METAFLAC --import-vc-from=- $flacfile)
261 check_exit
262 check_flac
263 (set -x && $METAFLAC --list --block-type=VORBIS_COMMENT $flacfile)
264 check_exit
265
266 cat > vc.txt << EOF
267 artist=Fartist
268 artist=artits
269 EOF
270 (set -x && $METAFLAC --import-vc-from=vc.txt $flacfile)
271 check_exit
272 check_flac
273 (set -x && $METAFLAC --list --block-type=VORBIS_COMMENT $flacfile)
274 check_exit
275
276 rm vc.txt
277
278 exit 0