1 /* test_libFLAC++ - Unit tester for libFLAC++
2 * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
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.
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.
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.
27 #if defined _MSC_VER || defined __MINGW32__
28 #if _MSC_VER <= 1200 /* @@@ [2G limit] */
34 #include "FLAC/assert.h"
35 #include "FLAC/metadata.h" // for ::FLAC__metadata_object_is_equal()
36 #include "FLAC++/decoder.h"
37 #include "share/grabbag.h"
39 #include "test_libs_common/file_utils_flac.h"
40 #include "test_libs_common/metadata_utils.h"
44 // warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
45 #pragma warning ( disable : 4800 )
49 LAYER_STREAM = 0, /* FLAC__stream_decoder_init_stream() without seeking */
50 LAYER_SEEKABLE_STREAM, /* FLAC__stream_decoder_init_stream() with seeking */
51 LAYER_FILE, /* FLAC__stream_decoder_init_FILE() */
52 LAYER_FILENAME /* FLAC__stream_decoder_init_file() */
55 static const char * const LayerString[] = {
62 static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_;
63 static ::FLAC__StreamMetadata *expected_metadata_sequence_[9];
64 static unsigned num_expected_;
65 static const char *flacfilename_ = "metadata.flac";
66 static off_t flacfilesize_;
68 static bool die_(const char *msg)
70 printf("ERROR: %s\n", msg);
74 static FLAC__bool die_s_(const char *msg, const FLAC::Decoder::Stream *decoder)
76 FLAC::Decoder::Stream::State state = decoder->get_state();
79 printf("FAILED, %s", msg);
83 printf(", state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
88 static void init_metadata_blocks_()
90 mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
93 static void free_metadata_blocks_()
95 mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
98 static bool generate_file_()
100 printf("\n\ngenerating FLAC file for decoder tests...\n");
103 expected_metadata_sequence_[num_expected_++] = &padding_;
104 expected_metadata_sequence_[num_expected_++] = &seektable_;
105 expected_metadata_sequence_[num_expected_++] = &application1_;
106 expected_metadata_sequence_[num_expected_++] = &application2_;
107 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
108 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
109 expected_metadata_sequence_[num_expected_++] = &picture_;
110 expected_metadata_sequence_[num_expected_++] = &unknown_;
112 if(!file_utils__generate_flacfile(flacfilename_, &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
113 return die_("creating the encoded file");
119 class DecoderCommon {
122 unsigned current_metadata_number_;
124 bool error_occurred_;
126 DecoderCommon(Layer layer): layer_(layer), current_metadata_number_(0), ignore_errors_(false), error_occurred_(false) { }
127 ::FLAC__StreamDecoderWriteStatus common_write_callback_(const ::FLAC__Frame *frame);
128 void common_metadata_callback_(const ::FLAC__StreamMetadata *metadata);
129 void common_error_callback_(::FLAC__StreamDecoderErrorStatus status);
132 ::FLAC__StreamDecoderWriteStatus DecoderCommon::common_write_callback_(const ::FLAC__Frame *frame)
135 return ::FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
138 (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) ||
139 (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0)
141 printf("content... ");
145 return ::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
148 void DecoderCommon::common_metadata_callback_(const ::FLAC__StreamMetadata *metadata)
153 printf("%d... ", current_metadata_number_);
156 if(current_metadata_number_ >= num_expected_) {
157 (void)die_("got more metadata blocks than expected");
158 error_occurred_ = true;
161 if(!::FLAC__metadata_object_is_equal(expected_metadata_sequence_[current_metadata_number_], metadata)) {
162 (void)die_("metadata block mismatch");
163 error_occurred_ = true;
166 current_metadata_number_++;
169 void DecoderCommon::common_error_callback_(::FLAC__StreamDecoderErrorStatus status)
171 if(!ignore_errors_) {
172 printf("ERROR: got error callback: err = %u (%s)\n", (unsigned)status, ::FLAC__StreamDecoderErrorStatusString[status]);
173 error_occurred_ = true;
177 class StreamDecoder : public FLAC::Decoder::Stream, public DecoderCommon {
181 StreamDecoder(Layer layer): FLAC::Decoder::Stream(), DecoderCommon(layer), file_(0) { }
184 // from FLAC::Decoder::Stream
185 ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
186 ::FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
187 ::FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
188 ::FLAC__StreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length);
190 ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
191 void metadata_callback(const ::FLAC__StreamMetadata *metadata);
192 void error_callback(::FLAC__StreamDecoderErrorStatus status);
197 ::FLAC__StreamDecoderReadStatus StreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
199 const unsigned requested_bytes = *bytes;
202 return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT;
206 return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
208 else if(requested_bytes > 0) {
209 *bytes = ::fread(buffer, 1, requested_bytes, file_);
212 return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
214 return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
217 return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
221 return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
224 ::FLAC__StreamDecoderSeekStatus StreamDecoder::seek_callback(FLAC__uint64 absolute_byte_offset)
226 if(layer_ == LAYER_STREAM)
227 return ::FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
230 return ::FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
232 if(fseeko(file_, (off_t)absolute_byte_offset, SEEK_SET) < 0) {
233 error_occurred_ = true;
234 return ::FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
237 return ::FLAC__STREAM_DECODER_SEEK_STATUS_OK;
240 ::FLAC__StreamDecoderTellStatus StreamDecoder::tell_callback(FLAC__uint64 *absolute_byte_offset)
242 if(layer_ == LAYER_STREAM)
243 return ::FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
246 return ::FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
248 off_t offset = ftello(file_);
249 *absolute_byte_offset = (FLAC__uint64)offset;
252 error_occurred_ = true;
253 return ::FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
256 return ::FLAC__STREAM_DECODER_TELL_STATUS_OK;
259 ::FLAC__StreamDecoderLengthStatus StreamDecoder::length_callback(FLAC__uint64 *stream_length)
261 if(layer_ == LAYER_STREAM)
262 return ::FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
265 return ::FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
267 *stream_length = (FLAC__uint64)flacfilesize_;
268 return ::FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
271 bool StreamDecoder::eof_callback()
273 if(layer_ == LAYER_STREAM)
279 return (bool)feof(file_);
282 ::FLAC__StreamDecoderWriteStatus StreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
286 return common_write_callback_(frame);
289 void StreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
291 common_metadata_callback_(metadata);
294 void StreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
296 common_error_callback_(status);
299 bool StreamDecoder::test_respond()
301 if(!set_md5_checking(true)) {
302 printf("FAILED at set_md5_checking(), returned false\n");
306 printf("testing init()... ");
307 if(init() != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
308 return die_s_(0, this);
311 current_metadata_number_ = 0;
313 if(fseeko(file_, 0, SEEK_SET) < 0) {
314 printf("FAILED rewinding input, errno = %d\n", errno);
318 printf("testing process_until_end_of_stream()... ");
319 if(!process_until_end_of_stream()) {
320 State state = get_state();
321 printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
326 printf("testing finish()... ");
333 class FileDecoder : public FLAC::Decoder::File, public DecoderCommon {
335 FileDecoder(Layer layer): FLAC::Decoder::File(), DecoderCommon(layer) { }
338 // from FLAC::Decoder::Stream
339 ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
340 void metadata_callback(const ::FLAC__StreamMetadata *metadata);
341 void error_callback(::FLAC__StreamDecoderErrorStatus status);
346 ::FLAC__StreamDecoderWriteStatus FileDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
349 return common_write_callback_(frame);
352 void FileDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
354 common_metadata_callback_(metadata);
357 void FileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
359 common_error_callback_(status);
362 bool FileDecoder::test_respond()
364 if(!set_md5_checking(true)) {
365 printf("FAILED at set_md5_checking(), returned false\n");
372 printf("opening FLAC file... ");
373 FILE *file = ::fopen(flacfilename_, "rb");
375 printf("ERROR (%s)\n", strerror(errno));
380 printf("testing init()... ");
381 if(init(file) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
382 return die_s_(0, this);
386 printf("testing init()... ");
387 if(init(flacfilename_) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
388 return die_s_(0, this);
391 die_("internal error 001");
396 current_metadata_number_ = 0;
398 printf("testing process_until_end_of_stream()... ");
399 if(!process_until_end_of_stream()) {
400 State state = get_state();
401 printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
406 printf("testing finish()... ");
414 static FLAC::Decoder::Stream *new_by_layer(Layer layer)
416 if(layer < LAYER_FILE)
417 return new StreamDecoder(layer);
419 return new FileDecoder(layer);
422 static bool test_stream_decoder(Layer layer)
424 FLAC::Decoder::Stream *decoder;
427 printf("\n+++ libFLAC++ unit test: FLAC::Decoder::%s (layer: %s)\n\n", layer<LAYER_FILE? "Stream":"File", LayerString[layer]);
430 // test new -> delete
432 printf("allocating decoder instance... ");
433 decoder = new_by_layer(layer);
435 printf("FAILED, new returned NULL\n");
440 printf("testing is_valid()... ");
441 if(!decoder->is_valid()) {
442 printf("FAILED, returned false\n");
447 printf("freeing decoder instance... ");
452 // test new -> init -> delete
454 printf("allocating decoder instance... ");
455 decoder = new_by_layer(layer);
457 printf("FAILED, new returned NULL\n");
462 printf("testing is_valid()... ");
463 if(!decoder->is_valid()) {
464 printf("FAILED, returned false\n");
469 printf("testing init()... ");
472 case LAYER_SEEKABLE_STREAM:
473 dynamic_cast<StreamDecoder*>(decoder)->file_ = stdin;
474 if(decoder->init() != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
475 return die_s_(0, decoder);
478 if(dynamic_cast<FLAC::Decoder::File*>(decoder)->init(stdin) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
479 return die_s_(0, decoder);
482 if(dynamic_cast<FLAC::Decoder::File*>(decoder)->init(flacfilename_) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
483 return die_s_(0, decoder);
486 die_("internal error 006");
491 printf("freeing decoder instance... ");
499 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
501 printf("allocating decoder instance... ");
502 decoder = new_by_layer(layer);
504 printf("FAILED, new returned NULL\n");
509 printf("testing is_valid()... ");
510 if(!decoder->is_valid()) {
511 printf("FAILED, returned false\n");
516 if(!decoder->set_md5_checking(true)) {
517 printf("FAILED at set_md5_checking(), returned false\n");
523 case LAYER_SEEKABLE_STREAM:
524 printf("opening FLAC file... ");
525 dynamic_cast<StreamDecoder*>(decoder)->file_ = ::fopen(flacfilename_, "rb");
526 if(0 == dynamic_cast<StreamDecoder*>(decoder)->file_) {
527 printf("ERROR (%s)\n", strerror(errno));
532 printf("testing init()... ");
533 if(decoder->init() != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
534 return die_s_(0, decoder);
538 printf("opening FLAC file... ");
539 FILE *file = ::fopen(flacfilename_, "rb");
541 printf("ERROR (%s)\n", strerror(errno));
546 printf("testing init()... ");
547 if(dynamic_cast<FLAC::Decoder::File*>(decoder)->init(file) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
548 return die_s_(0, decoder);
552 printf("testing init()... ");
553 if(dynamic_cast<FLAC::Decoder::File*>(decoder)->init(flacfilename_) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
554 return die_s_(0, decoder);
557 die_("internal error 009");
562 printf("testing get_state()... ");
563 FLAC::Decoder::Stream::State state = decoder->get_state();
564 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
566 dynamic_cast<DecoderCommon*>(decoder)->current_metadata_number_ = 0;
567 dynamic_cast<DecoderCommon*>(decoder)->ignore_errors_ = false;
568 dynamic_cast<DecoderCommon*>(decoder)->error_occurred_ = false;
570 printf("testing get_md5_checking()... ");
571 if(!decoder->get_md5_checking()) {
572 printf("FAILED, returned false, expected true\n");
577 printf("testing process_until_end_of_metadata()... ");
578 if(!decoder->process_until_end_of_metadata())
579 return die_s_("returned false", decoder);
582 printf("testing process_single()... ");
583 if(!decoder->process_single())
584 return die_s_("returned false", decoder);
587 printf("testing skip_single_frame()... ");
588 if(!decoder->skip_single_frame())
589 return die_s_("returned false", decoder);
592 if(layer < LAYER_FILE) {
593 printf("testing flush()... ");
594 if(!decoder->flush())
595 return die_s_("returned false", decoder);
598 dynamic_cast<DecoderCommon*>(decoder)->ignore_errors_ = true;
599 printf("testing process_single()... ");
600 if(!decoder->process_single())
601 return die_s_("returned false", decoder);
603 dynamic_cast<DecoderCommon*>(decoder)->ignore_errors_ = false;
606 expect = (layer != LAYER_STREAM);
607 printf("testing seek_absolute()... ");
608 if(decoder->seek_absolute(0) != expect)
609 return die_s_(expect? "returned false" : "returned true", decoder);
612 printf("testing process_until_end_of_stream()... ");
613 if(!decoder->process_until_end_of_stream())
614 return die_s_("returned false", decoder);
617 expect = (layer != LAYER_STREAM);
618 printf("testing seek_absolute()... ");
619 if(decoder->seek_absolute(0) != expect)
620 return die_s_(expect? "returned false" : "returned true", decoder);
623 printf("testing get_channels()... ");
625 unsigned channels = decoder->get_channels();
626 if(channels != streaminfo_.data.stream_info.channels) {
627 printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
633 printf("testing get_bits_per_sample()... ");
635 unsigned bits_per_sample = decoder->get_bits_per_sample();
636 if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
637 printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
643 printf("testing get_sample_rate()... ");
645 unsigned sample_rate = decoder->get_sample_rate();
646 if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
647 printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
653 printf("testing get_blocksize()... ");
655 unsigned blocksize = decoder->get_blocksize();
656 /* value could be anything since we're at the last block, so accept any reasonable answer */
657 printf("returned %u... %s\n", blocksize, blocksize>0? "OK" : "FAILED");
662 printf("testing get_channel_assignment()... ");
664 ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
665 printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
668 if(layer < LAYER_FILE) {
669 printf("testing reset()... ");
670 if(!decoder->reset())
671 return die_s_("returned false", decoder);
674 if(layer == LAYER_STREAM) {
675 /* after a reset() we have to rewind the input ourselves */
676 printf("rewinding input... ");
677 if(fseeko(dynamic_cast<StreamDecoder*>(decoder)->file_, 0, SEEK_SET) < 0) {
678 printf("FAILED, errno = %d\n", errno);
684 dynamic_cast<DecoderCommon*>(decoder)->current_metadata_number_ = 0;
686 printf("testing process_until_end_of_stream()... ");
687 if(!decoder->process_until_end_of_stream())
688 return die_s_("returned false", decoder);
692 printf("testing finish()... ");
700 printf("testing set_metadata_respond_all()... ");
701 if(!decoder->set_metadata_respond_all()) {
702 printf("FAILED, returned false\n");
708 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
709 expected_metadata_sequence_[num_expected_++] = &padding_;
710 expected_metadata_sequence_[num_expected_++] = &seektable_;
711 expected_metadata_sequence_[num_expected_++] = &application1_;
712 expected_metadata_sequence_[num_expected_++] = &application2_;
713 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
714 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
715 expected_metadata_sequence_[num_expected_++] = &picture_;
716 expected_metadata_sequence_[num_expected_++] = &unknown_;
718 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
725 printf("testing set_metadata_ignore_all()... ");
726 if(!decoder->set_metadata_ignore_all()) {
727 printf("FAILED, returned false\n");
734 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
738 * respond all, ignore VORBIS_COMMENT
741 printf("testing set_metadata_respond_all()... ");
742 if(!decoder->set_metadata_respond_all()) {
743 printf("FAILED, returned false\n");
748 printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
749 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
750 printf("FAILED, returned false\n");
756 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
757 expected_metadata_sequence_[num_expected_++] = &padding_;
758 expected_metadata_sequence_[num_expected_++] = &seektable_;
759 expected_metadata_sequence_[num_expected_++] = &application1_;
760 expected_metadata_sequence_[num_expected_++] = &application2_;
761 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
762 expected_metadata_sequence_[num_expected_++] = &picture_;
763 expected_metadata_sequence_[num_expected_++] = &unknown_;
765 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
769 * respond all, ignore APPLICATION
772 printf("testing set_metadata_respond_all()... ");
773 if(!decoder->set_metadata_respond_all()) {
774 printf("FAILED, returned false\n");
779 printf("testing set_metadata_ignore(APPLICATION)... ");
780 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
781 printf("FAILED, returned false\n");
787 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
788 expected_metadata_sequence_[num_expected_++] = &padding_;
789 expected_metadata_sequence_[num_expected_++] = &seektable_;
790 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
791 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
792 expected_metadata_sequence_[num_expected_++] = &picture_;
793 expected_metadata_sequence_[num_expected_++] = &unknown_;
795 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
799 * respond all, ignore APPLICATION id of app#1
802 printf("testing set_metadata_respond_all()... ");
803 if(!decoder->set_metadata_respond_all()) {
804 printf("FAILED, returned false\n");
809 printf("testing set_metadata_ignore_application(of app block #1)... ");
810 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
811 printf("FAILED, returned false\n");
817 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
818 expected_metadata_sequence_[num_expected_++] = &padding_;
819 expected_metadata_sequence_[num_expected_++] = &seektable_;
820 expected_metadata_sequence_[num_expected_++] = &application2_;
821 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
822 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
823 expected_metadata_sequence_[num_expected_++] = &picture_;
824 expected_metadata_sequence_[num_expected_++] = &unknown_;
826 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
830 * respond all, ignore APPLICATION id of app#1 & app#2
833 printf("testing set_metadata_respond_all()... ");
834 if(!decoder->set_metadata_respond_all()) {
835 printf("FAILED, returned false\n");
840 printf("testing set_metadata_ignore_application(of app block #1)... ");
841 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
842 printf("FAILED, returned false\n");
847 printf("testing set_metadata_ignore_application(of app block #2)... ");
848 if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
849 printf("FAILED, returned false\n");
855 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
856 expected_metadata_sequence_[num_expected_++] = &padding_;
857 expected_metadata_sequence_[num_expected_++] = &seektable_;
858 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
859 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
860 expected_metadata_sequence_[num_expected_++] = &picture_;
861 expected_metadata_sequence_[num_expected_++] = &unknown_;
863 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
867 * ignore all, respond VORBIS_COMMENT
870 printf("testing set_metadata_ignore_all()... ");
871 if(!decoder->set_metadata_ignore_all()) {
872 printf("FAILED, returned false\n");
877 printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
878 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
879 printf("FAILED, returned false\n");
885 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
887 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
891 * ignore all, respond APPLICATION
894 printf("testing set_metadata_ignore_all()... ");
895 if(!decoder->set_metadata_ignore_all()) {
896 printf("FAILED, returned false\n");
901 printf("testing set_metadata_respond(APPLICATION)... ");
902 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
903 printf("FAILED, returned false\n");
909 expected_metadata_sequence_[num_expected_++] = &application1_;
910 expected_metadata_sequence_[num_expected_++] = &application2_;
912 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
916 * ignore all, respond APPLICATION id of app#1
919 printf("testing set_metadata_ignore_all()... ");
920 if(!decoder->set_metadata_ignore_all()) {
921 printf("FAILED, returned false\n");
926 printf("testing set_metadata_respond_application(of app block #1)... ");
927 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
928 printf("FAILED, returned false\n");
934 expected_metadata_sequence_[num_expected_++] = &application1_;
936 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
940 * ignore all, respond APPLICATION id of app#1 & app#2
943 printf("testing set_metadata_ignore_all()... ");
944 if(!decoder->set_metadata_ignore_all()) {
945 printf("FAILED, returned false\n");
950 printf("testing set_metadata_respond_application(of app block #1)... ");
951 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
952 printf("FAILED, returned false\n");
957 printf("testing set_metadata_respond_application(of app block #2)... ");
958 if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
959 printf("FAILED, returned false\n");
965 expected_metadata_sequence_[num_expected_++] = &application1_;
966 expected_metadata_sequence_[num_expected_++] = &application2_;
968 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
972 * respond all, ignore APPLICATION, respond APPLICATION id of app#1
975 printf("testing set_metadata_respond_all()... ");
976 if(!decoder->set_metadata_respond_all()) {
977 printf("FAILED, returned false\n");
982 printf("testing set_metadata_ignore(APPLICATION)... ");
983 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
984 printf("FAILED, returned false\n");
989 printf("testing set_metadata_respond_application(of app block #1)... ");
990 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
991 printf("FAILED, returned false\n");
997 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
998 expected_metadata_sequence_[num_expected_++] = &padding_;
999 expected_metadata_sequence_[num_expected_++] = &seektable_;
1000 expected_metadata_sequence_[num_expected_++] = &application1_;
1001 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1002 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1003 expected_metadata_sequence_[num_expected_++] = &picture_;
1004 expected_metadata_sequence_[num_expected_++] = &unknown_;
1006 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
1010 * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
1013 printf("testing set_metadata_ignore_all()... ");
1014 if(!decoder->set_metadata_ignore_all()) {
1015 printf("FAILED, returned false\n");
1020 printf("testing set_metadata_respond(APPLICATION)... ");
1021 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
1022 printf("FAILED, returned false\n");
1027 printf("testing set_metadata_ignore_application(of app block #1)... ");
1028 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1029 printf("FAILED, returned false\n");
1035 expected_metadata_sequence_[num_expected_++] = &application2_;
1037 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
1040 if(layer < LAYER_FILE) /* for LAYER_FILE, FLAC__stream_decoder_finish() closes the file */
1041 ::fclose(dynamic_cast<StreamDecoder*>(decoder)->file_);
1043 printf("freeing decoder instance... ");
1047 printf("\nPASSED!\n");
1052 bool test_decoders()
1054 init_metadata_blocks_();
1056 if(!generate_file_())
1059 if(!test_stream_decoder(LAYER_STREAM))
1062 if(!test_stream_decoder(LAYER_SEEKABLE_STREAM))
1065 if(!test_stream_decoder(LAYER_FILE))
1068 if(!test_stream_decoder(LAYER_FILENAME))
1071 (void) grabbag__file_remove_file(flacfilename_);
1073 free_metadata_blocks_();