1 /* test_libFLAC++ - Unit tester for libFLAC++
2 * Copyright (C) 2002 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.
21 #include "file_utils.h"
23 #include "FLAC/assert.h"
24 #include "FLAC/metadata.h" // for ::FLAC__metadata_object_is_equal()
25 #include "FLAC++/decoder.h"
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_;
37 static bool die_(const char *msg)
39 printf("ERROR: %s\n", msg);
43 static void *malloc_or_die_(size_t size)
45 void *x = malloc(size);
47 fprintf(stderr, "ERROR: out of memory allocating %u bytes\n", (unsigned)size);
53 static void init_metadata_blocks_()
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
59 remember, the metadata interface gets tested after the decoders,
60 so we do all the metadata manipulation here without it.
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);
77 padding_.is_last = false;
78 padding_.type = ::FLAC__METADATA_TYPE_PADDING;
79 padding_.length = 1234;
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;
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);
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;
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;
121 static void free_metadata_blocks_()
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);
130 static bool generate_file_()
132 printf("\n\ngenerating FLAC file for decoder tests...\n");
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_;
141 if(!file_utils__generate_flacfile(flacfilename_, &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
142 return die_("creating the encoded file");
148 class DecoderCommon {
151 unsigned current_metadata_number_;
153 bool error_occurred_;
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);
162 ::FLAC__StreamDecoderReadStatus DecoderCommon::common_read_callback_(FLAC__byte buffer[], unsigned *bytes)
165 return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT;
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) {
173 return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
175 return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
179 return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
183 return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
186 ::FLAC__StreamDecoderWriteStatus DecoderCommon::common_write_callback_(const ::FLAC__Frame *frame)
189 return ::FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
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)
195 printf("content... ");
199 return ::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
202 void DecoderCommon::common_metadata_callback_(const ::FLAC__StreamMetadata *metadata)
207 printf("%d... ", current_metadata_number_);
210 if(current_metadata_number_ >= num_expected_) {
211 (void)die_("got more metadata blocks than expected");
212 error_occurred_ = true;
215 if(!::FLAC__metadata_object_is_equal(expected_metadata_sequence_[current_metadata_number_], metadata)) {
216 (void)die_("metadata block mismatch");
217 error_occurred_ = true;
220 current_metadata_number_++;
223 void DecoderCommon::common_error_callback_(::FLAC__StreamDecoderErrorStatus status)
225 if(!ignore_errors_) {
226 printf("ERROR: got error callback: err = %u (%s)\n", (unsigned)status, ::FLAC__StreamDecoderErrorStatusString[status]);
227 error_occurred_ = true;
231 class StreamDecoder : public FLAC::Decoder::Stream, public DecoderCommon {
233 StreamDecoder(): FLAC::Decoder::Stream(), DecoderCommon() { }
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);
242 bool die(const char *msg = 0) const;
247 ::FLAC__StreamDecoderReadStatus StreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
249 return common_read_callback_(buffer, bytes);
252 ::FLAC__StreamDecoderWriteStatus StreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
256 return common_write_callback_(frame);
259 void StreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
261 return common_metadata_callback_(metadata);
264 void StreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
266 return common_error_callback_(status);
269 bool StreamDecoder::die(const char *msg) const
271 State state = get_state();
274 printf("FAILED, %s, state = %u (%s)\n", msg, (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
276 printf("FAILED, state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
281 bool StreamDecoder::test_respond()
283 printf("testing init()... ");
284 if(init() != ::FLAC__STREAM_DECODER_SEARCH_FOR_METADATA)
288 current_metadata_number_ = 0;
290 if(::fseek(file_, 0, SEEK_SET) < 0) {
291 printf("FAILED rewinding input, errno = %d\n", errno);
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());
303 printf("testing finish()... ");
310 static bool test_stream_decoder()
312 StreamDecoder *decoder;
314 printf("\n+++ libFLAC++ unit test: FLAC::Decoder::Stream\n\n");
317 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
319 printf("allocating decoder instance... ");
320 decoder = new StreamDecoder();
322 printf("FAILED, new returned NULL\n");
327 printf("testing is_valid()... ");
328 if(!decoder->is_valid()) {
329 printf("FAILED, returned false\n");
334 printf("testing init()... ");
335 if(decoder->init() != ::FLAC__STREAM_DECODER_SEARCH_FOR_METADATA)
336 return decoder->die();
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());
343 decoder->current_metadata_number_ = 0;
344 decoder->ignore_errors_ = false;
345 decoder->error_occurred_ = false;
347 printf("opening FLAC file... ");
348 decoder->file_ = ::fopen(flacfilename_, "rb");
349 if(0 == decoder->file_) {
355 printf("testing process_metadata()... ");
356 if(!decoder->process_metadata())
357 return decoder->die("returned false");
360 printf("testing process_one_frame()... ");
361 if(!decoder->process_one_frame())
362 return decoder->die("returned false");
365 printf("testing flush()... ");
366 if(!decoder->flush())
367 return decoder->die("returned false");
370 decoder->ignore_errors_ = true;
371 printf("testing process_one_frame()... ");
372 if(!decoder->process_one_frame())
373 return decoder->die("returned false");
375 decoder->ignore_errors_ = false;
377 printf("testing process_remaining_frames()... ");
378 if(!decoder->process_remaining_frames())
379 return decoder->die("returned false");
382 printf("testing get_channels()... ");
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);
392 printf("testing get_bits_per_sample()... ");
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);
402 printf("testing get_sample_rate()... ");
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);
412 printf("testing get_blocksize()... ");
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);
419 printf("testing get_channel_assignment()... ");
421 ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
422 printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
425 printf("testing reset()... ");
426 if(!decoder->reset())
427 return decoder->die("returned false");
430 decoder->current_metadata_number_ = 0;
432 printf("rewinding input... ");
433 if(::fseek(decoder->file_, 0, SEEK_SET) < 0) {
434 printf("FAILED, errno = %d\n", errno);
439 printf("testing process_whole_stream()... ");
440 if(!decoder->process_whole_stream())
441 return decoder->die("returned false");
444 printf("testing finish()... ");
452 printf("testing set_metadata_respond_all()... ");
453 if(!decoder->set_metadata_respond_all()) {
454 printf("FAILED, returned false\n");
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_;
467 if(!decoder->test_respond())
474 printf("testing set_metadata_ignore_all()... ");
475 if(!decoder->set_metadata_ignore_all()) {
476 printf("FAILED, returned false\n");
483 if(!decoder->test_respond())
487 * respond all, ignore VORBIS_COMMENT
490 printf("testing set_metadata_respond_all()... ");
491 if(!decoder->set_metadata_respond_all()) {
492 printf("FAILED, returned false\n");
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");
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_;
511 if(!decoder->test_respond())
515 * respond all, ignore APPLICATION
518 printf("testing set_metadata_respond_all()... ");
519 if(!decoder->set_metadata_respond_all()) {
520 printf("FAILED, returned false\n");
525 printf("testing set_metadata_ignore(APPLICATION)... ");
526 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
527 printf("FAILED, returned false\n");
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_;
538 if(!decoder->test_respond())
542 * respond all, ignore APPLICATION id of app#1
545 printf("testing set_metadata_respond_all()... ");
546 if(!decoder->set_metadata_respond_all()) {
547 printf("FAILED, returned false\n");
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");
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_;
566 if(!decoder->test_respond())
570 * respond all, ignore APPLICATION id of app#1 & app#2
573 printf("testing set_metadata_respond_all()... ");
574 if(!decoder->set_metadata_respond_all()) {
575 printf("FAILED, returned false\n");
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");
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");
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_;
600 if(!decoder->test_respond())
604 * ignore all, respond VORBIS_COMMENT
607 printf("testing set_metadata_ignore_all()... ");
608 if(!decoder->set_metadata_ignore_all()) {
609 printf("FAILED, returned false\n");
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");
622 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
624 if(!decoder->test_respond())
628 * ignore all, respond APPLICATION
631 printf("testing set_metadata_ignore_all()... ");
632 if(!decoder->set_metadata_ignore_all()) {
633 printf("FAILED, returned false\n");
638 printf("testing set_metadata_respond(APPLICATION)... ");
639 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
640 printf("FAILED, returned false\n");
646 expected_metadata_sequence_[num_expected_++] = &application1_;
647 expected_metadata_sequence_[num_expected_++] = &application2_;
649 if(!decoder->test_respond())
653 * ignore all, respond APPLICATION id of app#1
656 printf("testing set_metadata_ignore_all()... ");
657 if(!decoder->set_metadata_ignore_all()) {
658 printf("FAILED, returned false\n");
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");
671 expected_metadata_sequence_[num_expected_++] = &application1_;
673 if(!decoder->test_respond())
677 * ignore all, respond APPLICATION id of app#1 & app#2
680 printf("testing set_metadata_ignore_all()... ");
681 if(!decoder->set_metadata_ignore_all()) {
682 printf("FAILED, returned false\n");
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");
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");
702 expected_metadata_sequence_[num_expected_++] = &application1_;
703 expected_metadata_sequence_[num_expected_++] = &application2_;
705 if(!decoder->test_respond())
709 * respond all, ignore APPLICATION, respond APPLICATION id of app#1
712 printf("testing set_metadata_respond_all()... ");
713 if(!decoder->set_metadata_respond_all()) {
714 printf("FAILED, returned false\n");
719 printf("testing set_metadata_ignore(APPLICATION)... ");
720 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
721 printf("FAILED, returned false\n");
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");
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_;
740 if(!decoder->test_respond())
744 * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
747 printf("testing set_metadata_ignore_all()... ");
748 if(!decoder->set_metadata_ignore_all()) {
749 printf("FAILED, returned false\n");
754 printf("testing set_metadata_respond(APPLICATION)... ");
755 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
756 printf("FAILED, returned false\n");
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");
769 expected_metadata_sequence_[num_expected_++] = &application2_;
771 if(!decoder->test_respond())
774 /* done, now leave the sequence the way we found it... */
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_;
783 ::fclose(decoder->file_);
785 printf("freeing decoder instance... ");
789 printf("\nPASSED!\n");
794 class SeekableStreamDecoder : public FLAC::Decoder::SeekableStream, public DecoderCommon {
796 SeekableStreamDecoder(): FLAC::Decoder::SeekableStream(), DecoderCommon() { }
797 ~SeekableStreamDecoder() { }
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);
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);
809 bool die(const char *msg = 0) const;
814 ::FLAC__SeekableStreamDecoderReadStatus SeekableStreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
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;
824 return ::FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
828 ::FLAC__SeekableStreamDecoderSeekStatus SeekableStreamDecoder::seek_callback(FLAC__uint64 absolute_byte_offset)
831 return ::FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
833 if(::fseek(file_, absolute_byte_offset, SEEK_SET) < 0) {
834 error_occurred_ = true;
835 return ::FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
838 return ::FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
841 ::FLAC__SeekableStreamDecoderTellStatus SeekableStreamDecoder::tell_callback(FLAC__uint64 *absolute_byte_offset)
844 return ::FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
846 long offset = ::ftell(file_);
847 *absolute_byte_offset = (FLAC__uint64)offset;
850 error_occurred_ = true;
851 return ::FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
854 return ::FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;
857 ::FLAC__SeekableStreamDecoderLengthStatus SeekableStreamDecoder::length_callback(FLAC__uint64 *stream_length)
860 return ::FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR;
862 *stream_length = (FLAC__uint64)flacfilesize_;
863 return ::FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;
866 bool SeekableStreamDecoder::eof_callback()
874 ::FLAC__StreamDecoderWriteStatus SeekableStreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
878 return common_write_callback_(frame);
881 void SeekableStreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
883 common_metadata_callback_(metadata);
886 void SeekableStreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
888 common_error_callback_(status);
891 bool SeekableStreamDecoder::die(const char *msg) const
893 State state = get_state();
896 printf("FAILED, %s, state = %u (%s)\n", msg, (unsigned)((::FLAC__SeekableStreamDecoderState)state), state.as_cstring());
898 printf("FAILED, state = %u (%s)\n", (unsigned)((::FLAC__SeekableStreamDecoderState)state), state.as_cstring());
903 bool SeekableStreamDecoder::test_respond()
905 if(!set_md5_checking(true)) {
906 printf("FAILED at set_md5_checking(), returned false\n");
910 printf("testing init()... ");
911 if(init() != ::FLAC__SEEKABLE_STREAM_DECODER_OK)
915 current_metadata_number_ = 0;
917 if(::fseek(file_, 0, SEEK_SET) < 0) {
918 printf("FAILED rewinding input, errno = %d\n", errno);
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());
930 printf("testing finish()... ");
937 static bool test_seekable_stream_decoder()
939 SeekableStreamDecoder *decoder;
941 printf("\n+++ libFLAC++ unit test: FLAC::Decoder::SeekableStream\n\n");
944 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
946 printf("allocating decoder instance... ");
947 decoder = new SeekableStreamDecoder();
949 printf("FAILED, new returned NULL\n");
954 printf("testing is_valid()... ");
955 if(!decoder->is_valid()) {
956 printf("FAILED, returned false\n");
961 printf("testing set_md5_checking()... ");
962 if(!decoder->set_md5_checking(true)) {
963 printf("FAILED, returned false\n");
968 printf("testing init()... ");
969 if(decoder->init() != ::FLAC__SEEKABLE_STREAM_DECODER_OK)
970 return decoder->die();
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());
977 decoder->current_metadata_number_ = 0;
978 decoder->ignore_errors_ = false;
979 decoder->error_occurred_ = false;
981 printf("opening FLAC file... ");
982 decoder->file_ = ::fopen(flacfilename_, "rb");
983 if(0 == decoder->file_) {
989 printf("testing get_md5_checking()... ");
990 if(!decoder->get_md5_checking()) {
991 printf("FAILED, returned false, expected true\n");
996 printf("testing process_metadata()... ");
997 if(!decoder->process_metadata())
998 return decoder->die("returned false");
1001 printf("testing process_one_frame()... ");
1002 if(!decoder->process_one_frame())
1003 return decoder->die("returned false");
1006 printf("testing flush()... ");
1007 if(!decoder->flush())
1008 return decoder->die("returned false");
1011 decoder->ignore_errors_ = true;
1012 printf("testing process_one_frame()... ");
1013 if(!decoder->process_one_frame())
1014 return decoder->die("returned false");
1016 decoder->ignore_errors_ = false;
1018 printf("testing seek_absolute()... ");
1019 if(!decoder->seek_absolute(0))
1020 return decoder->die("returned false");
1023 printf("testing process_remaining_frames()... ");
1024 if(!decoder->process_remaining_frames())
1025 return decoder->die("returned false");
1028 printf("testing get_channels()... ");
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);
1038 printf("testing get_bits_per_sample()... ");
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);
1048 printf("testing get_sample_rate()... ");
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);
1058 printf("testing get_blocksize()... ");
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);
1065 printf("testing get_channel_assignment()... ");
1067 ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
1068 printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
1071 printf("testing reset()... ");
1072 if(!decoder->reset())
1073 return decoder->die("returned false");
1076 decoder->current_metadata_number_ = 0;
1078 printf("rewinding input... ");
1079 if(::fseek(decoder->file_, 0, SEEK_SET) < 0) {
1080 printf("FAILED, errno = %d\n", errno);
1085 printf("testing process_whole_stream()... ");
1086 if(!decoder->process_whole_stream())
1087 return decoder->die("returned false");
1090 printf("testing finish()... ");
1098 printf("testing set_metadata_respond_all()... ");
1099 if(!decoder->set_metadata_respond_all()) {
1100 printf("FAILED, returned false\n");
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_;
1113 if(!decoder->test_respond())
1120 printf("testing set_metadata_ignore_all()... ");
1121 if(!decoder->set_metadata_ignore_all()) {
1122 printf("FAILED, returned false\n");
1129 if(!decoder->test_respond())
1133 * respond all, ignore VORBIS_COMMENT
1136 printf("testing set_metadata_respond_all()... ");
1137 if(!decoder->set_metadata_respond_all()) {
1138 printf("FAILED, returned false\n");
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");
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_;
1157 if(!decoder->test_respond())
1161 * respond all, ignore APPLICATION
1164 printf("testing set_metadata_respond_all()... ");
1165 if(!decoder->set_metadata_respond_all()) {
1166 printf("FAILED, returned false\n");
1171 printf("testing set_metadata_ignore(APPLICATION)... ");
1172 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1173 printf("FAILED, returned false\n");
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_;
1184 if(!decoder->test_respond())
1188 * respond all, ignore APPLICATION id of app#1
1191 printf("testing set_metadata_respond_all()... ");
1192 if(!decoder->set_metadata_respond_all()) {
1193 printf("FAILED, returned false\n");
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");
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_;
1212 if(!decoder->test_respond())
1216 * respond all, ignore APPLICATION id of app#1 & app#2
1219 printf("testing set_metadata_respond_all()... ");
1220 if(!decoder->set_metadata_respond_all()) {
1221 printf("FAILED, returned false\n");
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");
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");
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_;
1246 if(!decoder->test_respond())
1250 * ignore all, respond VORBIS_COMMENT
1253 printf("testing set_metadata_ignore_all()... ");
1254 if(!decoder->set_metadata_ignore_all()) {
1255 printf("FAILED, returned false\n");
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");
1268 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1270 if(!decoder->test_respond())
1274 * ignore all, respond APPLICATION
1277 printf("testing set_metadata_ignore_all()... ");
1278 if(!decoder->set_metadata_ignore_all()) {
1279 printf("FAILED, returned false\n");
1284 printf("testing set_metadata_respond(APPLICATION)... ");
1285 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
1286 printf("FAILED, returned false\n");
1292 expected_metadata_sequence_[num_expected_++] = &application1_;
1293 expected_metadata_sequence_[num_expected_++] = &application2_;
1295 if(!decoder->test_respond())
1299 * ignore all, respond APPLICATION id of app#1
1302 printf("testing set_metadata_ignore_all()... ");
1303 if(!decoder->set_metadata_ignore_all()) {
1304 printf("FAILED, returned false\n");
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");
1317 expected_metadata_sequence_[num_expected_++] = &application1_;
1319 if(!decoder->test_respond())
1323 * ignore all, respond APPLICATION id of app#1 & app#2
1326 printf("testing set_metadata_ignore_all()... ");
1327 if(!decoder->set_metadata_ignore_all()) {
1328 printf("FAILED, returned false\n");
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");
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");
1348 expected_metadata_sequence_[num_expected_++] = &application1_;
1349 expected_metadata_sequence_[num_expected_++] = &application2_;
1351 if(!decoder->test_respond())
1355 * respond all, ignore APPLICATION, respond APPLICATION id of app#1
1358 printf("testing set_metadata_respond_all()... ");
1359 if(!decoder->set_metadata_respond_all()) {
1360 printf("FAILED, returned false\n");
1365 printf("testing set_metadata_ignore(APPLICATION)... ");
1366 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1367 printf("FAILED, returned false\n");
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");
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_;
1386 if(!decoder->test_respond())
1390 * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
1393 printf("testing set_metadata_ignore_all()... ");
1394 if(!decoder->set_metadata_ignore_all()) {
1395 printf("FAILED, returned false\n");
1400 printf("testing set_metadata_respond(APPLICATION)... ");
1401 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
1402 printf("FAILED, returned false\n");
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");
1415 expected_metadata_sequence_[num_expected_++] = &application2_;
1417 if(!decoder->test_respond())
1420 /* done, now leave the sequence the way we found it... */
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_;
1429 ::fclose(decoder->file_);
1431 printf("freeing decoder instance... ");
1435 printf("\nPASSED!\n");
1440 class FileDecoder : public FLAC::Decoder::File, public DecoderCommon {
1442 FileDecoder(): FLAC::Decoder::File(), DecoderCommon() { }
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);
1450 bool die(const char *msg = 0) const;
1452 bool test_respond();
1455 ::FLAC__StreamDecoderWriteStatus FileDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
1458 return common_write_callback_(frame);
1461 void FileDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
1463 common_metadata_callback_(metadata);
1466 void FileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
1468 common_error_callback_(status);
1471 bool FileDecoder::die(const char *msg) const
1473 State state = get_state();
1476 printf("FAILED, %s, state = %u (%s)\n", msg, (unsigned)((::FLAC__FileDecoderState)state), state.as_cstring());
1478 printf("FAILED, state = %u (%s)\n", (unsigned)((::FLAC__FileDecoderState)state), state.as_cstring());
1483 bool FileDecoder::test_respond()
1485 if(!set_filename(flacfilename_)) {
1486 printf("FAILED at set_filename(), returned false\n");
1490 if(!set_md5_checking(true)) {
1491 printf("FAILED at set_md5_checking(), returned false\n");
1495 printf("testing init()... ");
1496 if(init() != ::FLAC__FILE_DECODER_OK)
1500 current_metadata_number_ = 0;
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());
1510 printf("testing finish()... ");
1517 static bool test_file_decoder()
1519 FileDecoder *decoder;
1521 printf("\n+++ libFLAC++ unit test: FLAC::Decoder::File\n\n");
1524 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1526 printf("allocating decoder instance... ");
1527 decoder = new FileDecoder();
1529 printf("FAILED, new returned NULL\n");
1534 printf("testing is_valid()... ");
1535 if(!decoder->is_valid()) {
1536 printf("FAILED, returned false\n");
1541 printf("testing set_filename()... ");
1542 if(!decoder->set_filename(flacfilename_)) {
1543 printf("FAILED, returned false\n");
1548 printf("testing set_md5_checking()... ");
1549 if(!decoder->set_md5_checking(true)) {
1550 printf("FAILED, returned false\n");
1555 printf("testing init()... ");
1556 if(decoder->init() != ::FLAC__FILE_DECODER_OK)
1557 return decoder->die();
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());
1564 decoder->current_metadata_number_ = 0;
1565 decoder->ignore_errors_ = false;
1566 decoder->error_occurred_ = false;
1568 printf("testing get_md5_checking()... ");
1569 if(!decoder->get_md5_checking()) {
1570 printf("FAILED, returned false, expected true\n");
1575 printf("testing process_metadata()... ");
1576 if(!decoder->process_metadata())
1577 return decoder->die("returned false");
1580 printf("testing process_one_frame()... ");
1581 if(!decoder->process_one_frame())
1582 return decoder->die("returned false");
1585 printf("testing seek_absolute()... ");
1586 if(!decoder->seek_absolute(0))
1587 return decoder->die("returned false");
1590 printf("testing process_remaining_frames()... ");
1591 if(!decoder->process_remaining_frames())
1592 return decoder->die("returned false");
1595 printf("testing get_channels()... ");
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);
1605 printf("testing get_bits_per_sample()... ");
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);
1615 printf("testing get_sample_rate()... ");
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);
1625 printf("testing get_blocksize()... ");
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);
1632 printf("testing get_channel_assignment()... ");
1634 ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
1635 printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
1638 printf("testing finish()... ");
1646 printf("testing set_metadata_respond_all()... ");
1647 if(!decoder->set_metadata_respond_all()) {
1648 printf("FAILED, returned false\n");
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_;
1661 if(!decoder->test_respond())
1668 printf("testing set_metadata_ignore_all()... ");
1669 if(!decoder->set_metadata_ignore_all()) {
1670 printf("FAILED, returned false\n");
1677 if(!decoder->test_respond())
1681 * respond all, ignore VORBIS_COMMENT
1684 printf("testing set_metadata_respond_all()... ");
1685 if(!decoder->set_metadata_respond_all()) {
1686 printf("FAILED, returned false\n");
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");
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_;
1705 if(!decoder->test_respond())
1709 * respond all, ignore APPLICATION
1712 printf("testing set_metadata_respond_all()... ");
1713 if(!decoder->set_metadata_respond_all()) {
1714 printf("FAILED, returned false\n");
1719 printf("testing set_metadata_ignore(APPLICATION)... ");
1720 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1721 printf("FAILED, returned false\n");
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_;
1732 if(!decoder->test_respond())
1736 * respond all, ignore APPLICATION id of app#1
1739 printf("testing set_metadata_respond_all()... ");
1740 if(!decoder->set_metadata_respond_all()) {
1741 printf("FAILED, returned false\n");
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");
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_;
1760 if(!decoder->test_respond())
1764 * respond all, ignore APPLICATION id of app#1 & app#2
1767 printf("testing set_metadata_respond_all()... ");
1768 if(!decoder->set_metadata_respond_all()) {
1769 printf("FAILED, returned false\n");
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");
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");
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_;
1794 if(!decoder->test_respond())
1798 * ignore all, respond VORBIS_COMMENT
1801 printf("testing set_metadata_ignore_all()... ");
1802 if(!decoder->set_metadata_ignore_all()) {
1803 printf("FAILED, returned false\n");
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");
1816 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1818 if(!decoder->test_respond())
1822 * ignore all, respond APPLICATION
1825 printf("testing set_metadata_ignore_all()... ");
1826 if(!decoder->set_metadata_ignore_all()) {
1827 printf("FAILED, returned false\n");
1832 printf("testing set_metadata_respond(APPLICATION)... ");
1833 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
1834 printf("FAILED, returned false\n");
1840 expected_metadata_sequence_[num_expected_++] = &application1_;
1841 expected_metadata_sequence_[num_expected_++] = &application2_;
1843 if(!decoder->test_respond())
1847 * ignore all, respond APPLICATION id of app#1
1850 printf("testing set_metadata_ignore_all()... ");
1851 if(!decoder->set_metadata_ignore_all()) {
1852 printf("FAILED, returned false\n");
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");
1865 expected_metadata_sequence_[num_expected_++] = &application1_;
1867 if(!decoder->test_respond())
1871 * ignore all, respond APPLICATION id of app#1 & app#2
1874 printf("testing set_metadata_ignore_all()... ");
1875 if(!decoder->set_metadata_ignore_all()) {
1876 printf("FAILED, returned false\n");
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");
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");
1896 expected_metadata_sequence_[num_expected_++] = &application1_;
1897 expected_metadata_sequence_[num_expected_++] = &application2_;
1899 if(!decoder->test_respond())
1903 * respond all, ignore APPLICATION, respond APPLICATION id of app#1
1906 printf("testing set_metadata_respond_all()... ");
1907 if(!decoder->set_metadata_respond_all()) {
1908 printf("FAILED, returned false\n");
1913 printf("testing set_metadata_ignore(APPLICATION)... ");
1914 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1915 printf("FAILED, returned false\n");
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");
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_;
1934 if(!decoder->test_respond())
1938 * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
1941 printf("testing set_metadata_ignore_all()... ");
1942 if(!decoder->set_metadata_ignore_all()) {
1943 printf("FAILED, returned false\n");
1948 printf("testing set_metadata_respond(APPLICATION)... ");
1949 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
1950 printf("FAILED, returned false\n");
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");
1963 expected_metadata_sequence_[num_expected_++] = &application2_;
1965 if(!decoder->test_respond())
1968 /* done, now leave the sequence the way we found it... */
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_;
1977 printf("freeing decoder instance... ");
1981 printf("\nPASSED!\n");
1986 bool test_decoders()
1988 init_metadata_blocks_();
1989 if(!generate_file_())
1992 if(!test_stream_decoder())
1995 if(!test_seekable_stream_decoder())
1998 if(!test_file_decoder())
2001 (void) file_utils__remove_file(flacfilename_);
2002 free_metadata_blocks_();