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"
34 // warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
35 #pragma warning ( disable : 4800 )
38 static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, unknown_;
39 static ::FLAC__StreamMetadata *expected_metadata_sequence_[8];
40 static unsigned num_expected_;
41 static const char *flacfilename_ = "metadata.flac";
42 static unsigned flacfilesize_;
44 static bool die_(const char *msg)
46 printf("ERROR: %s\n", msg);
50 static void init_metadata_blocks_()
52 mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
55 static void free_metadata_blocks_()
57 mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
60 static bool generate_file_()
62 printf("\n\ngenerating FLAC file for decoder tests...\n");
65 expected_metadata_sequence_[num_expected_++] = &padding_;
66 expected_metadata_sequence_[num_expected_++] = &seektable_;
67 expected_metadata_sequence_[num_expected_++] = &application1_;
68 expected_metadata_sequence_[num_expected_++] = &application2_;
69 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
70 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
71 expected_metadata_sequence_[num_expected_++] = &unknown_;
73 if(!file_utils__generate_flacfile(flacfilename_, &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
74 return die_("creating the encoded file");
83 unsigned current_metadata_number_;
87 DecoderCommon(): file_(0), current_metadata_number_(0), ignore_errors_(false), error_occurred_(false) { }
88 ::FLAC__StreamDecoderReadStatus common_read_callback_(FLAC__byte buffer[], unsigned *bytes);
89 ::FLAC__StreamDecoderWriteStatus common_write_callback_(const ::FLAC__Frame *frame);
90 void common_metadata_callback_(const ::FLAC__StreamMetadata *metadata);
91 void common_error_callback_(::FLAC__StreamDecoderErrorStatus status);
94 ::FLAC__StreamDecoderReadStatus DecoderCommon::common_read_callback_(FLAC__byte buffer[], unsigned *bytes)
97 return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT;
100 return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
101 else if(*bytes > 0) {
102 unsigned bytes_read = ::fread(buffer, 1, *bytes, file_);
103 if(bytes_read == 0) {
105 return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
107 return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
111 return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
115 return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
118 ::FLAC__StreamDecoderWriteStatus DecoderCommon::common_write_callback_(const ::FLAC__Frame *frame)
121 return ::FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
124 (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) ||
125 (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0)
127 printf("content... ");
131 return ::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
134 void DecoderCommon::common_metadata_callback_(const ::FLAC__StreamMetadata *metadata)
139 printf("%d... ", current_metadata_number_);
142 if(current_metadata_number_ >= num_expected_) {
143 (void)die_("got more metadata blocks than expected");
144 error_occurred_ = true;
147 if(!::FLAC__metadata_object_is_equal(expected_metadata_sequence_[current_metadata_number_], metadata)) {
148 (void)die_("metadata block mismatch");
149 error_occurred_ = true;
152 current_metadata_number_++;
155 void DecoderCommon::common_error_callback_(::FLAC__StreamDecoderErrorStatus status)
157 if(!ignore_errors_) {
158 printf("ERROR: got error callback: err = %u (%s)\n", (unsigned)status, ::FLAC__StreamDecoderErrorStatusString[status]);
159 error_occurred_ = true;
163 class StreamDecoder : public FLAC::Decoder::Stream, public DecoderCommon {
165 StreamDecoder(): FLAC::Decoder::Stream(), DecoderCommon() { }
168 // from FLAC::Decoder::Stream
169 ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
170 ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
171 void metadata_callback(const ::FLAC__StreamMetadata *metadata);
172 void error_callback(::FLAC__StreamDecoderErrorStatus status);
174 bool die(const char *msg = 0) const;
179 ::FLAC__StreamDecoderReadStatus StreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
181 return common_read_callback_(buffer, bytes);
184 ::FLAC__StreamDecoderWriteStatus StreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
188 return common_write_callback_(frame);
191 void StreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
193 common_metadata_callback_(metadata);
196 void StreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
198 common_error_callback_(status);
201 bool StreamDecoder::die(const char *msg) const
203 State state = get_state();
206 printf("FAILED, %s", msg);
210 printf(", state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
215 bool StreamDecoder::test_respond()
217 printf("testing init()... ");
218 if(init() != ::FLAC__STREAM_DECODER_SEARCH_FOR_METADATA)
222 current_metadata_number_ = 0;
224 if(::fseek(file_, 0, SEEK_SET) < 0) {
225 printf("FAILED rewinding input, errno = %d\n", errno);
229 printf("testing process_until_end_of_stream()... ");
230 if(!process_until_end_of_stream()) {
231 State state = get_state();
232 printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
237 printf("testing finish()... ");
244 static bool test_stream_decoder()
246 StreamDecoder *decoder;
248 printf("\n+++ libFLAC++ unit test: FLAC::Decoder::Stream\n\n");
251 // test new -> delete
253 printf("allocating decoder instance... ");
254 decoder = new StreamDecoder();
256 printf("FAILED, new returned NULL\n");
261 printf("testing is_valid()... ");
262 if(!decoder->is_valid()) {
263 printf("FAILED, returned false\n");
268 printf("freeing decoder instance... ");
273 // test new -> init -> delete
275 printf("allocating decoder instance... ");
276 decoder = new StreamDecoder();
278 printf("FAILED, new returned NULL\n");
283 printf("testing is_valid()... ");
284 if(!decoder->is_valid()) {
285 printf("FAILED, returned false\n");
290 printf("testing init()... ");
291 if(decoder->init() != ::FLAC__STREAM_DECODER_SEARCH_FOR_METADATA)
292 return decoder->die();
295 printf("freeing decoder instance... ");
303 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
305 printf("allocating decoder instance... ");
306 decoder = new StreamDecoder();
308 printf("FAILED, new returned NULL\n");
313 printf("testing is_valid()... ");
314 if(!decoder->is_valid()) {
315 printf("FAILED, returned false\n");
320 printf("testing init()... ");
321 if(decoder->init() != ::FLAC__STREAM_DECODER_SEARCH_FOR_METADATA)
322 return decoder->die();
325 printf("testing get_state()... ");
326 FLAC::Decoder::Stream::State state = decoder->get_state();
327 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state), state.as_cstring());
329 decoder->current_metadata_number_ = 0;
330 decoder->ignore_errors_ = false;
331 decoder->error_occurred_ = false;
333 printf("opening FLAC file... ");
334 decoder->file_ = ::fopen(flacfilename_, "rb");
335 if(0 == decoder->file_) {
341 printf("testing process_until_end_of_metadata()... ");
342 if(!decoder->process_until_end_of_metadata())
343 return decoder->die("returned false");
346 printf("testing process_single()... ");
347 if(!decoder->process_single())
348 return decoder->die("returned false");
351 printf("testing skip_single_frame()... ");
352 if(!decoder->skip_single_frame())
353 return decoder->die("returned false");
356 printf("testing flush()... ");
357 if(!decoder->flush())
358 return decoder->die("returned false");
361 decoder->ignore_errors_ = true;
362 printf("testing process_single()... ");
363 if(!decoder->process_single())
364 return decoder->die("returned false");
366 decoder->ignore_errors_ = false;
368 printf("testing process_until_end_of_stream()... ");
369 if(!decoder->process_until_end_of_stream())
370 return decoder->die("returned false");
373 printf("testing get_channels()... ");
375 unsigned channels = decoder->get_channels();
376 if(channels != streaminfo_.data.stream_info.channels) {
377 printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
383 printf("testing get_bits_per_sample()... ");
385 unsigned bits_per_sample = decoder->get_bits_per_sample();
386 if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
387 printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
393 printf("testing get_sample_rate()... ");
395 unsigned sample_rate = decoder->get_sample_rate();
396 if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
397 printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
403 printf("testing get_blocksize()... ");
405 unsigned blocksize = decoder->get_blocksize();
406 /* value could be anything since we're at the last block, so accept any answer */
407 printf("returned %u... OK\n", blocksize);
410 printf("testing get_channel_assignment()... ");
412 ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
413 printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
416 printf("testing reset()... ");
417 if(!decoder->reset())
418 return decoder->die("returned false");
421 decoder->current_metadata_number_ = 0;
423 printf("rewinding input... ");
424 if(::fseek(decoder->file_, 0, SEEK_SET) < 0) {
425 printf("FAILED, errno = %d\n", errno);
430 printf("testing process_until_end_of_stream()... ");
431 if(!decoder->process_until_end_of_stream())
432 return decoder->die("returned false");
435 printf("testing finish()... ");
443 printf("testing set_metadata_respond_all()... ");
444 if(!decoder->set_metadata_respond_all()) {
445 printf("FAILED, returned false\n");
451 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
452 expected_metadata_sequence_[num_expected_++] = &padding_;
453 expected_metadata_sequence_[num_expected_++] = &seektable_;
454 expected_metadata_sequence_[num_expected_++] = &application1_;
455 expected_metadata_sequence_[num_expected_++] = &application2_;
456 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
457 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
458 expected_metadata_sequence_[num_expected_++] = &unknown_;
460 if(!decoder->test_respond())
467 printf("testing set_metadata_ignore_all()... ");
468 if(!decoder->set_metadata_ignore_all()) {
469 printf("FAILED, returned false\n");
476 if(!decoder->test_respond())
480 * respond all, ignore VORBIS_COMMENT
483 printf("testing set_metadata_respond_all()... ");
484 if(!decoder->set_metadata_respond_all()) {
485 printf("FAILED, returned false\n");
490 printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
491 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
492 printf("FAILED, returned false\n");
498 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
499 expected_metadata_sequence_[num_expected_++] = &padding_;
500 expected_metadata_sequence_[num_expected_++] = &seektable_;
501 expected_metadata_sequence_[num_expected_++] = &application1_;
502 expected_metadata_sequence_[num_expected_++] = &application2_;
503 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
504 expected_metadata_sequence_[num_expected_++] = &unknown_;
506 if(!decoder->test_respond())
510 * respond all, ignore APPLICATION
513 printf("testing set_metadata_respond_all()... ");
514 if(!decoder->set_metadata_respond_all()) {
515 printf("FAILED, returned false\n");
520 printf("testing set_metadata_ignore(APPLICATION)... ");
521 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
522 printf("FAILED, returned false\n");
528 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
529 expected_metadata_sequence_[num_expected_++] = &padding_;
530 expected_metadata_sequence_[num_expected_++] = &seektable_;
531 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
532 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
533 expected_metadata_sequence_[num_expected_++] = &unknown_;
535 if(!decoder->test_respond())
539 * respond all, ignore APPLICATION id of app#1
542 printf("testing set_metadata_respond_all()... ");
543 if(!decoder->set_metadata_respond_all()) {
544 printf("FAILED, returned false\n");
549 printf("testing set_metadata_ignore_application(of app block #1)... ");
550 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
551 printf("FAILED, returned false\n");
557 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
558 expected_metadata_sequence_[num_expected_++] = &padding_;
559 expected_metadata_sequence_[num_expected_++] = &seektable_;
560 expected_metadata_sequence_[num_expected_++] = &application2_;
561 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
562 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
563 expected_metadata_sequence_[num_expected_++] = &unknown_;
565 if(!decoder->test_respond())
569 * respond all, ignore APPLICATION id of app#1 & app#2
572 printf("testing set_metadata_respond_all()... ");
573 if(!decoder->set_metadata_respond_all()) {
574 printf("FAILED, returned false\n");
579 printf("testing set_metadata_ignore_application(of app block #1)... ");
580 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
581 printf("FAILED, returned false\n");
586 printf("testing set_metadata_ignore_application(of app block #2)... ");
587 if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
588 printf("FAILED, returned false\n");
594 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
595 expected_metadata_sequence_[num_expected_++] = &padding_;
596 expected_metadata_sequence_[num_expected_++] = &seektable_;
597 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
598 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
599 expected_metadata_sequence_[num_expected_++] = &unknown_;
601 if(!decoder->test_respond())
605 * ignore all, respond VORBIS_COMMENT
608 printf("testing set_metadata_ignore_all()... ");
609 if(!decoder->set_metadata_ignore_all()) {
610 printf("FAILED, returned false\n");
615 printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
616 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
617 printf("FAILED, returned false\n");
623 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
625 if(!decoder->test_respond())
629 * ignore all, respond APPLICATION
632 printf("testing set_metadata_ignore_all()... ");
633 if(!decoder->set_metadata_ignore_all()) {
634 printf("FAILED, returned false\n");
639 printf("testing set_metadata_respond(APPLICATION)... ");
640 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
641 printf("FAILED, returned false\n");
647 expected_metadata_sequence_[num_expected_++] = &application1_;
648 expected_metadata_sequence_[num_expected_++] = &application2_;
650 if(!decoder->test_respond())
654 * ignore all, respond APPLICATION id of app#1
657 printf("testing set_metadata_ignore_all()... ");
658 if(!decoder->set_metadata_ignore_all()) {
659 printf("FAILED, returned false\n");
664 printf("testing set_metadata_respond_application(of app block #1)... ");
665 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
666 printf("FAILED, returned false\n");
672 expected_metadata_sequence_[num_expected_++] = &application1_;
674 if(!decoder->test_respond())
678 * ignore all, respond APPLICATION id of app#1 & app#2
681 printf("testing set_metadata_ignore_all()... ");
682 if(!decoder->set_metadata_ignore_all()) {
683 printf("FAILED, returned false\n");
688 printf("testing set_metadata_respond_application(of app block #1)... ");
689 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
690 printf("FAILED, returned false\n");
695 printf("testing set_metadata_respond_application(of app block #2)... ");
696 if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
697 printf("FAILED, returned false\n");
703 expected_metadata_sequence_[num_expected_++] = &application1_;
704 expected_metadata_sequence_[num_expected_++] = &application2_;
706 if(!decoder->test_respond())
710 * respond all, ignore APPLICATION, respond APPLICATION id of app#1
713 printf("testing set_metadata_respond_all()... ");
714 if(!decoder->set_metadata_respond_all()) {
715 printf("FAILED, returned false\n");
720 printf("testing set_metadata_ignore(APPLICATION)... ");
721 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
722 printf("FAILED, returned false\n");
727 printf("testing set_metadata_respond_application(of app block #1)... ");
728 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
729 printf("FAILED, returned false\n");
735 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
736 expected_metadata_sequence_[num_expected_++] = &padding_;
737 expected_metadata_sequence_[num_expected_++] = &seektable_;
738 expected_metadata_sequence_[num_expected_++] = &application1_;
739 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
740 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
741 expected_metadata_sequence_[num_expected_++] = &unknown_;
743 if(!decoder->test_respond())
747 * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
750 printf("testing set_metadata_ignore_all()... ");
751 if(!decoder->set_metadata_ignore_all()) {
752 printf("FAILED, returned false\n");
757 printf("testing set_metadata_respond(APPLICATION)... ");
758 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
759 printf("FAILED, returned false\n");
764 printf("testing set_metadata_ignore_application(of app block #1)... ");
765 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
766 printf("FAILED, returned false\n");
772 expected_metadata_sequence_[num_expected_++] = &application2_;
774 if(!decoder->test_respond())
777 /* done, now leave the sequence the way we found it... */
779 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
780 expected_metadata_sequence_[num_expected_++] = &padding_;
781 expected_metadata_sequence_[num_expected_++] = &seektable_;
782 expected_metadata_sequence_[num_expected_++] = &application1_;
783 expected_metadata_sequence_[num_expected_++] = &application2_;
784 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
785 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
786 expected_metadata_sequence_[num_expected_++] = &unknown_;
788 ::fclose(decoder->file_);
790 printf("freeing decoder instance... ");
794 printf("\nPASSED!\n");
799 class SeekableStreamDecoder : public FLAC::Decoder::SeekableStream, public DecoderCommon {
801 SeekableStreamDecoder(): FLAC::Decoder::SeekableStream(), DecoderCommon() { }
802 ~SeekableStreamDecoder() { }
804 // from FLAC::Decoder::SeekableStream
805 ::FLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
806 ::FLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
807 ::FLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
808 ::FLAC__SeekableStreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length);
810 ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
811 void metadata_callback(const ::FLAC__StreamMetadata *metadata);
812 void error_callback(::FLAC__StreamDecoderErrorStatus status);
814 bool die(const char *msg = 0) const;
819 ::FLAC__SeekableStreamDecoderReadStatus SeekableStreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
821 switch(common_read_callback_(buffer, bytes)) {
822 case ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
823 return ::FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
824 case ::FLAC__STREAM_DECODER_READ_STATUS_ABORT:
825 case ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
826 return ::FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
829 return ::FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
833 ::FLAC__SeekableStreamDecoderSeekStatus SeekableStreamDecoder::seek_callback(FLAC__uint64 absolute_byte_offset)
836 return ::FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
838 if(::fseek(file_, (long)absolute_byte_offset, SEEK_SET) < 0) {
839 error_occurred_ = true;
840 return ::FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
843 return ::FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
846 ::FLAC__SeekableStreamDecoderTellStatus SeekableStreamDecoder::tell_callback(FLAC__uint64 *absolute_byte_offset)
849 return ::FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
851 long offset = ::ftell(file_);
852 *absolute_byte_offset = (FLAC__uint64)offset;
855 error_occurred_ = true;
856 return ::FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
859 return ::FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;
862 ::FLAC__SeekableStreamDecoderLengthStatus SeekableStreamDecoder::length_callback(FLAC__uint64 *stream_length)
865 return ::FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR;
867 *stream_length = (FLAC__uint64)flacfilesize_;
868 return ::FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;
871 bool SeekableStreamDecoder::eof_callback()
876 return (bool)feof(file_);
879 ::FLAC__StreamDecoderWriteStatus SeekableStreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
883 return common_write_callback_(frame);
886 void SeekableStreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
888 common_metadata_callback_(metadata);
891 void SeekableStreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
893 common_error_callback_(status);
896 bool SeekableStreamDecoder::die(const char *msg) const
898 State state = get_state();
901 printf("FAILED, %s", msg);
905 printf(", state = %u (%s)\n", (unsigned)((::FLAC__SeekableStreamDecoderState)state), state.as_cstring());
906 if(state == ::FLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR) {
907 FLAC::Decoder::Stream::State state_ = get_stream_decoder_state();
908 printf(" stream decoder state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state_), state_.as_cstring());
914 bool SeekableStreamDecoder::test_respond()
916 if(!set_md5_checking(true)) {
917 printf("FAILED at set_md5_checking(), returned false\n");
921 printf("testing init()... ");
922 if(init() != ::FLAC__SEEKABLE_STREAM_DECODER_OK)
926 current_metadata_number_ = 0;
928 if(::fseek(file_, 0, SEEK_SET) < 0) {
929 printf("FAILED rewinding input, errno = %d\n", errno);
933 printf("testing process_until_end_of_stream()... ");
934 if(!process_until_end_of_stream()) {
935 State state = get_state();
936 printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::FLAC__SeekableStreamDecoderState)state), state.as_cstring());
941 printf("testing finish()... ");
948 static bool test_seekable_stream_decoder()
950 SeekableStreamDecoder *decoder;
952 printf("\n+++ libFLAC++ unit test: FLAC::Decoder::SeekableStream\n\n");
955 // test new -> delete
957 printf("allocating decoder instance... ");
958 decoder = new SeekableStreamDecoder();
960 printf("FAILED, new returned NULL\n");
965 printf("testing is_valid()... ");
966 if(!decoder->is_valid()) {
967 printf("FAILED, returned false\n");
972 printf("freeing decoder instance... ");
977 // test new -> init -> delete
979 printf("allocating decoder instance... ");
980 decoder = new SeekableStreamDecoder();
982 printf("FAILED, new returned NULL\n");
987 printf("testing is_valid()... ");
988 if(!decoder->is_valid()) {
989 printf("FAILED, returned false\n");
994 printf("testing init()... ");
995 if(decoder->init() != ::FLAC__SEEKABLE_STREAM_DECODER_OK)
996 return decoder->die();
999 printf("freeing decoder instance... ");
1004 // test normal usage
1007 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1009 printf("allocating decoder instance... ");
1010 decoder = new SeekableStreamDecoder();
1012 printf("FAILED, new returned NULL\n");
1017 printf("testing is_valid()... ");
1018 if(!decoder->is_valid()) {
1019 printf("FAILED, returned false\n");
1024 printf("testing set_md5_checking()... ");
1025 if(!decoder->set_md5_checking(true)) {
1026 printf("FAILED, returned false\n");
1031 printf("testing init()... ");
1032 if(decoder->init() != ::FLAC__SEEKABLE_STREAM_DECODER_OK)
1033 return decoder->die();
1036 printf("testing get_state()... ");
1037 FLAC::Decoder::SeekableStream::State state = decoder->get_state();
1038 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__SeekableStreamDecoderState)state), state.as_cstring());
1040 printf("testing get_stream_decoder_state()... ");
1041 FLAC::Decoder::Stream::State state_ = decoder->get_stream_decoder_state();
1042 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state_), state_.as_cstring());
1044 decoder->current_metadata_number_ = 0;
1045 decoder->ignore_errors_ = false;
1046 decoder->error_occurred_ = false;
1048 printf("opening FLAC file... ");
1049 decoder->file_ = ::fopen(flacfilename_, "rb");
1050 if(0 == decoder->file_) {
1056 printf("testing get_md5_checking()... ");
1057 if(!decoder->get_md5_checking()) {
1058 printf("FAILED, returned false, expected true\n");
1063 printf("testing process_until_end_of_metadata()... ");
1064 if(!decoder->process_until_end_of_metadata())
1065 return decoder->die("returned false");
1068 printf("testing process_single()... ");
1069 if(!decoder->process_single())
1070 return decoder->die("returned false");
1073 printf("testing skip_single_frame()... ");
1074 if(!decoder->skip_single_frame())
1075 return decoder->die("returned false");
1078 printf("testing flush()... ");
1079 if(!decoder->flush())
1080 return decoder->die("returned false");
1083 decoder->ignore_errors_ = true;
1084 printf("testing process_single()... ");
1085 if(!decoder->process_single())
1086 return decoder->die("returned false");
1088 decoder->ignore_errors_ = false;
1090 printf("testing seek_absolute()... ");
1091 if(!decoder->seek_absolute(0))
1092 return decoder->die("returned false");
1095 printf("testing process_until_end_of_stream()... ");
1096 if(!decoder->process_until_end_of_stream())
1097 return decoder->die("returned false");
1100 printf("testing get_channels()... ");
1102 unsigned channels = decoder->get_channels();
1103 if(channels != streaminfo_.data.stream_info.channels) {
1104 printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
1110 printf("testing get_bits_per_sample()... ");
1112 unsigned bits_per_sample = decoder->get_bits_per_sample();
1113 if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
1114 printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
1120 printf("testing get_sample_rate()... ");
1122 unsigned sample_rate = decoder->get_sample_rate();
1123 if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
1124 printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
1130 printf("testing get_blocksize()... ");
1132 unsigned blocksize = decoder->get_blocksize();
1133 /* value could be anything since we're at the last block, so accept any answer */
1134 printf("returned %u... OK\n", blocksize);
1137 printf("testing get_channel_assignment()... ");
1139 ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
1140 printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
1143 printf("testing reset()... ");
1144 if(!decoder->reset())
1145 return decoder->die("returned false");
1148 decoder->current_metadata_number_ = 0;
1150 printf("rewinding input... ");
1151 if(::fseek(decoder->file_, 0, SEEK_SET) < 0) {
1152 printf("FAILED, errno = %d\n", errno);
1157 printf("testing process_until_end_of_stream()... ");
1158 if(!decoder->process_until_end_of_stream())
1159 return decoder->die("returned false");
1162 printf("testing finish()... ");
1170 printf("testing set_metadata_respond_all()... ");
1171 if(!decoder->set_metadata_respond_all()) {
1172 printf("FAILED, returned false\n");
1178 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1179 expected_metadata_sequence_[num_expected_++] = &padding_;
1180 expected_metadata_sequence_[num_expected_++] = &seektable_;
1181 expected_metadata_sequence_[num_expected_++] = &application1_;
1182 expected_metadata_sequence_[num_expected_++] = &application2_;
1183 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1184 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1185 expected_metadata_sequence_[num_expected_++] = &unknown_;
1187 if(!decoder->test_respond())
1194 printf("testing set_metadata_ignore_all()... ");
1195 if(!decoder->set_metadata_ignore_all()) {
1196 printf("FAILED, returned false\n");
1203 if(!decoder->test_respond())
1207 * respond all, ignore VORBIS_COMMENT
1210 printf("testing set_metadata_respond_all()... ");
1211 if(!decoder->set_metadata_respond_all()) {
1212 printf("FAILED, returned false\n");
1217 printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
1218 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
1219 printf("FAILED, returned false\n");
1225 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1226 expected_metadata_sequence_[num_expected_++] = &padding_;
1227 expected_metadata_sequence_[num_expected_++] = &seektable_;
1228 expected_metadata_sequence_[num_expected_++] = &application1_;
1229 expected_metadata_sequence_[num_expected_++] = &application2_;
1230 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1231 expected_metadata_sequence_[num_expected_++] = &unknown_;
1233 if(!decoder->test_respond())
1237 * respond all, ignore APPLICATION
1240 printf("testing set_metadata_respond_all()... ");
1241 if(!decoder->set_metadata_respond_all()) {
1242 printf("FAILED, returned false\n");
1247 printf("testing set_metadata_ignore(APPLICATION)... ");
1248 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1249 printf("FAILED, returned false\n");
1255 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1256 expected_metadata_sequence_[num_expected_++] = &padding_;
1257 expected_metadata_sequence_[num_expected_++] = &seektable_;
1258 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1259 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1260 expected_metadata_sequence_[num_expected_++] = &unknown_;
1262 if(!decoder->test_respond())
1266 * respond all, ignore APPLICATION id of app#1
1269 printf("testing set_metadata_respond_all()... ");
1270 if(!decoder->set_metadata_respond_all()) {
1271 printf("FAILED, returned false\n");
1276 printf("testing set_metadata_ignore_application(of app block #1)... ");
1277 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1278 printf("FAILED, returned false\n");
1284 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1285 expected_metadata_sequence_[num_expected_++] = &padding_;
1286 expected_metadata_sequence_[num_expected_++] = &seektable_;
1287 expected_metadata_sequence_[num_expected_++] = &application2_;
1288 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1289 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1290 expected_metadata_sequence_[num_expected_++] = &unknown_;
1292 if(!decoder->test_respond())
1296 * respond all, ignore APPLICATION id of app#1 & app#2
1299 printf("testing set_metadata_respond_all()... ");
1300 if(!decoder->set_metadata_respond_all()) {
1301 printf("FAILED, returned false\n");
1306 printf("testing set_metadata_ignore_application(of app block #1)... ");
1307 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1308 printf("FAILED, returned false\n");
1313 printf("testing set_metadata_ignore_application(of app block #2)... ");
1314 if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
1315 printf("FAILED, returned false\n");
1321 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1322 expected_metadata_sequence_[num_expected_++] = &padding_;
1323 expected_metadata_sequence_[num_expected_++] = &seektable_;
1324 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1325 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1326 expected_metadata_sequence_[num_expected_++] = &unknown_;
1328 if(!decoder->test_respond())
1332 * ignore all, respond VORBIS_COMMENT
1335 printf("testing set_metadata_ignore_all()... ");
1336 if(!decoder->set_metadata_ignore_all()) {
1337 printf("FAILED, returned false\n");
1342 printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
1343 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
1344 printf("FAILED, returned false\n");
1350 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1352 if(!decoder->test_respond())
1356 * ignore all, respond APPLICATION
1359 printf("testing set_metadata_ignore_all()... ");
1360 if(!decoder->set_metadata_ignore_all()) {
1361 printf("FAILED, returned false\n");
1366 printf("testing set_metadata_respond(APPLICATION)... ");
1367 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
1368 printf("FAILED, returned false\n");
1374 expected_metadata_sequence_[num_expected_++] = &application1_;
1375 expected_metadata_sequence_[num_expected_++] = &application2_;
1377 if(!decoder->test_respond())
1381 * ignore all, respond APPLICATION id of app#1
1384 printf("testing set_metadata_ignore_all()... ");
1385 if(!decoder->set_metadata_ignore_all()) {
1386 printf("FAILED, returned false\n");
1391 printf("testing set_metadata_respond_application(of app block #1)... ");
1392 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1393 printf("FAILED, returned false\n");
1399 expected_metadata_sequence_[num_expected_++] = &application1_;
1401 if(!decoder->test_respond())
1405 * ignore all, respond APPLICATION id of app#1 & app#2
1408 printf("testing set_metadata_ignore_all()... ");
1409 if(!decoder->set_metadata_ignore_all()) {
1410 printf("FAILED, returned false\n");
1415 printf("testing set_metadata_respond_application(of app block #1)... ");
1416 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1417 printf("FAILED, returned false\n");
1422 printf("testing set_metadata_respond_application(of app block #2)... ");
1423 if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
1424 printf("FAILED, returned false\n");
1430 expected_metadata_sequence_[num_expected_++] = &application1_;
1431 expected_metadata_sequence_[num_expected_++] = &application2_;
1433 if(!decoder->test_respond())
1437 * respond all, ignore APPLICATION, respond APPLICATION id of app#1
1440 printf("testing set_metadata_respond_all()... ");
1441 if(!decoder->set_metadata_respond_all()) {
1442 printf("FAILED, returned false\n");
1447 printf("testing set_metadata_ignore(APPLICATION)... ");
1448 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1449 printf("FAILED, returned false\n");
1454 printf("testing set_metadata_respond_application(of app block #1)... ");
1455 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1456 printf("FAILED, returned false\n");
1462 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1463 expected_metadata_sequence_[num_expected_++] = &padding_;
1464 expected_metadata_sequence_[num_expected_++] = &seektable_;
1465 expected_metadata_sequence_[num_expected_++] = &application1_;
1466 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1467 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1468 expected_metadata_sequence_[num_expected_++] = &unknown_;
1470 if(!decoder->test_respond())
1474 * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
1477 printf("testing set_metadata_ignore_all()... ");
1478 if(!decoder->set_metadata_ignore_all()) {
1479 printf("FAILED, returned false\n");
1484 printf("testing set_metadata_respond(APPLICATION)... ");
1485 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
1486 printf("FAILED, returned false\n");
1491 printf("testing set_metadata_ignore_application(of app block #1)... ");
1492 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1493 printf("FAILED, returned false\n");
1499 expected_metadata_sequence_[num_expected_++] = &application2_;
1501 if(!decoder->test_respond())
1504 /* done, now leave the sequence the way we found it... */
1506 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1507 expected_metadata_sequence_[num_expected_++] = &padding_;
1508 expected_metadata_sequence_[num_expected_++] = &seektable_;
1509 expected_metadata_sequence_[num_expected_++] = &application1_;
1510 expected_metadata_sequence_[num_expected_++] = &application2_;
1511 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1512 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1513 expected_metadata_sequence_[num_expected_++] = &unknown_;
1515 ::fclose(decoder->file_);
1517 printf("freeing decoder instance... ");
1521 printf("\nPASSED!\n");
1526 class FileDecoder : public FLAC::Decoder::File, public DecoderCommon {
1528 FileDecoder(): FLAC::Decoder::File(), DecoderCommon() { }
1531 // from FLAC::Decoder::File
1532 ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
1533 void metadata_callback(const ::FLAC__StreamMetadata *metadata);
1534 void error_callback(::FLAC__StreamDecoderErrorStatus status);
1536 bool die(const char *msg = 0) const;
1538 bool test_respond();
1541 ::FLAC__StreamDecoderWriteStatus FileDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
1544 return common_write_callback_(frame);
1547 void FileDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
1549 common_metadata_callback_(metadata);
1552 void FileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
1554 common_error_callback_(status);
1557 bool FileDecoder::die(const char *msg) const
1559 State state = get_state();
1562 printf("FAILED, %s", msg);
1566 printf(", state = %u (%s)\n", (unsigned)((::FLAC__FileDecoderState)state), state.as_cstring());
1567 if(state == ::FLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR) {
1568 FLAC::Decoder::SeekableStream::State state_ = get_seekable_stream_decoder_state();
1569 printf(" seekable stream decoder state = %u (%s)\n", (unsigned)((::FLAC__SeekableStreamDecoderState)state_), state_.as_cstring());
1570 if(state_ == ::FLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR) {
1571 FLAC::Decoder::Stream::State state__ = get_stream_decoder_state();
1572 printf(" stream decoder state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state__), state__.as_cstring());
1579 bool FileDecoder::test_respond()
1581 if(!set_filename(flacfilename_)) {
1582 printf("FAILED at set_filename(), returned false\n");
1586 if(!set_md5_checking(true)) {
1587 printf("FAILED at set_md5_checking(), returned false\n");
1591 printf("testing init()... ");
1592 if(init() != ::FLAC__FILE_DECODER_OK)
1596 current_metadata_number_ = 0;
1598 printf("testing process_until_end_of_file()... ");
1599 if(!process_until_end_of_file()) {
1600 State state = get_state();
1601 printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::FLAC__FileDecoderState)state), state.as_cstring());
1606 printf("testing finish()... ");
1613 static bool test_file_decoder()
1615 FileDecoder *decoder;
1617 printf("\n+++ libFLAC++ unit test: FLAC::Decoder::File\n\n");
1620 // test new -> delete
1622 printf("allocating decoder instance... ");
1623 decoder = new FileDecoder();
1625 printf("FAILED, new returned NULL\n");
1630 printf("testing is_valid()... ");
1631 if(!decoder->is_valid()) {
1632 printf("FAILED, returned false\n");
1637 printf("freeing decoder instance... ");
1642 // test new -> init -> delete
1644 printf("allocating decoder instance... ");
1645 decoder = new FileDecoder();
1647 printf("FAILED, new returned NULL\n");
1652 printf("testing is_valid()... ");
1653 if(!decoder->is_valid()) {
1654 printf("FAILED, returned false\n");
1659 printf("testing init()... ");
1660 if(decoder->init() != ::FLAC__FILE_DECODER_OK)
1661 return decoder->die();
1664 printf("freeing decoder instance... ");
1669 // test normal usage
1672 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1674 printf("allocating decoder instance... ");
1675 decoder = new FileDecoder();
1677 printf("FAILED, new returned NULL\n");
1682 printf("testing is_valid()... ");
1683 if(!decoder->is_valid()) {
1684 printf("FAILED, returned false\n");
1689 printf("testing set_filename()... ");
1690 if(!decoder->set_filename(flacfilename_)) {
1691 printf("FAILED, returned false\n");
1696 printf("testing set_md5_checking()... ");
1697 if(!decoder->set_md5_checking(true)) {
1698 printf("FAILED, returned false\n");
1703 printf("testing init()... ");
1704 if(decoder->init() != ::FLAC__FILE_DECODER_OK)
1705 return decoder->die();
1708 printf("testing get_state()... ");
1709 FLAC::Decoder::File::State state = decoder->get_state();
1710 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__FileDecoderState)state), state.as_cstring());
1712 printf("testing get_seekable_stream_decoder_state()... ");
1713 FLAC::Decoder::SeekableStream::State state_ = decoder->get_seekable_stream_decoder_state();
1714 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__SeekableStreamDecoderState)state_), state_.as_cstring());
1716 printf("testing get_stream_decoder_state()... ");
1717 FLAC::Decoder::Stream::State state__ = decoder->get_stream_decoder_state();
1718 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state__), state__.as_cstring());
1720 decoder->current_metadata_number_ = 0;
1721 decoder->ignore_errors_ = false;
1722 decoder->error_occurred_ = false;
1724 printf("testing get_md5_checking()... ");
1725 if(!decoder->get_md5_checking()) {
1726 printf("FAILED, returned false, expected true\n");
1731 printf("testing process_until_end_of_metadata()... ");
1732 if(!decoder->process_until_end_of_metadata())
1733 return decoder->die("returned false");
1736 printf("testing process_single()... ");
1737 if(!decoder->process_single())
1738 return decoder->die("returned false");
1741 printf("testing skip_single_frame()... ");
1742 if(!decoder->skip_single_frame())
1743 return decoder->die("returned false");
1746 printf("testing seek_absolute()... ");
1747 if(!decoder->seek_absolute(0))
1748 return decoder->die("returned false");
1751 printf("testing process_until_end_of_file()... ");
1752 if(!decoder->process_until_end_of_file())
1753 return decoder->die("returned false");
1756 printf("testing get_channels()... ");
1758 unsigned channels = decoder->get_channels();
1759 if(channels != streaminfo_.data.stream_info.channels) {
1760 printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
1766 printf("testing get_bits_per_sample()... ");
1768 unsigned bits_per_sample = decoder->get_bits_per_sample();
1769 if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
1770 printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
1776 printf("testing get_sample_rate()... ");
1778 unsigned sample_rate = decoder->get_sample_rate();
1779 if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
1780 printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
1786 printf("testing get_blocksize()... ");
1788 unsigned blocksize = decoder->get_blocksize();
1789 /* value could be anything since we're at the last block, so accept any answer */
1790 printf("returned %u... OK\n", blocksize);
1793 printf("testing get_channel_assignment()... ");
1795 ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
1796 printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
1799 printf("testing finish()... ");
1807 printf("testing set_metadata_respond_all()... ");
1808 if(!decoder->set_metadata_respond_all()) {
1809 printf("FAILED, returned false\n");
1815 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1816 expected_metadata_sequence_[num_expected_++] = &padding_;
1817 expected_metadata_sequence_[num_expected_++] = &seektable_;
1818 expected_metadata_sequence_[num_expected_++] = &application1_;
1819 expected_metadata_sequence_[num_expected_++] = &application2_;
1820 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1821 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1822 expected_metadata_sequence_[num_expected_++] = &unknown_;
1824 if(!decoder->test_respond())
1831 printf("testing set_metadata_ignore_all()... ");
1832 if(!decoder->set_metadata_ignore_all()) {
1833 printf("FAILED, returned false\n");
1840 if(!decoder->test_respond())
1844 * respond all, ignore VORBIS_COMMENT
1847 printf("testing set_metadata_respond_all()... ");
1848 if(!decoder->set_metadata_respond_all()) {
1849 printf("FAILED, returned false\n");
1854 printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
1855 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
1856 printf("FAILED, returned false\n");
1862 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1863 expected_metadata_sequence_[num_expected_++] = &padding_;
1864 expected_metadata_sequence_[num_expected_++] = &seektable_;
1865 expected_metadata_sequence_[num_expected_++] = &application1_;
1866 expected_metadata_sequence_[num_expected_++] = &application2_;
1867 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1868 expected_metadata_sequence_[num_expected_++] = &unknown_;
1870 if(!decoder->test_respond())
1874 * respond all, ignore APPLICATION
1877 printf("testing set_metadata_respond_all()... ");
1878 if(!decoder->set_metadata_respond_all()) {
1879 printf("FAILED, returned false\n");
1884 printf("testing set_metadata_ignore(APPLICATION)... ");
1885 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1886 printf("FAILED, returned false\n");
1892 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1893 expected_metadata_sequence_[num_expected_++] = &padding_;
1894 expected_metadata_sequence_[num_expected_++] = &seektable_;
1895 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1896 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1897 expected_metadata_sequence_[num_expected_++] = &unknown_;
1899 if(!decoder->test_respond())
1903 * respond all, ignore 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(of app block #1)... ");
1914 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1915 printf("FAILED, returned false\n");
1921 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1922 expected_metadata_sequence_[num_expected_++] = &padding_;
1923 expected_metadata_sequence_[num_expected_++] = &seektable_;
1924 expected_metadata_sequence_[num_expected_++] = &application2_;
1925 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1926 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1927 expected_metadata_sequence_[num_expected_++] = &unknown_;
1929 if(!decoder->test_respond())
1933 * respond all, ignore APPLICATION id of app#1 & app#2
1936 printf("testing set_metadata_respond_all()... ");
1937 if(!decoder->set_metadata_respond_all()) {
1938 printf("FAILED, returned false\n");
1943 printf("testing set_metadata_ignore_application(of app block #1)... ");
1944 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1945 printf("FAILED, returned false\n");
1950 printf("testing set_metadata_ignore_application(of app block #2)... ");
1951 if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
1952 printf("FAILED, returned false\n");
1958 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1959 expected_metadata_sequence_[num_expected_++] = &padding_;
1960 expected_metadata_sequence_[num_expected_++] = &seektable_;
1961 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1962 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1963 expected_metadata_sequence_[num_expected_++] = &unknown_;
1965 if(!decoder->test_respond())
1969 * ignore all, respond VORBIS_COMMENT
1972 printf("testing set_metadata_ignore_all()... ");
1973 if(!decoder->set_metadata_ignore_all()) {
1974 printf("FAILED, returned false\n");
1979 printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
1980 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
1981 printf("FAILED, returned false\n");
1987 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1989 if(!decoder->test_respond())
1993 * ignore all, respond APPLICATION
1996 printf("testing set_metadata_ignore_all()... ");
1997 if(!decoder->set_metadata_ignore_all()) {
1998 printf("FAILED, returned false\n");
2003 printf("testing set_metadata_respond(APPLICATION)... ");
2004 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
2005 printf("FAILED, returned false\n");
2011 expected_metadata_sequence_[num_expected_++] = &application1_;
2012 expected_metadata_sequence_[num_expected_++] = &application2_;
2014 if(!decoder->test_respond())
2018 * ignore all, respond APPLICATION id of app#1
2021 printf("testing set_metadata_ignore_all()... ");
2022 if(!decoder->set_metadata_ignore_all()) {
2023 printf("FAILED, returned false\n");
2028 printf("testing set_metadata_respond_application(of app block #1)... ");
2029 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
2030 printf("FAILED, returned false\n");
2036 expected_metadata_sequence_[num_expected_++] = &application1_;
2038 if(!decoder->test_respond())
2042 * ignore all, respond APPLICATION id of app#1 & app#2
2045 printf("testing set_metadata_ignore_all()... ");
2046 if(!decoder->set_metadata_ignore_all()) {
2047 printf("FAILED, returned false\n");
2052 printf("testing set_metadata_respond_application(of app block #1)... ");
2053 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
2054 printf("FAILED, returned false\n");
2059 printf("testing set_metadata_respond_application(of app block #2)... ");
2060 if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
2061 printf("FAILED, returned false\n");
2067 expected_metadata_sequence_[num_expected_++] = &application1_;
2068 expected_metadata_sequence_[num_expected_++] = &application2_;
2070 if(!decoder->test_respond())
2074 * respond all, ignore APPLICATION, respond APPLICATION id of app#1
2077 printf("testing set_metadata_respond_all()... ");
2078 if(!decoder->set_metadata_respond_all()) {
2079 printf("FAILED, returned false\n");
2084 printf("testing set_metadata_ignore(APPLICATION)... ");
2085 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
2086 printf("FAILED, returned false\n");
2091 printf("testing set_metadata_respond_application(of app block #1)... ");
2092 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
2093 printf("FAILED, returned false\n");
2099 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
2100 expected_metadata_sequence_[num_expected_++] = &padding_;
2101 expected_metadata_sequence_[num_expected_++] = &seektable_;
2102 expected_metadata_sequence_[num_expected_++] = &application1_;
2103 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
2104 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
2105 expected_metadata_sequence_[num_expected_++] = &unknown_;
2107 if(!decoder->test_respond())
2111 * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
2114 printf("testing set_metadata_ignore_all()... ");
2115 if(!decoder->set_metadata_ignore_all()) {
2116 printf("FAILED, returned false\n");
2121 printf("testing set_metadata_respond(APPLICATION)... ");
2122 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
2123 printf("FAILED, returned false\n");
2128 printf("testing set_metadata_ignore_application(of app block #1)... ");
2129 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
2130 printf("FAILED, returned false\n");
2136 expected_metadata_sequence_[num_expected_++] = &application2_;
2138 if(!decoder->test_respond())
2141 /* done, now leave the sequence the way we found it... */
2143 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
2144 expected_metadata_sequence_[num_expected_++] = &padding_;
2145 expected_metadata_sequence_[num_expected_++] = &seektable_;
2146 expected_metadata_sequence_[num_expected_++] = &application1_;
2147 expected_metadata_sequence_[num_expected_++] = &application2_;
2148 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
2149 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
2150 expected_metadata_sequence_[num_expected_++] = &unknown_;
2152 printf("freeing decoder instance... ");
2156 printf("\nPASSED!\n");
2161 bool test_decoders()
2163 init_metadata_blocks_();
2165 if(!generate_file_())
2168 if(!test_stream_decoder())
2171 if(!test_seekable_stream_decoder())
2174 if(!test_file_decoder())
2177 (void) grabbag__file_remove_file(flacfilename_);
2179 free_metadata_blocks_();