Huge Windows utf8 I/O patch.
[flac.git] / src / test_libFLAC / decoders.c
1 /* test_libFLAC - Unit tester for libFLAC
2  * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009  Josh Coalson
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19 #if HAVE_CONFIG_H
20 #  include <config.h>
21 #endif
22
23 #include <errno.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include "decoders.h"
28 #include "FLAC/assert.h"
29 #include "FLAC/stream_decoder.h"
30 #include "share/grabbag.h"
31 #include "share/compat.h"
32 #include "share/safe_str.h"
33 #include "test_libs_common/file_utils_flac.h"
34 #include "test_libs_common/metadata_utils.h"
35
36 typedef enum {
37         LAYER_STREAM = 0, /* FLAC__stream_decoder_init_[ogg_]stream() without seeking */
38         LAYER_SEEKABLE_STREAM, /* FLAC__stream_decoder_init_[ogg_]stream() with seeking */
39         LAYER_FILE, /* FLAC__stream_decoder_init_[ogg_]FILE() */
40         LAYER_FILENAME /* FLAC__stream_decoder_init_[ogg_]file() */
41 } Layer;
42
43 static const char * const LayerString[] = {
44         "Stream",
45         "Seekable Stream",
46         "FILE*",
47         "Filename"
48 };
49
50 typedef struct {
51         Layer layer;
52         FILE *file;
53         char filename[512];
54         unsigned current_metadata_number;
55         FLAC__bool ignore_errors;
56         FLAC__bool error_occurred;
57 } StreamDecoderClientData;
58
59 static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_;
60 static FLAC__StreamMetadata *expected_metadata_sequence_[9];
61 static unsigned num_expected_;
62 static FLAC__off_t flacfilesize_;
63
64 static const char *flacfilename(FLAC__bool is_ogg)
65 {
66         return is_ogg? "metadata.oga" : "metadata.flac";
67 }
68
69 static FLAC__bool die_(const char *msg)
70 {
71         printf("ERROR: %s\n", msg);
72         return false;
73 }
74
75 static FLAC__bool die_s_(const char *msg, const FLAC__StreamDecoder *decoder)
76 {
77         FLAC__StreamDecoderState state = FLAC__stream_decoder_get_state(decoder);
78
79         if(msg)
80                 printf("FAILED, %s", msg);
81         else
82                 printf("FAILED");
83
84         printf(", state = %u (%s)\n", (unsigned)state, FLAC__StreamDecoderStateString[state]);
85
86         return false;
87 }
88
89 static void open_test_file(StreamDecoderClientData * pdcd, int is_ogg, const char * mode)
90 {
91         pdcd->file = flac_fopen(flacfilename(is_ogg), mode);
92         safe_strncpy(pdcd->filename, flacfilename(is_ogg), sizeof (pdcd->filename));
93 }
94
95 static void init_metadata_blocks_(void)
96 {
97         mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
98 }
99
100 static void free_metadata_blocks_(void)
101 {
102         mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
103 }
104
105 static FLAC__bool generate_file_(FLAC__bool is_ogg)
106 {
107         printf("\n\ngenerating %sFLAC file for decoder tests...\n", is_ogg? "Ogg ":"");
108
109         num_expected_ = 0;
110         expected_metadata_sequence_[num_expected_++] = &padding_;
111         expected_metadata_sequence_[num_expected_++] = &seektable_;
112         expected_metadata_sequence_[num_expected_++] = &application1_;
113         expected_metadata_sequence_[num_expected_++] = &application2_;
114         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
115         expected_metadata_sequence_[num_expected_++] = &cuesheet_;
116         expected_metadata_sequence_[num_expected_++] = &picture_;
117         expected_metadata_sequence_[num_expected_++] = &unknown_;
118         /* WATCHOUT: for Ogg FLAC the encoder should move the VORBIS_COMMENT block to the front, right after STREAMINFO */
119
120         if(!file_utils__generate_flacfile(is_ogg, flacfilename(is_ogg), &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
121                 return die_("creating the encoded file");
122
123         return true;
124 }
125
126 static FLAC__StreamDecoderReadStatus stream_decoder_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
127 {
128         StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
129         const size_t requested_bytes = *bytes;
130
131         (void)decoder;
132
133         if(0 == dcd) {
134                 printf("ERROR: client_data in read callback is NULL\n");
135                 return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
136         }
137
138         if(dcd->error_occurred)
139                 return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
140
141         if(feof(dcd->file)) {
142                 *bytes = 0;
143                 return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
144         }
145         else if(requested_bytes > 0) {
146                 *bytes = fread(buffer, 1, requested_bytes, dcd->file);
147                 if(*bytes == 0) {
148                         if(feof(dcd->file))
149                                 return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
150                         else
151                                 return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
152                 }
153                 else {
154                         return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
155                 }
156         }
157         else
158                 return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
159 }
160
161 static FLAC__StreamDecoderSeekStatus stream_decoder_seek_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
162 {
163         StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
164
165         (void)decoder;
166
167         if(0 == dcd) {
168                 printf("ERROR: client_data in seek callback is NULL\n");
169                 return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
170         }
171
172         if(dcd->error_occurred)
173                 return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
174
175         if(fseeko(dcd->file, (FLAC__off_t)absolute_byte_offset, SEEK_SET) < 0) {
176                 dcd->error_occurred = true;
177                 return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
178         }
179
180         return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
181 }
182
183 static FLAC__StreamDecoderTellStatus stream_decoder_tell_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
184 {
185         StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
186         FLAC__off_t offset;
187
188         (void)decoder;
189
190         if(0 == dcd) {
191                 printf("ERROR: client_data in tell callback is NULL\n");
192                 return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
193         }
194
195         if(dcd->error_occurred)
196                 return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
197
198         offset = ftello(dcd->file);
199         *absolute_byte_offset = (FLAC__uint64)offset;
200
201         if(offset < 0) {
202                 dcd->error_occurred = true;
203                 return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
204         }
205
206         return FLAC__STREAM_DECODER_TELL_STATUS_OK;
207 }
208
209 static FLAC__StreamDecoderLengthStatus stream_decoder_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
210 {
211         StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
212
213         (void)decoder;
214
215         if(0 == dcd) {
216                 printf("ERROR: client_data in length callback is NULL\n");
217                 return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
218         }
219
220         if(dcd->error_occurred)
221                 return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
222
223         *stream_length = (FLAC__uint64)flacfilesize_;
224         return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
225 }
226
227 static FLAC__bool stream_decoder_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
228 {
229         StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
230
231         (void)decoder;
232
233         if(0 == dcd) {
234                 printf("ERROR: client_data in eof callback is NULL\n");
235                 return true;
236         }
237
238         if(dcd->error_occurred)
239                 return true;
240
241         return feof(dcd->file);
242 }
243
244 static FLAC__StreamDecoderWriteStatus stream_decoder_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
245 {
246         StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
247
248         (void)decoder, (void)buffer;
249
250         if(0 == dcd) {
251                 printf("ERROR: client_data in write callback is NULL\n");
252                 return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
253         }
254
255         if(dcd->error_occurred)
256                 return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
257
258         if(
259                 (frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) ||
260                 (frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0)
261         ) {
262                 printf("content... ");
263                 fflush(stdout);
264         }
265
266         return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
267 }
268
269 static void stream_decoder_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
270 {
271         StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
272
273         (void)decoder;
274
275         if(0 == dcd) {
276                 printf("ERROR: client_data in metadata callback is NULL\n");
277                 return;
278         }
279
280         if(dcd->error_occurred)
281                 return;
282
283         printf("%d... ", dcd->current_metadata_number);
284         fflush(stdout);
285
286         if(dcd->current_metadata_number >= num_expected_) {
287                 (void)die_("got more metadata blocks than expected");
288                 dcd->error_occurred = true;
289         }
290         else {
291                 if(!mutils__compare_block(expected_metadata_sequence_[dcd->current_metadata_number], metadata)) {
292                         (void)die_("metadata block mismatch");
293                         dcd->error_occurred = true;
294                 }
295         }
296         dcd->current_metadata_number++;
297 }
298
299 static void stream_decoder_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
300 {
301         StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
302
303         (void)decoder;
304
305         if(0 == dcd) {
306                 printf("ERROR: client_data in error callback is NULL\n");
307                 return;
308         }
309
310         if(!dcd->ignore_errors) {
311                 printf("ERROR: got error callback: err = %u (%s)\n", (unsigned)status, FLAC__StreamDecoderErrorStatusString[status]);
312                 dcd->error_occurred = true;
313         }
314 }
315
316 static FLAC__bool stream_decoder_test_respond_(FLAC__StreamDecoder *decoder, StreamDecoderClientData *dcd, FLAC__bool is_ogg)
317 {
318         FLAC__StreamDecoderInitStatus init_status;
319
320         if(!FLAC__stream_decoder_set_md5_checking(decoder, true))
321                 return die_s_("at FLAC__stream_decoder_set_md5_checking(), returned false", decoder);
322
323         /* for FLAC__stream_encoder_init_FILE(), the FLAC__stream_encoder_finish() closes the file so we have to keep re-opening: */
324         if(dcd->layer == LAYER_FILE) {
325                 printf("opening %sFLAC file... ", is_ogg? "Ogg ":"");
326                 open_test_file(dcd, is_ogg, "rb");
327                 if(0 == dcd->file) {
328                         printf("ERROR (%s)\n", strerror(errno));
329                         return false;
330                 }
331                 printf("OK\n");
332         }
333
334         switch(dcd->layer) {
335                 case LAYER_STREAM:
336                         printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":"");
337                         init_status = is_ogg?
338                                 FLAC__stream_decoder_init_ogg_stream(decoder, stream_decoder_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd) :
339                                 FLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd)
340                         ;
341                         break;
342                 case LAYER_SEEKABLE_STREAM:
343                         printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":"");
344                         init_status = is_ogg?
345                                 FLAC__stream_decoder_init_ogg_stream(decoder, stream_decoder_read_callback_, stream_decoder_seek_callback_, stream_decoder_tell_callback_, stream_decoder_length_callback_, stream_decoder_eof_callback_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd) :
346                                 FLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, stream_decoder_seek_callback_, stream_decoder_tell_callback_, stream_decoder_length_callback_, stream_decoder_eof_callback_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd);
347                         break;
348                 case LAYER_FILE:
349                         printf("testing FLAC__stream_decoder_init_%sFILE()... ", is_ogg? "ogg_":"");
350                         init_status = is_ogg?
351                                 FLAC__stream_decoder_init_ogg_FILE(decoder, dcd->file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd) :
352                                 FLAC__stream_decoder_init_FILE(decoder, dcd->file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd);
353                         break;
354                 case LAYER_FILENAME:
355                         printf("testing FLAC__stream_decoder_init_%sfile()... ", is_ogg? "ogg_":"");
356                         init_status = is_ogg?
357                                 FLAC__stream_decoder_init_ogg_file(decoder, flacfilename(is_ogg), stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd) :
358                                 FLAC__stream_decoder_init_file(decoder, flacfilename(is_ogg), stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd);
359                         break;
360                 default:
361                         die_("internal error 000");
362                         return false;
363         }
364         if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK)
365                 return die_s_(0, decoder);
366         printf("OK\n");
367
368         dcd->current_metadata_number = 0;
369
370         if(dcd->layer < LAYER_FILE && fseeko(dcd->file, 0, SEEK_SET) < 0) {
371                 printf("FAILED rewinding input, errno = %d\n", errno);
372                 return false;
373         }
374
375         printf("testing FLAC__stream_decoder_process_until_end_of_stream()... ");
376         if(!FLAC__stream_decoder_process_until_end_of_stream(decoder))
377                 return die_s_("returned false", decoder);
378         printf("OK\n");
379
380         printf("testing FLAC__stream_decoder_finish()... ");
381         if(!FLAC__stream_decoder_finish(decoder))
382                 return die_s_("returned false", decoder);
383         printf("OK\n");
384
385         return true;
386 }
387
388 static FLAC__bool test_stream_decoder(Layer layer, FLAC__bool is_ogg)
389 {
390         FLAC__StreamDecoder *decoder;
391         FLAC__StreamDecoderInitStatus init_status;
392         FLAC__StreamDecoderState state;
393         StreamDecoderClientData decoder_client_data;
394         FLAC__bool expect;
395
396         decoder_client_data.layer = layer;
397
398         printf("\n+++ libFLAC unit test: FLAC__StreamDecoder (layer: %s, format: %s)\n\n", LayerString[layer], is_ogg? "Ogg FLAC" : "FLAC");
399
400         printf("testing FLAC__stream_decoder_new()... ");
401         decoder = FLAC__stream_decoder_new();
402         if(0 == decoder) {
403                 printf("FAILED, returned NULL\n");
404                 return false;
405         }
406         printf("OK\n");
407
408         printf("testing FLAC__stream_decoder_delete()... ");
409         FLAC__stream_decoder_delete(decoder);
410         printf("OK\n");
411
412         printf("testing FLAC__stream_decoder_new()... ");
413         decoder = FLAC__stream_decoder_new();
414         if(0 == decoder) {
415                 printf("FAILED, returned NULL\n");
416                 return false;
417         }
418         printf("OK\n");
419
420         switch(layer) {
421                 case LAYER_STREAM:
422                 case LAYER_SEEKABLE_STREAM:
423                         printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":"");
424                         init_status = is_ogg?
425                                 FLAC__stream_decoder_init_ogg_stream(decoder, 0, 0, 0, 0, 0, 0, 0, 0, 0) :
426                                 FLAC__stream_decoder_init_stream(decoder, 0, 0, 0, 0, 0, 0, 0, 0, 0);
427                         break;
428                 case LAYER_FILE:
429                         printf("testing FLAC__stream_decoder_init_%sFILE()... ", is_ogg? "ogg_":"");
430                         init_status = is_ogg?
431                                 FLAC__stream_decoder_init_ogg_FILE(decoder, stdin, 0, 0, 0, 0) :
432                                 FLAC__stream_decoder_init_FILE(decoder, stdin, 0, 0, 0, 0);
433                         break;
434                 case LAYER_FILENAME:
435                         printf("testing FLAC__stream_decoder_init_%sfile()... ", is_ogg? "ogg_":"");
436                         init_status = is_ogg?
437                                 FLAC__stream_decoder_init_ogg_file(decoder, flacfilename(is_ogg), 0, 0, 0, 0) :
438                                 FLAC__stream_decoder_init_file(decoder, flacfilename(is_ogg), 0, 0, 0, 0);
439                         break;
440                 default:
441                         die_("internal error 003");
442                         return false;
443         }
444         if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS)
445                 return die_s_(0, decoder);
446         printf("OK\n");
447
448         printf("testing FLAC__stream_decoder_delete()... ");
449         FLAC__stream_decoder_delete(decoder);
450         printf("OK\n");
451
452         num_expected_ = 0;
453         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
454
455         printf("testing FLAC__stream_decoder_new()... ");
456         decoder = FLAC__stream_decoder_new();
457         if(0 == decoder) {
458                 printf("FAILED, returned NULL\n");
459                 return false;
460         }
461         printf("OK\n");
462
463         if(is_ogg) {
464                 printf("testing FLAC__stream_decoder_set_ogg_serial_number()... ");
465                 if(!FLAC__stream_decoder_set_ogg_serial_number(decoder, file_utils__ogg_serial_number))
466                         return die_s_("returned false", decoder);
467                 printf("OK\n");
468         }
469
470         printf("testing FLAC__stream_decoder_set_md5_checking()... ");
471         if(!FLAC__stream_decoder_set_md5_checking(decoder, true))
472                 return die_s_("returned false", decoder);
473         printf("OK\n");
474
475         if(layer < LAYER_FILENAME) {
476                 printf("opening %sFLAC file... ", is_ogg? "Ogg ":"");
477                 open_test_file(&decoder_client_data, is_ogg, "rb");
478                 if(0 == decoder_client_data.file) {
479                         printf("ERROR (%s)\n", strerror(errno));
480                         return false;
481                 }
482                 printf("OK\n");
483         }
484
485         switch(layer) {
486                 case LAYER_STREAM:
487                         printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":"");
488                         init_status = is_ogg?
489                                 FLAC__stream_decoder_init_ogg_stream(decoder, stream_decoder_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) :
490                                 FLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data);
491                         break;
492                 case LAYER_SEEKABLE_STREAM:
493                         printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":"");
494                         init_status = is_ogg?
495                                 FLAC__stream_decoder_init_ogg_stream(decoder, stream_decoder_read_callback_, stream_decoder_seek_callback_, stream_decoder_tell_callback_, stream_decoder_length_callback_, stream_decoder_eof_callback_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) :
496                                 FLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, stream_decoder_seek_callback_, stream_decoder_tell_callback_, stream_decoder_length_callback_, stream_decoder_eof_callback_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data);
497                         break;
498                 case LAYER_FILE:
499                         printf("testing FLAC__stream_decoder_init_%sFILE()... ", is_ogg? "ogg_":"");
500                         init_status = is_ogg?
501                                 FLAC__stream_decoder_init_ogg_FILE(decoder, decoder_client_data.file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) :
502                                 FLAC__stream_decoder_init_FILE(decoder, decoder_client_data.file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data);
503                         break;
504                 case LAYER_FILENAME:
505                         printf("testing FLAC__stream_decoder_init_%sfile()... ", is_ogg? "ogg_":"");
506                         init_status = is_ogg?
507                                 FLAC__stream_decoder_init_ogg_file(decoder, flacfilename(is_ogg), stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) :
508                                 FLAC__stream_decoder_init_file(decoder, flacfilename(is_ogg), stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data);
509                         break;
510                 default:
511                         die_("internal error 009");
512                         return false;
513         }
514         if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK)
515                 return die_s_(0, decoder);
516         printf("OK\n");
517
518         printf("testing FLAC__stream_decoder_get_state()... ");
519         state = FLAC__stream_decoder_get_state(decoder);
520         printf("returned state = %u (%s)... OK\n", state, FLAC__StreamDecoderStateString[state]);
521
522         decoder_client_data.current_metadata_number = 0;
523         decoder_client_data.ignore_errors = false;
524         decoder_client_data.error_occurred = false;
525
526         printf("testing FLAC__stream_decoder_get_md5_checking()... ");
527         if(!FLAC__stream_decoder_get_md5_checking(decoder)) {
528                 printf("FAILED, returned false, expected true\n");
529                 return false;
530         }
531         printf("OK\n");
532
533         printf("testing FLAC__stream_decoder_process_until_end_of_metadata()... ");
534         if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder))
535                 return die_s_("returned false", decoder);
536         printf("OK\n");
537
538         printf("testing FLAC__stream_decoder_process_single()... ");
539         if(!FLAC__stream_decoder_process_single(decoder))
540                 return die_s_("returned false", decoder);
541         printf("OK\n");
542
543         printf("testing FLAC__stream_decoder_skip_single_frame()... ");
544         if(!FLAC__stream_decoder_skip_single_frame(decoder))
545                 return die_s_("returned false", decoder);
546         printf("OK\n");
547
548         if(layer < LAYER_FILE) {
549                 printf("testing FLAC__stream_decoder_flush()... ");
550                 if(!FLAC__stream_decoder_flush(decoder))
551                         return die_s_("returned false", decoder);
552                 printf("OK\n");
553
554                 decoder_client_data.ignore_errors = true;
555                 printf("testing FLAC__stream_decoder_process_single()... ");
556                 if(!FLAC__stream_decoder_process_single(decoder))
557                         return die_s_("returned false", decoder);
558                 printf("OK\n");
559                 decoder_client_data.ignore_errors = false;
560         }
561
562         expect = (layer != LAYER_STREAM);
563         printf("testing FLAC__stream_decoder_seek_absolute()... ");
564         if(FLAC__stream_decoder_seek_absolute(decoder, 0) != expect)
565                 return die_s_(expect? "returned false" : "returned true", decoder);
566         printf("OK\n");
567
568         printf("testing FLAC__stream_decoder_process_until_end_of_stream()... ");
569         if(!FLAC__stream_decoder_process_until_end_of_stream(decoder))
570                 return die_s_("returned false", decoder);
571         printf("OK\n");
572
573         expect = (layer != LAYER_STREAM);
574         printf("testing FLAC__stream_decoder_seek_absolute()... ");
575         if(FLAC__stream_decoder_seek_absolute(decoder, 0) != expect)
576                 return die_s_(expect? "returned false" : "returned true", decoder);
577         printf("OK\n");
578
579         printf("testing FLAC__stream_decoder_get_channels()... ");
580         {
581                 unsigned channels = FLAC__stream_decoder_get_channels(decoder);
582                 if(channels != streaminfo_.data.stream_info.channels) {
583                         printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
584                         return false;
585                 }
586         }
587         printf("OK\n");
588
589         printf("testing FLAC__stream_decoder_get_bits_per_sample()... ");
590         {
591                 unsigned bits_per_sample = FLAC__stream_decoder_get_bits_per_sample(decoder);
592                 if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
593                         printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
594                         return false;
595                 }
596         }
597         printf("OK\n");
598
599         printf("testing FLAC__stream_decoder_get_sample_rate()... ");
600         {
601                 unsigned sample_rate = FLAC__stream_decoder_get_sample_rate(decoder);
602                 if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
603                         printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
604                         return false;
605                 }
606         }
607         printf("OK\n");
608
609         printf("testing FLAC__stream_decoder_get_blocksize()... ");
610         {
611                 unsigned blocksize = FLAC__stream_decoder_get_blocksize(decoder);
612                 /* value could be anything since we're at the last block, so accept any reasonable answer */
613                 printf("returned %u... %s\n", blocksize, blocksize>0? "OK" : "FAILED");
614                 if(blocksize == 0)
615                         return false;
616         }
617
618         printf("testing FLAC__stream_decoder_get_channel_assignment()... ");
619         {
620                 FLAC__ChannelAssignment ca = FLAC__stream_decoder_get_channel_assignment(decoder);
621                 printf("returned %u (%s)... OK\n", (unsigned)ca, FLAC__ChannelAssignmentString[ca]);
622         }
623
624         if(layer < LAYER_FILE) {
625                 printf("testing FLAC__stream_decoder_reset()... ");
626                 if(!FLAC__stream_decoder_reset(decoder)) {
627                         state = FLAC__stream_decoder_get_state(decoder);
628                         printf("FAILED, returned false, state = %u (%s)\n", state, FLAC__StreamDecoderStateString[state]);
629                         return false;
630                 }
631                 printf("OK\n");
632
633                 if(layer == LAYER_STREAM) {
634                         /* after a reset() we have to rewind the input ourselves */
635                         printf("rewinding input... ");
636                         if(fseeko(decoder_client_data.file, 0, SEEK_SET) < 0) {
637                                 printf("FAILED, errno = %d\n", errno);
638                                 return false;
639                         }
640                         printf("OK\n");
641                 }
642
643                 decoder_client_data.current_metadata_number = 0;
644
645                 printf("testing FLAC__stream_decoder_process_until_end_of_stream()... ");
646                 if(!FLAC__stream_decoder_process_until_end_of_stream(decoder))
647                         return die_s_("returned false", decoder);
648                 printf("OK\n");
649         }
650
651         printf("testing FLAC__stream_decoder_finish()... ");
652         if(!FLAC__stream_decoder_finish(decoder))
653                 return die_s_("returned false", decoder);
654         printf("OK\n");
655
656         /*
657          * respond all
658          */
659
660         printf("testing FLAC__stream_decoder_set_metadata_respond_all()... ");
661         if(!FLAC__stream_decoder_set_metadata_respond_all(decoder))
662                 return die_s_("returned false", decoder);
663         printf("OK\n");
664
665         num_expected_ = 0;
666         if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
667                 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
668                 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
669                 expected_metadata_sequence_[num_expected_++] = &padding_;
670                 expected_metadata_sequence_[num_expected_++] = &seektable_;
671                 expected_metadata_sequence_[num_expected_++] = &application1_;
672                 expected_metadata_sequence_[num_expected_++] = &application2_;
673                 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
674                 expected_metadata_sequence_[num_expected_++] = &picture_;
675                 expected_metadata_sequence_[num_expected_++] = &unknown_;
676         }
677         else {
678                 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
679                 expected_metadata_sequence_[num_expected_++] = &padding_;
680                 expected_metadata_sequence_[num_expected_++] = &seektable_;
681                 expected_metadata_sequence_[num_expected_++] = &application1_;
682                 expected_metadata_sequence_[num_expected_++] = &application2_;
683                 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
684                 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
685                 expected_metadata_sequence_[num_expected_++] = &picture_;
686                 expected_metadata_sequence_[num_expected_++] = &unknown_;
687         }
688
689         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
690                 return false;
691
692         /*
693          * ignore all
694          */
695
696         printf("testing FLAC__stream_decoder_set_metadata_ignore_all()... ");
697         if(!FLAC__stream_decoder_set_metadata_ignore_all(decoder))
698                 return die_s_("returned false", decoder);
699         printf("OK\n");
700
701         num_expected_ = 0;
702
703         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
704                 return false;
705
706         /*
707          * respond all, ignore VORBIS_COMMENT
708          */
709
710         printf("testing FLAC__stream_decoder_set_metadata_respond_all()... ");
711         if(!FLAC__stream_decoder_set_metadata_respond_all(decoder))
712                 return die_s_("returned false", decoder);
713         printf("OK\n");
714
715         printf("testing FLAC__stream_decoder_set_metadata_ignore(VORBIS_COMMENT)... ");
716         if(!FLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT))
717                 return die_s_("returned false", decoder);
718         printf("OK\n");
719
720         num_expected_ = 0;
721         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
722         expected_metadata_sequence_[num_expected_++] = &padding_;
723         expected_metadata_sequence_[num_expected_++] = &seektable_;
724         expected_metadata_sequence_[num_expected_++] = &application1_;
725         expected_metadata_sequence_[num_expected_++] = &application2_;
726         expected_metadata_sequence_[num_expected_++] = &cuesheet_;
727         expected_metadata_sequence_[num_expected_++] = &picture_;
728         expected_metadata_sequence_[num_expected_++] = &unknown_;
729
730         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
731                 return false;
732
733         /*
734          * respond all, ignore APPLICATION
735          */
736
737         printf("testing FLAC__stream_decoder_set_metadata_respond_all()... ");
738         if(!FLAC__stream_decoder_set_metadata_respond_all(decoder))
739                 return die_s_("returned false", decoder);
740         printf("OK\n");
741
742         printf("testing FLAC__stream_decoder_set_metadata_ignore(APPLICATION)... ");
743         if(!FLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_APPLICATION))
744                 return die_s_("returned false", decoder);
745         printf("OK\n");
746
747         num_expected_ = 0;
748         if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
749                 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
750                 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
751                 expected_metadata_sequence_[num_expected_++] = &padding_;
752                 expected_metadata_sequence_[num_expected_++] = &seektable_;
753                 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
754                 expected_metadata_sequence_[num_expected_++] = &picture_;
755                 expected_metadata_sequence_[num_expected_++] = &unknown_;
756         }
757         else {
758                 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
759                 expected_metadata_sequence_[num_expected_++] = &padding_;
760                 expected_metadata_sequence_[num_expected_++] = &seektable_;
761                 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
762                 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
763                 expected_metadata_sequence_[num_expected_++] = &picture_;
764                 expected_metadata_sequence_[num_expected_++] = &unknown_;
765         }
766
767         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
768                 return false;
769
770         /*
771          * respond all, ignore APPLICATION id of app#1
772          */
773
774         printf("testing FLAC__stream_decoder_set_metadata_respond_all()... ");
775         if(!FLAC__stream_decoder_set_metadata_respond_all(decoder))
776                 return die_s_("returned false", decoder);
777         printf("OK\n");
778
779         printf("testing FLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... ");
780         if(!FLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
781                 return die_s_("returned false", decoder);
782         printf("OK\n");
783
784         num_expected_ = 0;
785         if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
786                 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
787                 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
788                 expected_metadata_sequence_[num_expected_++] = &padding_;
789                 expected_metadata_sequence_[num_expected_++] = &seektable_;
790                 expected_metadata_sequence_[num_expected_++] = &application2_;
791                 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
792                 expected_metadata_sequence_[num_expected_++] = &picture_;
793                 expected_metadata_sequence_[num_expected_++] = &unknown_;
794         }
795         else {
796                 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
797                 expected_metadata_sequence_[num_expected_++] = &padding_;
798                 expected_metadata_sequence_[num_expected_++] = &seektable_;
799                 expected_metadata_sequence_[num_expected_++] = &application2_;
800                 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
801                 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
802                 expected_metadata_sequence_[num_expected_++] = &picture_;
803                 expected_metadata_sequence_[num_expected_++] = &unknown_;
804         }
805
806         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
807                 return false;
808
809         /*
810          * respond all, ignore APPLICATION id of app#1 & app#2
811          */
812
813         printf("testing FLAC__stream_decoder_set_metadata_respond_all()... ");
814         if(!FLAC__stream_decoder_set_metadata_respond_all(decoder))
815                 return die_s_("returned false", decoder);
816         printf("OK\n");
817
818         printf("testing FLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... ");
819         if(!FLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
820                 return die_s_("returned false", decoder);
821         printf("OK\n");
822
823         printf("testing FLAC__stream_decoder_set_metadata_ignore_application(of app block #2)... ");
824         if(!FLAC__stream_decoder_set_metadata_ignore_application(decoder, application2_.data.application.id))
825                 return die_s_("returned false", decoder);
826         printf("OK\n");
827
828         num_expected_ = 0;
829         if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
830                 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
831                 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
832                 expected_metadata_sequence_[num_expected_++] = &padding_;
833                 expected_metadata_sequence_[num_expected_++] = &seektable_;
834                 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
835                 expected_metadata_sequence_[num_expected_++] = &picture_;
836                 expected_metadata_sequence_[num_expected_++] = &unknown_;
837         }
838         else {
839                 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
840                 expected_metadata_sequence_[num_expected_++] = &padding_;
841                 expected_metadata_sequence_[num_expected_++] = &seektable_;
842                 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
843                 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
844                 expected_metadata_sequence_[num_expected_++] = &picture_;
845                 expected_metadata_sequence_[num_expected_++] = &unknown_;
846         }
847
848         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
849                 return false;
850
851         /*
852          * ignore all, respond VORBIS_COMMENT
853          */
854
855         printf("testing FLAC__stream_decoder_set_metadata_ignore_all()... ");
856         if(!FLAC__stream_decoder_set_metadata_ignore_all(decoder))
857                 return die_s_("returned false", decoder);
858         printf("OK\n");
859
860         printf("testing FLAC__stream_decoder_set_metadata_respond(VORBIS_COMMENT)... ");
861         if(!FLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT))
862                 return die_s_("returned false", decoder);
863         printf("OK\n");
864
865         num_expected_ = 0;
866         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
867
868         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
869                 return false;
870
871         /*
872          * ignore all, respond APPLICATION
873          */
874
875         printf("testing FLAC__stream_decoder_set_metadata_ignore_all()... ");
876         if(!FLAC__stream_decoder_set_metadata_ignore_all(decoder))
877                 return die_s_("returned false", decoder);
878         printf("OK\n");
879
880         printf("testing FLAC__stream_decoder_set_metadata_respond(APPLICATION)... ");
881         if(!FLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_APPLICATION))
882                 return die_s_("returned false", decoder);
883         printf("OK\n");
884
885         num_expected_ = 0;
886         expected_metadata_sequence_[num_expected_++] = &application1_;
887         expected_metadata_sequence_[num_expected_++] = &application2_;
888
889         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
890                 return false;
891
892         /*
893          * ignore all, respond APPLICATION id of app#1
894          */
895
896         printf("testing FLAC__stream_decoder_set_metadata_ignore_all()... ");
897         if(!FLAC__stream_decoder_set_metadata_ignore_all(decoder))
898                 return die_s_("returned false", decoder);
899         printf("OK\n");
900
901         printf("testing FLAC__stream_decoder_set_metadata_respond_application(of app block #1)... ");
902         if(!FLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
903                 return die_s_("returned false", decoder);
904         printf("OK\n");
905
906         num_expected_ = 0;
907         expected_metadata_sequence_[num_expected_++] = &application1_;
908
909         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
910                 return false;
911
912         /*
913          * ignore all, respond APPLICATION id of app#1 & app#2
914          */
915
916         printf("testing FLAC__stream_decoder_set_metadata_ignore_all()... ");
917         if(!FLAC__stream_decoder_set_metadata_ignore_all(decoder))
918                 return die_s_("returned false", decoder);
919         printf("OK\n");
920
921         printf("testing FLAC__stream_decoder_set_metadata_respond_application(of app block #1)... ");
922         if(!FLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
923                 return die_s_("returned false", decoder);
924         printf("OK\n");
925
926         printf("testing FLAC__stream_decoder_set_metadata_respond_application(of app block #2)... ");
927         if(!FLAC__stream_decoder_set_metadata_respond_application(decoder, application2_.data.application.id))
928                 return die_s_("returned false", decoder);
929         printf("OK\n");
930
931         num_expected_ = 0;
932         expected_metadata_sequence_[num_expected_++] = &application1_;
933         expected_metadata_sequence_[num_expected_++] = &application2_;
934
935         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
936                 return false;
937
938         /*
939          * respond all, ignore APPLICATION, respond APPLICATION id of app#1
940          */
941
942         printf("testing FLAC__stream_decoder_set_metadata_respond_all()... ");
943         if(!FLAC__stream_decoder_set_metadata_respond_all(decoder))
944                 return die_s_("returned false", decoder);
945         printf("OK\n");
946
947         printf("testing FLAC__stream_decoder_set_metadata_ignore(APPLICATION)... ");
948         if(!FLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_APPLICATION))
949                 return die_s_("returned false", decoder);
950         printf("OK\n");
951
952         printf("testing FLAC__stream_decoder_set_metadata_respond_application(of app block #1)... ");
953         if(!FLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
954                 return die_s_("returned false", decoder);
955         printf("OK\n");
956
957         num_expected_ = 0;
958         if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
959                 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
960                 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
961                 expected_metadata_sequence_[num_expected_++] = &padding_;
962                 expected_metadata_sequence_[num_expected_++] = &seektable_;
963                 expected_metadata_sequence_[num_expected_++] = &application1_;
964                 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
965                 expected_metadata_sequence_[num_expected_++] = &picture_;
966                 expected_metadata_sequence_[num_expected_++] = &unknown_;
967         }
968         else {
969                 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
970                 expected_metadata_sequence_[num_expected_++] = &padding_;
971                 expected_metadata_sequence_[num_expected_++] = &seektable_;
972                 expected_metadata_sequence_[num_expected_++] = &application1_;
973                 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
974                 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
975                 expected_metadata_sequence_[num_expected_++] = &picture_;
976                 expected_metadata_sequence_[num_expected_++] = &unknown_;
977         }
978
979         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
980                 return false;
981
982         /*
983          * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
984          */
985
986         printf("testing FLAC__stream_decoder_set_metadata_ignore_all()... ");
987         if(!FLAC__stream_decoder_set_metadata_ignore_all(decoder))
988                 return die_s_("returned false", decoder);
989         printf("OK\n");
990
991         printf("testing FLAC__stream_decoder_set_metadata_respond(APPLICATION)... ");
992         if(!FLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_APPLICATION))
993                 return die_s_("returned false", decoder);
994         printf("OK\n");
995
996         printf("testing FLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... ");
997         if(!FLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
998                 return die_s_("returned false", decoder);
999         printf("OK\n");
1000
1001         num_expected_ = 0;
1002         expected_metadata_sequence_[num_expected_++] = &application2_;
1003
1004         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
1005                 return false;
1006
1007         if(layer < LAYER_FILE) /* for LAYER_FILE, FLAC__stream_decoder_finish() closes the file */
1008                 fclose(decoder_client_data.file);
1009
1010         printf("testing FLAC__stream_decoder_delete()... ");
1011         FLAC__stream_decoder_delete(decoder);
1012         printf("OK\n");
1013
1014         printf("\nPASSED!\n");
1015
1016         return true;
1017 }
1018
1019 FLAC__bool test_decoders(void)
1020 {
1021         FLAC__bool is_ogg = false;
1022
1023         while(1) {
1024                 init_metadata_blocks_();
1025
1026                 if(!generate_file_(is_ogg))
1027                         return false;
1028
1029                 if(!test_stream_decoder(LAYER_STREAM, is_ogg))
1030                         return false;
1031
1032                 if(!test_stream_decoder(LAYER_SEEKABLE_STREAM, is_ogg))
1033                         return false;
1034
1035                 if(!test_stream_decoder(LAYER_FILE, is_ogg))
1036                         return false;
1037
1038                 if(!test_stream_decoder(LAYER_FILENAME, is_ogg))
1039                         return false;
1040
1041                 (void) grabbag__file_remove_file(flacfilename(is_ogg));
1042
1043                 free_metadata_blocks_();
1044
1045                 if(!FLAC_API_SUPPORTS_OGG_FLAC || is_ogg)
1046                         break;
1047                 is_ogg = true;
1048         }
1049
1050         return true;
1051 }