move common stuff into metadata_utils
[flac.git] / src / test_libOggFLAC / decoders.c
1 /* test_libOggFLAC - Unit tester for libOggFLAC
2  * Copyright (C) 2002,2003  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
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  */
18
19 #include "decoders.h"
20 #include "file_utils.h"
21 #include "metadata_utils.h"
22 #include "FLAC/assert.h"
23 #include "OggFLAC/stream_decoder.h"
24 #include "share/grabbag.h"
25 #include <errno.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29
30 typedef struct {
31         FILE *file;
32         unsigned current_metadata_number;
33         FLAC__bool ignore_errors;
34         FLAC__bool error_occurred;
35 } stream_decoder_client_data_struct;
36
37 static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_;
38 static FLAC__StreamMetadata *expected_metadata_sequence_[7];
39 static unsigned num_expected_;
40 static const char *oggflacfilename_ = "metadata.ogg";
41 static unsigned oggflacfilesize_;
42
43 static FLAC__bool die_(const char *msg)
44 {
45         printf("ERROR: %s\n", msg);
46         return false;
47 }
48
49 static FLAC__bool die_s_(const char *msg, const OggFLAC__StreamDecoder *decoder)
50 {
51         OggFLAC__StreamDecoderState state = OggFLAC__stream_decoder_get_state(decoder);
52
53         if(msg)
54                 printf("FAILED, %s", msg);
55         else
56                 printf("FAILED");
57
58         printf(", state = %u (%s)\n", (unsigned)state, OggFLAC__StreamDecoderStateString[state]);
59         if(state == OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR) {
60                 FLAC__StreamDecoderState state_ = OggFLAC__stream_decoder_get_FLAC_stream_decoder_state(decoder);
61                 printf("      FLAC stream decoder state = %u (%s)\n", (unsigned)state_, FLAC__StreamDecoderStateString[state_]);
62         }
63
64         return false;
65 }
66
67 static void init_metadata_blocks_()
68 {
69         mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_);
70 }
71
72 static void free_metadata_blocks_()
73 {
74         mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_);
75 }
76
77 static FLAC__bool generate_file_()
78 {
79         printf("\n\ngenerating Ogg FLAC file for decoder tests...\n");
80
81         num_expected_ = 0;
82         expected_metadata_sequence_[num_expected_++] = &padding_;
83         expected_metadata_sequence_[num_expected_++] = &seektable_;
84         expected_metadata_sequence_[num_expected_++] = &application1_;
85         expected_metadata_sequence_[num_expected_++] = &application2_;
86         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
87         expected_metadata_sequence_[num_expected_++] = &cuesheet_;
88
89         if(!file_utils__generate_oggflacfile(oggflacfilename_, &oggflacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
90                 return die_("creating the encoded file");
91
92         return true;
93 }
94
95 static FLAC__StreamDecoderReadStatus stream_decoder_read_callback_(const OggFLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
96 {
97         stream_decoder_client_data_struct *dcd = (stream_decoder_client_data_struct*)client_data;
98
99         (void)decoder;
100
101         if(0 == dcd) {
102                 printf("ERROR: client_data in read callback is NULL\n");
103                 return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
104         }
105
106         if(dcd->error_occurred)
107                 return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
108
109         if(feof(dcd->file))
110                 return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
111         else if(*bytes > 0) {
112                 unsigned bytes_read = fread(buffer, 1, *bytes, dcd->file);
113                 if(bytes_read == 0) {
114                         if(feof(dcd->file))
115                                 return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
116                         else
117                                 return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
118                 }
119                 else {
120                         *bytes = bytes_read;
121                         return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
122                 }
123         }
124         else
125                 return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
126 }
127
128 static FLAC__StreamDecoderWriteStatus stream_decoder_write_callback_(const OggFLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
129 {
130         stream_decoder_client_data_struct *dcd = (stream_decoder_client_data_struct*)client_data;
131
132         (void)decoder, (void)buffer;
133
134         if(0 == dcd) {
135                 printf("ERROR: client_data in write callback is NULL\n");
136                 return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
137         }
138
139         if(dcd->error_occurred)
140                 return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
141
142         if(
143                 (frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) ||
144                 (frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0)
145         ) {
146                 printf("content... ");
147                 fflush(stdout);
148         }
149
150         return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
151 }
152
153 static void stream_decoder_metadata_callback_(const OggFLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
154 {
155         stream_decoder_client_data_struct *dcd = (stream_decoder_client_data_struct*)client_data;
156
157         (void)decoder;
158
159         if(0 == dcd) {
160                 printf("ERROR: client_data in metadata callback is NULL\n");
161                 return;
162         }
163
164         if(dcd->error_occurred)
165                 return;
166
167         printf("%d... ", dcd->current_metadata_number);
168         fflush(stdout);
169
170         if(dcd->current_metadata_number >= num_expected_) {
171                 (void)die_("got more metadata blocks than expected");
172                 dcd->error_occurred = true;
173         }
174         else {
175                 if(!mutils__compare_block(expected_metadata_sequence_[dcd->current_metadata_number], metadata)) {
176                         (void)die_("metadata block mismatch");
177                         dcd->error_occurred = true;
178                 }
179         }
180         dcd->current_metadata_number++;
181 }
182
183 static void stream_decoder_error_callback_(const OggFLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
184 {
185         stream_decoder_client_data_struct *dcd = (stream_decoder_client_data_struct*)client_data;
186
187         (void)decoder;
188
189         if(0 == dcd) {
190                 printf("ERROR: client_data in error callback is NULL\n");
191                 return;
192         }
193
194         if(!dcd->ignore_errors) {
195                 printf("ERROR: got error callback: err = %u (%s)\n", (unsigned)status, FLAC__StreamDecoderErrorStatusString[status]);
196                 dcd->error_occurred = true;
197         }
198 }
199
200 static FLAC__bool stream_decoder_test_respond_(OggFLAC__StreamDecoder *decoder, stream_decoder_client_data_struct *dcd)
201 {
202         if(!OggFLAC__stream_decoder_set_read_callback(decoder, stream_decoder_read_callback_))
203                 return die_s_("at OggFLAC__stream_decoder_set_read_callback(), returned false", decoder);
204
205         if(!OggFLAC__stream_decoder_set_write_callback(decoder, stream_decoder_write_callback_))
206                 return die_s_("at OggFLAC__stream_decoder_set_write_callback(), returned false", decoder);
207
208         if(!OggFLAC__stream_decoder_set_metadata_callback(decoder, stream_decoder_metadata_callback_))
209                 return die_s_("at OggFLAC__stream_decoder_set_metadata_callback(), returned false", decoder);
210
211         if(!OggFLAC__stream_decoder_set_error_callback(decoder, stream_decoder_error_callback_))
212                 return die_s_("at OggFLAC__stream_decoder_set_error_callback(), returned false", decoder);
213
214         if(!OggFLAC__stream_decoder_set_client_data(decoder, dcd))
215                 return die_s_("at OggFLAC__stream_decoder_set_client_data(), returned false", decoder);
216
217         printf("testing OggFLAC__stream_decoder_init()... ");
218         if(OggFLAC__stream_decoder_init(decoder) != OggFLAC__STREAM_DECODER_OK)
219                 return die_s_(0, decoder);
220         printf("OK\n");
221
222         dcd->current_metadata_number = 0;
223
224         if(fseek(dcd->file, 0, SEEK_SET) < 0) {
225                 printf("FAILED rewinding input, errno = %d\n", errno);
226                 return false;
227         }
228
229         printf("testing OggFLAC__stream_decoder_process_until_end_of_stream()... ");
230         if(!OggFLAC__stream_decoder_process_until_end_of_stream(decoder))
231                 return die_s_("returned false", decoder);
232         printf("OK\n");
233
234         printf("testing OggFLAC__stream_decoder_finish()... ");
235         OggFLAC__stream_decoder_finish(decoder);
236         printf("OK\n");
237
238         return true;
239 }
240
241 static FLAC__bool test_stream_decoder()
242 {
243         OggFLAC__StreamDecoder *decoder;
244         OggFLAC__StreamDecoderState state;
245         stream_decoder_client_data_struct decoder_client_data;
246
247         printf("\n+++ libOggFLAC unit test: OggFLAC__StreamDecoder\n\n");
248
249         printf("testing OggFLAC__stream_decoder_new()... ");
250         decoder = OggFLAC__stream_decoder_new();
251         if(0 == decoder) {
252                 printf("FAILED, returned NULL\n");
253                 return false;
254         }
255         printf("OK\n");
256
257         printf("testing OggFLAC__stream_decoder_delete()... ");
258         OggFLAC__stream_decoder_delete(decoder);
259         printf("OK\n");
260
261         printf("testing OggFLAC__stream_decoder_new()... ");
262         decoder = OggFLAC__stream_decoder_new();
263         if(0 == decoder) {
264                 printf("FAILED, returned NULL\n");
265                 return false;
266         }
267         printf("OK\n");
268
269         printf("testing OggFLAC__stream_decoder_init()... ");
270         if(OggFLAC__stream_decoder_init(decoder) == OggFLAC__STREAM_DECODER_OK)
271                 return die_s_(0, decoder);
272         printf("OK\n");
273
274         printf("testing OggFLAC__stream_decoder_delete()... ");
275         OggFLAC__stream_decoder_delete(decoder);
276         printf("OK\n");
277
278         num_expected_ = 0;
279         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
280
281         printf("testing OggFLAC__stream_decoder_new()... ");
282         decoder = OggFLAC__stream_decoder_new();
283         if(0 == decoder) {
284                 printf("FAILED, returned NULL\n");
285                 return false;
286         }
287         printf("OK\n");
288
289         printf("testing OggFLAC__stream_decoder_set_serial_number()... ");
290         if(!OggFLAC__stream_decoder_set_serial_number(decoder, file_utils__serial_number))
291                 return die_s_("returned false", decoder);
292         printf("OK\n");
293
294         printf("testing OggFLAC__stream_decoder_set_read_callback()... ");
295         if(!OggFLAC__stream_decoder_set_read_callback(decoder, stream_decoder_read_callback_))
296                 return die_s_("returned false", decoder);
297         printf("OK\n");
298
299         printf("testing OggFLAC__stream_decoder_set_write_callback()... ");
300         if(!OggFLAC__stream_decoder_set_write_callback(decoder, stream_decoder_write_callback_))
301                 return die_s_("returned false", decoder);
302         printf("OK\n");
303
304         printf("testing OggFLAC__stream_decoder_set_metadata_callback()... ");
305         if(!OggFLAC__stream_decoder_set_metadata_callback(decoder, stream_decoder_metadata_callback_))
306                 return die_s_("returned false", decoder);
307         printf("OK\n");
308
309         printf("testing OggFLAC__stream_decoder_set_error_callback()... ");
310         if(!OggFLAC__stream_decoder_set_error_callback(decoder, stream_decoder_error_callback_))
311                 return die_s_("returned false", decoder);
312         printf("OK\n");
313
314         printf("testing OggFLAC__stream_decoder_set_client_data()... ");
315         if(!OggFLAC__stream_decoder_set_client_data(decoder, &decoder_client_data))
316                 return die_s_("returned false", decoder);
317         printf("OK\n");
318
319         printf("testing OggFLAC__stream_decoder_init()... ");
320         if(OggFLAC__stream_decoder_init(decoder) != OggFLAC__STREAM_DECODER_OK)
321                 return die_s_(0, decoder);
322         printf("OK\n");
323
324         printf("testing OggFLAC__stream_decoder_get_state()... ");
325         state = OggFLAC__stream_decoder_get_state(decoder);
326         printf("returned state = %u (%s)... OK\n", state, OggFLAC__StreamDecoderStateString[state]);
327
328         decoder_client_data.current_metadata_number = 0;
329         decoder_client_data.ignore_errors = false;
330         decoder_client_data.error_occurred = false;
331
332         printf("opening Ogg FLAC file... ");
333         decoder_client_data.file = fopen(oggflacfilename_, "rb");
334         if(0 == decoder_client_data.file) {
335                 printf("ERROR\n");
336                 return false;
337         }
338         printf("OK\n");
339
340         printf("testing OggFLAC__stream_decoder_process_until_end_of_metadata()... ");
341         if(!OggFLAC__stream_decoder_process_until_end_of_metadata(decoder))
342                 return die_s_("returned false", decoder);
343         printf("OK\n");
344
345         printf("testing OggFLAC__stream_decoder_process_single()... ");
346         if(!OggFLAC__stream_decoder_process_single(decoder))
347                 return die_s_("returned false", decoder);
348         printf("OK\n");
349
350         printf("testing OggFLAC__stream_decoder_flush()... ");
351         if(!OggFLAC__stream_decoder_flush(decoder))
352                 return die_s_("returned false", decoder);
353         printf("OK\n");
354
355         decoder_client_data.ignore_errors = true;
356         printf("testing OggFLAC__stream_decoder_process_single()... ");
357         if(!OggFLAC__stream_decoder_process_single(decoder))
358                 return die_s_("returned false", decoder);
359         printf("OK\n");
360         decoder_client_data.ignore_errors = false;
361
362         printf("testing OggFLAC__stream_decoder_process_until_end_of_stream()... ");
363         if(!OggFLAC__stream_decoder_process_until_end_of_stream(decoder))
364                 return die_s_("returned false", decoder);
365         printf("OK\n");
366
367         printf("testing OggFLAC__stream_decoder_get_channels()... ");
368         {
369                 unsigned channels = OggFLAC__stream_decoder_get_channels(decoder);
370                 if(channels != streaminfo_.data.stream_info.channels) {
371                         printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
372                         return false;
373                 }
374         }
375         printf("OK\n");
376
377         printf("testing OggFLAC__stream_decoder_get_bits_per_sample()... ");
378         {
379                 unsigned bits_per_sample = OggFLAC__stream_decoder_get_bits_per_sample(decoder);
380                 if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
381                         printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
382                         return false;
383                 }
384         }
385         printf("OK\n");
386
387         printf("testing OggFLAC__stream_decoder_get_sample_rate()... ");
388         {
389                 unsigned sample_rate = OggFLAC__stream_decoder_get_sample_rate(decoder);
390                 if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
391                         printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
392                         return false;
393                 }
394         }
395         printf("OK\n");
396
397         printf("testing OggFLAC__stream_decoder_get_blocksize()... ");
398         {
399                 unsigned blocksize = OggFLAC__stream_decoder_get_blocksize(decoder);
400                 /* value could be anything since we're at the last block, so accept any answer */
401                 printf("returned %u... OK\n", blocksize);
402         }
403
404         printf("testing OggFLAC__stream_decoder_get_channel_assignment()... ");
405         {
406                 FLAC__ChannelAssignment ca = OggFLAC__stream_decoder_get_channel_assignment(decoder);
407                 printf("returned %u (%s)... OK\n", (unsigned)ca, FLAC__ChannelAssignmentString[ca]);
408         }
409
410         printf("testing OggFLAC__stream_decoder_reset()... ");
411         if(!OggFLAC__stream_decoder_reset(decoder)) {
412                 state = OggFLAC__stream_decoder_get_state(decoder);
413                 printf("FAILED, returned false, state = %u (%s)\n", state, FLAC__StreamDecoderStateString[state]);
414                 return false;
415         }
416         printf("OK\n");
417
418         decoder_client_data.current_metadata_number = 0;
419
420         printf("rewinding input... ");
421         if(fseek(decoder_client_data.file, 0, SEEK_SET) < 0) {
422                 printf("FAILED, errno = %d\n", errno);
423                 return false;
424         }
425         printf("OK\n");
426
427         printf("testing OggFLAC__stream_decoder_process_until_end_of_stream()... ");
428         if(!OggFLAC__stream_decoder_process_until_end_of_stream(decoder))
429                 return die_s_("returned false", decoder);
430         printf("OK\n");
431
432         printf("testing OggFLAC__stream_decoder_finish()... ");
433         OggFLAC__stream_decoder_finish(decoder);
434         printf("OK\n");
435
436         /*
437          * respond all
438          */
439
440         printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
441         if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
442                 return die_s_("returned false", decoder);
443         printf("OK\n");
444
445         num_expected_ = 0;
446         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
447         expected_metadata_sequence_[num_expected_++] = &padding_;
448         expected_metadata_sequence_[num_expected_++] = &seektable_;
449         expected_metadata_sequence_[num_expected_++] = &application1_;
450         expected_metadata_sequence_[num_expected_++] = &application2_;
451         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
452         expected_metadata_sequence_[num_expected_++] = &cuesheet_;
453
454         if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
455                 return false;
456
457         /*
458          * ignore all
459          */
460
461         printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
462         if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
463                 return die_s_("returned false", decoder);
464         printf("OK\n");
465
466         num_expected_ = 0;
467
468         if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
469                 return false;
470
471         /*
472          * respond all, ignore VORBIS_COMMENT
473          */
474
475         printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
476         if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
477                 return die_s_("returned false", decoder);
478         printf("OK\n");
479
480         printf("testing OggFLAC__stream_decoder_set_metadata_ignore(VORBIS_COMMENT)... ");
481         if(!OggFLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT))
482                 return die_s_("returned false", decoder);
483         printf("OK\n");
484
485         num_expected_ = 0;
486         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
487         expected_metadata_sequence_[num_expected_++] = &padding_;
488         expected_metadata_sequence_[num_expected_++] = &seektable_;
489         expected_metadata_sequence_[num_expected_++] = &application1_;
490         expected_metadata_sequence_[num_expected_++] = &application2_;
491         expected_metadata_sequence_[num_expected_++] = &cuesheet_;
492
493         if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
494                 return false;
495
496         /*
497          * respond all, ignore APPLICATION
498          */
499
500         printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
501         if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
502                 return die_s_("returned false", decoder);
503         printf("OK\n");
504
505         printf("testing OggFLAC__stream_decoder_set_metadata_ignore(APPLICATION)... ");
506         if(!OggFLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_APPLICATION))
507                 return die_s_("returned false", decoder);
508         printf("OK\n");
509
510         num_expected_ = 0;
511         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
512         expected_metadata_sequence_[num_expected_++] = &padding_;
513         expected_metadata_sequence_[num_expected_++] = &seektable_;
514         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
515         expected_metadata_sequence_[num_expected_++] = &cuesheet_;
516
517         if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
518                 return false;
519
520         /*
521          * respond all, ignore APPLICATION id of app#1
522          */
523
524         printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
525         if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
526                 return die_s_("returned false", decoder);
527         printf("OK\n");
528
529         printf("testing OggFLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... ");
530         if(!OggFLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
531                 return die_s_("returned false", decoder);
532         printf("OK\n");
533
534         num_expected_ = 0;
535         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
536         expected_metadata_sequence_[num_expected_++] = &padding_;
537         expected_metadata_sequence_[num_expected_++] = &seektable_;
538         expected_metadata_sequence_[num_expected_++] = &application2_;
539         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
540         expected_metadata_sequence_[num_expected_++] = &cuesheet_;
541
542         if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
543                 return false;
544
545         /*
546          * respond all, ignore APPLICATION id of app#1 & app#2
547          */
548
549         printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
550         if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
551                 return die_s_("returned false", decoder);
552         printf("OK\n");
553
554         printf("testing OggFLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... ");
555         if(!OggFLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
556                 return die_s_("returned false", decoder);
557         printf("OK\n");
558
559         printf("testing OggFLAC__stream_decoder_set_metadata_ignore_application(of app block #2)... ");
560         if(!OggFLAC__stream_decoder_set_metadata_ignore_application(decoder, application2_.data.application.id))
561                 return die_s_("returned false", decoder);
562         printf("OK\n");
563
564         num_expected_ = 0;
565         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
566         expected_metadata_sequence_[num_expected_++] = &padding_;
567         expected_metadata_sequence_[num_expected_++] = &seektable_;
568         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
569         expected_metadata_sequence_[num_expected_++] = &cuesheet_;
570
571         if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
572                 return false;
573
574         /*
575          * ignore all, respond VORBIS_COMMENT
576          */
577
578         printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
579         if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
580                 return die_s_("returned false", decoder);
581         printf("OK\n");
582
583         printf("testing OggFLAC__stream_decoder_set_metadata_respond(VORBIS_COMMENT)... ");
584         if(!OggFLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT))
585                 return die_s_("returned false", decoder);
586         printf("OK\n");
587
588         num_expected_ = 0;
589         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
590
591         if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
592                 return false;
593
594         /*
595          * ignore all, respond APPLICATION
596          */
597
598         printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
599         if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
600                 return die_s_("returned false", decoder);
601         printf("OK\n");
602
603         printf("testing OggFLAC__stream_decoder_set_metadata_respond(APPLICATION)... ");
604         if(!OggFLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_APPLICATION))
605                 return die_s_("returned false", decoder);
606         printf("OK\n");
607
608         num_expected_ = 0;
609         expected_metadata_sequence_[num_expected_++] = &application1_;
610         expected_metadata_sequence_[num_expected_++] = &application2_;
611
612         if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
613                 return false;
614
615         /*
616          * ignore all, respond APPLICATION id of app#1
617          */
618
619         printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
620         if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
621                 return die_s_("returned false", decoder);
622         printf("OK\n");
623
624         printf("testing OggFLAC__stream_decoder_set_metadata_respond_application(of app block #1)... ");
625         if(!OggFLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
626                 return die_s_("returned false", decoder);
627         printf("OK\n");
628
629         num_expected_ = 0;
630         expected_metadata_sequence_[num_expected_++] = &application1_;
631
632         if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
633                 return false;
634
635         /*
636          * ignore all, respond APPLICATION id of app#1 & app#2
637          */
638
639         printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
640         if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
641                 return die_s_("returned false", decoder);
642         printf("OK\n");
643
644         printf("testing OggFLAC__stream_decoder_set_metadata_respond_application(of app block #1)... ");
645         if(!OggFLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
646                 return die_s_("returned false", decoder);
647         printf("OK\n");
648
649         printf("testing OggFLAC__stream_decoder_set_metadata_respond_application(of app block #2)... ");
650         if(!OggFLAC__stream_decoder_set_metadata_respond_application(decoder, application2_.data.application.id))
651                 return die_s_("returned false", decoder);
652         printf("OK\n");
653
654         num_expected_ = 0;
655         expected_metadata_sequence_[num_expected_++] = &application1_;
656         expected_metadata_sequence_[num_expected_++] = &application2_;
657
658         if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
659                 return false;
660
661         /*
662          * respond all, ignore APPLICATION, respond APPLICATION id of app#1
663          */
664
665         printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
666         if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
667                 return die_s_("returned false", decoder);
668         printf("OK\n");
669
670         printf("testing OggFLAC__stream_decoder_set_metadata_ignore(APPLICATION)... ");
671         if(!OggFLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_APPLICATION))
672                 return die_s_("returned false", decoder);
673         printf("OK\n");
674
675         printf("testing OggFLAC__stream_decoder_set_metadata_respond_application(of app block #1)... ");
676         if(!OggFLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
677                 return die_s_("returned false", decoder);
678         printf("OK\n");
679
680         num_expected_ = 0;
681         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
682         expected_metadata_sequence_[num_expected_++] = &padding_;
683         expected_metadata_sequence_[num_expected_++] = &seektable_;
684         expected_metadata_sequence_[num_expected_++] = &application1_;
685         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
686         expected_metadata_sequence_[num_expected_++] = &cuesheet_;
687
688         if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
689                 return false;
690
691         /*
692          * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
693          */
694
695         printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
696         if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
697                 return die_s_("returned false", decoder);
698         printf("OK\n");
699
700         printf("testing OggFLAC__stream_decoder_set_metadata_respond(APPLICATION)... ");
701         if(!OggFLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_APPLICATION))
702                 return die_s_("returned false", decoder);
703         printf("OK\n");
704
705         printf("testing OggFLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... ");
706         if(!OggFLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
707                 return die_s_("returned false", decoder);
708         printf("OK\n");
709
710         num_expected_ = 0;
711         expected_metadata_sequence_[num_expected_++] = &application2_;
712
713         if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
714                 return false;
715
716         /* done, now leave the sequence the way we found it... */
717         num_expected_ = 0;
718         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
719         expected_metadata_sequence_[num_expected_++] = &padding_;
720         expected_metadata_sequence_[num_expected_++] = &seektable_;
721         expected_metadata_sequence_[num_expected_++] = &application1_;
722         expected_metadata_sequence_[num_expected_++] = &application2_;
723         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
724         expected_metadata_sequence_[num_expected_++] = &cuesheet_;
725
726         printf("testing OggFLAC__stream_decoder_delete()... ");
727         OggFLAC__stream_decoder_delete(decoder);
728         printf("OK\n");
729
730         fclose(decoder_client_data.file);
731
732         printf("\nPASSED!\n");
733
734         return true;
735 }
736
737 FLAC__bool test_decoders()
738 {
739         init_metadata_blocks_();
740         if(!generate_file_())
741                 return false;
742
743         if(!test_stream_decoder())
744                 return false;
745
746         (void) grabbag__file_remove_file(oggflacfilename_);
747         free_metadata_blocks_();
748
749         return true;
750 }