1 /* test_libOggFLAC++ - Unit tester for libOggFLAC++
2 * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #if defined _MSC_VER || defined __MINGW32__
24 //@@@ [2G limit] hacks for MSVC6
30 #include "file_utils.h"
31 #include "metadata_utils.h"
33 #include "FLAC/assert.h"
34 #include "FLAC/metadata.h" // for ::FLAC__metadata_object_is_equal()
35 #include "OggFLAC++/decoder.h"
36 #include "share/grabbag.h"
39 // warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
40 #pragma warning ( disable : 4800 )
43 static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, unknown_;
44 static ::FLAC__StreamMetadata *expected_metadata_sequence_[8];
45 static unsigned num_expected_;
46 static const char *oggflacfilename_ = "metadata.ogg";
47 static off_t oggflacfilesize_;
49 static bool die_(const char *msg)
51 printf("ERROR: %s\n", msg);
55 static void init_metadata_blocks_()
57 mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
60 static void free_metadata_blocks_()
62 mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
65 static bool generate_file_()
67 printf("\n\ngenerating Ogg FLAC file for decoder tests...\n");
70 expected_metadata_sequence_[num_expected_++] = &padding_;
71 expected_metadata_sequence_[num_expected_++] = &seektable_;
72 expected_metadata_sequence_[num_expected_++] = &application1_;
73 expected_metadata_sequence_[num_expected_++] = &application2_;
74 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
75 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
76 expected_metadata_sequence_[num_expected_++] = &unknown_;
77 /* WATCHOUT: the encoder should move the VORBIS_COMMENT block to the front, right after STREAMINFO */
79 if(!file_utils__generate_oggflacfile(oggflacfilename_, &oggflacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
80 return die_("creating the encoded file");
89 unsigned current_metadata_number_;
93 DecoderCommon(): file_(0), current_metadata_number_(0), ignore_errors_(false), error_occurred_(false) { }
94 ::FLAC__StreamDecoderReadStatus common_read_callback_(FLAC__byte buffer[], unsigned *bytes);
95 ::FLAC__StreamDecoderWriteStatus common_write_callback_(const ::FLAC__Frame *frame);
96 void common_metadata_callback_(const ::FLAC__StreamMetadata *metadata);
97 void common_error_callback_(::FLAC__StreamDecoderErrorStatus status);
100 ::FLAC__StreamDecoderReadStatus DecoderCommon::common_read_callback_(FLAC__byte buffer[], unsigned *bytes)
103 return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT;
107 return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
109 else if(*bytes > 0) {
110 *bytes = ::fread(buffer, 1, *bytes, file_);
113 return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
115 return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
118 return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
122 return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
125 ::FLAC__StreamDecoderWriteStatus DecoderCommon::common_write_callback_(const ::FLAC__Frame *frame)
128 return ::FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
131 (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) ||
132 (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0)
134 printf("content... ");
138 return ::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
141 void DecoderCommon::common_metadata_callback_(const ::FLAC__StreamMetadata *metadata)
146 printf("%d... ", current_metadata_number_);
149 if(current_metadata_number_ >= num_expected_) {
150 (void)die_("got more metadata blocks than expected");
151 error_occurred_ = true;
154 if(!::FLAC__metadata_object_is_equal(expected_metadata_sequence_[current_metadata_number_], metadata)) {
155 (void)die_("metadata block mismatch");
156 error_occurred_ = true;
159 current_metadata_number_++;
162 void DecoderCommon::common_error_callback_(::FLAC__StreamDecoderErrorStatus status)
164 if(!ignore_errors_) {
165 printf("ERROR: got error callback: err = %u (%s)\n", (unsigned)status, ::FLAC__StreamDecoderErrorStatusString[status]);
166 error_occurred_ = true;
170 class StreamDecoder : public OggFLAC::Decoder::Stream, public DecoderCommon {
172 StreamDecoder(): OggFLAC::Decoder::Stream(), DecoderCommon() { }
175 // from OggFLAC::Decoder::Stream
176 ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
177 ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
178 void metadata_callback(const ::FLAC__StreamMetadata *metadata);
179 void error_callback(::FLAC__StreamDecoderErrorStatus status);
181 bool die(const char *msg = 0) const;
186 ::FLAC__StreamDecoderReadStatus StreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
188 return common_read_callback_(buffer, bytes);
191 ::FLAC__StreamDecoderWriteStatus StreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
195 return common_write_callback_(frame);
198 void StreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
200 common_metadata_callback_(metadata);
203 void StreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
205 common_error_callback_(status);
208 bool StreamDecoder::die(const char *msg) const
210 State state = get_state();
213 printf("FAILED, %s", msg);
217 printf(", state = %u (%s)\n", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring());
222 bool StreamDecoder::test_respond()
224 printf("testing init()... ");
225 if(init() != ::OggFLAC__STREAM_DECODER_OK)
229 current_metadata_number_ = 0;
231 if(fseeko(file_, 0, SEEK_SET) < 0) {
232 printf("FAILED rewinding input, errno = %d\n", errno);
236 printf("testing process_until_end_of_stream()... ");
237 if(!process_until_end_of_stream()) {
238 State state = get_state();
239 printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring());
244 printf("testing finish()... ");
251 static bool test_stream_decoder()
253 StreamDecoder *decoder;
255 printf("\n+++ libOggFLAC++ unit test: OggFLAC::Decoder::Stream\n\n");
258 // test new -> delete
260 printf("allocating decoder instance... ");
261 decoder = new StreamDecoder();
263 printf("FAILED, new returned NULL\n");
268 printf("testing is_valid()... ");
269 if(!decoder->is_valid()) {
270 printf("FAILED, returned false\n");
275 printf("freeing decoder instance... ");
280 // test new -> init -> delete
282 printf("allocating decoder instance... ");
283 decoder = new StreamDecoder();
285 printf("FAILED, new returned NULL\n");
290 printf("testing is_valid()... ");
291 if(!decoder->is_valid()) {
292 printf("FAILED, returned false\n");
297 printf("testing init()... ");
298 if(decoder->init() != ::OggFLAC__STREAM_DECODER_OK)
299 return decoder->die();
302 printf("freeing decoder instance... ");
310 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
312 printf("allocating decoder instance... ");
313 decoder = new StreamDecoder();
315 printf("FAILED, new returned NULL\n");
320 printf("testing is_valid()... ");
321 if(!decoder->is_valid()) {
322 printf("FAILED, returned false\n");
327 printf("testing set_serial_number()... ");
328 if(!decoder->set_serial_number(file_utils__serial_number))
329 return decoder->die("returned false");
332 printf("testing init()... ");
333 if(decoder->init() != ::OggFLAC__STREAM_DECODER_OK)
334 return decoder->die();
337 printf("testing get_state()... ");
338 OggFLAC::Decoder::Stream::State state = decoder->get_state();
339 printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring());
341 printf("testing get_FLAC_stream_decoder_state()... ");
342 FLAC::Decoder::Stream::State state_ = decoder->get_FLAC_stream_decoder_state();
343 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state_), state_.as_cstring());
345 decoder->current_metadata_number_ = 0;
346 decoder->ignore_errors_ = false;
347 decoder->error_occurred_ = false;
349 printf("opening Ogg FLAC file... ");
350 decoder->file_ = ::fopen(oggflacfilename_, "rb");
351 if(0 == decoder->file_) {
352 printf("ERROR (%s)\n", strerror(errno));
357 printf("testing process_until_end_of_metadata()... ");
358 if(!decoder->process_until_end_of_metadata())
359 return decoder->die("returned false");
362 printf("testing process_single()... ");
363 if(!decoder->process_single())
364 return decoder->die("returned false");
367 printf("testing flush()... ");
368 if(!decoder->flush())
369 return decoder->die("returned false");
372 decoder->ignore_errors_ = true;
373 printf("testing process_single()... ");
374 if(!decoder->process_single())
375 return decoder->die("returned false");
377 decoder->ignore_errors_ = false;
379 printf("testing process_until_end_of_stream()... ");
380 if(!decoder->process_until_end_of_stream())
381 return decoder->die("returned false");
384 printf("testing get_channels()... ");
386 unsigned channels = decoder->get_channels();
387 if(channels != streaminfo_.data.stream_info.channels) {
388 printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
394 printf("testing get_bits_per_sample()... ");
396 unsigned bits_per_sample = decoder->get_bits_per_sample();
397 if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
398 printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
404 printf("testing get_sample_rate()... ");
406 unsigned sample_rate = decoder->get_sample_rate();
407 if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
408 printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
414 printf("testing get_blocksize()... ");
416 unsigned blocksize = decoder->get_blocksize();
417 /* value could be anything since we're at the last block, so accept any answer */
418 printf("returned %u... OK\n", blocksize);
421 printf("testing get_channel_assignment()... ");
423 ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
424 printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
427 printf("testing reset()... ");
428 if(!decoder->reset())
429 return decoder->die("returned false");
432 decoder->current_metadata_number_ = 0;
434 printf("rewinding input... ");
435 if(fseeko(decoder->file_, 0, SEEK_SET) < 0) {
436 printf("FAILED, errno = %d\n", errno);
441 printf("testing process_until_end_of_stream()... ");
442 if(!decoder->process_until_end_of_stream())
443 return decoder->die("returned false");
446 printf("testing finish()... ");
454 printf("testing set_metadata_respond_all()... ");
455 if(!decoder->set_metadata_respond_all()) {
456 printf("FAILED, returned false\n");
462 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
463 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
464 expected_metadata_sequence_[num_expected_++] = &padding_;
465 expected_metadata_sequence_[num_expected_++] = &seektable_;
466 expected_metadata_sequence_[num_expected_++] = &application1_;
467 expected_metadata_sequence_[num_expected_++] = &application2_;
468 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
469 expected_metadata_sequence_[num_expected_++] = &unknown_;
471 if(!decoder->test_respond())
478 printf("testing set_metadata_ignore_all()... ");
479 if(!decoder->set_metadata_ignore_all()) {
480 printf("FAILED, returned false\n");
487 if(!decoder->test_respond())
491 * respond all, ignore VORBIS_COMMENT
494 printf("testing set_metadata_respond_all()... ");
495 if(!decoder->set_metadata_respond_all()) {
496 printf("FAILED, returned false\n");
501 printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
502 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
503 printf("FAILED, returned false\n");
509 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
510 expected_metadata_sequence_[num_expected_++] = &padding_;
511 expected_metadata_sequence_[num_expected_++] = &seektable_;
512 expected_metadata_sequence_[num_expected_++] = &application1_;
513 expected_metadata_sequence_[num_expected_++] = &application2_;
514 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
515 expected_metadata_sequence_[num_expected_++] = &unknown_;
517 if(!decoder->test_respond())
521 * respond all, ignore APPLICATION
524 printf("testing set_metadata_respond_all()... ");
525 if(!decoder->set_metadata_respond_all()) {
526 printf("FAILED, returned false\n");
531 printf("testing set_metadata_ignore(APPLICATION)... ");
532 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
533 printf("FAILED, returned false\n");
539 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
540 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
541 expected_metadata_sequence_[num_expected_++] = &padding_;
542 expected_metadata_sequence_[num_expected_++] = &seektable_;
543 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
544 expected_metadata_sequence_[num_expected_++] = &unknown_;
546 if(!decoder->test_respond())
550 * respond all, ignore APPLICATION id of app#1
553 printf("testing set_metadata_respond_all()... ");
554 if(!decoder->set_metadata_respond_all()) {
555 printf("FAILED, returned false\n");
560 printf("testing set_metadata_ignore_application(of app block #1)... ");
561 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
562 printf("FAILED, returned false\n");
568 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
569 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
570 expected_metadata_sequence_[num_expected_++] = &padding_;
571 expected_metadata_sequence_[num_expected_++] = &seektable_;
572 expected_metadata_sequence_[num_expected_++] = &application2_;
573 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
574 expected_metadata_sequence_[num_expected_++] = &unknown_;
576 if(!decoder->test_respond())
580 * respond all, ignore APPLICATION id of app#1 & app#2
583 printf("testing set_metadata_respond_all()... ");
584 if(!decoder->set_metadata_respond_all()) {
585 printf("FAILED, returned false\n");
590 printf("testing set_metadata_ignore_application(of app block #1)... ");
591 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
592 printf("FAILED, returned false\n");
597 printf("testing set_metadata_ignore_application(of app block #2)... ");
598 if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
599 printf("FAILED, returned false\n");
605 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
606 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
607 expected_metadata_sequence_[num_expected_++] = &padding_;
608 expected_metadata_sequence_[num_expected_++] = &seektable_;
609 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
610 expected_metadata_sequence_[num_expected_++] = &unknown_;
612 if(!decoder->test_respond())
616 * ignore all, respond VORBIS_COMMENT
619 printf("testing set_metadata_ignore_all()... ");
620 if(!decoder->set_metadata_ignore_all()) {
621 printf("FAILED, returned false\n");
626 printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
627 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
628 printf("FAILED, returned false\n");
634 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
636 if(!decoder->test_respond())
640 * ignore all, respond APPLICATION
643 printf("testing set_metadata_ignore_all()... ");
644 if(!decoder->set_metadata_ignore_all()) {
645 printf("FAILED, returned false\n");
650 printf("testing set_metadata_respond(APPLICATION)... ");
651 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
652 printf("FAILED, returned false\n");
658 expected_metadata_sequence_[num_expected_++] = &application1_;
659 expected_metadata_sequence_[num_expected_++] = &application2_;
661 if(!decoder->test_respond())
665 * ignore all, respond APPLICATION id of app#1
668 printf("testing set_metadata_ignore_all()... ");
669 if(!decoder->set_metadata_ignore_all()) {
670 printf("FAILED, returned false\n");
675 printf("testing set_metadata_respond_application(of app block #1)... ");
676 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
677 printf("FAILED, returned false\n");
683 expected_metadata_sequence_[num_expected_++] = &application1_;
685 if(!decoder->test_respond())
689 * ignore all, respond APPLICATION id of app#1 & app#2
692 printf("testing set_metadata_ignore_all()... ");
693 if(!decoder->set_metadata_ignore_all()) {
694 printf("FAILED, returned false\n");
699 printf("testing set_metadata_respond_application(of app block #1)... ");
700 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
701 printf("FAILED, returned false\n");
706 printf("testing set_metadata_respond_application(of app block #2)... ");
707 if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
708 printf("FAILED, returned false\n");
714 expected_metadata_sequence_[num_expected_++] = &application1_;
715 expected_metadata_sequence_[num_expected_++] = &application2_;
717 if(!decoder->test_respond())
721 * respond all, ignore APPLICATION, respond APPLICATION id of app#1
724 printf("testing set_metadata_respond_all()... ");
725 if(!decoder->set_metadata_respond_all()) {
726 printf("FAILED, returned false\n");
731 printf("testing set_metadata_ignore(APPLICATION)... ");
732 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
733 printf("FAILED, returned false\n");
738 printf("testing set_metadata_respond_application(of app block #1)... ");
739 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
740 printf("FAILED, returned false\n");
746 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
747 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
748 expected_metadata_sequence_[num_expected_++] = &padding_;
749 expected_metadata_sequence_[num_expected_++] = &seektable_;
750 expected_metadata_sequence_[num_expected_++] = &application1_;
751 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
752 expected_metadata_sequence_[num_expected_++] = &unknown_;
754 if(!decoder->test_respond())
758 * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
761 printf("testing set_metadata_ignore_all()... ");
762 if(!decoder->set_metadata_ignore_all()) {
763 printf("FAILED, returned false\n");
768 printf("testing set_metadata_respond(APPLICATION)... ");
769 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
770 printf("FAILED, returned false\n");
775 printf("testing set_metadata_ignore_application(of app block #1)... ");
776 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
777 printf("FAILED, returned false\n");
783 expected_metadata_sequence_[num_expected_++] = &application2_;
785 if(!decoder->test_respond())
788 /* done, now leave the sequence the way we found it... */
790 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
791 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
792 expected_metadata_sequence_[num_expected_++] = &padding_;
793 expected_metadata_sequence_[num_expected_++] = &seektable_;
794 expected_metadata_sequence_[num_expected_++] = &application1_;
795 expected_metadata_sequence_[num_expected_++] = &application2_;
796 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
797 expected_metadata_sequence_[num_expected_++] = &unknown_;
799 ::fclose(decoder->file_);
801 printf("freeing decoder instance... ");
805 printf("\nPASSED!\n");
810 class SeekableStreamDecoder : public OggFLAC::Decoder::SeekableStream, public DecoderCommon {
812 SeekableStreamDecoder(): OggFLAC::Decoder::SeekableStream(), DecoderCommon() { }
813 ~SeekableStreamDecoder() { }
815 // from OggFLAC::Decoder::SeekableStream
816 ::OggFLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
817 ::OggFLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
818 ::OggFLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
819 ::OggFLAC__SeekableStreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length);
821 ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
822 void metadata_callback(const ::FLAC__StreamMetadata *metadata);
823 void error_callback(::FLAC__StreamDecoderErrorStatus status);
825 bool die(const char *msg = 0) const;
830 ::OggFLAC__SeekableStreamDecoderReadStatus SeekableStreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
832 switch(common_read_callback_(buffer, bytes)) {
833 case ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
834 case ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
835 return ::OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
836 case ::FLAC__STREAM_DECODER_READ_STATUS_ABORT:
837 return ::OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
840 return ::OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
844 ::OggFLAC__SeekableStreamDecoderSeekStatus SeekableStreamDecoder::seek_callback(FLAC__uint64 absolute_byte_offset)
847 return ::OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
849 if(fseeko(file_, (off_t)absolute_byte_offset, SEEK_SET) < 0) {
850 error_occurred_ = true;
851 return ::OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
854 return ::OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
857 ::OggFLAC__SeekableStreamDecoderTellStatus SeekableStreamDecoder::tell_callback(FLAC__uint64 *absolute_byte_offset)
860 return ::OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
862 off_t offset = ftello(file_);
863 *absolute_byte_offset = (FLAC__uint64)offset;
866 error_occurred_ = true;
867 return ::OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
870 return ::OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;
873 ::OggFLAC__SeekableStreamDecoderLengthStatus SeekableStreamDecoder::length_callback(FLAC__uint64 *stream_length)
876 return ::OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR;
878 *stream_length = (FLAC__uint64)oggflacfilesize_;
879 return ::OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;
882 bool SeekableStreamDecoder::eof_callback()
887 return (bool)feof(file_);
890 ::FLAC__StreamDecoderWriteStatus SeekableStreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
894 return common_write_callback_(frame);
897 void SeekableStreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
899 common_metadata_callback_(metadata);
902 void SeekableStreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
904 common_error_callback_(status);
907 bool SeekableStreamDecoder::die(const char *msg) const
909 State state = get_state();
912 printf("FAILED, %s", msg);
916 printf(", state = %u (%s)\n", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state), state.as_cstring());
917 if(state == ::OggFLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR) {
918 OggFLAC::Decoder::Stream::State state_ = get_stream_decoder_state();
919 printf(" stream decoder state = %u (%s)\n", (unsigned)((::OggFLAC__StreamDecoderState)state_), state_.as_cstring());
920 if(state_ == ::OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR) {
921 FLAC::Decoder::Stream::State state__ = get_FLAC_stream_decoder_state();
922 printf(" FLAC stream decoder state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state__), state__.as_cstring());
929 bool SeekableStreamDecoder::test_respond()
931 if(!set_md5_checking(true)) {
932 printf("FAILED at set_md5_checking(), returned false\n");
936 printf("testing init()... ");
937 if(init() != ::OggFLAC__SEEKABLE_STREAM_DECODER_OK)
941 current_metadata_number_ = 0;
943 if(fseeko(file_, 0, SEEK_SET) < 0) {
944 printf("FAILED rewinding input, errno = %d\n", errno);
948 printf("testing process_until_end_of_stream()... ");
949 if(!process_until_end_of_stream()) {
950 State state = get_state();
951 printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state), state.as_cstring());
956 printf("testing finish()... ");
963 static bool test_seekable_stream_decoder()
965 SeekableStreamDecoder *decoder;
967 printf("\n+++ libOggFLAC++ unit test: OggFLAC::Decoder::SeekableStream\n\n");
970 // test new -> delete
972 printf("allocating decoder instance... ");
973 decoder = new SeekableStreamDecoder();
975 printf("FAILED, new returned NULL\n");
980 printf("testing is_valid()... ");
981 if(!decoder->is_valid()) {
982 printf("FAILED, returned false\n");
987 printf("freeing decoder instance... ");
992 // test new -> init -> delete
994 printf("allocating decoder instance... ");
995 decoder = new SeekableStreamDecoder();
997 printf("FAILED, new returned NULL\n");
1002 printf("testing is_valid()... ");
1003 if(!decoder->is_valid()) {
1004 printf("FAILED, returned false\n");
1009 printf("testing init()... ");
1010 if(decoder->init() != ::OggFLAC__SEEKABLE_STREAM_DECODER_OK)
1011 return decoder->die();
1014 printf("freeing decoder instance... ");
1019 // test normal usage
1022 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1024 printf("allocating decoder instance... ");
1025 decoder = new SeekableStreamDecoder();
1027 printf("FAILED, new returned NULL\n");
1032 printf("testing is_valid()... ");
1033 if(!decoder->is_valid()) {
1034 printf("FAILED, returned false\n");
1039 printf("testing set_md5_checking()... ");
1040 if(!decoder->set_md5_checking(true)) {
1041 printf("FAILED, returned false\n");
1046 printf("testing set_serial_number()... ");
1047 if(!decoder->set_serial_number(file_utils__serial_number))
1048 return decoder->die("returned false");
1051 printf("testing init()... ");
1052 if(decoder->init() != ::OggFLAC__SEEKABLE_STREAM_DECODER_OK)
1053 return decoder->die();
1056 printf("testing get_state()... ");
1057 OggFLAC::Decoder::SeekableStream::State state = decoder->get_state();
1058 printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state), state.as_cstring());
1060 printf("testing get_stream_decoder_state()... ");
1061 OggFLAC::Decoder::Stream::State state_ = decoder->get_stream_decoder_state();
1062 printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__StreamDecoderState)state_), state_.as_cstring());
1064 printf("testing get_FLAC_stream_decoder_state()... ");
1065 FLAC::Decoder::Stream::State state__ = decoder->get_FLAC_stream_decoder_state();
1066 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state__), state__.as_cstring());
1068 decoder->current_metadata_number_ = 0;
1069 decoder->ignore_errors_ = false;
1070 decoder->error_occurred_ = false;
1072 printf("opening Ogg FLAC file... ");
1073 decoder->file_ = ::fopen(oggflacfilename_, "rb");
1074 if(0 == decoder->file_) {
1075 printf("ERROR (%s)\n", strerror(errno));
1080 printf("testing get_md5_checking()... ");
1081 if(!decoder->get_md5_checking()) {
1082 printf("FAILED, returned false, expected true\n");
1087 printf("testing process_until_end_of_metadata()... ");
1088 if(!decoder->process_until_end_of_metadata())
1089 return decoder->die("returned false");
1092 printf("testing process_single()... ");
1093 if(!decoder->process_single())
1094 return decoder->die("returned false");
1097 printf("testing flush()... ");
1098 if(!decoder->flush())
1099 return decoder->die("returned false");
1102 decoder->ignore_errors_ = true;
1103 printf("testing process_single()... ");
1104 if(!decoder->process_single())
1105 return decoder->die("returned false");
1107 decoder->ignore_errors_ = false;
1109 printf("testing seek_absolute()... ");
1110 if(!decoder->seek_absolute(0))
1111 return decoder->die("returned false");
1114 printf("testing process_until_end_of_stream()... ");
1115 if(!decoder->process_until_end_of_stream())
1116 return decoder->die("returned false");
1119 printf("testing get_channels()... ");
1121 unsigned channels = decoder->get_channels();
1122 if(channels != streaminfo_.data.stream_info.channels) {
1123 printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
1129 printf("testing get_bits_per_sample()... ");
1131 unsigned bits_per_sample = decoder->get_bits_per_sample();
1132 if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
1133 printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
1139 printf("testing get_sample_rate()... ");
1141 unsigned sample_rate = decoder->get_sample_rate();
1142 if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
1143 printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
1149 printf("testing get_blocksize()... ");
1151 unsigned blocksize = decoder->get_blocksize();
1152 /* value could be anything since we're at the last block, so accept any answer */
1153 printf("returned %u... OK\n", blocksize);
1156 printf("testing get_channel_assignment()... ");
1158 ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
1159 printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
1162 printf("testing reset()... ");
1163 if(!decoder->reset())
1164 return decoder->die("returned false");
1167 decoder->current_metadata_number_ = 0;
1169 printf("rewinding input... ");
1170 if(fseeko(decoder->file_, 0, SEEK_SET) < 0) {
1171 printf("FAILED, errno = %d\n", errno);
1176 printf("testing process_until_end_of_stream()... ");
1177 if(!decoder->process_until_end_of_stream())
1178 return decoder->die("returned false");
1181 printf("testing finish()... ");
1189 printf("testing set_metadata_respond_all()... ");
1190 if(!decoder->set_metadata_respond_all()) {
1191 printf("FAILED, returned false\n");
1197 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1198 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1199 expected_metadata_sequence_[num_expected_++] = &padding_;
1200 expected_metadata_sequence_[num_expected_++] = &seektable_;
1201 expected_metadata_sequence_[num_expected_++] = &application1_;
1202 expected_metadata_sequence_[num_expected_++] = &application2_;
1203 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1204 expected_metadata_sequence_[num_expected_++] = &unknown_;
1206 if(!decoder->test_respond())
1213 printf("testing set_metadata_ignore_all()... ");
1214 if(!decoder->set_metadata_ignore_all()) {
1215 printf("FAILED, returned false\n");
1222 if(!decoder->test_respond())
1226 * respond all, ignore VORBIS_COMMENT
1229 printf("testing set_metadata_respond_all()... ");
1230 if(!decoder->set_metadata_respond_all()) {
1231 printf("FAILED, returned false\n");
1236 printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
1237 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
1238 printf("FAILED, returned false\n");
1244 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1245 expected_metadata_sequence_[num_expected_++] = &padding_;
1246 expected_metadata_sequence_[num_expected_++] = &seektable_;
1247 expected_metadata_sequence_[num_expected_++] = &application1_;
1248 expected_metadata_sequence_[num_expected_++] = &application2_;
1249 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1250 expected_metadata_sequence_[num_expected_++] = &unknown_;
1252 if(!decoder->test_respond())
1256 * respond all, ignore APPLICATION
1259 printf("testing set_metadata_respond_all()... ");
1260 if(!decoder->set_metadata_respond_all()) {
1261 printf("FAILED, returned false\n");
1266 printf("testing set_metadata_ignore(APPLICATION)... ");
1267 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1268 printf("FAILED, returned false\n");
1274 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1275 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1276 expected_metadata_sequence_[num_expected_++] = &padding_;
1277 expected_metadata_sequence_[num_expected_++] = &seektable_;
1278 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1279 expected_metadata_sequence_[num_expected_++] = &unknown_;
1281 if(!decoder->test_respond())
1285 * respond all, ignore APPLICATION id of app#1
1288 printf("testing set_metadata_respond_all()... ");
1289 if(!decoder->set_metadata_respond_all()) {
1290 printf("FAILED, returned false\n");
1295 printf("testing set_metadata_ignore_application(of app block #1)... ");
1296 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1297 printf("FAILED, returned false\n");
1303 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1304 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1305 expected_metadata_sequence_[num_expected_++] = &padding_;
1306 expected_metadata_sequence_[num_expected_++] = &seektable_;
1307 expected_metadata_sequence_[num_expected_++] = &application2_;
1308 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1309 expected_metadata_sequence_[num_expected_++] = &unknown_;
1311 if(!decoder->test_respond())
1315 * respond all, ignore APPLICATION id of app#1 & app#2
1318 printf("testing set_metadata_respond_all()... ");
1319 if(!decoder->set_metadata_respond_all()) {
1320 printf("FAILED, returned false\n");
1325 printf("testing set_metadata_ignore_application(of app block #1)... ");
1326 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1327 printf("FAILED, returned false\n");
1332 printf("testing set_metadata_ignore_application(of app block #2)... ");
1333 if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
1334 printf("FAILED, returned false\n");
1340 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1341 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1342 expected_metadata_sequence_[num_expected_++] = &padding_;
1343 expected_metadata_sequence_[num_expected_++] = &seektable_;
1344 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1345 expected_metadata_sequence_[num_expected_++] = &unknown_;
1347 if(!decoder->test_respond())
1351 * ignore all, respond VORBIS_COMMENT
1354 printf("testing set_metadata_ignore_all()... ");
1355 if(!decoder->set_metadata_ignore_all()) {
1356 printf("FAILED, returned false\n");
1361 printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
1362 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
1363 printf("FAILED, returned false\n");
1369 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1371 if(!decoder->test_respond())
1375 * ignore all, respond APPLICATION
1378 printf("testing set_metadata_ignore_all()... ");
1379 if(!decoder->set_metadata_ignore_all()) {
1380 printf("FAILED, returned false\n");
1385 printf("testing set_metadata_respond(APPLICATION)... ");
1386 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
1387 printf("FAILED, returned false\n");
1393 expected_metadata_sequence_[num_expected_++] = &application1_;
1394 expected_metadata_sequence_[num_expected_++] = &application2_;
1396 if(!decoder->test_respond())
1400 * ignore all, respond APPLICATION id of app#1
1403 printf("testing set_metadata_ignore_all()... ");
1404 if(!decoder->set_metadata_ignore_all()) {
1405 printf("FAILED, returned false\n");
1410 printf("testing set_metadata_respond_application(of app block #1)... ");
1411 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1412 printf("FAILED, returned false\n");
1418 expected_metadata_sequence_[num_expected_++] = &application1_;
1420 if(!decoder->test_respond())
1424 * ignore all, respond APPLICATION id of app#1 & app#2
1427 printf("testing set_metadata_ignore_all()... ");
1428 if(!decoder->set_metadata_ignore_all()) {
1429 printf("FAILED, returned false\n");
1434 printf("testing set_metadata_respond_application(of app block #1)... ");
1435 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1436 printf("FAILED, returned false\n");
1441 printf("testing set_metadata_respond_application(of app block #2)... ");
1442 if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
1443 printf("FAILED, returned false\n");
1449 expected_metadata_sequence_[num_expected_++] = &application1_;
1450 expected_metadata_sequence_[num_expected_++] = &application2_;
1452 if(!decoder->test_respond())
1456 * respond all, ignore APPLICATION, respond APPLICATION id of app#1
1459 printf("testing set_metadata_respond_all()... ");
1460 if(!decoder->set_metadata_respond_all()) {
1461 printf("FAILED, returned false\n");
1466 printf("testing set_metadata_ignore(APPLICATION)... ");
1467 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1468 printf("FAILED, returned false\n");
1473 printf("testing set_metadata_respond_application(of app block #1)... ");
1474 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1475 printf("FAILED, returned false\n");
1481 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1482 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1483 expected_metadata_sequence_[num_expected_++] = &padding_;
1484 expected_metadata_sequence_[num_expected_++] = &seektable_;
1485 expected_metadata_sequence_[num_expected_++] = &application1_;
1486 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1487 expected_metadata_sequence_[num_expected_++] = &unknown_;
1489 if(!decoder->test_respond())
1493 * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
1496 printf("testing set_metadata_ignore_all()... ");
1497 if(!decoder->set_metadata_ignore_all()) {
1498 printf("FAILED, returned false\n");
1503 printf("testing set_metadata_respond(APPLICATION)... ");
1504 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
1505 printf("FAILED, returned false\n");
1510 printf("testing set_metadata_ignore_application(of app block #1)... ");
1511 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1512 printf("FAILED, returned false\n");
1518 expected_metadata_sequence_[num_expected_++] = &application2_;
1520 if(!decoder->test_respond())
1523 /* done, now leave the sequence the way we found it... */
1525 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1526 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1527 expected_metadata_sequence_[num_expected_++] = &padding_;
1528 expected_metadata_sequence_[num_expected_++] = &seektable_;
1529 expected_metadata_sequence_[num_expected_++] = &application1_;
1530 expected_metadata_sequence_[num_expected_++] = &application2_;
1531 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1532 expected_metadata_sequence_[num_expected_++] = &unknown_;
1534 ::fclose(decoder->file_);
1536 printf("freeing decoder instance... ");
1540 printf("\nPASSED!\n");
1545 class FileDecoder : public OggFLAC::Decoder::File, public DecoderCommon {
1547 FileDecoder(): OggFLAC::Decoder::File(), DecoderCommon() { }
1550 // from OggFLAC::Decoder::File
1551 ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
1552 void metadata_callback(const ::FLAC__StreamMetadata *metadata);
1553 void error_callback(::FLAC__StreamDecoderErrorStatus status);
1555 bool die(const char *msg = 0) const;
1557 bool test_respond();
1560 ::FLAC__StreamDecoderWriteStatus FileDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
1563 return common_write_callback_(frame);
1566 void FileDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
1568 common_metadata_callback_(metadata);
1571 void FileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
1573 common_error_callback_(status);
1576 bool FileDecoder::die(const char *msg) const
1578 State state = get_state();
1581 printf("FAILED, %s", msg);
1585 printf(", state = %u (%s)\n", (unsigned)((::OggFLAC__FileDecoderState)state), state.as_cstring());
1586 if(state == ::OggFLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR) {
1587 OggFLAC::Decoder::SeekableStream::State state_ = get_seekable_stream_decoder_state();
1588 printf(" seekable stream decoder state = %u (%s)\n", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state_), state_.as_cstring());
1589 if(state_ == ::OggFLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR) {
1590 OggFLAC::Decoder::Stream::State state__ = get_stream_decoder_state();
1591 printf(" stream decoder state = %u (%s)\n", (unsigned)((::OggFLAC__StreamDecoderState)state__), state__.as_cstring());
1592 if(state__ == ::OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR) {
1593 FLAC::Decoder::Stream::State state___ = get_FLAC_stream_decoder_state();
1594 printf(" FLAC stream decoder state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state___), state___.as_cstring());
1602 bool FileDecoder::test_respond()
1604 if(!set_filename(oggflacfilename_)) {
1605 printf("FAILED at set_filename(), returned false\n");
1609 if(!set_md5_checking(true)) {
1610 printf("FAILED at set_md5_checking(), returned false\n");
1614 printf("testing init()... ");
1615 if(init() != ::OggFLAC__FILE_DECODER_OK)
1619 current_metadata_number_ = 0;
1621 printf("testing process_until_end_of_file()... ");
1622 if(!process_until_end_of_file()) {
1623 State state = get_state();
1624 printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::OggFLAC__FileDecoderState)state), state.as_cstring());
1629 printf("testing finish()... ");
1636 static bool test_file_decoder()
1638 FileDecoder *decoder;
1640 printf("\n+++ libOggFLAC++ unit test: OggFLAC::Decoder::File\n\n");
1643 // test new -> delete
1645 printf("allocating decoder instance... ");
1646 decoder = new FileDecoder();
1648 printf("FAILED, new returned NULL\n");
1653 printf("testing is_valid()... ");
1654 if(!decoder->is_valid()) {
1655 printf("FAILED, returned false\n");
1660 printf("freeing decoder instance... ");
1665 // test new -> init -> delete
1667 printf("allocating decoder instance... ");
1668 decoder = new FileDecoder();
1670 printf("FAILED, new returned NULL\n");
1675 printf("testing is_valid()... ");
1676 if(!decoder->is_valid()) {
1677 printf("FAILED, returned false\n");
1682 printf("testing init()... ");
1683 if(decoder->init() != ::OggFLAC__FILE_DECODER_OK)
1684 return decoder->die();
1687 printf("freeing decoder instance... ");
1692 // test normal usage
1695 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1697 printf("allocating decoder instance... ");
1698 decoder = new FileDecoder();
1700 printf("FAILED, new returned NULL\n");
1705 printf("testing is_valid()... ");
1706 if(!decoder->is_valid()) {
1707 printf("FAILED, returned false\n");
1712 printf("testing set_filename()... ");
1713 if(!decoder->set_filename(oggflacfilename_)) {
1714 printf("FAILED, returned false\n");
1719 printf("testing set_md5_checking()... ");
1720 if(!decoder->set_md5_checking(true)) {
1721 printf("FAILED, returned false\n");
1726 printf("testing set_serial_number()... ");
1727 if(!decoder->set_serial_number(file_utils__serial_number))
1728 return decoder->die("returned false");
1731 printf("testing init()... ");
1732 if(decoder->init() != ::OggFLAC__FILE_DECODER_OK)
1733 return decoder->die();
1736 printf("testing get_state()... ");
1737 OggFLAC::Decoder::File::State state = decoder->get_state();
1738 printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__FileDecoderState)state), state.as_cstring());
1740 printf("testing get_seekable_stream_decoder_state()... ");
1741 OggFLAC::Decoder::SeekableStream::State state_ = decoder->get_seekable_stream_decoder_state();
1742 printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state_), state_.as_cstring());
1744 printf("testing get_stream_decoder_state()... ");
1745 OggFLAC::Decoder::Stream::State state__ = decoder->get_stream_decoder_state();
1746 printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__StreamDecoderState)state__), state__.as_cstring());
1748 printf("testing get_FLAC_stream_decoder_state()... ");
1749 FLAC::Decoder::Stream::State state___ = decoder->get_FLAC_stream_decoder_state();
1750 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state___), state___.as_cstring());
1752 decoder->current_metadata_number_ = 0;
1753 decoder->ignore_errors_ = false;
1754 decoder->error_occurred_ = false;
1756 printf("testing get_md5_checking()... ");
1757 if(!decoder->get_md5_checking()) {
1758 printf("FAILED, returned false, expected true\n");
1763 printf("testing process_until_end_of_metadata()... ");
1764 if(!decoder->process_until_end_of_metadata())
1765 return decoder->die("returned false");
1768 printf("testing process_single()... ");
1769 if(!decoder->process_single())
1770 return decoder->die("returned false");
1773 printf("testing seek_absolute()... ");
1774 if(!decoder->seek_absolute(0))
1775 return decoder->die("returned false");
1778 printf("testing process_until_end_of_file()... ");
1779 if(!decoder->process_until_end_of_file())
1780 return decoder->die("returned false");
1783 printf("testing get_channels()... ");
1785 unsigned channels = decoder->get_channels();
1786 if(channels != streaminfo_.data.stream_info.channels) {
1787 printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
1793 printf("testing get_bits_per_sample()... ");
1795 unsigned bits_per_sample = decoder->get_bits_per_sample();
1796 if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
1797 printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
1803 printf("testing get_sample_rate()... ");
1805 unsigned sample_rate = decoder->get_sample_rate();
1806 if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
1807 printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
1813 printf("testing get_blocksize()... ");
1815 unsigned blocksize = decoder->get_blocksize();
1816 /* value could be anything since we're at the last block, so accept any answer */
1817 printf("returned %u... OK\n", blocksize);
1820 printf("testing get_channel_assignment()... ");
1822 ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
1823 printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
1826 printf("testing finish()... ");
1834 printf("testing set_metadata_respond_all()... ");
1835 if(!decoder->set_metadata_respond_all()) {
1836 printf("FAILED, returned false\n");
1842 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1843 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1844 expected_metadata_sequence_[num_expected_++] = &padding_;
1845 expected_metadata_sequence_[num_expected_++] = &seektable_;
1846 expected_metadata_sequence_[num_expected_++] = &application1_;
1847 expected_metadata_sequence_[num_expected_++] = &application2_;
1848 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1849 expected_metadata_sequence_[num_expected_++] = &unknown_;
1851 if(!decoder->test_respond())
1858 printf("testing set_metadata_ignore_all()... ");
1859 if(!decoder->set_metadata_ignore_all()) {
1860 printf("FAILED, returned false\n");
1867 if(!decoder->test_respond())
1871 * respond all, ignore VORBIS_COMMENT
1874 printf("testing set_metadata_respond_all()... ");
1875 if(!decoder->set_metadata_respond_all()) {
1876 printf("FAILED, returned false\n");
1881 printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
1882 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
1883 printf("FAILED, returned false\n");
1889 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1890 expected_metadata_sequence_[num_expected_++] = &padding_;
1891 expected_metadata_sequence_[num_expected_++] = &seektable_;
1892 expected_metadata_sequence_[num_expected_++] = &application1_;
1893 expected_metadata_sequence_[num_expected_++] = &application2_;
1894 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1895 expected_metadata_sequence_[num_expected_++] = &unknown_;
1897 if(!decoder->test_respond())
1901 * respond all, ignore APPLICATION
1904 printf("testing set_metadata_respond_all()... ");
1905 if(!decoder->set_metadata_respond_all()) {
1906 printf("FAILED, returned false\n");
1911 printf("testing set_metadata_ignore(APPLICATION)... ");
1912 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1913 printf("FAILED, returned false\n");
1919 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1920 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1921 expected_metadata_sequence_[num_expected_++] = &padding_;
1922 expected_metadata_sequence_[num_expected_++] = &seektable_;
1923 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1924 expected_metadata_sequence_[num_expected_++] = &unknown_;
1926 if(!decoder->test_respond())
1930 * respond all, ignore APPLICATION id of app#1
1933 printf("testing set_metadata_respond_all()... ");
1934 if(!decoder->set_metadata_respond_all()) {
1935 printf("FAILED, returned false\n");
1940 printf("testing set_metadata_ignore_application(of app block #1)... ");
1941 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1942 printf("FAILED, returned false\n");
1948 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1949 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1950 expected_metadata_sequence_[num_expected_++] = &padding_;
1951 expected_metadata_sequence_[num_expected_++] = &seektable_;
1952 expected_metadata_sequence_[num_expected_++] = &application2_;
1953 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1954 expected_metadata_sequence_[num_expected_++] = &unknown_;
1956 if(!decoder->test_respond())
1960 * respond all, ignore APPLICATION id of app#1 & app#2
1963 printf("testing set_metadata_respond_all()... ");
1964 if(!decoder->set_metadata_respond_all()) {
1965 printf("FAILED, returned false\n");
1970 printf("testing set_metadata_ignore_application(of app block #1)... ");
1971 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1972 printf("FAILED, returned false\n");
1977 printf("testing set_metadata_ignore_application(of app block #2)... ");
1978 if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
1979 printf("FAILED, returned false\n");
1985 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1986 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1987 expected_metadata_sequence_[num_expected_++] = &padding_;
1988 expected_metadata_sequence_[num_expected_++] = &seektable_;
1989 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1990 expected_metadata_sequence_[num_expected_++] = &unknown_;
1992 if(!decoder->test_respond())
1996 * ignore all, respond VORBIS_COMMENT
1999 printf("testing set_metadata_ignore_all()... ");
2000 if(!decoder->set_metadata_ignore_all()) {
2001 printf("FAILED, returned false\n");
2006 printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
2007 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
2008 printf("FAILED, returned false\n");
2014 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
2016 if(!decoder->test_respond())
2020 * ignore all, respond APPLICATION
2023 printf("testing set_metadata_ignore_all()... ");
2024 if(!decoder->set_metadata_ignore_all()) {
2025 printf("FAILED, returned false\n");
2030 printf("testing set_metadata_respond(APPLICATION)... ");
2031 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
2032 printf("FAILED, returned false\n");
2038 expected_metadata_sequence_[num_expected_++] = &application1_;
2039 expected_metadata_sequence_[num_expected_++] = &application2_;
2041 if(!decoder->test_respond())
2045 * ignore all, respond APPLICATION id of app#1
2048 printf("testing set_metadata_ignore_all()... ");
2049 if(!decoder->set_metadata_ignore_all()) {
2050 printf("FAILED, returned false\n");
2055 printf("testing set_metadata_respond_application(of app block #1)... ");
2056 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
2057 printf("FAILED, returned false\n");
2063 expected_metadata_sequence_[num_expected_++] = &application1_;
2065 if(!decoder->test_respond())
2069 * ignore all, respond APPLICATION id of app#1 & app#2
2072 printf("testing set_metadata_ignore_all()... ");
2073 if(!decoder->set_metadata_ignore_all()) {
2074 printf("FAILED, returned false\n");
2079 printf("testing set_metadata_respond_application(of app block #1)... ");
2080 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
2081 printf("FAILED, returned false\n");
2086 printf("testing set_metadata_respond_application(of app block #2)... ");
2087 if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
2088 printf("FAILED, returned false\n");
2094 expected_metadata_sequence_[num_expected_++] = &application1_;
2095 expected_metadata_sequence_[num_expected_++] = &application2_;
2097 if(!decoder->test_respond())
2101 * respond all, ignore APPLICATION, respond APPLICATION id of app#1
2104 printf("testing set_metadata_respond_all()... ");
2105 if(!decoder->set_metadata_respond_all()) {
2106 printf("FAILED, returned false\n");
2111 printf("testing set_metadata_ignore(APPLICATION)... ");
2112 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
2113 printf("FAILED, returned false\n");
2118 printf("testing set_metadata_respond_application(of app block #1)... ");
2119 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
2120 printf("FAILED, returned false\n");
2126 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
2127 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
2128 expected_metadata_sequence_[num_expected_++] = &padding_;
2129 expected_metadata_sequence_[num_expected_++] = &seektable_;
2130 expected_metadata_sequence_[num_expected_++] = &application1_;
2131 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
2132 expected_metadata_sequence_[num_expected_++] = &unknown_;
2134 if(!decoder->test_respond())
2138 * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
2141 printf("testing set_metadata_ignore_all()... ");
2142 if(!decoder->set_metadata_ignore_all()) {
2143 printf("FAILED, returned false\n");
2148 printf("testing set_metadata_respond(APPLICATION)... ");
2149 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
2150 printf("FAILED, returned false\n");
2155 printf("testing set_metadata_ignore_application(of app block #1)... ");
2156 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
2157 printf("FAILED, returned false\n");
2163 expected_metadata_sequence_[num_expected_++] = &application2_;
2165 if(!decoder->test_respond())
2168 /* done, now leave the sequence the way we found it... */
2170 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
2171 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
2172 expected_metadata_sequence_[num_expected_++] = &padding_;
2173 expected_metadata_sequence_[num_expected_++] = &seektable_;
2174 expected_metadata_sequence_[num_expected_++] = &application1_;
2175 expected_metadata_sequence_[num_expected_++] = &application2_;
2176 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
2177 expected_metadata_sequence_[num_expected_++] = &unknown_;
2179 printf("freeing decoder instance... ");
2183 printf("\nPASSED!\n");
2188 bool test_decoders()
2190 init_metadata_blocks_();
2192 if(!generate_file_())
2195 if(!test_stream_decoder())
2198 if(!test_seekable_stream_decoder())
2201 if(!test_file_decoder())
2204 (void) grabbag__file_remove_file(oggflacfilename_);
2206 free_metadata_blocks_();