1 /* test_libFLAC++ - Unit tester for libFLAC++
2 * Copyright (C) 2002,2003,2004 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"
22 #include "metadata_utils.h"
24 #include "FLAC/assert.h"
25 #include "FLAC/metadata.h" // for ::FLAC__metadata_object_is_equal()
26 #include "FLAC++/decoder.h"
27 #include "share/grabbag.h"
33 static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, unknown_;
34 static ::FLAC__StreamMetadata *expected_metadata_sequence_[8];
35 static unsigned num_expected_;
36 static const char *flacfilename_ = "metadata.flac";
37 static unsigned flacfilesize_;
39 static bool die_(const char *msg)
41 printf("ERROR: %s\n", msg);
45 static void init_metadata_blocks_()
47 mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
50 static void free_metadata_blocks_()
52 mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
55 static bool generate_file_()
57 printf("\n\ngenerating FLAC file for decoder tests...\n");
60 expected_metadata_sequence_[num_expected_++] = &padding_;
61 expected_metadata_sequence_[num_expected_++] = &seektable_;
62 expected_metadata_sequence_[num_expected_++] = &application1_;
63 expected_metadata_sequence_[num_expected_++] = &application2_;
64 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
65 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
66 expected_metadata_sequence_[num_expected_++] = &unknown_;
68 if(!file_utils__generate_flacfile(flacfilename_, &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
69 return die_("creating the encoded file");
78 unsigned current_metadata_number_;
82 DecoderCommon(): file_(0), current_metadata_number_(0), ignore_errors_(false), error_occurred_(false) { }
83 ::FLAC__StreamDecoderReadStatus common_read_callback_(FLAC__byte buffer[], unsigned *bytes);
84 ::FLAC__StreamDecoderWriteStatus common_write_callback_(const ::FLAC__Frame *frame);
85 void common_metadata_callback_(const ::FLAC__StreamMetadata *metadata);
86 void common_error_callback_(::FLAC__StreamDecoderErrorStatus status);
89 ::FLAC__StreamDecoderReadStatus DecoderCommon::common_read_callback_(FLAC__byte buffer[], unsigned *bytes)
92 return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT;
95 return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
97 unsigned bytes_read = ::fread(buffer, 1, *bytes, file_);
100 return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
102 return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
106 return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
110 return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
113 ::FLAC__StreamDecoderWriteStatus DecoderCommon::common_write_callback_(const ::FLAC__Frame *frame)
116 return ::FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
119 (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) ||
120 (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0)
122 printf("content... ");
126 return ::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
129 void DecoderCommon::common_metadata_callback_(const ::FLAC__StreamMetadata *metadata)
134 printf("%d... ", current_metadata_number_);
137 if(current_metadata_number_ >= num_expected_) {
138 (void)die_("got more metadata blocks than expected");
139 error_occurred_ = true;
142 if(!::FLAC__metadata_object_is_equal(expected_metadata_sequence_[current_metadata_number_], metadata)) {
143 (void)die_("metadata block mismatch");
144 error_occurred_ = true;
147 current_metadata_number_++;
150 void DecoderCommon::common_error_callback_(::FLAC__StreamDecoderErrorStatus status)
152 if(!ignore_errors_) {
153 printf("ERROR: got error callback: err = %u (%s)\n", (unsigned)status, ::FLAC__StreamDecoderErrorStatusString[status]);
154 error_occurred_ = true;
158 class StreamDecoder : public FLAC::Decoder::Stream, public DecoderCommon {
160 StreamDecoder(): FLAC::Decoder::Stream(), DecoderCommon() { }
163 // from FLAC::Decoder::Stream
164 ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
165 ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
166 void metadata_callback(const ::FLAC__StreamMetadata *metadata);
167 void error_callback(::FLAC__StreamDecoderErrorStatus status);
169 bool die(const char *msg = 0) const;
174 ::FLAC__StreamDecoderReadStatus StreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
176 return common_read_callback_(buffer, bytes);
179 ::FLAC__StreamDecoderWriteStatus StreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
183 return common_write_callback_(frame);
186 void StreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
188 common_metadata_callback_(metadata);
191 void StreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
193 common_error_callback_(status);
196 bool StreamDecoder::die(const char *msg) const
198 State state = get_state();
201 printf("FAILED, %s", msg);
205 printf(", state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
210 bool StreamDecoder::test_respond()
212 printf("testing init()... ");
213 if(init() != ::FLAC__STREAM_DECODER_SEARCH_FOR_METADATA)
217 current_metadata_number_ = 0;
219 if(::fseek(file_, 0, SEEK_SET) < 0) {
220 printf("FAILED rewinding input, errno = %d\n", errno);
224 printf("testing process_until_end_of_stream()... ");
225 if(!process_until_end_of_stream()) {
226 State state = get_state();
227 printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
232 printf("testing finish()... ");
239 static bool test_stream_decoder()
241 StreamDecoder *decoder;
243 printf("\n+++ libFLAC++ unit test: FLAC::Decoder::Stream\n\n");
246 // test new -> delete
248 printf("allocating decoder instance... ");
249 decoder = new StreamDecoder();
251 printf("FAILED, new returned NULL\n");
256 printf("testing is_valid()... ");
257 if(!decoder->is_valid()) {
258 printf("FAILED, returned false\n");
263 printf("freeing decoder instance... ");
268 // test new -> init -> delete
270 printf("allocating decoder instance... ");
271 decoder = new StreamDecoder();
273 printf("FAILED, new returned NULL\n");
278 printf("testing is_valid()... ");
279 if(!decoder->is_valid()) {
280 printf("FAILED, returned false\n");
285 printf("testing init()... ");
286 if(decoder->init() != ::FLAC__STREAM_DECODER_SEARCH_FOR_METADATA)
287 return decoder->die();
290 printf("freeing decoder instance... ");
298 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
300 printf("allocating decoder instance... ");
301 decoder = new StreamDecoder();
303 printf("FAILED, new returned NULL\n");
308 printf("testing is_valid()... ");
309 if(!decoder->is_valid()) {
310 printf("FAILED, returned false\n");
315 printf("testing init()... ");
316 if(decoder->init() != ::FLAC__STREAM_DECODER_SEARCH_FOR_METADATA)
317 return decoder->die();
320 printf("testing get_state()... ");
321 FLAC::Decoder::Stream::State state = decoder->get_state();
322 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
324 decoder->current_metadata_number_ = 0;
325 decoder->ignore_errors_ = false;
326 decoder->error_occurred_ = false;
328 printf("opening FLAC file... ");
329 decoder->file_ = ::fopen(flacfilename_, "rb");
330 if(0 == decoder->file_) {
336 printf("testing process_until_end_of_metadata()... ");
337 if(!decoder->process_until_end_of_metadata())
338 return decoder->die("returned false");
341 printf("testing process_single()... ");
342 if(!decoder->process_single())
343 return decoder->die("returned false");
346 printf("testing flush()... ");
347 if(!decoder->flush())
348 return decoder->die("returned false");
351 decoder->ignore_errors_ = true;
352 printf("testing process_single()... ");
353 if(!decoder->process_single())
354 return decoder->die("returned false");
356 decoder->ignore_errors_ = false;
358 printf("testing process_until_end_of_stream()... ");
359 if(!decoder->process_until_end_of_stream())
360 return decoder->die("returned false");
363 printf("testing get_channels()... ");
365 unsigned channels = decoder->get_channels();
366 if(channels != streaminfo_.data.stream_info.channels) {
367 printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
373 printf("testing get_bits_per_sample()... ");
375 unsigned bits_per_sample = decoder->get_bits_per_sample();
376 if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
377 printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
383 printf("testing get_sample_rate()... ");
385 unsigned sample_rate = decoder->get_sample_rate();
386 if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
387 printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
393 printf("testing get_blocksize()... ");
395 unsigned blocksize = decoder->get_blocksize();
396 /* value could be anything since we're at the last block, so accept any answer */
397 printf("returned %u... OK\n", blocksize);
400 printf("testing get_channel_assignment()... ");
402 ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
403 printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
406 printf("testing reset()... ");
407 if(!decoder->reset())
408 return decoder->die("returned false");
411 decoder->current_metadata_number_ = 0;
413 printf("rewinding input... ");
414 if(::fseek(decoder->file_, 0, SEEK_SET) < 0) {
415 printf("FAILED, errno = %d\n", errno);
420 printf("testing process_until_end_of_stream()... ");
421 if(!decoder->process_until_end_of_stream())
422 return decoder->die("returned false");
425 printf("testing finish()... ");
433 printf("testing set_metadata_respond_all()... ");
434 if(!decoder->set_metadata_respond_all()) {
435 printf("FAILED, returned false\n");
441 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
442 expected_metadata_sequence_[num_expected_++] = &padding_;
443 expected_metadata_sequence_[num_expected_++] = &seektable_;
444 expected_metadata_sequence_[num_expected_++] = &application1_;
445 expected_metadata_sequence_[num_expected_++] = &application2_;
446 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
447 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
448 expected_metadata_sequence_[num_expected_++] = &unknown_;
450 if(!decoder->test_respond())
457 printf("testing set_metadata_ignore_all()... ");
458 if(!decoder->set_metadata_ignore_all()) {
459 printf("FAILED, returned false\n");
466 if(!decoder->test_respond())
470 * respond all, ignore VORBIS_COMMENT
473 printf("testing set_metadata_respond_all()... ");
474 if(!decoder->set_metadata_respond_all()) {
475 printf("FAILED, returned false\n");
480 printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
481 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
482 printf("FAILED, returned false\n");
488 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
489 expected_metadata_sequence_[num_expected_++] = &padding_;
490 expected_metadata_sequence_[num_expected_++] = &seektable_;
491 expected_metadata_sequence_[num_expected_++] = &application1_;
492 expected_metadata_sequence_[num_expected_++] = &application2_;
493 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
494 expected_metadata_sequence_[num_expected_++] = &unknown_;
496 if(!decoder->test_respond())
500 * respond all, ignore APPLICATION
503 printf("testing set_metadata_respond_all()... ");
504 if(!decoder->set_metadata_respond_all()) {
505 printf("FAILED, returned false\n");
510 printf("testing set_metadata_ignore(APPLICATION)... ");
511 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
512 printf("FAILED, returned false\n");
518 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
519 expected_metadata_sequence_[num_expected_++] = &padding_;
520 expected_metadata_sequence_[num_expected_++] = &seektable_;
521 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
522 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
523 expected_metadata_sequence_[num_expected_++] = &unknown_;
525 if(!decoder->test_respond())
529 * respond all, ignore APPLICATION id of app#1
532 printf("testing set_metadata_respond_all()... ");
533 if(!decoder->set_metadata_respond_all()) {
534 printf("FAILED, returned false\n");
539 printf("testing set_metadata_ignore_application(of app block #1)... ");
540 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
541 printf("FAILED, returned false\n");
547 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
548 expected_metadata_sequence_[num_expected_++] = &padding_;
549 expected_metadata_sequence_[num_expected_++] = &seektable_;
550 expected_metadata_sequence_[num_expected_++] = &application2_;
551 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
552 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
553 expected_metadata_sequence_[num_expected_++] = &unknown_;
555 if(!decoder->test_respond())
559 * respond all, ignore APPLICATION id of app#1 & app#2
562 printf("testing set_metadata_respond_all()... ");
563 if(!decoder->set_metadata_respond_all()) {
564 printf("FAILED, returned false\n");
569 printf("testing set_metadata_ignore_application(of app block #1)... ");
570 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
571 printf("FAILED, returned false\n");
576 printf("testing set_metadata_ignore_application(of app block #2)... ");
577 if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
578 printf("FAILED, returned false\n");
584 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
585 expected_metadata_sequence_[num_expected_++] = &padding_;
586 expected_metadata_sequence_[num_expected_++] = &seektable_;
587 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
588 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
589 expected_metadata_sequence_[num_expected_++] = &unknown_;
591 if(!decoder->test_respond())
595 * ignore all, respond VORBIS_COMMENT
598 printf("testing set_metadata_ignore_all()... ");
599 if(!decoder->set_metadata_ignore_all()) {
600 printf("FAILED, returned false\n");
605 printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
606 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
607 printf("FAILED, returned false\n");
613 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
615 if(!decoder->test_respond())
619 * ignore all, respond APPLICATION
622 printf("testing set_metadata_ignore_all()... ");
623 if(!decoder->set_metadata_ignore_all()) {
624 printf("FAILED, returned false\n");
629 printf("testing set_metadata_respond(APPLICATION)... ");
630 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
631 printf("FAILED, returned false\n");
637 expected_metadata_sequence_[num_expected_++] = &application1_;
638 expected_metadata_sequence_[num_expected_++] = &application2_;
640 if(!decoder->test_respond())
644 * ignore all, respond APPLICATION id of app#1
647 printf("testing set_metadata_ignore_all()... ");
648 if(!decoder->set_metadata_ignore_all()) {
649 printf("FAILED, returned false\n");
654 printf("testing set_metadata_respond_application(of app block #1)... ");
655 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
656 printf("FAILED, returned false\n");
662 expected_metadata_sequence_[num_expected_++] = &application1_;
664 if(!decoder->test_respond())
668 * ignore all, respond APPLICATION id of app#1 & app#2
671 printf("testing set_metadata_ignore_all()... ");
672 if(!decoder->set_metadata_ignore_all()) {
673 printf("FAILED, returned false\n");
678 printf("testing set_metadata_respond_application(of app block #1)... ");
679 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
680 printf("FAILED, returned false\n");
685 printf("testing set_metadata_respond_application(of app block #2)... ");
686 if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
687 printf("FAILED, returned false\n");
693 expected_metadata_sequence_[num_expected_++] = &application1_;
694 expected_metadata_sequence_[num_expected_++] = &application2_;
696 if(!decoder->test_respond())
700 * respond all, ignore APPLICATION, respond APPLICATION id of app#1
703 printf("testing set_metadata_respond_all()... ");
704 if(!decoder->set_metadata_respond_all()) {
705 printf("FAILED, returned false\n");
710 printf("testing set_metadata_ignore(APPLICATION)... ");
711 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
712 printf("FAILED, returned false\n");
717 printf("testing set_metadata_respond_application(of app block #1)... ");
718 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
719 printf("FAILED, returned false\n");
725 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
726 expected_metadata_sequence_[num_expected_++] = &padding_;
727 expected_metadata_sequence_[num_expected_++] = &seektable_;
728 expected_metadata_sequence_[num_expected_++] = &application1_;
729 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
730 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
731 expected_metadata_sequence_[num_expected_++] = &unknown_;
733 if(!decoder->test_respond())
737 * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
740 printf("testing set_metadata_ignore_all()... ");
741 if(!decoder->set_metadata_ignore_all()) {
742 printf("FAILED, returned false\n");
747 printf("testing set_metadata_respond(APPLICATION)... ");
748 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
749 printf("FAILED, returned false\n");
754 printf("testing set_metadata_ignore_application(of app block #1)... ");
755 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
756 printf("FAILED, returned false\n");
762 expected_metadata_sequence_[num_expected_++] = &application2_;
764 if(!decoder->test_respond())
767 /* done, now leave the sequence the way we found it... */
769 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
770 expected_metadata_sequence_[num_expected_++] = &padding_;
771 expected_metadata_sequence_[num_expected_++] = &seektable_;
772 expected_metadata_sequence_[num_expected_++] = &application1_;
773 expected_metadata_sequence_[num_expected_++] = &application2_;
774 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
775 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
776 expected_metadata_sequence_[num_expected_++] = &unknown_;
778 ::fclose(decoder->file_);
780 printf("freeing decoder instance... ");
784 printf("\nPASSED!\n");
789 class SeekableStreamDecoder : public FLAC::Decoder::SeekableStream, public DecoderCommon {
791 SeekableStreamDecoder(): FLAC::Decoder::SeekableStream(), DecoderCommon() { }
792 ~SeekableStreamDecoder() { }
794 // from FLAC::Decoder::SeekableStream
795 ::FLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
796 ::FLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
797 ::FLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
798 ::FLAC__SeekableStreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length);
800 ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
801 void metadata_callback(const ::FLAC__StreamMetadata *metadata);
802 void error_callback(::FLAC__StreamDecoderErrorStatus status);
804 bool die(const char *msg = 0) const;
809 ::FLAC__SeekableStreamDecoderReadStatus SeekableStreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
811 switch(common_read_callback_(buffer, bytes)) {
812 case ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
813 return ::FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
814 case ::FLAC__STREAM_DECODER_READ_STATUS_ABORT:
815 case ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
816 return ::FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
819 return ::FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
823 ::FLAC__SeekableStreamDecoderSeekStatus SeekableStreamDecoder::seek_callback(FLAC__uint64 absolute_byte_offset)
826 return ::FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
828 if(::fseek(file_, (long)absolute_byte_offset, SEEK_SET) < 0) {
829 error_occurred_ = true;
830 return ::FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
833 return ::FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
836 ::FLAC__SeekableStreamDecoderTellStatus SeekableStreamDecoder::tell_callback(FLAC__uint64 *absolute_byte_offset)
839 return ::FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
841 long offset = ::ftell(file_);
842 *absolute_byte_offset = (FLAC__uint64)offset;
845 error_occurred_ = true;
846 return ::FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
849 return ::FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;
852 ::FLAC__SeekableStreamDecoderLengthStatus SeekableStreamDecoder::length_callback(FLAC__uint64 *stream_length)
855 return ::FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR;
857 *stream_length = (FLAC__uint64)flacfilesize_;
858 return ::FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;
861 bool SeekableStreamDecoder::eof_callback()
866 return (bool)feof(file_);
869 ::FLAC__StreamDecoderWriteStatus SeekableStreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
873 return common_write_callback_(frame);
876 void SeekableStreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
878 common_metadata_callback_(metadata);
881 void SeekableStreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
883 common_error_callback_(status);
886 bool SeekableStreamDecoder::die(const char *msg) const
888 State state = get_state();
891 printf("FAILED, %s", msg);
895 printf(", state = %u (%s)\n", (unsigned)((::FLAC__SeekableStreamDecoderState)state), state.as_cstring());
896 if(state == ::FLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR) {
897 FLAC::Decoder::Stream::State state_ = get_stream_decoder_state();
898 printf(" stream decoder state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state_), state_.as_cstring());
904 bool SeekableStreamDecoder::test_respond()
906 if(!set_md5_checking(true)) {
907 printf("FAILED at set_md5_checking(), returned false\n");
911 printf("testing init()... ");
912 if(init() != ::FLAC__SEEKABLE_STREAM_DECODER_OK)
916 current_metadata_number_ = 0;
918 if(::fseek(file_, 0, SEEK_SET) < 0) {
919 printf("FAILED rewinding input, errno = %d\n", errno);
923 printf("testing process_until_end_of_stream()... ");
924 if(!process_until_end_of_stream()) {
925 State state = get_state();
926 printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::FLAC__SeekableStreamDecoderState)state), state.as_cstring());
931 printf("testing finish()... ");
938 static bool test_seekable_stream_decoder()
940 SeekableStreamDecoder *decoder;
942 printf("\n+++ libFLAC++ unit test: FLAC::Decoder::SeekableStream\n\n");
945 // test new -> delete
947 printf("allocating decoder instance... ");
948 decoder = new SeekableStreamDecoder();
950 printf("FAILED, new returned NULL\n");
955 printf("testing is_valid()... ");
956 if(!decoder->is_valid()) {
957 printf("FAILED, returned false\n");
962 printf("freeing decoder instance... ");
967 // test new -> init -> delete
969 printf("allocating decoder instance... ");
970 decoder = new SeekableStreamDecoder();
972 printf("FAILED, new returned NULL\n");
977 printf("testing is_valid()... ");
978 if(!decoder->is_valid()) {
979 printf("FAILED, returned false\n");
984 printf("testing init()... ");
985 if(decoder->init() != ::FLAC__SEEKABLE_STREAM_DECODER_OK)
986 return decoder->die();
989 printf("freeing decoder instance... ");
997 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
999 printf("allocating decoder instance... ");
1000 decoder = new SeekableStreamDecoder();
1002 printf("FAILED, new returned NULL\n");
1007 printf("testing is_valid()... ");
1008 if(!decoder->is_valid()) {
1009 printf("FAILED, returned false\n");
1014 printf("testing set_md5_checking()... ");
1015 if(!decoder->set_md5_checking(true)) {
1016 printf("FAILED, returned false\n");
1021 printf("testing init()... ");
1022 if(decoder->init() != ::FLAC__SEEKABLE_STREAM_DECODER_OK)
1023 return decoder->die();
1026 printf("testing get_state()... ");
1027 FLAC::Decoder::SeekableStream::State state = decoder->get_state();
1028 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__SeekableStreamDecoderState)state), state.as_cstring());
1030 printf("testing get_stream_decoder_state()... ");
1031 FLAC::Decoder::Stream::State state_ = decoder->get_stream_decoder_state();
1032 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state_), state_.as_cstring());
1034 decoder->current_metadata_number_ = 0;
1035 decoder->ignore_errors_ = false;
1036 decoder->error_occurred_ = false;
1038 printf("opening FLAC file... ");
1039 decoder->file_ = ::fopen(flacfilename_, "rb");
1040 if(0 == decoder->file_) {
1046 printf("testing get_md5_checking()... ");
1047 if(!decoder->get_md5_checking()) {
1048 printf("FAILED, returned false, expected true\n");
1053 printf("testing process_until_end_of_metadata()... ");
1054 if(!decoder->process_until_end_of_metadata())
1055 return decoder->die("returned false");
1058 printf("testing process_single()... ");
1059 if(!decoder->process_single())
1060 return decoder->die("returned false");
1063 printf("testing flush()... ");
1064 if(!decoder->flush())
1065 return decoder->die("returned false");
1068 decoder->ignore_errors_ = true;
1069 printf("testing process_single()... ");
1070 if(!decoder->process_single())
1071 return decoder->die("returned false");
1073 decoder->ignore_errors_ = false;
1075 printf("testing seek_absolute()... ");
1076 if(!decoder->seek_absolute(0))
1077 return decoder->die("returned false");
1080 printf("testing process_until_end_of_stream()... ");
1081 if(!decoder->process_until_end_of_stream())
1082 return decoder->die("returned false");
1085 printf("testing get_channels()... ");
1087 unsigned channels = decoder->get_channels();
1088 if(channels != streaminfo_.data.stream_info.channels) {
1089 printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
1095 printf("testing get_bits_per_sample()... ");
1097 unsigned bits_per_sample = decoder->get_bits_per_sample();
1098 if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
1099 printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
1105 printf("testing get_sample_rate()... ");
1107 unsigned sample_rate = decoder->get_sample_rate();
1108 if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
1109 printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
1115 printf("testing get_blocksize()... ");
1117 unsigned blocksize = decoder->get_blocksize();
1118 /* value could be anything since we're at the last block, so accept any answer */
1119 printf("returned %u... OK\n", blocksize);
1122 printf("testing get_channel_assignment()... ");
1124 ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
1125 printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
1128 printf("testing reset()... ");
1129 if(!decoder->reset())
1130 return decoder->die("returned false");
1133 decoder->current_metadata_number_ = 0;
1135 printf("rewinding input... ");
1136 if(::fseek(decoder->file_, 0, SEEK_SET) < 0) {
1137 printf("FAILED, errno = %d\n", errno);
1142 printf("testing process_until_end_of_stream()... ");
1143 if(!decoder->process_until_end_of_stream())
1144 return decoder->die("returned false");
1147 printf("testing finish()... ");
1155 printf("testing set_metadata_respond_all()... ");
1156 if(!decoder->set_metadata_respond_all()) {
1157 printf("FAILED, returned false\n");
1163 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1164 expected_metadata_sequence_[num_expected_++] = &padding_;
1165 expected_metadata_sequence_[num_expected_++] = &seektable_;
1166 expected_metadata_sequence_[num_expected_++] = &application1_;
1167 expected_metadata_sequence_[num_expected_++] = &application2_;
1168 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1169 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1170 expected_metadata_sequence_[num_expected_++] = &unknown_;
1172 if(!decoder->test_respond())
1179 printf("testing set_metadata_ignore_all()... ");
1180 if(!decoder->set_metadata_ignore_all()) {
1181 printf("FAILED, returned false\n");
1188 if(!decoder->test_respond())
1192 * respond all, ignore VORBIS_COMMENT
1195 printf("testing set_metadata_respond_all()... ");
1196 if(!decoder->set_metadata_respond_all()) {
1197 printf("FAILED, returned false\n");
1202 printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
1203 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
1204 printf("FAILED, returned false\n");
1210 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1211 expected_metadata_sequence_[num_expected_++] = &padding_;
1212 expected_metadata_sequence_[num_expected_++] = &seektable_;
1213 expected_metadata_sequence_[num_expected_++] = &application1_;
1214 expected_metadata_sequence_[num_expected_++] = &application2_;
1215 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1216 expected_metadata_sequence_[num_expected_++] = &unknown_;
1218 if(!decoder->test_respond())
1222 * respond all, ignore APPLICATION
1225 printf("testing set_metadata_respond_all()... ");
1226 if(!decoder->set_metadata_respond_all()) {
1227 printf("FAILED, returned false\n");
1232 printf("testing set_metadata_ignore(APPLICATION)... ");
1233 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1234 printf("FAILED, returned false\n");
1240 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1241 expected_metadata_sequence_[num_expected_++] = &padding_;
1242 expected_metadata_sequence_[num_expected_++] = &seektable_;
1243 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1244 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1245 expected_metadata_sequence_[num_expected_++] = &unknown_;
1247 if(!decoder->test_respond())
1251 * respond all, ignore APPLICATION id of app#1
1254 printf("testing set_metadata_respond_all()... ");
1255 if(!decoder->set_metadata_respond_all()) {
1256 printf("FAILED, returned false\n");
1261 printf("testing set_metadata_ignore_application(of app block #1)... ");
1262 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1263 printf("FAILED, returned false\n");
1269 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1270 expected_metadata_sequence_[num_expected_++] = &padding_;
1271 expected_metadata_sequence_[num_expected_++] = &seektable_;
1272 expected_metadata_sequence_[num_expected_++] = &application2_;
1273 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1274 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1275 expected_metadata_sequence_[num_expected_++] = &unknown_;
1277 if(!decoder->test_respond())
1281 * respond all, ignore APPLICATION id of app#1 & app#2
1284 printf("testing set_metadata_respond_all()... ");
1285 if(!decoder->set_metadata_respond_all()) {
1286 printf("FAILED, returned false\n");
1291 printf("testing set_metadata_ignore_application(of app block #1)... ");
1292 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1293 printf("FAILED, returned false\n");
1298 printf("testing set_metadata_ignore_application(of app block #2)... ");
1299 if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
1300 printf("FAILED, returned false\n");
1306 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1307 expected_metadata_sequence_[num_expected_++] = &padding_;
1308 expected_metadata_sequence_[num_expected_++] = &seektable_;
1309 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1310 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1311 expected_metadata_sequence_[num_expected_++] = &unknown_;
1313 if(!decoder->test_respond())
1317 * ignore all, respond VORBIS_COMMENT
1320 printf("testing set_metadata_ignore_all()... ");
1321 if(!decoder->set_metadata_ignore_all()) {
1322 printf("FAILED, returned false\n");
1327 printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
1328 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
1329 printf("FAILED, returned false\n");
1335 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1337 if(!decoder->test_respond())
1341 * ignore all, respond APPLICATION
1344 printf("testing set_metadata_ignore_all()... ");
1345 if(!decoder->set_metadata_ignore_all()) {
1346 printf("FAILED, returned false\n");
1351 printf("testing set_metadata_respond(APPLICATION)... ");
1352 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
1353 printf("FAILED, returned false\n");
1359 expected_metadata_sequence_[num_expected_++] = &application1_;
1360 expected_metadata_sequence_[num_expected_++] = &application2_;
1362 if(!decoder->test_respond())
1366 * ignore all, respond APPLICATION id of app#1
1369 printf("testing set_metadata_ignore_all()... ");
1370 if(!decoder->set_metadata_ignore_all()) {
1371 printf("FAILED, returned false\n");
1376 printf("testing set_metadata_respond_application(of app block #1)... ");
1377 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1378 printf("FAILED, returned false\n");
1384 expected_metadata_sequence_[num_expected_++] = &application1_;
1386 if(!decoder->test_respond())
1390 * ignore all, respond APPLICATION id of app#1 & app#2
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(of app block #1)... ");
1401 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1402 printf("FAILED, returned false\n");
1407 printf("testing set_metadata_respond_application(of app block #2)... ");
1408 if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
1409 printf("FAILED, returned false\n");
1415 expected_metadata_sequence_[num_expected_++] = &application1_;
1416 expected_metadata_sequence_[num_expected_++] = &application2_;
1418 if(!decoder->test_respond())
1422 * respond all, ignore APPLICATION, respond APPLICATION id of app#1
1425 printf("testing set_metadata_respond_all()... ");
1426 if(!decoder->set_metadata_respond_all()) {
1427 printf("FAILED, returned false\n");
1432 printf("testing set_metadata_ignore(APPLICATION)... ");
1433 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1434 printf("FAILED, returned false\n");
1439 printf("testing set_metadata_respond_application(of app block #1)... ");
1440 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1441 printf("FAILED, returned false\n");
1447 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1448 expected_metadata_sequence_[num_expected_++] = &padding_;
1449 expected_metadata_sequence_[num_expected_++] = &seektable_;
1450 expected_metadata_sequence_[num_expected_++] = &application1_;
1451 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1452 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1453 expected_metadata_sequence_[num_expected_++] = &unknown_;
1455 if(!decoder->test_respond())
1459 * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
1462 printf("testing set_metadata_ignore_all()... ");
1463 if(!decoder->set_metadata_ignore_all()) {
1464 printf("FAILED, returned false\n");
1469 printf("testing set_metadata_respond(APPLICATION)... ");
1470 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
1471 printf("FAILED, returned false\n");
1476 printf("testing set_metadata_ignore_application(of app block #1)... ");
1477 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1478 printf("FAILED, returned false\n");
1484 expected_metadata_sequence_[num_expected_++] = &application2_;
1486 if(!decoder->test_respond())
1489 /* done, now leave the sequence the way we found it... */
1491 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1492 expected_metadata_sequence_[num_expected_++] = &padding_;
1493 expected_metadata_sequence_[num_expected_++] = &seektable_;
1494 expected_metadata_sequence_[num_expected_++] = &application1_;
1495 expected_metadata_sequence_[num_expected_++] = &application2_;
1496 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1497 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1498 expected_metadata_sequence_[num_expected_++] = &unknown_;
1500 ::fclose(decoder->file_);
1502 printf("freeing decoder instance... ");
1506 printf("\nPASSED!\n");
1511 class FileDecoder : public FLAC::Decoder::File, public DecoderCommon {
1513 FileDecoder(): FLAC::Decoder::File(), DecoderCommon() { }
1516 // from FLAC::Decoder::File
1517 ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
1518 void metadata_callback(const ::FLAC__StreamMetadata *metadata);
1519 void error_callback(::FLAC__StreamDecoderErrorStatus status);
1521 bool die(const char *msg = 0) const;
1523 bool test_respond();
1526 ::FLAC__StreamDecoderWriteStatus FileDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
1529 return common_write_callback_(frame);
1532 void FileDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
1534 common_metadata_callback_(metadata);
1537 void FileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
1539 common_error_callback_(status);
1542 bool FileDecoder::die(const char *msg) const
1544 State state = get_state();
1547 printf("FAILED, %s", msg);
1551 printf(", state = %u (%s)\n", (unsigned)((::FLAC__FileDecoderState)state), state.as_cstring());
1552 if(state == ::FLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR) {
1553 FLAC::Decoder::SeekableStream::State state_ = get_seekable_stream_decoder_state();
1554 printf(" seekable stream decoder state = %u (%s)\n", (unsigned)((::FLAC__SeekableStreamDecoderState)state_), state_.as_cstring());
1555 if(state_ == ::FLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR) {
1556 FLAC::Decoder::Stream::State state__ = get_stream_decoder_state();
1557 printf(" stream decoder state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state__), state__.as_cstring());
1564 bool FileDecoder::test_respond()
1566 if(!set_filename(flacfilename_)) {
1567 printf("FAILED at set_filename(), returned false\n");
1571 if(!set_md5_checking(true)) {
1572 printf("FAILED at set_md5_checking(), returned false\n");
1576 printf("testing init()... ");
1577 if(init() != ::FLAC__FILE_DECODER_OK)
1581 current_metadata_number_ = 0;
1583 printf("testing process_until_end_of_file()... ");
1584 if(!process_until_end_of_file()) {
1585 State state = get_state();
1586 printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::FLAC__FileDecoderState)state), state.as_cstring());
1591 printf("testing finish()... ");
1598 static bool test_file_decoder()
1600 FileDecoder *decoder;
1602 printf("\n+++ libFLAC++ unit test: FLAC::Decoder::File\n\n");
1605 // test new -> delete
1607 printf("allocating decoder instance... ");
1608 decoder = new FileDecoder();
1610 printf("FAILED, new returned NULL\n");
1615 printf("testing is_valid()... ");
1616 if(!decoder->is_valid()) {
1617 printf("FAILED, returned false\n");
1622 printf("freeing decoder instance... ");
1627 // test new -> init -> delete
1629 printf("allocating decoder instance... ");
1630 decoder = new FileDecoder();
1632 printf("FAILED, new returned NULL\n");
1637 printf("testing is_valid()... ");
1638 if(!decoder->is_valid()) {
1639 printf("FAILED, returned false\n");
1644 printf("testing init()... ");
1645 if(decoder->init() != ::FLAC__FILE_DECODER_OK)
1646 return decoder->die();
1649 printf("freeing decoder instance... ");
1654 // test normal usage
1657 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1659 printf("allocating decoder instance... ");
1660 decoder = new FileDecoder();
1662 printf("FAILED, new returned NULL\n");
1667 printf("testing is_valid()... ");
1668 if(!decoder->is_valid()) {
1669 printf("FAILED, returned false\n");
1674 printf("testing set_filename()... ");
1675 if(!decoder->set_filename(flacfilename_)) {
1676 printf("FAILED, returned false\n");
1681 printf("testing set_md5_checking()... ");
1682 if(!decoder->set_md5_checking(true)) {
1683 printf("FAILED, returned false\n");
1688 printf("testing init()... ");
1689 if(decoder->init() != ::FLAC__FILE_DECODER_OK)
1690 return decoder->die();
1693 printf("testing get_state()... ");
1694 FLAC::Decoder::File::State state = decoder->get_state();
1695 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__FileDecoderState)state), state.as_cstring());
1697 printf("testing get_seekable_stream_decoder_state()... ");
1698 FLAC::Decoder::SeekableStream::State state_ = decoder->get_seekable_stream_decoder_state();
1699 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__SeekableStreamDecoderState)state_), state_.as_cstring());
1701 printf("testing get_stream_decoder_state()... ");
1702 FLAC::Decoder::Stream::State state__ = decoder->get_stream_decoder_state();
1703 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state__), state__.as_cstring());
1705 decoder->current_metadata_number_ = 0;
1706 decoder->ignore_errors_ = false;
1707 decoder->error_occurred_ = false;
1709 printf("testing get_md5_checking()... ");
1710 if(!decoder->get_md5_checking()) {
1711 printf("FAILED, returned false, expected true\n");
1716 printf("testing process_until_end_of_metadata()... ");
1717 if(!decoder->process_until_end_of_metadata())
1718 return decoder->die("returned false");
1721 printf("testing process_single()... ");
1722 if(!decoder->process_single())
1723 return decoder->die("returned false");
1726 printf("testing seek_absolute()... ");
1727 if(!decoder->seek_absolute(0))
1728 return decoder->die("returned false");
1731 printf("testing process_until_end_of_file()... ");
1732 if(!decoder->process_until_end_of_file())
1733 return decoder->die("returned false");
1736 printf("testing get_channels()... ");
1738 unsigned channels = decoder->get_channels();
1739 if(channels != streaminfo_.data.stream_info.channels) {
1740 printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
1746 printf("testing get_bits_per_sample()... ");
1748 unsigned bits_per_sample = decoder->get_bits_per_sample();
1749 if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
1750 printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
1756 printf("testing get_sample_rate()... ");
1758 unsigned sample_rate = decoder->get_sample_rate();
1759 if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
1760 printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
1766 printf("testing get_blocksize()... ");
1768 unsigned blocksize = decoder->get_blocksize();
1769 /* value could be anything since we're at the last block, so accept any answer */
1770 printf("returned %u... OK\n", blocksize);
1773 printf("testing get_channel_assignment()... ");
1775 ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
1776 printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
1779 printf("testing finish()... ");
1787 printf("testing set_metadata_respond_all()... ");
1788 if(!decoder->set_metadata_respond_all()) {
1789 printf("FAILED, returned false\n");
1795 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1796 expected_metadata_sequence_[num_expected_++] = &padding_;
1797 expected_metadata_sequence_[num_expected_++] = &seektable_;
1798 expected_metadata_sequence_[num_expected_++] = &application1_;
1799 expected_metadata_sequence_[num_expected_++] = &application2_;
1800 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1801 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1802 expected_metadata_sequence_[num_expected_++] = &unknown_;
1804 if(!decoder->test_respond())
1811 printf("testing set_metadata_ignore_all()... ");
1812 if(!decoder->set_metadata_ignore_all()) {
1813 printf("FAILED, returned false\n");
1820 if(!decoder->test_respond())
1824 * respond all, ignore VORBIS_COMMENT
1827 printf("testing set_metadata_respond_all()... ");
1828 if(!decoder->set_metadata_respond_all()) {
1829 printf("FAILED, returned false\n");
1834 printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
1835 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
1836 printf("FAILED, returned false\n");
1842 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1843 expected_metadata_sequence_[num_expected_++] = &padding_;
1844 expected_metadata_sequence_[num_expected_++] = &seektable_;
1845 expected_metadata_sequence_[num_expected_++] = &application1_;
1846 expected_metadata_sequence_[num_expected_++] = &application2_;
1847 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1848 expected_metadata_sequence_[num_expected_++] = &unknown_;
1850 if(!decoder->test_respond())
1854 * respond all, ignore APPLICATION
1857 printf("testing set_metadata_respond_all()... ");
1858 if(!decoder->set_metadata_respond_all()) {
1859 printf("FAILED, returned false\n");
1864 printf("testing set_metadata_ignore(APPLICATION)... ");
1865 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1866 printf("FAILED, returned false\n");
1872 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1873 expected_metadata_sequence_[num_expected_++] = &padding_;
1874 expected_metadata_sequence_[num_expected_++] = &seektable_;
1875 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1876 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1877 expected_metadata_sequence_[num_expected_++] = &unknown_;
1879 if(!decoder->test_respond())
1883 * respond all, ignore APPLICATION id of app#1
1886 printf("testing set_metadata_respond_all()... ");
1887 if(!decoder->set_metadata_respond_all()) {
1888 printf("FAILED, returned false\n");
1893 printf("testing set_metadata_ignore_application(of app block #1)... ");
1894 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1895 printf("FAILED, returned false\n");
1901 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1902 expected_metadata_sequence_[num_expected_++] = &padding_;
1903 expected_metadata_sequence_[num_expected_++] = &seektable_;
1904 expected_metadata_sequence_[num_expected_++] = &application2_;
1905 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1906 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1907 expected_metadata_sequence_[num_expected_++] = &unknown_;
1909 if(!decoder->test_respond())
1913 * respond all, ignore APPLICATION id of app#1 & app#2
1916 printf("testing set_metadata_respond_all()... ");
1917 if(!decoder->set_metadata_respond_all()) {
1918 printf("FAILED, returned false\n");
1923 printf("testing set_metadata_ignore_application(of app block #1)... ");
1924 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1925 printf("FAILED, returned false\n");
1930 printf("testing set_metadata_ignore_application(of app block #2)... ");
1931 if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
1932 printf("FAILED, returned false\n");
1938 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1939 expected_metadata_sequence_[num_expected_++] = &padding_;
1940 expected_metadata_sequence_[num_expected_++] = &seektable_;
1941 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1942 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1943 expected_metadata_sequence_[num_expected_++] = &unknown_;
1945 if(!decoder->test_respond())
1949 * ignore all, respond VORBIS_COMMENT
1952 printf("testing set_metadata_ignore_all()... ");
1953 if(!decoder->set_metadata_ignore_all()) {
1954 printf("FAILED, returned false\n");
1959 printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
1960 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
1961 printf("FAILED, returned false\n");
1967 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1969 if(!decoder->test_respond())
1973 * ignore all, respond APPLICATION
1976 printf("testing set_metadata_ignore_all()... ");
1977 if(!decoder->set_metadata_ignore_all()) {
1978 printf("FAILED, returned false\n");
1983 printf("testing set_metadata_respond(APPLICATION)... ");
1984 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
1985 printf("FAILED, returned false\n");
1991 expected_metadata_sequence_[num_expected_++] = &application1_;
1992 expected_metadata_sequence_[num_expected_++] = &application2_;
1994 if(!decoder->test_respond())
1998 * ignore all, respond APPLICATION id of app#1
2001 printf("testing set_metadata_ignore_all()... ");
2002 if(!decoder->set_metadata_ignore_all()) {
2003 printf("FAILED, returned false\n");
2008 printf("testing set_metadata_respond_application(of app block #1)... ");
2009 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
2010 printf("FAILED, returned false\n");
2016 expected_metadata_sequence_[num_expected_++] = &application1_;
2018 if(!decoder->test_respond())
2022 * ignore all, respond APPLICATION id of app#1 & app#2
2025 printf("testing set_metadata_ignore_all()... ");
2026 if(!decoder->set_metadata_ignore_all()) {
2027 printf("FAILED, returned false\n");
2032 printf("testing set_metadata_respond_application(of app block #1)... ");
2033 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
2034 printf("FAILED, returned false\n");
2039 printf("testing set_metadata_respond_application(of app block #2)... ");
2040 if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
2041 printf("FAILED, returned false\n");
2047 expected_metadata_sequence_[num_expected_++] = &application1_;
2048 expected_metadata_sequence_[num_expected_++] = &application2_;
2050 if(!decoder->test_respond())
2054 * respond all, ignore APPLICATION, respond APPLICATION id of app#1
2057 printf("testing set_metadata_respond_all()... ");
2058 if(!decoder->set_metadata_respond_all()) {
2059 printf("FAILED, returned false\n");
2064 printf("testing set_metadata_ignore(APPLICATION)... ");
2065 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
2066 printf("FAILED, returned false\n");
2071 printf("testing set_metadata_respond_application(of app block #1)... ");
2072 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
2073 printf("FAILED, returned false\n");
2079 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
2080 expected_metadata_sequence_[num_expected_++] = &padding_;
2081 expected_metadata_sequence_[num_expected_++] = &seektable_;
2082 expected_metadata_sequence_[num_expected_++] = &application1_;
2083 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
2084 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
2085 expected_metadata_sequence_[num_expected_++] = &unknown_;
2087 if(!decoder->test_respond())
2091 * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
2094 printf("testing set_metadata_ignore_all()... ");
2095 if(!decoder->set_metadata_ignore_all()) {
2096 printf("FAILED, returned false\n");
2101 printf("testing set_metadata_respond(APPLICATION)... ");
2102 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
2103 printf("FAILED, returned false\n");
2108 printf("testing set_metadata_ignore_application(of app block #1)... ");
2109 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
2110 printf("FAILED, returned false\n");
2116 expected_metadata_sequence_[num_expected_++] = &application2_;
2118 if(!decoder->test_respond())
2121 /* done, now leave the sequence the way we found it... */
2123 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
2124 expected_metadata_sequence_[num_expected_++] = &padding_;
2125 expected_metadata_sequence_[num_expected_++] = &seektable_;
2126 expected_metadata_sequence_[num_expected_++] = &application1_;
2127 expected_metadata_sequence_[num_expected_++] = &application2_;
2128 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
2129 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
2130 expected_metadata_sequence_[num_expected_++] = &unknown_;
2132 printf("freeing decoder instance... ");
2136 printf("\nPASSED!\n");
2141 bool test_decoders()
2143 init_metadata_blocks_();
2145 if(!generate_file_())
2148 if(!test_stream_decoder())
2151 if(!test_seekable_stream_decoder())
2154 if(!test_file_decoder())
2157 (void) grabbag__file_remove_file(flacfilename_);
2159 free_metadata_blocks_();