6c39a8d627a57902fee37fdd0c774369aa1fc292
[platform/upstream/flac.git] / src / test_libFLAC++ / decoders.cc
1 /* test_libFLAC++ - Unit tester for libFLAC++
2  * Copyright (C) 2002  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 extern "C" {
21 #include "file_utils.h"
22 }
23 #include "FLAC/assert.h"
24 #include "FLAC/metadata.h" // for ::FLAC__metadata_object_is_equal()
25 #include "FLAC++/decoder.h"
26 #include <errno.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30
31 static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_;
32 static ::FLAC__StreamMetadata *expected_metadata_sequence_[6];
33 static unsigned num_expected_;
34 static const char *flacfilename_ = "metadata.flac";
35 static unsigned flacfilesize_;
36
37 static bool die_(const char *msg)
38 {
39         printf("ERROR: %s\n", msg);
40         return false;
41 }
42
43 static void *malloc_or_die_(size_t size)
44 {
45         void *x = malloc(size);
46         if(0 == x) {
47                 fprintf(stderr, "ERROR: out of memory allocating %u bytes\n", (unsigned)size);
48                 exit(1);
49         }
50         return x;
51 }
52
53 static void init_metadata_blocks_()
54 {
55         /*
56                 most of the actual numbers and data in the blocks don't matter,
57                 we just want to make sure the decoder parses them correctly
58
59                 remember, the metadata interface gets tested after the decoders,
60                 so we do all the metadata manipulation here without it.
61         */
62
63         /* min/max_framesize and md5sum don't get written at first, so we have to leave them 0 */
64     streaminfo_.is_last = false;
65     streaminfo_.type = ::FLAC__METADATA_TYPE_STREAMINFO;
66     streaminfo_.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
67     streaminfo_.data.stream_info.min_blocksize = 576;
68     streaminfo_.data.stream_info.max_blocksize = 576;
69     streaminfo_.data.stream_info.min_framesize = 0;
70     streaminfo_.data.stream_info.max_framesize = 0;
71     streaminfo_.data.stream_info.sample_rate = 44100;
72     streaminfo_.data.stream_info.channels = 1;
73     streaminfo_.data.stream_info.bits_per_sample = 8;
74     streaminfo_.data.stream_info.total_samples = 0;
75         memset(streaminfo_.data.stream_info.md5sum, 0, 16);
76
77     padding_.is_last = false;
78     padding_.type = ::FLAC__METADATA_TYPE_PADDING;
79     padding_.length = 1234;
80
81     seektable_.is_last = false;
82     seektable_.type = ::FLAC__METADATA_TYPE_SEEKTABLE;
83         seektable_.data.seek_table.num_points = 2;
84     seektable_.length = seektable_.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
85         seektable_.data.seek_table.points = (::FLAC__StreamMetadata_SeekPoint*)malloc_or_die_(seektable_.data.seek_table.num_points * sizeof(::FLAC__StreamMetadata_SeekPoint));
86         seektable_.data.seek_table.points[0].sample_number = 0;
87         seektable_.data.seek_table.points[0].stream_offset = 0;
88         seektable_.data.seek_table.points[0].frame_samples = streaminfo_.data.stream_info.min_blocksize;
89         seektable_.data.seek_table.points[1].sample_number = ::FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
90         seektable_.data.seek_table.points[1].stream_offset = 1000;
91         seektable_.data.seek_table.points[1].frame_samples = streaminfo_.data.stream_info.min_blocksize;
92
93     application1_.is_last = false;
94     application1_.type = ::FLAC__METADATA_TYPE_APPLICATION;
95     application1_.length = 8;
96         memcpy(application1_.data.application.id, "\xfe\xdc\xba\x98", 4);
97         application1_.data.application.data = (FLAC__byte*)malloc_or_die_(4);
98         memcpy(application1_.data.application.data, "\xf0\xe1\xd2\xc3", 4);
99
100     application2_.is_last = false;
101     application2_.type = ::FLAC__METADATA_TYPE_APPLICATION;
102     application2_.length = 4;
103         memcpy(application2_.data.application.id, "\x76\x54\x32\x10", 4);
104         application2_.data.application.data = 0;
105
106     vorbiscomment_.is_last = true;
107     vorbiscomment_.type = ::FLAC__METADATA_TYPE_VORBIS_COMMENT;
108     vorbiscomment_.length = (4 + 8) + 4 + (4 + 5) + (4 + 0);
109         vorbiscomment_.data.vorbis_comment.vendor_string.length = 8;
110         vorbiscomment_.data.vorbis_comment.vendor_string.entry = (FLAC__byte*)malloc_or_die_(8);
111         memcpy(vorbiscomment_.data.vorbis_comment.vendor_string.entry, "flac 1.x", 8);
112         vorbiscomment_.data.vorbis_comment.num_comments = 2;
113         vorbiscomment_.data.vorbis_comment.comments = (::FLAC__StreamMetadata_VorbisComment_Entry*)malloc_or_die_(vorbiscomment_.data.vorbis_comment.num_comments * sizeof(::FLAC__StreamMetadata_VorbisComment_Entry));
114         vorbiscomment_.data.vorbis_comment.comments[0].length = 5;
115         vorbiscomment_.data.vorbis_comment.comments[0].entry = (FLAC__byte*)malloc_or_die_(5);
116         memcpy(vorbiscomment_.data.vorbis_comment.comments[0].entry, "ab=cd", 5);
117         vorbiscomment_.data.vorbis_comment.comments[1].length = 0;
118         vorbiscomment_.data.vorbis_comment.comments[1].entry = 0;
119 }
120
121 static void free_metadata_blocks_()
122 {
123         free(seektable_.data.seek_table.points);
124         free(application1_.data.application.data);
125         free(vorbiscomment_.data.vorbis_comment.vendor_string.entry);
126         free(vorbiscomment_.data.vorbis_comment.comments[0].entry);
127         free(vorbiscomment_.data.vorbis_comment.comments);
128 }
129
130 static bool generate_file_()
131 {
132         printf("\n\ngenerating FLAC file for decoder tests...\n");
133
134         expected_metadata_sequence_[0] = &padding_;
135         expected_metadata_sequence_[1] = &seektable_;
136         expected_metadata_sequence_[2] = &application1_;
137         expected_metadata_sequence_[3] = &application2_;
138         expected_metadata_sequence_[4] = &vorbiscomment_;
139         num_expected_ = 5;
140
141         if(!file_utils__generate_flacfile(flacfilename_, &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
142                 return die_("creating the encoded file"); 
143
144         return true;
145 }
146
147
148 class DecoderCommon {
149 public:
150         FILE *file_;
151         unsigned current_metadata_number_;
152         bool ignore_errors_;
153         bool error_occurred_;
154
155         DecoderCommon(): file_(0), current_metadata_number_(0), ignore_errors_(false), error_occurred_(false) { }
156         ::FLAC__StreamDecoderReadStatus common_read_callback_(FLAC__byte buffer[], unsigned *bytes);
157         ::FLAC__StreamDecoderWriteStatus common_write_callback_(const ::FLAC__Frame *frame);
158         void common_metadata_callback_(const ::FLAC__StreamMetadata *metadata);
159         void common_error_callback_(::FLAC__StreamDecoderErrorStatus status);
160 };
161
162 ::FLAC__StreamDecoderReadStatus DecoderCommon::common_read_callback_(FLAC__byte buffer[], unsigned *bytes)
163 {
164         if(error_occurred_)
165                 return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT;
166
167         if(feof(file_))
168                 return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
169     else if(*bytes > 0) {
170         unsigned bytes_read = ::fread(buffer, 1, *bytes, file_);
171         if(bytes_read == 0) {
172             if(feof(file_))
173                 return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
174             else
175                 return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
176         }
177         else {
178             *bytes = bytes_read;
179             return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
180         }
181     }
182     else
183         return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
184 }
185
186 ::FLAC__StreamDecoderWriteStatus DecoderCommon::common_write_callback_(const ::FLAC__Frame *frame)
187 {
188         if(error_occurred_)
189                 return ::FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
190
191     if(
192         (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) ||
193         (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0)
194     ) {
195         printf("content... ");
196         fflush(stdout);
197     }
198
199         return ::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
200 }
201
202 void DecoderCommon::common_metadata_callback_(const ::FLAC__StreamMetadata *metadata)
203 {
204         if(error_occurred_)
205                 return;
206
207         printf("%d... ", current_metadata_number_);
208         fflush(stdout);
209
210         if(current_metadata_number_ >= num_expected_) {
211                 (void)die_("got more metadata blocks than expected");
212                 error_occurred_ = true;
213         }
214         else {
215                 if(!::FLAC__metadata_object_is_equal(expected_metadata_sequence_[current_metadata_number_], metadata)) {
216                         (void)die_("metadata block mismatch");
217                         error_occurred_ = true;
218                 }
219         }
220         current_metadata_number_++;
221 }
222
223 void DecoderCommon::common_error_callback_(::FLAC__StreamDecoderErrorStatus status)
224 {
225         if(!ignore_errors_) {
226                 printf("ERROR: got error callback: err = %u (%s)\n", (unsigned)status, ::FLAC__StreamDecoderErrorStatusString[status]);
227                 error_occurred_ = true;
228         }
229 }
230
231 class StreamDecoder : public FLAC::Decoder::Stream, public DecoderCommon {
232 public:
233         StreamDecoder(): FLAC::Decoder::Stream(), DecoderCommon() { }
234         ~StreamDecoder() { }
235
236         // from FLAC::Decoder::Stream
237         ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
238         ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
239         void metadata_callback(const ::FLAC__StreamMetadata *metadata);
240         void error_callback(::FLAC__StreamDecoderErrorStatus status);
241
242         bool die(const char *msg = 0) const;
243
244         bool test_respond();
245 };
246
247 ::FLAC__StreamDecoderReadStatus StreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
248 {
249         return common_read_callback_(buffer, bytes);
250 }
251
252 ::FLAC__StreamDecoderWriteStatus StreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
253 {
254         (void)buffer;
255
256         return common_write_callback_(frame);
257 }
258
259 void StreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
260 {
261         return common_metadata_callback_(metadata);
262 }
263
264 void StreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
265 {
266         return common_error_callback_(status);
267 }
268
269 bool StreamDecoder::die(const char *msg) const
270 {
271         State state = get_state();
272
273         if(msg)
274                 printf("FAILED, %s, state = %u (%s)\n", msg, (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
275         else
276                 printf("FAILED, state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
277
278         return false;
279 }
280
281 bool StreamDecoder::test_respond()
282 {
283         printf("testing init()... ");
284         if(init() != ::FLAC__STREAM_DECODER_SEARCH_FOR_METADATA)
285                 return die();
286         printf("OK\n");
287
288         current_metadata_number_ = 0;
289
290         if(::fseek(file_, 0, SEEK_SET) < 0) {
291                 printf("FAILED rewinding input, errno = %d\n", errno);
292                 return false;
293         }
294
295         printf("testing process_whole_stream()... ");
296         if(!process_whole_stream()) {
297                 State state = get_state();
298                 printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
299                 return false;
300         }
301         printf("OK\n");
302
303         printf("testing finish()... ");
304         finish();
305         printf("OK\n");
306
307         return true;
308 }
309
310 static bool test_stream_decoder()
311 {
312         StreamDecoder *decoder;
313
314         printf("\n+++ libFLAC++ unit test: FLAC::Decoder::Stream\n\n");
315
316         num_expected_ = 0;
317         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
318
319         printf("allocating decoder instance... ");
320         decoder = new StreamDecoder();
321         if(0 == decoder) {
322                 printf("FAILED, new returned NULL\n");
323                 return false;
324         }
325         printf("OK\n");
326
327         printf("testing is_valid()... ");
328         if(!decoder->is_valid()) {
329                 printf("FAILED, returned false\n");
330                 return false;
331         }
332         printf("OK\n");
333
334         printf("testing init()... ");
335         if(decoder->init() != ::FLAC__STREAM_DECODER_SEARCH_FOR_METADATA)
336                 return decoder->die();
337         printf("OK\n");
338
339         printf("testing get_state()... ");
340         FLAC::Decoder::Stream::State state = decoder->get_state();
341         printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
342
343         decoder->current_metadata_number_ = 0;
344         decoder->ignore_errors_ = false;
345         decoder->error_occurred_ = false;
346
347         printf("opening FLAC file... ");
348         decoder->file_ = ::fopen(flacfilename_, "rb");
349         if(0 == decoder->file_) {
350                 printf("ERROR\n");
351                 return false;
352         }
353         printf("OK\n");
354
355         printf("testing process_metadata()... ");
356         if(!decoder->process_metadata())
357                 return decoder->die("returned false");
358         printf("OK\n");
359
360         printf("testing process_one_frame()... ");
361         if(!decoder->process_one_frame())
362                 return decoder->die("returned false");
363         printf("OK\n");
364
365         printf("testing flush()... ");
366         if(!decoder->flush())
367                 return decoder->die("returned false");
368         printf("OK\n");
369
370         decoder->ignore_errors_ = true;
371         printf("testing process_one_frame()... ");
372         if(!decoder->process_one_frame())
373                 return decoder->die("returned false");
374         printf("OK\n");
375         decoder->ignore_errors_ = false;
376
377         printf("testing process_remaining_frames()... ");
378         if(!decoder->process_remaining_frames())
379                 return decoder->die("returned false");
380         printf("OK\n");
381
382         printf("testing get_channels()... ");
383         {
384                 unsigned channels = decoder->get_channels();
385                 if(channels != streaminfo_.data.stream_info.channels) {
386                         printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
387                         return false;
388                 }
389         }
390         printf("OK\n");
391
392         printf("testing get_bits_per_sample()... ");
393         {
394                 unsigned bits_per_sample = decoder->get_bits_per_sample();
395                 if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
396                         printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
397                         return false;
398                 }
399         }
400         printf("OK\n");
401
402         printf("testing get_sample_rate()... ");
403         {
404                 unsigned sample_rate = decoder->get_sample_rate();
405                 if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
406                         printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
407                         return false;
408                 }
409         }
410         printf("OK\n");
411
412         printf("testing get_blocksize()... ");
413         {
414                 unsigned blocksize = decoder->get_blocksize();
415                 /* value could be anything since we're at the last block, so accept any answer */
416                 printf("returned %u... OK\n", blocksize);
417         }
418
419         printf("testing get_channel_assignment()... ");
420         {
421                 ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
422                 printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
423         }
424
425         printf("testing reset()... ");
426         if(!decoder->reset())
427                 return decoder->die("returned false");
428         printf("OK\n");
429
430         decoder->current_metadata_number_ = 0;
431
432         printf("rewinding input... ");
433         if(::fseek(decoder->file_, 0, SEEK_SET) < 0) {
434                 printf("FAILED, errno = %d\n", errno);
435                 return false;
436         }
437         printf("OK\n");
438
439         printf("testing process_whole_stream()... ");
440         if(!decoder->process_whole_stream())
441                 return decoder->die("returned false");
442         printf("OK\n");
443
444         printf("testing finish()... ");
445         decoder->finish();
446         printf("OK\n");
447
448         /*
449          * respond all
450          */
451
452         printf("testing set_metadata_respond_all()... ");
453         if(!decoder->set_metadata_respond_all()) {
454                 printf("FAILED, returned false\n");
455                 return false;
456         }
457         printf("OK\n");
458
459         num_expected_ = 0;
460         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
461         expected_metadata_sequence_[num_expected_++] = &padding_;
462         expected_metadata_sequence_[num_expected_++] = &seektable_;
463         expected_metadata_sequence_[num_expected_++] = &application1_;
464         expected_metadata_sequence_[num_expected_++] = &application2_;
465         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
466
467         if(!decoder->test_respond())
468                 return false;
469
470         /*
471          * ignore all
472          */
473
474         printf("testing set_metadata_ignore_all()... ");
475         if(!decoder->set_metadata_ignore_all()) {
476                 printf("FAILED, returned false\n");
477                 return false;
478         }
479         printf("OK\n");
480
481         num_expected_ = 0;
482
483         if(!decoder->test_respond())
484                 return false;
485
486         /*
487          * respond all, ignore VORBIS_COMMENT
488          */
489
490         printf("testing set_metadata_respond_all()... ");
491         if(!decoder->set_metadata_respond_all()) {
492                 printf("FAILED, returned false\n");
493                 return false;
494         }
495         printf("OK\n");
496
497         printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
498         if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
499                 printf("FAILED, returned false\n");
500                 return false;
501         }
502         printf("OK\n");
503
504         num_expected_ = 0;
505         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
506         expected_metadata_sequence_[num_expected_++] = &padding_;
507         expected_metadata_sequence_[num_expected_++] = &seektable_;
508         expected_metadata_sequence_[num_expected_++] = &application1_;
509         expected_metadata_sequence_[num_expected_++] = &application2_;
510
511         if(!decoder->test_respond())
512                 return false;
513
514         /*
515          * respond all, ignore APPLICATION
516          */
517
518         printf("testing set_metadata_respond_all()... ");
519         if(!decoder->set_metadata_respond_all()) {
520                 printf("FAILED, returned false\n");
521                 return false;
522         }
523         printf("OK\n");
524
525         printf("testing set_metadata_ignore(APPLICATION)... ");
526         if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
527                 printf("FAILED, returned false\n");
528                 return false;
529         }
530         printf("OK\n");
531
532         num_expected_ = 0;
533         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
534         expected_metadata_sequence_[num_expected_++] = &padding_;
535         expected_metadata_sequence_[num_expected_++] = &seektable_;
536         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
537
538         if(!decoder->test_respond())
539                 return false;
540
541         /*
542          * respond all, ignore APPLICATION id of app#1
543          */
544
545         printf("testing set_metadata_respond_all()... ");
546         if(!decoder->set_metadata_respond_all()) {
547                 printf("FAILED, returned false\n");
548                 return false;
549         }
550         printf("OK\n");
551
552         printf("testing set_metadata_ignore_application(of app block #1)... ");
553         if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
554                 printf("FAILED, returned false\n");
555                 return false;
556         }
557         printf("OK\n");
558
559         num_expected_ = 0;
560         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
561         expected_metadata_sequence_[num_expected_++] = &padding_;
562         expected_metadata_sequence_[num_expected_++] = &seektable_;
563         expected_metadata_sequence_[num_expected_++] = &application2_;
564         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
565
566         if(!decoder->test_respond())
567                 return false;
568
569         /*
570          * respond all, ignore APPLICATION id of app#1 & app#2
571          */
572
573         printf("testing set_metadata_respond_all()... ");
574         if(!decoder->set_metadata_respond_all()) {
575                 printf("FAILED, returned false\n");
576                 return false;
577         }
578         printf("OK\n");
579
580         printf("testing set_metadata_ignore_application(of app block #1)... ");
581         if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
582                 printf("FAILED, returned false\n");
583                 return false;
584         }
585         printf("OK\n");
586
587         printf("testing set_metadata_ignore_application(of app block #2)... ");
588         if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
589                 printf("FAILED, returned false\n");
590                 return false;
591         }
592         printf("OK\n");
593
594         num_expected_ = 0;
595         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
596         expected_metadata_sequence_[num_expected_++] = &padding_;
597         expected_metadata_sequence_[num_expected_++] = &seektable_;
598         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
599
600         if(!decoder->test_respond())
601                 return false;
602
603         /*
604          * ignore all, respond VORBIS_COMMENT
605          */
606
607         printf("testing set_metadata_ignore_all()... ");
608         if(!decoder->set_metadata_ignore_all()) {
609                 printf("FAILED, returned false\n");
610                 return false;
611         }
612         printf("OK\n");
613
614         printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
615         if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
616                 printf("FAILED, returned false\n");
617                 return false;
618         }
619         printf("OK\n");
620
621         num_expected_ = 0;
622         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
623
624         if(!decoder->test_respond())
625                 return false;
626
627         /*
628          * ignore all, respond APPLICATION
629          */
630
631         printf("testing set_metadata_ignore_all()... ");
632         if(!decoder->set_metadata_ignore_all()) {
633                 printf("FAILED, returned false\n");
634                 return false;
635         }
636         printf("OK\n");
637
638         printf("testing set_metadata_respond(APPLICATION)... ");
639         if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
640                 printf("FAILED, returned false\n");
641                 return false;
642         }
643         printf("OK\n");
644
645         num_expected_ = 0;
646         expected_metadata_sequence_[num_expected_++] = &application1_;
647         expected_metadata_sequence_[num_expected_++] = &application2_;
648
649         if(!decoder->test_respond())
650                 return false;
651
652         /*
653          * ignore all, respond APPLICATION id of app#1
654          */
655
656         printf("testing set_metadata_ignore_all()... ");
657         if(!decoder->set_metadata_ignore_all()) {
658                 printf("FAILED, returned false\n");
659                 return false;
660         }
661         printf("OK\n");
662
663         printf("testing set_metadata_respond_application(of app block #1)... ");
664         if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
665                 printf("FAILED, returned false\n");
666                 return false;
667         }
668         printf("OK\n");
669
670         num_expected_ = 0;
671         expected_metadata_sequence_[num_expected_++] = &application1_;
672
673         if(!decoder->test_respond())
674                 return false;
675
676         /*
677          * ignore all, respond APPLICATION id of app#1 & app#2
678          */
679
680         printf("testing set_metadata_ignore_all()... ");
681         if(!decoder->set_metadata_ignore_all()) {
682                 printf("FAILED, returned false\n");
683                 return false;
684         }
685         printf("OK\n");
686
687         printf("testing set_metadata_respond_application(of app block #1)... ");
688         if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
689                 printf("FAILED, returned false\n");
690                 return false;
691         }
692         printf("OK\n");
693
694         printf("testing set_metadata_respond_application(of app block #2)... ");
695         if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
696                 printf("FAILED, returned false\n");
697                 return false;
698         }
699         printf("OK\n");
700
701         num_expected_ = 0;
702         expected_metadata_sequence_[num_expected_++] = &application1_;
703         expected_metadata_sequence_[num_expected_++] = &application2_;
704
705         if(!decoder->test_respond())
706                 return false;
707
708         /*
709          * respond all, ignore APPLICATION, respond APPLICATION id of app#1
710          */
711
712         printf("testing set_metadata_respond_all()... ");
713         if(!decoder->set_metadata_respond_all()) {
714                 printf("FAILED, returned false\n");
715                 return false;
716         }
717         printf("OK\n");
718
719         printf("testing set_metadata_ignore(APPLICATION)... ");
720         if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
721                 printf("FAILED, returned false\n");
722                 return false;
723         }
724         printf("OK\n");
725
726         printf("testing set_metadata_respond_application(of app block #1)... ");
727         if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
728                 printf("FAILED, returned false\n");
729                 return false;
730         }
731         printf("OK\n");
732
733         num_expected_ = 0;
734         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
735         expected_metadata_sequence_[num_expected_++] = &padding_;
736         expected_metadata_sequence_[num_expected_++] = &seektable_;
737         expected_metadata_sequence_[num_expected_++] = &application1_;
738         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
739
740         if(!decoder->test_respond())
741                 return false;
742
743         /*
744          * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
745          */
746
747         printf("testing set_metadata_ignore_all()... ");
748         if(!decoder->set_metadata_ignore_all()) {
749                 printf("FAILED, returned false\n");
750                 return false;
751         }
752         printf("OK\n");
753
754         printf("testing set_metadata_respond(APPLICATION)... ");
755         if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
756                 printf("FAILED, returned false\n");
757                 return false;
758         }
759         printf("OK\n");
760
761         printf("testing set_metadata_ignore_application(of app block #1)... ");
762         if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
763                 printf("FAILED, returned false\n");
764                 return false;
765         }
766         printf("OK\n");
767
768         num_expected_ = 0;
769         expected_metadata_sequence_[num_expected_++] = &application2_;
770
771         if(!decoder->test_respond())
772                 return false;
773
774         /* done, now leave the sequence the way we found it... */
775         num_expected_ = 0;
776         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
777         expected_metadata_sequence_[num_expected_++] = &padding_;
778         expected_metadata_sequence_[num_expected_++] = &seektable_;
779         expected_metadata_sequence_[num_expected_++] = &application1_;
780         expected_metadata_sequence_[num_expected_++] = &application2_;
781         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
782
783         ::fclose(decoder->file_);
784
785         printf("freeing decoder instance... ");
786         delete decoder;
787         printf("OK\n");
788
789         printf("\nPASSED!\n");
790
791         return true;
792 }
793
794 class SeekableStreamDecoder : public FLAC::Decoder::SeekableStream, public DecoderCommon {
795 public:
796         SeekableStreamDecoder(): FLAC::Decoder::SeekableStream(), DecoderCommon() { }
797         ~SeekableStreamDecoder() { }
798
799         // from FLAC::Decoder::SeekableStream
800         ::FLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
801         ::FLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
802         ::FLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
803         ::FLAC__SeekableStreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length);
804         bool eof_callback();
805         ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
806         void metadata_callback(const ::FLAC__StreamMetadata *metadata);
807         void error_callback(::FLAC__StreamDecoderErrorStatus status);
808
809         bool die(const char *msg = 0) const;
810
811         bool test_respond();
812 };
813
814 ::FLAC__SeekableStreamDecoderReadStatus SeekableStreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
815 {
816         switch(common_read_callback_(buffer, bytes)) {
817                 case ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
818                         return ::FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
819                 case ::FLAC__STREAM_DECODER_READ_STATUS_ABORT:
820                 case ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
821                         return ::FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
822                 default:
823                         FLAC__ASSERT(0);
824                         return ::FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
825         }
826 }
827
828 ::FLAC__SeekableStreamDecoderSeekStatus SeekableStreamDecoder::seek_callback(FLAC__uint64 absolute_byte_offset)
829 {
830         if(error_occurred_)
831                 return ::FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
832
833         if(::fseek(file_, absolute_byte_offset, SEEK_SET) < 0) {
834                 error_occurred_ = true;
835                 return ::FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
836         }
837
838         return ::FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
839 }
840
841 ::FLAC__SeekableStreamDecoderTellStatus SeekableStreamDecoder::tell_callback(FLAC__uint64 *absolute_byte_offset)
842 {
843         if(error_occurred_)
844                 return ::FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
845
846         long offset = ::ftell(file_);
847         *absolute_byte_offset = (FLAC__uint64)offset;
848
849         if(offset < 0) {
850                 error_occurred_ = true;
851                 return ::FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
852         }
853
854         return ::FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;
855 }
856
857 ::FLAC__SeekableStreamDecoderLengthStatus SeekableStreamDecoder::length_callback(FLAC__uint64 *stream_length)
858 {
859         if(error_occurred_)
860                 return ::FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR;
861
862         *stream_length = (FLAC__uint64)flacfilesize_;
863         return ::FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;
864 }
865
866 bool SeekableStreamDecoder::eof_callback()
867 {
868         if(error_occurred_)
869                 return true;
870
871         return feof(file_);
872 }
873
874 ::FLAC__StreamDecoderWriteStatus SeekableStreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
875 {
876         (void)buffer;
877
878         return common_write_callback_(frame);
879 }
880
881 void SeekableStreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
882 {
883         common_metadata_callback_(metadata);
884 }
885
886 void SeekableStreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
887 {
888         common_error_callback_(status);
889 }
890
891 bool SeekableStreamDecoder::die(const char *msg) const
892 {
893         State state = get_state();
894
895         if(msg)
896                 printf("FAILED, %s, state = %u (%s)\n", msg, (unsigned)((::FLAC__SeekableStreamDecoderState)state), state.as_cstring());
897         else
898                 printf("FAILED, state = %u (%s)\n", (unsigned)((::FLAC__SeekableStreamDecoderState)state), state.as_cstring());
899
900         return false;
901 }
902
903 bool SeekableStreamDecoder::test_respond()
904 {
905         if(!set_md5_checking(true)) {
906                 printf("FAILED at set_md5_checking(), returned false\n");
907                 return false;
908         }
909
910         printf("testing init()... ");
911         if(init() != ::FLAC__SEEKABLE_STREAM_DECODER_OK)
912                 return die();
913         printf("OK\n");
914
915         current_metadata_number_ = 0;
916
917         if(::fseek(file_, 0, SEEK_SET) < 0) {
918                 printf("FAILED rewinding input, errno = %d\n", errno);
919                 return false;
920         }
921
922         printf("testing process_whole_stream()... ");
923         if(!process_whole_stream()) {
924                 State state = get_state();
925                 printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::FLAC__SeekableStreamDecoderState)state), state.as_cstring());
926                 return false;
927         }
928         printf("OK\n");
929
930         printf("testing finish()... ");
931         finish();
932         printf("OK\n");
933
934         return true;
935 }
936
937 static bool test_seekable_stream_decoder()
938 {
939         SeekableStreamDecoder *decoder;
940
941         printf("\n+++ libFLAC++ unit test: FLAC::Decoder::SeekableStream\n\n");
942
943         num_expected_ = 0;
944         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
945
946         printf("allocating decoder instance... ");
947         decoder = new SeekableStreamDecoder();
948         if(0 == decoder) {
949                 printf("FAILED, new returned NULL\n");
950                 return false;
951         }
952         printf("OK\n");
953
954         printf("testing is_valid()... ");
955         if(!decoder->is_valid()) {
956                 printf("FAILED, returned false\n");
957                 return false;
958         }
959         printf("OK\n");
960
961         printf("testing set_md5_checking()... ");
962         if(!decoder->set_md5_checking(true)) {
963                 printf("FAILED, returned false\n");
964                 return false;
965         }
966         printf("OK\n");
967
968         printf("testing init()... ");
969         if(decoder->init() != ::FLAC__SEEKABLE_STREAM_DECODER_OK)
970                 return decoder->die();
971         printf("OK\n");
972
973         printf("testing get_state()... ");
974         FLAC::Decoder::SeekableStream::State state = decoder->get_state();
975         printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__SeekableStreamDecoderState)state), state.as_cstring());
976
977         decoder->current_metadata_number_ = 0;
978         decoder->ignore_errors_ = false;
979         decoder->error_occurred_ = false;
980
981         printf("opening FLAC file... ");
982         decoder->file_ = ::fopen(flacfilename_, "rb");
983         if(0 == decoder->file_) {
984                 printf("ERROR\n");
985                 return false;
986         }
987         printf("OK\n");
988
989         printf("testing get_md5_checking()... ");
990         if(!decoder->get_md5_checking()) {
991                 printf("FAILED, returned false, expected true\n");
992                 return false;
993         }
994         printf("OK\n");
995
996         printf("testing process_metadata()... ");
997         if(!decoder->process_metadata())
998                 return decoder->die("returned false");
999         printf("OK\n");
1000
1001         printf("testing process_one_frame()... ");
1002         if(!decoder->process_one_frame())
1003                 return decoder->die("returned false");
1004         printf("OK\n");
1005
1006         printf("testing flush()... ");
1007         if(!decoder->flush())
1008                 return decoder->die("returned false");
1009         printf("OK\n");
1010
1011         decoder->ignore_errors_ = true;
1012         printf("testing process_one_frame()... ");
1013         if(!decoder->process_one_frame())
1014                 return decoder->die("returned false");
1015         printf("OK\n");
1016         decoder->ignore_errors_ = false;
1017
1018         printf("testing seek_absolute()... ");
1019         if(!decoder->seek_absolute(0))
1020                 return decoder->die("returned false");
1021         printf("OK\n");
1022
1023         printf("testing process_remaining_frames()... ");
1024         if(!decoder->process_remaining_frames())
1025                 return decoder->die("returned false");
1026         printf("OK\n");
1027
1028         printf("testing get_channels()... ");
1029         {
1030                 unsigned channels = decoder->get_channels();
1031                 if(channels != streaminfo_.data.stream_info.channels) {
1032                         printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
1033                         return false;
1034                 }
1035         }
1036         printf("OK\n");
1037
1038         printf("testing get_bits_per_sample()... ");
1039         {
1040                 unsigned bits_per_sample = decoder->get_bits_per_sample();
1041                 if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
1042                         printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
1043                         return false;
1044                 }
1045         }
1046         printf("OK\n");
1047
1048         printf("testing get_sample_rate()... ");
1049         {
1050                 unsigned sample_rate = decoder->get_sample_rate();
1051                 if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
1052                         printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
1053                         return false;
1054                 }
1055         }
1056         printf("OK\n");
1057
1058         printf("testing get_blocksize()... ");
1059         {
1060                 unsigned blocksize = decoder->get_blocksize();
1061                 /* value could be anything since we're at the last block, so accept any answer */
1062                 printf("returned %u... OK\n", blocksize);
1063         }
1064
1065         printf("testing get_channel_assignment()... ");
1066         {
1067                 ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
1068                 printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
1069         }
1070
1071         printf("testing reset()... ");
1072         if(!decoder->reset())
1073                 return decoder->die("returned false");
1074         printf("OK\n");
1075
1076         decoder->current_metadata_number_ = 0;
1077
1078         printf("rewinding input... ");
1079         if(::fseek(decoder->file_, 0, SEEK_SET) < 0) {
1080                 printf("FAILED, errno = %d\n", errno);
1081                 return false;
1082         }
1083         printf("OK\n");
1084
1085         printf("testing process_whole_stream()... ");
1086         if(!decoder->process_whole_stream())
1087                 return decoder->die("returned false");
1088         printf("OK\n");
1089
1090         printf("testing finish()... ");
1091         decoder->finish();
1092         printf("OK\n");
1093
1094         /*
1095          * respond all
1096          */
1097
1098         printf("testing set_metadata_respond_all()... ");
1099         if(!decoder->set_metadata_respond_all()) {
1100                 printf("FAILED, returned false\n");
1101                 return false;
1102         }
1103         printf("OK\n");
1104
1105         num_expected_ = 0;
1106         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1107         expected_metadata_sequence_[num_expected_++] = &padding_;
1108         expected_metadata_sequence_[num_expected_++] = &seektable_;
1109         expected_metadata_sequence_[num_expected_++] = &application1_;
1110         expected_metadata_sequence_[num_expected_++] = &application2_;
1111         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1112
1113         if(!decoder->test_respond())
1114                 return false;
1115
1116         /*
1117          * ignore all
1118          */
1119
1120         printf("testing set_metadata_ignore_all()... ");
1121         if(!decoder->set_metadata_ignore_all()) {
1122                 printf("FAILED, returned false\n");
1123                 return false;
1124         }
1125         printf("OK\n");
1126
1127         num_expected_ = 0;
1128
1129         if(!decoder->test_respond())
1130                 return false;
1131
1132         /*
1133          * respond all, ignore VORBIS_COMMENT
1134          */
1135
1136         printf("testing set_metadata_respond_all()... ");
1137         if(!decoder->set_metadata_respond_all()) {
1138                 printf("FAILED, returned false\n");
1139                 return false;
1140         }
1141         printf("OK\n");
1142
1143         printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
1144         if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
1145                 printf("FAILED, returned false\n");
1146                 return false;
1147         }
1148         printf("OK\n");
1149
1150         num_expected_ = 0;
1151         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1152         expected_metadata_sequence_[num_expected_++] = &padding_;
1153         expected_metadata_sequence_[num_expected_++] = &seektable_;
1154         expected_metadata_sequence_[num_expected_++] = &application1_;
1155         expected_metadata_sequence_[num_expected_++] = &application2_;
1156
1157         if(!decoder->test_respond())
1158                 return false;
1159
1160         /*
1161          * respond all, ignore APPLICATION
1162          */
1163
1164         printf("testing set_metadata_respond_all()... ");
1165         if(!decoder->set_metadata_respond_all()) {
1166                 printf("FAILED, returned false\n");
1167                 return false;
1168         }
1169         printf("OK\n");
1170
1171         printf("testing set_metadata_ignore(APPLICATION)... ");
1172         if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1173                 printf("FAILED, returned false\n");
1174                 return false;
1175         }
1176         printf("OK\n");
1177
1178         num_expected_ = 0;
1179         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1180         expected_metadata_sequence_[num_expected_++] = &padding_;
1181         expected_metadata_sequence_[num_expected_++] = &seektable_;
1182         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1183
1184         if(!decoder->test_respond())
1185                 return false;
1186
1187         /*
1188          * respond all, ignore APPLICATION id of app#1
1189          */
1190
1191         printf("testing set_metadata_respond_all()... ");
1192         if(!decoder->set_metadata_respond_all()) {
1193                 printf("FAILED, returned false\n");
1194                 return false;
1195         }
1196         printf("OK\n");
1197
1198         printf("testing set_metadata_ignore_application(of app block #1)... ");
1199         if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1200                 printf("FAILED, returned false\n");
1201                 return false;
1202         }
1203         printf("OK\n");
1204
1205         num_expected_ = 0;
1206         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1207         expected_metadata_sequence_[num_expected_++] = &padding_;
1208         expected_metadata_sequence_[num_expected_++] = &seektable_;
1209         expected_metadata_sequence_[num_expected_++] = &application2_;
1210         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1211
1212         if(!decoder->test_respond())
1213                 return false;
1214
1215         /*
1216          * respond all, ignore APPLICATION id of app#1 & app#2
1217          */
1218
1219         printf("testing set_metadata_respond_all()... ");
1220         if(!decoder->set_metadata_respond_all()) {
1221                 printf("FAILED, returned false\n");
1222                 return false;
1223         }
1224         printf("OK\n");
1225
1226         printf("testing set_metadata_ignore_application(of app block #1)... ");
1227         if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1228                 printf("FAILED, returned false\n");
1229                 return false;
1230         }
1231         printf("OK\n");
1232
1233         printf("testing set_metadata_ignore_application(of app block #2)... ");
1234         if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
1235                 printf("FAILED, returned false\n");
1236                 return false;
1237         }
1238         printf("OK\n");
1239
1240         num_expected_ = 0;
1241         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1242         expected_metadata_sequence_[num_expected_++] = &padding_;
1243         expected_metadata_sequence_[num_expected_++] = &seektable_;
1244         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1245
1246         if(!decoder->test_respond())
1247                 return false;
1248
1249         /*
1250          * ignore all, respond VORBIS_COMMENT
1251          */
1252
1253         printf("testing set_metadata_ignore_all()... ");
1254         if(!decoder->set_metadata_ignore_all()) {
1255                 printf("FAILED, returned false\n");
1256                 return false;
1257         }
1258         printf("OK\n");
1259
1260         printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
1261         if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
1262                 printf("FAILED, returned false\n");
1263                 return false;
1264         }
1265         printf("OK\n");
1266
1267         num_expected_ = 0;
1268         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1269
1270         if(!decoder->test_respond())
1271                 return false;
1272
1273         /*
1274          * ignore all, respond APPLICATION
1275          */
1276
1277         printf("testing set_metadata_ignore_all()... ");
1278         if(!decoder->set_metadata_ignore_all()) {
1279                 printf("FAILED, returned false\n");
1280                 return false;
1281         }
1282         printf("OK\n");
1283
1284         printf("testing set_metadata_respond(APPLICATION)... ");
1285         if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
1286                 printf("FAILED, returned false\n");
1287                 return false;
1288         }
1289         printf("OK\n");
1290
1291         num_expected_ = 0;
1292         expected_metadata_sequence_[num_expected_++] = &application1_;
1293         expected_metadata_sequence_[num_expected_++] = &application2_;
1294
1295         if(!decoder->test_respond())
1296                 return false;
1297
1298         /*
1299          * ignore all, respond APPLICATION id of app#1
1300          */
1301
1302         printf("testing set_metadata_ignore_all()... ");
1303         if(!decoder->set_metadata_ignore_all()) {
1304                 printf("FAILED, returned false\n");
1305                 return false;
1306         }
1307         printf("OK\n");
1308
1309         printf("testing set_metadata_respond_application(of app block #1)... ");
1310         if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1311                 printf("FAILED, returned false\n");
1312                 return false;
1313         }
1314         printf("OK\n");
1315
1316         num_expected_ = 0;
1317         expected_metadata_sequence_[num_expected_++] = &application1_;
1318
1319         if(!decoder->test_respond())
1320                 return false;
1321
1322         /*
1323          * ignore all, respond APPLICATION id of app#1 & app#2
1324          */
1325
1326         printf("testing set_metadata_ignore_all()... ");
1327         if(!decoder->set_metadata_ignore_all()) {
1328                 printf("FAILED, returned false\n");
1329                 return false;
1330         }
1331         printf("OK\n");
1332
1333         printf("testing set_metadata_respond_application(of app block #1)... ");
1334         if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1335                 printf("FAILED, returned false\n");
1336                 return false;
1337         }
1338         printf("OK\n");
1339
1340         printf("testing set_metadata_respond_application(of app block #2)... ");
1341         if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
1342                 printf("FAILED, returned false\n");
1343                 return false;
1344         }
1345         printf("OK\n");
1346
1347         num_expected_ = 0;
1348         expected_metadata_sequence_[num_expected_++] = &application1_;
1349         expected_metadata_sequence_[num_expected_++] = &application2_;
1350
1351         if(!decoder->test_respond())
1352                 return false;
1353
1354         /*
1355          * respond all, ignore APPLICATION, respond APPLICATION id of app#1
1356          */
1357
1358         printf("testing set_metadata_respond_all()... ");
1359         if(!decoder->set_metadata_respond_all()) {
1360                 printf("FAILED, returned false\n");
1361                 return false;
1362         }
1363         printf("OK\n");
1364
1365         printf("testing set_metadata_ignore(APPLICATION)... ");
1366         if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1367                 printf("FAILED, returned false\n");
1368                 return false;
1369         }
1370         printf("OK\n");
1371
1372         printf("testing set_metadata_respond_application(of app block #1)... ");
1373         if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1374                 printf("FAILED, returned false\n");
1375                 return false;
1376         }
1377         printf("OK\n");
1378
1379         num_expected_ = 0;
1380         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1381         expected_metadata_sequence_[num_expected_++] = &padding_;
1382         expected_metadata_sequence_[num_expected_++] = &seektable_;
1383         expected_metadata_sequence_[num_expected_++] = &application1_;
1384         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1385
1386         if(!decoder->test_respond())
1387                 return false;
1388
1389         /*
1390          * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
1391          */
1392
1393         printf("testing set_metadata_ignore_all()... ");
1394         if(!decoder->set_metadata_ignore_all()) {
1395                 printf("FAILED, returned false\n");
1396                 return false;
1397         }
1398         printf("OK\n");
1399
1400         printf("testing set_metadata_respond(APPLICATION)... ");
1401         if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
1402                 printf("FAILED, returned false\n");
1403                 return false;
1404         }
1405         printf("OK\n");
1406
1407         printf("testing set_metadata_ignore_application(of app block #1)... ");
1408         if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1409                 printf("FAILED, returned false\n");
1410                 return false;
1411         }
1412         printf("OK\n");
1413
1414         num_expected_ = 0;
1415         expected_metadata_sequence_[num_expected_++] = &application2_;
1416
1417         if(!decoder->test_respond())
1418                 return false;
1419
1420         /* done, now leave the sequence the way we found it... */
1421         num_expected_ = 0;
1422         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1423         expected_metadata_sequence_[num_expected_++] = &padding_;
1424         expected_metadata_sequence_[num_expected_++] = &seektable_;
1425         expected_metadata_sequence_[num_expected_++] = &application1_;
1426         expected_metadata_sequence_[num_expected_++] = &application2_;
1427         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1428
1429         ::fclose(decoder->file_);
1430
1431         printf("freeing decoder instance... ");
1432         delete decoder;
1433         printf("OK\n");
1434
1435         printf("\nPASSED!\n");
1436
1437         return true;
1438 }
1439
1440 class FileDecoder : public FLAC::Decoder::File, public DecoderCommon {
1441 public:
1442         FileDecoder(): FLAC::Decoder::File(), DecoderCommon() { }
1443         ~FileDecoder() { }
1444
1445         // from FLAC::Decoder::File
1446         ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
1447         void metadata_callback(const ::FLAC__StreamMetadata *metadata);
1448         void error_callback(::FLAC__StreamDecoderErrorStatus status);
1449
1450         bool die(const char *msg = 0) const;
1451
1452         bool test_respond();
1453 };
1454
1455 ::FLAC__StreamDecoderWriteStatus FileDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
1456 {
1457         (void)buffer;
1458         return common_write_callback_(frame);
1459 }
1460
1461 void FileDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
1462 {
1463         common_metadata_callback_(metadata);
1464 }
1465
1466 void FileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
1467 {
1468         common_error_callback_(status);
1469 }
1470
1471 bool FileDecoder::die(const char *msg) const
1472 {
1473         State state = get_state();
1474
1475         if(msg)
1476                 printf("FAILED, %s, state = %u (%s)\n", msg, (unsigned)((::FLAC__FileDecoderState)state), state.as_cstring());
1477         else
1478                 printf("FAILED, state = %u (%s)\n", (unsigned)((::FLAC__FileDecoderState)state), state.as_cstring());
1479
1480         return false;
1481 }
1482
1483 bool FileDecoder::test_respond()
1484 {
1485         if(!set_filename(flacfilename_)) {
1486                 printf("FAILED at set_filename(), returned false\n");
1487                 return false;
1488         }
1489
1490         if(!set_md5_checking(true)) {
1491                 printf("FAILED at set_md5_checking(), returned false\n");
1492                 return false;
1493         }
1494
1495         printf("testing init()... ");
1496         if(init() != ::FLAC__FILE_DECODER_OK)
1497                 return die();
1498         printf("OK\n");
1499
1500         current_metadata_number_ = 0;
1501
1502         printf("testing process_whole_file()... ");
1503         if(!process_whole_file()) {
1504                 State state = get_state();
1505                 printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::FLAC__FileDecoderState)state), state.as_cstring());
1506                 return false;
1507         }
1508         printf("OK\n");
1509
1510         printf("testing finish()... ");
1511         finish();
1512         printf("OK\n");
1513
1514         return true;
1515 }
1516
1517 static bool test_file_decoder()
1518 {
1519         FileDecoder *decoder;
1520
1521         printf("\n+++ libFLAC++ unit test: FLAC::Decoder::File\n\n");
1522
1523         num_expected_ = 0;
1524         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1525
1526         printf("allocating decoder instance... ");
1527         decoder = new FileDecoder();
1528         if(0 == decoder) {
1529                 printf("FAILED, new returned NULL\n");
1530                 return false;
1531         }
1532         printf("OK\n");
1533
1534         printf("testing is_valid()... ");
1535         if(!decoder->is_valid()) {
1536                 printf("FAILED, returned false\n");
1537                 return false;
1538         }
1539         printf("OK\n");
1540
1541         printf("testing set_filename()... ");
1542         if(!decoder->set_filename(flacfilename_)) {
1543                 printf("FAILED, returned false\n");
1544                 return false;
1545         }
1546         printf("OK\n");
1547
1548         printf("testing set_md5_checking()... ");
1549         if(!decoder->set_md5_checking(true)) {
1550                 printf("FAILED, returned false\n");
1551                 return false;
1552         }
1553         printf("OK\n");
1554
1555         printf("testing init()... ");
1556         if(decoder->init() != ::FLAC__FILE_DECODER_OK)
1557                 return decoder->die();
1558         printf("OK\n");
1559
1560         printf("testing get_state()... ");
1561         FLAC::Decoder::File::State state = decoder->get_state();
1562         printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__FileDecoderState)state), state.as_cstring());
1563
1564         decoder->current_metadata_number_ = 0;
1565         decoder->ignore_errors_ = false;
1566         decoder->error_occurred_ = false;
1567
1568         printf("testing get_md5_checking()... ");
1569         if(!decoder->get_md5_checking()) {
1570                 printf("FAILED, returned false, expected true\n");
1571                 return false;
1572         }
1573         printf("OK\n");
1574
1575         printf("testing process_metadata()... ");
1576         if(!decoder->process_metadata())
1577                 return decoder->die("returned false");
1578         printf("OK\n");
1579
1580         printf("testing process_one_frame()... ");
1581         if(!decoder->process_one_frame())
1582                 return decoder->die("returned false");
1583         printf("OK\n");
1584
1585         printf("testing seek_absolute()... ");
1586         if(!decoder->seek_absolute(0))
1587                 return decoder->die("returned false");
1588         printf("OK\n");
1589
1590         printf("testing process_remaining_frames()... ");
1591         if(!decoder->process_remaining_frames())
1592                 return decoder->die("returned false");
1593         printf("OK\n");
1594
1595         printf("testing get_channels()... ");
1596         {
1597                 unsigned channels = decoder->get_channels();
1598                 if(channels != streaminfo_.data.stream_info.channels) {
1599                         printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
1600                         return false;
1601                 }
1602         }
1603         printf("OK\n");
1604
1605         printf("testing get_bits_per_sample()... ");
1606         {
1607                 unsigned bits_per_sample = decoder->get_bits_per_sample();
1608                 if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
1609                         printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
1610                         return false;
1611                 }
1612         }
1613         printf("OK\n");
1614
1615         printf("testing get_sample_rate()... ");
1616         {
1617                 unsigned sample_rate = decoder->get_sample_rate();
1618                 if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
1619                         printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
1620                         return false;
1621                 }
1622         }
1623         printf("OK\n");
1624
1625         printf("testing get_blocksize()... ");
1626         {
1627                 unsigned blocksize = decoder->get_blocksize();
1628                 /* value could be anything since we're at the last block, so accept any answer */
1629                 printf("returned %u... OK\n", blocksize);
1630         }
1631
1632         printf("testing get_channel_assignment()... ");
1633         {
1634                 ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
1635                 printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
1636         }
1637
1638         printf("testing finish()... ");
1639         decoder->finish();
1640         printf("OK\n");
1641
1642         /*
1643          * respond all
1644          */
1645
1646         printf("testing set_metadata_respond_all()... ");
1647         if(!decoder->set_metadata_respond_all()) {
1648                 printf("FAILED, returned false\n");
1649                 return false;
1650         }
1651         printf("OK\n");
1652
1653         num_expected_ = 0;
1654         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1655         expected_metadata_sequence_[num_expected_++] = &padding_;
1656         expected_metadata_sequence_[num_expected_++] = &seektable_;
1657         expected_metadata_sequence_[num_expected_++] = &application1_;
1658         expected_metadata_sequence_[num_expected_++] = &application2_;
1659         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1660
1661         if(!decoder->test_respond())
1662                 return false;
1663
1664         /*
1665          * ignore all
1666          */
1667
1668         printf("testing set_metadata_ignore_all()... ");
1669         if(!decoder->set_metadata_ignore_all()) {
1670                 printf("FAILED, returned false\n");
1671                 return false;
1672         }
1673         printf("OK\n");
1674
1675         num_expected_ = 0;
1676
1677         if(!decoder->test_respond())
1678                 return false;
1679
1680         /*
1681          * respond all, ignore VORBIS_COMMENT
1682          */
1683
1684         printf("testing set_metadata_respond_all()... ");
1685         if(!decoder->set_metadata_respond_all()) {
1686                 printf("FAILED, returned false\n");
1687                 return false;
1688         }
1689         printf("OK\n");
1690
1691         printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
1692         if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
1693                 printf("FAILED, returned false\n");
1694                 return false;
1695         }
1696         printf("OK\n");
1697
1698         num_expected_ = 0;
1699         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1700         expected_metadata_sequence_[num_expected_++] = &padding_;
1701         expected_metadata_sequence_[num_expected_++] = &seektable_;
1702         expected_metadata_sequence_[num_expected_++] = &application1_;
1703         expected_metadata_sequence_[num_expected_++] = &application2_;
1704
1705         if(!decoder->test_respond())
1706                 return false;
1707
1708         /*
1709          * respond all, ignore APPLICATION
1710          */
1711
1712         printf("testing set_metadata_respond_all()... ");
1713         if(!decoder->set_metadata_respond_all()) {
1714                 printf("FAILED, returned false\n");
1715                 return false;
1716         }
1717         printf("OK\n");
1718
1719         printf("testing set_metadata_ignore(APPLICATION)... ");
1720         if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1721                 printf("FAILED, returned false\n");
1722                 return false;
1723         }
1724         printf("OK\n");
1725
1726         num_expected_ = 0;
1727         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1728         expected_metadata_sequence_[num_expected_++] = &padding_;
1729         expected_metadata_sequence_[num_expected_++] = &seektable_;
1730         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1731
1732         if(!decoder->test_respond())
1733                 return false;
1734
1735         /*
1736          * respond all, ignore APPLICATION id of app#1
1737          */
1738
1739         printf("testing set_metadata_respond_all()... ");
1740         if(!decoder->set_metadata_respond_all()) {
1741                 printf("FAILED, returned false\n");
1742                 return false;
1743         }
1744         printf("OK\n");
1745
1746         printf("testing set_metadata_ignore_application(of app block #1)... ");
1747         if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1748                 printf("FAILED, returned false\n");
1749                 return false;
1750         }
1751         printf("OK\n");
1752
1753         num_expected_ = 0;
1754         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1755         expected_metadata_sequence_[num_expected_++] = &padding_;
1756         expected_metadata_sequence_[num_expected_++] = &seektable_;
1757         expected_metadata_sequence_[num_expected_++] = &application2_;
1758         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1759
1760         if(!decoder->test_respond())
1761                 return false;
1762
1763         /*
1764          * respond all, ignore APPLICATION id of app#1 & app#2
1765          */
1766
1767         printf("testing set_metadata_respond_all()... ");
1768         if(!decoder->set_metadata_respond_all()) {
1769                 printf("FAILED, returned false\n");
1770                 return false;
1771         }
1772         printf("OK\n");
1773
1774         printf("testing set_metadata_ignore_application(of app block #1)... ");
1775         if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1776                 printf("FAILED, returned false\n");
1777                 return false;
1778         }
1779         printf("OK\n");
1780
1781         printf("testing set_metadata_ignore_application(of app block #2)... ");
1782         if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
1783                 printf("FAILED, returned false\n");
1784                 return false;
1785         }
1786         printf("OK\n");
1787
1788         num_expected_ = 0;
1789         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1790         expected_metadata_sequence_[num_expected_++] = &padding_;
1791         expected_metadata_sequence_[num_expected_++] = &seektable_;
1792         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1793
1794         if(!decoder->test_respond())
1795                 return false;
1796
1797         /*
1798          * ignore all, respond VORBIS_COMMENT
1799          */
1800
1801         printf("testing set_metadata_ignore_all()... ");
1802         if(!decoder->set_metadata_ignore_all()) {
1803                 printf("FAILED, returned false\n");
1804                 return false;
1805         }
1806         printf("OK\n");
1807
1808         printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
1809         if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
1810                 printf("FAILED, returned false\n");
1811                 return false;
1812         }
1813         printf("OK\n");
1814
1815         num_expected_ = 0;
1816         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1817
1818         if(!decoder->test_respond())
1819                 return false;
1820
1821         /*
1822          * ignore all, respond APPLICATION
1823          */
1824
1825         printf("testing set_metadata_ignore_all()... ");
1826         if(!decoder->set_metadata_ignore_all()) {
1827                 printf("FAILED, returned false\n");
1828                 return false;
1829         }
1830         printf("OK\n");
1831
1832         printf("testing set_metadata_respond(APPLICATION)... ");
1833         if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
1834                 printf("FAILED, returned false\n");
1835                 return false;
1836         }
1837         printf("OK\n");
1838
1839         num_expected_ = 0;
1840         expected_metadata_sequence_[num_expected_++] = &application1_;
1841         expected_metadata_sequence_[num_expected_++] = &application2_;
1842
1843         if(!decoder->test_respond())
1844                 return false;
1845
1846         /*
1847          * ignore all, respond APPLICATION id of app#1
1848          */
1849
1850         printf("testing set_metadata_ignore_all()... ");
1851         if(!decoder->set_metadata_ignore_all()) {
1852                 printf("FAILED, returned false\n");
1853                 return false;
1854         }
1855         printf("OK\n");
1856
1857         printf("testing set_metadata_respond_application(of app block #1)... ");
1858         if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1859                 printf("FAILED, returned false\n");
1860                 return false;
1861         }
1862         printf("OK\n");
1863
1864         num_expected_ = 0;
1865         expected_metadata_sequence_[num_expected_++] = &application1_;
1866
1867         if(!decoder->test_respond())
1868                 return false;
1869
1870         /*
1871          * ignore all, respond APPLICATION id of app#1 & app#2
1872          */
1873
1874         printf("testing set_metadata_ignore_all()... ");
1875         if(!decoder->set_metadata_ignore_all()) {
1876                 printf("FAILED, returned false\n");
1877                 return false;
1878         }
1879         printf("OK\n");
1880
1881         printf("testing set_metadata_respond_application(of app block #1)... ");
1882         if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1883                 printf("FAILED, returned false\n");
1884                 return false;
1885         }
1886         printf("OK\n");
1887
1888         printf("testing set_metadata_respond_application(of app block #2)... ");
1889         if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
1890                 printf("FAILED, returned false\n");
1891                 return false;
1892         }
1893         printf("OK\n");
1894
1895         num_expected_ = 0;
1896         expected_metadata_sequence_[num_expected_++] = &application1_;
1897         expected_metadata_sequence_[num_expected_++] = &application2_;
1898
1899         if(!decoder->test_respond())
1900                 return false;
1901
1902         /*
1903          * respond all, ignore APPLICATION, respond APPLICATION id of app#1
1904          */
1905
1906         printf("testing set_metadata_respond_all()... ");
1907         if(!decoder->set_metadata_respond_all()) {
1908                 printf("FAILED, returned false\n");
1909                 return false;
1910         }
1911         printf("OK\n");
1912
1913         printf("testing set_metadata_ignore(APPLICATION)... ");
1914         if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1915                 printf("FAILED, returned false\n");
1916                 return false;
1917         }
1918         printf("OK\n");
1919
1920         printf("testing set_metadata_respond_application(of app block #1)... ");
1921         if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1922                 printf("FAILED, returned false\n");
1923                 return false;
1924         }
1925         printf("OK\n");
1926
1927         num_expected_ = 0;
1928         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1929         expected_metadata_sequence_[num_expected_++] = &padding_;
1930         expected_metadata_sequence_[num_expected_++] = &seektable_;
1931         expected_metadata_sequence_[num_expected_++] = &application1_;
1932         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1933
1934         if(!decoder->test_respond())
1935                 return false;
1936
1937         /*
1938          * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
1939          */
1940
1941         printf("testing set_metadata_ignore_all()... ");
1942         if(!decoder->set_metadata_ignore_all()) {
1943                 printf("FAILED, returned false\n");
1944                 return false;
1945         }
1946         printf("OK\n");
1947
1948         printf("testing set_metadata_respond(APPLICATION)... ");
1949         if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
1950                 printf("FAILED, returned false\n");
1951                 return false;
1952         }
1953         printf("OK\n");
1954
1955         printf("testing set_metadata_ignore_application(of app block #1)... ");
1956         if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1957                 printf("FAILED, returned false\n");
1958                 return false;
1959         }
1960         printf("OK\n");
1961
1962         num_expected_ = 0;
1963         expected_metadata_sequence_[num_expected_++] = &application2_;
1964
1965         if(!decoder->test_respond())
1966                 return false;
1967
1968         /* done, now leave the sequence the way we found it... */
1969         num_expected_ = 0;
1970         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1971         expected_metadata_sequence_[num_expected_++] = &padding_;
1972         expected_metadata_sequence_[num_expected_++] = &seektable_;
1973         expected_metadata_sequence_[num_expected_++] = &application1_;
1974         expected_metadata_sequence_[num_expected_++] = &application2_;
1975         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1976
1977         printf("freeing decoder instance... ");
1978         delete decoder;
1979         printf("OK\n");
1980
1981         printf("\nPASSED!\n");
1982
1983         return true;
1984 }
1985
1986 bool test_decoders()
1987 {
1988         init_metadata_blocks_();
1989         if(!generate_file_())
1990                 return false;
1991
1992         if(!test_stream_decoder())
1993                 return false;
1994
1995         if(!test_seekable_stream_decoder())
1996                 return false;
1997
1998         if(!test_file_decoder())
1999                 return false;
2000
2001         (void) file_utils__remove_file(flacfilename_);
2002         free_metadata_blocks_();
2003
2004         return true;
2005 }