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 <= 1600 /* @@@ [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 off_t flacfilesize_;
67 static const char *flacfilename(bool is_ogg)
69 return is_ogg? "metadata.ogg" : "metadata.flac";
72 static bool die_(const char *msg)
74 printf("ERROR: %s\n", msg);
78 static FLAC__bool die_s_(const char *msg, const FLAC::Decoder::Stream *decoder)
80 FLAC::Decoder::Stream::State state = decoder->get_state();
83 printf("FAILED, %s", msg);
87 printf(", state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
92 static void init_metadata_blocks_()
94 mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
97 static void free_metadata_blocks_()
99 mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
102 static bool generate_file_(FLAC__bool is_ogg)
104 printf("\n\ngenerating %sFLAC file for decoder tests...\n", is_ogg? "Ogg ":"");
107 expected_metadata_sequence_[num_expected_++] = &padding_;
108 expected_metadata_sequence_[num_expected_++] = &seektable_;
109 expected_metadata_sequence_[num_expected_++] = &application1_;
110 expected_metadata_sequence_[num_expected_++] = &application2_;
111 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
112 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
113 expected_metadata_sequence_[num_expected_++] = &picture_;
114 expected_metadata_sequence_[num_expected_++] = &unknown_;
115 /* WATCHOUT: for Ogg FLAC the encoder should move the VORBIS_COMMENT block to the front, right after STREAMINFO */
117 if(!file_utils__generate_flacfile(is_ogg, flacfilename(is_ogg), &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
118 return die_("creating the encoded file");
124 class DecoderCommon {
127 unsigned current_metadata_number_;
129 bool error_occurred_;
131 DecoderCommon(Layer layer): layer_(layer), current_metadata_number_(0), ignore_errors_(false), error_occurred_(false) { }
132 ::FLAC__StreamDecoderWriteStatus common_write_callback_(const ::FLAC__Frame *frame);
133 void common_metadata_callback_(const ::FLAC__StreamMetadata *metadata);
134 void common_error_callback_(::FLAC__StreamDecoderErrorStatus status);
137 ::FLAC__StreamDecoderWriteStatus DecoderCommon::common_write_callback_(const ::FLAC__Frame *frame)
140 return ::FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
143 (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) ||
144 (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0)
146 printf("content... ");
150 return ::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
153 void DecoderCommon::common_metadata_callback_(const ::FLAC__StreamMetadata *metadata)
158 printf("%d... ", current_metadata_number_);
161 if(current_metadata_number_ >= num_expected_) {
162 (void)die_("got more metadata blocks than expected");
163 error_occurred_ = true;
166 if(!::FLAC__metadata_object_is_equal(expected_metadata_sequence_[current_metadata_number_], metadata)) {
167 (void)die_("metadata block mismatch");
168 error_occurred_ = true;
171 current_metadata_number_++;
174 void DecoderCommon::common_error_callback_(::FLAC__StreamDecoderErrorStatus status)
176 if(!ignore_errors_) {
177 printf("ERROR: got error callback: err = %u (%s)\n", (unsigned)status, ::FLAC__StreamDecoderErrorStatusString[status]);
178 error_occurred_ = true;
182 class StreamDecoder : public FLAC::Decoder::Stream, public DecoderCommon {
186 StreamDecoder(Layer layer): FLAC::Decoder::Stream(), DecoderCommon(layer), file_(0) { }
189 // from FLAC::Decoder::Stream
190 ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes);
191 ::FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
192 ::FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
193 ::FLAC__StreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length);
195 ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
196 void metadata_callback(const ::FLAC__StreamMetadata *metadata);
197 void error_callback(::FLAC__StreamDecoderErrorStatus status);
199 bool test_respond(bool is_ogg);
202 ::FLAC__StreamDecoderReadStatus StreamDecoder::read_callback(FLAC__byte buffer[], size_t *bytes)
204 const size_t requested_bytes = *bytes;
207 return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT;
211 return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
213 else if(requested_bytes > 0) {
214 *bytes = ::fread(buffer, 1, requested_bytes, file_);
217 return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
219 return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
222 return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
226 return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
229 ::FLAC__StreamDecoderSeekStatus StreamDecoder::seek_callback(FLAC__uint64 absolute_byte_offset)
231 if(layer_ == LAYER_STREAM)
232 return ::FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
235 return ::FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
237 if(fseeko(file_, (off_t)absolute_byte_offset, SEEK_SET) < 0) {
238 error_occurred_ = true;
239 return ::FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
242 return ::FLAC__STREAM_DECODER_SEEK_STATUS_OK;
245 ::FLAC__StreamDecoderTellStatus StreamDecoder::tell_callback(FLAC__uint64 *absolute_byte_offset)
247 if(layer_ == LAYER_STREAM)
248 return ::FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
251 return ::FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
253 off_t offset = ftello(file_);
254 *absolute_byte_offset = (FLAC__uint64)offset;
257 error_occurred_ = true;
258 return ::FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
261 return ::FLAC__STREAM_DECODER_TELL_STATUS_OK;
264 ::FLAC__StreamDecoderLengthStatus StreamDecoder::length_callback(FLAC__uint64 *stream_length)
266 if(layer_ == LAYER_STREAM)
267 return ::FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
270 return ::FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
272 *stream_length = (FLAC__uint64)flacfilesize_;
273 return ::FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
276 bool StreamDecoder::eof_callback()
278 if(layer_ == LAYER_STREAM)
284 return (bool)feof(file_);
287 ::FLAC__StreamDecoderWriteStatus StreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
291 return common_write_callback_(frame);
294 void StreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
296 common_metadata_callback_(metadata);
299 void StreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
301 common_error_callback_(status);
304 bool StreamDecoder::test_respond(bool is_ogg)
306 ::FLAC__StreamDecoderInitStatus init_status;
308 if(!set_md5_checking(true)) {
309 printf("FAILED at set_md5_checking(), returned false\n");
313 printf("testing init%s()... ", is_ogg? "_ogg":"");
314 init_status = is_ogg? init_ogg() : init();
315 if(init_status != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
316 return die_s_(0, this);
319 current_metadata_number_ = 0;
321 if(fseeko(file_, 0, SEEK_SET) < 0) {
322 printf("FAILED rewinding input, errno = %d\n", errno);
326 printf("testing process_until_end_of_stream()... ");
327 if(!process_until_end_of_stream()) {
328 State state = get_state();
329 printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
334 printf("testing finish()... ");
336 State state = get_state();
337 printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
345 class FileDecoder : public FLAC::Decoder::File, public DecoderCommon {
347 FileDecoder(Layer layer): FLAC::Decoder::File(), DecoderCommon(layer) { }
350 // from FLAC::Decoder::Stream
351 ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
352 void metadata_callback(const ::FLAC__StreamMetadata *metadata);
353 void error_callback(::FLAC__StreamDecoderErrorStatus status);
355 bool test_respond(bool is_ogg);
358 ::FLAC__StreamDecoderWriteStatus FileDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
361 return common_write_callback_(frame);
364 void FileDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
366 common_metadata_callback_(metadata);
369 void FileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
371 common_error_callback_(status);
374 bool FileDecoder::test_respond(bool is_ogg)
376 ::FLAC__StreamDecoderInitStatus init_status;
378 if(!set_md5_checking(true)) {
379 printf("FAILED at set_md5_checking(), returned false\n");
386 printf("opening %sFLAC file... ", is_ogg? "Ogg ":"");
387 FILE *file = ::fopen(flacfilename(is_ogg), "rb");
389 printf("ERROR (%s)\n", strerror(errno));
394 printf("testing init%s()... ", is_ogg? "_ogg":"");
395 init_status = is_ogg? init_ogg(file) : init(file);
399 printf("testing init%s()... ", is_ogg? "_ogg":"");
400 init_status = is_ogg? init_ogg(flacfilename(is_ogg)) : init(flacfilename(is_ogg));
403 die_("internal error 001");
406 if(init_status != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
407 return die_s_(0, this);
410 current_metadata_number_ = 0;
412 printf("testing process_until_end_of_stream()... ");
413 if(!process_until_end_of_stream()) {
414 State state = get_state();
415 printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
420 printf("testing finish()... ");
422 State state = get_state();
423 printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
432 static FLAC::Decoder::Stream *new_by_layer(Layer layer)
434 if(layer < LAYER_FILE)
435 return new StreamDecoder(layer);
437 return new FileDecoder(layer);
440 static bool test_stream_decoder(Layer layer, bool is_ogg)
442 FLAC::Decoder::Stream *decoder;
443 ::FLAC__StreamDecoderInitStatus init_status;
446 printf("\n+++ libFLAC++ unit test: FLAC::Decoder::%s (layer: %s, format: %s)\n\n", layer<LAYER_FILE? "Stream":"File", LayerString[layer], is_ogg? "Ogg FLAC" : "FLAC");
449 // test new -> delete
451 printf("allocating decoder instance... ");
452 decoder = new_by_layer(layer);
454 printf("FAILED, new returned NULL\n");
459 printf("testing is_valid()... ");
460 if(!decoder->is_valid()) {
461 printf("FAILED, returned false\n");
466 printf("freeing decoder instance... ");
471 // test new -> init -> delete
473 printf("allocating decoder instance... ");
474 decoder = new_by_layer(layer);
476 printf("FAILED, new returned NULL\n");
481 printf("testing is_valid()... ");
482 if(!decoder->is_valid()) {
483 printf("FAILED, returned false\n");
488 printf("testing init%s()... ", is_ogg? "_ogg":"");
491 case LAYER_SEEKABLE_STREAM:
492 dynamic_cast<StreamDecoder*>(decoder)->file_ = stdin;
493 init_status = is_ogg? decoder->init_ogg() : decoder->init();
496 init_status = is_ogg?
497 dynamic_cast<FLAC::Decoder::File*>(decoder)->init_ogg(stdin) :
498 dynamic_cast<FLAC::Decoder::File*>(decoder)->init(stdin);
501 init_status = is_ogg?
502 dynamic_cast<FLAC::Decoder::File*>(decoder)->init_ogg(flacfilename(is_ogg)) :
503 dynamic_cast<FLAC::Decoder::File*>(decoder)->init(flacfilename(is_ogg));
506 die_("internal error 006");
509 if(init_status != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
510 return die_s_(0, decoder);
513 printf("freeing decoder instance... ");
521 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
523 printf("allocating decoder instance... ");
524 decoder = new_by_layer(layer);
526 printf("FAILED, new returned NULL\n");
531 printf("testing is_valid()... ");
532 if(!decoder->is_valid()) {
533 printf("FAILED, returned false\n");
539 printf("testing set_ogg_serial_number()... ");
540 if(!decoder->set_ogg_serial_number(file_utils__ogg_serial_number))
541 return die_s_("returned false", decoder);
545 if(!decoder->set_md5_checking(true)) {
546 printf("FAILED at set_md5_checking(), returned false\n");
552 case LAYER_SEEKABLE_STREAM:
553 printf("opening %sFLAC file... ", is_ogg? "Ogg ":"");
554 dynamic_cast<StreamDecoder*>(decoder)->file_ = ::fopen(flacfilename(is_ogg), "rb");
555 if(0 == dynamic_cast<StreamDecoder*>(decoder)->file_) {
556 printf("ERROR (%s)\n", strerror(errno));
561 printf("testing init%s()... ", is_ogg? "_ogg":"");
562 init_status = is_ogg? decoder->init_ogg() : decoder->init();
566 printf("opening FLAC file... ");
567 FILE *file = ::fopen(flacfilename(is_ogg), "rb");
569 printf("ERROR (%s)\n", strerror(errno));
574 printf("testing init%s()... ", is_ogg? "_ogg":"");
575 init_status = is_ogg?
576 dynamic_cast<FLAC::Decoder::File*>(decoder)->init_ogg(file) :
577 dynamic_cast<FLAC::Decoder::File*>(decoder)->init(file);
581 printf("testing init%s()... ", is_ogg? "_ogg":"");
582 init_status = is_ogg?
583 dynamic_cast<FLAC::Decoder::File*>(decoder)->init_ogg(flacfilename(is_ogg)) :
584 dynamic_cast<FLAC::Decoder::File*>(decoder)->init(flacfilename(is_ogg));
587 die_("internal error 009");
590 if(init_status != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
591 return die_s_(0, decoder);
594 printf("testing get_state()... ");
595 FLAC::Decoder::Stream::State state = decoder->get_state();
596 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
598 dynamic_cast<DecoderCommon*>(decoder)->current_metadata_number_ = 0;
599 dynamic_cast<DecoderCommon*>(decoder)->ignore_errors_ = false;
600 dynamic_cast<DecoderCommon*>(decoder)->error_occurred_ = false;
602 printf("testing get_md5_checking()... ");
603 if(!decoder->get_md5_checking()) {
604 printf("FAILED, returned false, expected true\n");
609 printf("testing process_until_end_of_metadata()... ");
610 if(!decoder->process_until_end_of_metadata())
611 return die_s_("returned false", decoder);
614 printf("testing process_single()... ");
615 if(!decoder->process_single())
616 return die_s_("returned false", decoder);
619 printf("testing skip_single_frame()... ");
620 if(!decoder->skip_single_frame())
621 return die_s_("returned false", decoder);
624 if(layer < LAYER_FILE) {
625 printf("testing flush()... ");
626 if(!decoder->flush())
627 return die_s_("returned false", decoder);
630 dynamic_cast<DecoderCommon*>(decoder)->ignore_errors_ = true;
631 printf("testing process_single()... ");
632 if(!decoder->process_single())
633 return die_s_("returned false", decoder);
635 dynamic_cast<DecoderCommon*>(decoder)->ignore_errors_ = false;
638 expect = (layer != LAYER_STREAM);
639 printf("testing seek_absolute()... ");
640 if(decoder->seek_absolute(0) != expect)
641 return die_s_(expect? "returned false" : "returned true", decoder);
644 printf("testing process_until_end_of_stream()... ");
645 if(!decoder->process_until_end_of_stream())
646 return die_s_("returned false", decoder);
649 expect = (layer != LAYER_STREAM);
650 printf("testing seek_absolute()... ");
651 if(decoder->seek_absolute(0) != expect)
652 return die_s_(expect? "returned false" : "returned true", decoder);
655 printf("testing get_channels()... ");
657 unsigned channels = decoder->get_channels();
658 if(channels != streaminfo_.data.stream_info.channels) {
659 printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
665 printf("testing get_bits_per_sample()... ");
667 unsigned bits_per_sample = decoder->get_bits_per_sample();
668 if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
669 printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
675 printf("testing get_sample_rate()... ");
677 unsigned sample_rate = decoder->get_sample_rate();
678 if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
679 printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
685 printf("testing get_blocksize()... ");
687 unsigned blocksize = decoder->get_blocksize();
688 /* value could be anything since we're at the last block, so accept any reasonable answer */
689 printf("returned %u... %s\n", blocksize, blocksize>0? "OK" : "FAILED");
694 printf("testing get_channel_assignment()... ");
696 ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
697 printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
700 if(layer < LAYER_FILE) {
701 printf("testing reset()... ");
702 if(!decoder->reset())
703 return die_s_("returned false", decoder);
706 if(layer == LAYER_STREAM) {
707 /* after a reset() we have to rewind the input ourselves */
708 printf("rewinding input... ");
709 if(fseeko(dynamic_cast<StreamDecoder*>(decoder)->file_, 0, SEEK_SET) < 0) {
710 printf("FAILED, errno = %d\n", errno);
716 dynamic_cast<DecoderCommon*>(decoder)->current_metadata_number_ = 0;
718 printf("testing process_until_end_of_stream()... ");
719 if(!decoder->process_until_end_of_stream())
720 return die_s_("returned false", decoder);
724 printf("testing finish()... ");
725 if(!decoder->finish()) {
726 FLAC::Decoder::Stream::State state = decoder->get_state();
727 printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
736 printf("testing set_metadata_respond_all()... ");
737 if(!decoder->set_metadata_respond_all()) {
738 printf("FAILED, returned false\n");
744 if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
745 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
746 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
747 expected_metadata_sequence_[num_expected_++] = &padding_;
748 expected_metadata_sequence_[num_expected_++] = &seektable_;
749 expected_metadata_sequence_[num_expected_++] = &application1_;
750 expected_metadata_sequence_[num_expected_++] = &application2_;
751 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
752 expected_metadata_sequence_[num_expected_++] = &picture_;
753 expected_metadata_sequence_[num_expected_++] = &unknown_;
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_++] = &vorbiscomment_;
762 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
763 expected_metadata_sequence_[num_expected_++] = &picture_;
764 expected_metadata_sequence_[num_expected_++] = &unknown_;
767 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
774 printf("testing set_metadata_ignore_all()... ");
775 if(!decoder->set_metadata_ignore_all()) {
776 printf("FAILED, returned false\n");
783 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
787 * respond all, ignore VORBIS_COMMENT
790 printf("testing set_metadata_respond_all()... ");
791 if(!decoder->set_metadata_respond_all()) {
792 printf("FAILED, returned false\n");
797 printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
798 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
799 printf("FAILED, returned false\n");
805 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
806 expected_metadata_sequence_[num_expected_++] = &padding_;
807 expected_metadata_sequence_[num_expected_++] = &seektable_;
808 expected_metadata_sequence_[num_expected_++] = &application1_;
809 expected_metadata_sequence_[num_expected_++] = &application2_;
810 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
811 expected_metadata_sequence_[num_expected_++] = &picture_;
812 expected_metadata_sequence_[num_expected_++] = &unknown_;
814 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
818 * respond all, ignore APPLICATION
821 printf("testing set_metadata_respond_all()... ");
822 if(!decoder->set_metadata_respond_all()) {
823 printf("FAILED, returned false\n");
828 printf("testing set_metadata_ignore(APPLICATION)... ");
829 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
830 printf("FAILED, returned false\n");
836 if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
837 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
838 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
839 expected_metadata_sequence_[num_expected_++] = &padding_;
840 expected_metadata_sequence_[num_expected_++] = &seektable_;
841 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
842 expected_metadata_sequence_[num_expected_++] = &picture_;
843 expected_metadata_sequence_[num_expected_++] = &unknown_;
846 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
847 expected_metadata_sequence_[num_expected_++] = &padding_;
848 expected_metadata_sequence_[num_expected_++] = &seektable_;
849 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
850 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
851 expected_metadata_sequence_[num_expected_++] = &picture_;
852 expected_metadata_sequence_[num_expected_++] = &unknown_;
855 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
859 * respond all, ignore APPLICATION id of app#1
862 printf("testing set_metadata_respond_all()... ");
863 if(!decoder->set_metadata_respond_all()) {
864 printf("FAILED, returned false\n");
869 printf("testing set_metadata_ignore_application(of app block #1)... ");
870 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
871 printf("FAILED, returned false\n");
877 if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
878 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
879 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
880 expected_metadata_sequence_[num_expected_++] = &padding_;
881 expected_metadata_sequence_[num_expected_++] = &seektable_;
882 expected_metadata_sequence_[num_expected_++] = &application2_;
883 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
884 expected_metadata_sequence_[num_expected_++] = &picture_;
885 expected_metadata_sequence_[num_expected_++] = &unknown_;
888 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
889 expected_metadata_sequence_[num_expected_++] = &padding_;
890 expected_metadata_sequence_[num_expected_++] = &seektable_;
891 expected_metadata_sequence_[num_expected_++] = &application2_;
892 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
893 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
894 expected_metadata_sequence_[num_expected_++] = &picture_;
895 expected_metadata_sequence_[num_expected_++] = &unknown_;
898 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
902 * respond all, ignore APPLICATION id of app#1 & app#2
905 printf("testing set_metadata_respond_all()... ");
906 if(!decoder->set_metadata_respond_all()) {
907 printf("FAILED, returned false\n");
912 printf("testing set_metadata_ignore_application(of app block #1)... ");
913 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
914 printf("FAILED, returned false\n");
919 printf("testing set_metadata_ignore_application(of app block #2)... ");
920 if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
921 printf("FAILED, returned false\n");
927 if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
928 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
929 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
930 expected_metadata_sequence_[num_expected_++] = &padding_;
931 expected_metadata_sequence_[num_expected_++] = &seektable_;
932 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
933 expected_metadata_sequence_[num_expected_++] = &picture_;
934 expected_metadata_sequence_[num_expected_++] = &unknown_;
937 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
938 expected_metadata_sequence_[num_expected_++] = &padding_;
939 expected_metadata_sequence_[num_expected_++] = &seektable_;
940 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
941 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
942 expected_metadata_sequence_[num_expected_++] = &picture_;
943 expected_metadata_sequence_[num_expected_++] = &unknown_;
946 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
950 * ignore all, respond VORBIS_COMMENT
953 printf("testing set_metadata_ignore_all()... ");
954 if(!decoder->set_metadata_ignore_all()) {
955 printf("FAILED, returned false\n");
960 printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
961 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
962 printf("FAILED, returned false\n");
968 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
970 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
974 * ignore all, respond APPLICATION
977 printf("testing set_metadata_ignore_all()... ");
978 if(!decoder->set_metadata_ignore_all()) {
979 printf("FAILED, returned false\n");
984 printf("testing set_metadata_respond(APPLICATION)... ");
985 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
986 printf("FAILED, returned false\n");
992 expected_metadata_sequence_[num_expected_++] = &application1_;
993 expected_metadata_sequence_[num_expected_++] = &application2_;
995 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
999 * ignore all, respond APPLICATION id of app#1
1002 printf("testing set_metadata_ignore_all()... ");
1003 if(!decoder->set_metadata_ignore_all()) {
1004 printf("FAILED, returned false\n");
1009 printf("testing set_metadata_respond_application(of app block #1)... ");
1010 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1011 printf("FAILED, returned false\n");
1017 expected_metadata_sequence_[num_expected_++] = &application1_;
1019 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
1023 * ignore all, respond APPLICATION id of app#1 & app#2
1026 printf("testing set_metadata_ignore_all()... ");
1027 if(!decoder->set_metadata_ignore_all()) {
1028 printf("FAILED, returned false\n");
1033 printf("testing set_metadata_respond_application(of app block #1)... ");
1034 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1035 printf("FAILED, returned false\n");
1040 printf("testing set_metadata_respond_application(of app block #2)... ");
1041 if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
1042 printf("FAILED, returned false\n");
1048 expected_metadata_sequence_[num_expected_++] = &application1_;
1049 expected_metadata_sequence_[num_expected_++] = &application2_;
1051 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
1055 * respond all, ignore APPLICATION, respond APPLICATION id of app#1
1058 printf("testing set_metadata_respond_all()... ");
1059 if(!decoder->set_metadata_respond_all()) {
1060 printf("FAILED, returned false\n");
1065 printf("testing set_metadata_ignore(APPLICATION)... ");
1066 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1067 printf("FAILED, returned false\n");
1072 printf("testing set_metadata_respond_application(of app block #1)... ");
1073 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1074 printf("FAILED, returned false\n");
1080 if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
1081 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1082 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1083 expected_metadata_sequence_[num_expected_++] = &padding_;
1084 expected_metadata_sequence_[num_expected_++] = &seektable_;
1085 expected_metadata_sequence_[num_expected_++] = &application1_;
1086 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1087 expected_metadata_sequence_[num_expected_++] = &picture_;
1088 expected_metadata_sequence_[num_expected_++] = &unknown_;
1091 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1092 expected_metadata_sequence_[num_expected_++] = &padding_;
1093 expected_metadata_sequence_[num_expected_++] = &seektable_;
1094 expected_metadata_sequence_[num_expected_++] = &application1_;
1095 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1096 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1097 expected_metadata_sequence_[num_expected_++] = &picture_;
1098 expected_metadata_sequence_[num_expected_++] = &unknown_;
1101 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
1105 * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
1108 printf("testing set_metadata_ignore_all()... ");
1109 if(!decoder->set_metadata_ignore_all()) {
1110 printf("FAILED, returned false\n");
1115 printf("testing set_metadata_respond(APPLICATION)... ");
1116 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
1117 printf("FAILED, returned false\n");
1122 printf("testing set_metadata_ignore_application(of app block #1)... ");
1123 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1124 printf("FAILED, returned false\n");
1130 expected_metadata_sequence_[num_expected_++] = &application2_;
1132 if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
1135 if(layer < LAYER_FILE) /* for LAYER_FILE, FLAC__stream_decoder_finish() closes the file */
1136 ::fclose(dynamic_cast<StreamDecoder*>(decoder)->file_);
1138 printf("freeing decoder instance... ");
1142 printf("\nPASSED!\n");
1147 bool test_decoders()
1149 FLAC__bool is_ogg = false;
1152 init_metadata_blocks_();
1154 if(!generate_file_(is_ogg))
1157 if(!test_stream_decoder(LAYER_STREAM, is_ogg))
1160 if(!test_stream_decoder(LAYER_SEEKABLE_STREAM, is_ogg))
1163 if(!test_stream_decoder(LAYER_FILE, is_ogg))
1166 if(!test_stream_decoder(LAYER_FILENAME, is_ogg))
1169 (void) grabbag__file_remove_file(flacfilename(is_ogg));
1171 free_metadata_blocks_();
1173 if(!FLAC_API_SUPPORTS_OGG_FLAC || is_ogg)