1 /* test_libFLAC++ - Unit tester for libFLAC++
2 * Copyright (C) 2002-2009 Josh Coalson
3 * Copyright (C) 2011-2016 Xiph.Org Foundation
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "FLAC/assert.h"
30 #include "FLAC/metadata.h" // for ::FLAC__metadata_object_is_equal()
31 #include "FLAC++/decoder.h"
32 #include "share/grabbag.h"
33 #include "share/compat.h"
35 #include "test_libs_common/file_utils_flac.h"
36 #include "test_libs_common/metadata_utils.h"
40 // warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
41 #pragma warning ( disable : 4800 )
45 LAYER_STREAM
= 0, /* FLAC__stream_decoder_init_stream() without seeking */
46 LAYER_SEEKABLE_STREAM
, /* FLAC__stream_decoder_init_stream() with seeking */
47 LAYER_FILE
, /* FLAC__stream_decoder_init_FILE() */
48 LAYER_FILENAME
/* FLAC__stream_decoder_init_file() */
51 static const char * const LayerString
[] = {
58 static ::FLAC__StreamMetadata streaminfo_
, padding_
, seektable_
, application1_
, application2_
, vorbiscomment_
, cuesheet_
, picture_
, unknown_
;
59 static ::FLAC__StreamMetadata
*expected_metadata_sequence_
[9];
60 static uint32_t num_expected_
;
61 static FLAC__off_t flacfilesize_
;
63 static const char *flacfilename(bool is_ogg
)
65 return is_ogg
? "metadata.oga" : "metadata.flac";
68 static bool die_(const char *msg
)
70 printf("ERROR: %s\n", msg
);
74 static FLAC__bool
die_s_(const char *msg
, const FLAC::Decoder::Stream
*decoder
)
76 FLAC::Decoder::Stream::State state
= decoder
->get_state();
79 printf("FAILED, %s", msg
);
83 printf(", state = %u (%s)\n", (uint32_t)((::FLAC__StreamDecoderState
)state
), state
.as_cstring());
88 static void init_metadata_blocks_()
90 mutils__init_metadata_blocks(&streaminfo_
, &padding_
, &seektable_
, &application1_
, &application2_
, &vorbiscomment_
, &cuesheet_
, &picture_
, &unknown_
);
93 static void free_metadata_blocks_()
95 mutils__free_metadata_blocks(&streaminfo_
, &padding_
, &seektable_
, &application1_
, &application2_
, &vorbiscomment_
, &cuesheet_
, &picture_
, &unknown_
);
98 static bool generate_file_(FLAC__bool is_ogg
)
100 printf("\n\ngenerating %sFLAC file for decoder tests...\n", is_ogg
? "Ogg ":"");
103 expected_metadata_sequence_
[num_expected_
++] = &padding_
;
104 expected_metadata_sequence_
[num_expected_
++] = &seektable_
;
105 expected_metadata_sequence_
[num_expected_
++] = &application1_
;
106 expected_metadata_sequence_
[num_expected_
++] = &application2_
;
107 expected_metadata_sequence_
[num_expected_
++] = &vorbiscomment_
;
108 expected_metadata_sequence_
[num_expected_
++] = &cuesheet_
;
109 expected_metadata_sequence_
[num_expected_
++] = &picture_
;
110 expected_metadata_sequence_
[num_expected_
++] = &unknown_
;
111 /* WATCHOUT: for Ogg FLAC the encoder should move the VORBIS_COMMENT block to the front, right after STREAMINFO */
113 if(!file_utils__generate_flacfile(is_ogg
, flacfilename(is_ogg
), &flacfilesize_
, 512 * 1024, &streaminfo_
, expected_metadata_sequence_
, num_expected_
))
114 return die_("creating the encoded file");
120 class DecoderCommon
{
123 uint32_t current_metadata_number_
;
125 bool error_occurred_
;
127 DecoderCommon(Layer layer
): layer_(layer
), current_metadata_number_(0), ignore_errors_(false), error_occurred_(false) { }
128 virtual ~DecoderCommon(void) { }
129 ::FLAC__StreamDecoderWriteStatus
common_write_callback_(const ::FLAC__Frame
*frame
);
130 void common_metadata_callback_(const ::FLAC__StreamMetadata
*metadata
);
131 void common_error_callback_(::FLAC__StreamDecoderErrorStatus status
);
134 ::FLAC__StreamDecoderWriteStatus
DecoderCommon::common_write_callback_(const ::FLAC__Frame
*frame
)
137 return ::FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
;
140 (frame
->header
.number_type
== ::FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER
&& frame
->header
.number
.frame_number
== 0) ||
141 (frame
->header
.number_type
== ::FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER
&& frame
->header
.number
.sample_number
== 0)
143 printf("content... ");
147 return ::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE
;
150 void DecoderCommon::common_metadata_callback_(const ::FLAC__StreamMetadata
*metadata
)
155 printf("%u... ", current_metadata_number_
);
158 if(current_metadata_number_
>= num_expected_
) {
159 (void)die_("got more metadata blocks than expected");
160 error_occurred_
= true;
163 if(!::FLAC__metadata_object_is_equal(expected_metadata_sequence_
[current_metadata_number_
], metadata
)) {
164 (void)die_("metadata block mismatch");
165 error_occurred_
= true;
168 current_metadata_number_
++;
171 void DecoderCommon::common_error_callback_(::FLAC__StreamDecoderErrorStatus status
)
173 if(!ignore_errors_
) {
174 printf("ERROR: got error callback: err = %u (%s)\n", (uint32_t)status
, ::FLAC__StreamDecoderErrorStatusString
[status
]);
175 error_occurred_
= true;
179 class StreamDecoder
: public FLAC::Decoder::Stream
, public DecoderCommon
{
183 StreamDecoder(Layer layer
): FLAC::Decoder::Stream(), DecoderCommon(layer
), file_(0) { }
186 // from FLAC::Decoder::Stream
187 ::FLAC__StreamDecoderReadStatus
read_callback(FLAC__byte buffer
[], size_t *bytes
);
188 ::FLAC__StreamDecoderSeekStatus
seek_callback(FLAC__uint64 absolute_byte_offset
);
189 ::FLAC__StreamDecoderTellStatus
tell_callback(FLAC__uint64
*absolute_byte_offset
);
190 ::FLAC__StreamDecoderLengthStatus
length_callback(FLAC__uint64
*stream_length
);
192 ::FLAC__StreamDecoderWriteStatus
write_callback(const ::FLAC__Frame
*frame
, const FLAC__int32
* const buffer
[]);
193 void metadata_callback(const ::FLAC__StreamMetadata
*metadata
);
194 void error_callback(::FLAC__StreamDecoderErrorStatus status
);
196 bool test_respond(bool is_ogg
);
198 StreamDecoder(const StreamDecoder
&);
199 StreamDecoder
&operator=(const StreamDecoder
&);
202 ::FLAC__StreamDecoderReadStatus
StreamDecoder::read_callback(FLAC__byte buffer
[], size_t *bytes
)
204 const size_t requested_bytes
= *bytes
;
207 return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT
;
211 return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM
;
213 else if(requested_bytes
> 0) {
214 *bytes
= ::fread(buffer
, 1, requested_bytes
, file_
);
217 return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM
;
219 return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE
;
222 return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE
;
226 return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT
; /* abort to avoid a deadlock */
229 ::FLAC__StreamDecoderSeekStatus
StreamDecoder::seek_callback(FLAC__uint64 absolute_byte_offset
)
231 if(layer_
== LAYER_STREAM
)
232 return ::FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
;
235 return ::FLAC__STREAM_DECODER_SEEK_STATUS_ERROR
;
237 if(fseeko(file_
, (FLAC__off_t
)absolute_byte_offset
, SEEK_SET
) < 0) {
238 error_occurred_
= true;
239 return ::FLAC__STREAM_DECODER_SEEK_STATUS_ERROR
;
242 return ::FLAC__STREAM_DECODER_SEEK_STATUS_OK
;
245 ::FLAC__StreamDecoderTellStatus
StreamDecoder::tell_callback(FLAC__uint64
*absolute_byte_offset
)
247 if(layer_
== LAYER_STREAM
)
248 return ::FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
;
251 return ::FLAC__STREAM_DECODER_TELL_STATUS_ERROR
;
253 FLAC__off_t offset
= ftello(file_
);
254 *absolute_byte_offset
= (FLAC__uint64
)offset
;
257 error_occurred_
= true;
258 return ::FLAC__STREAM_DECODER_TELL_STATUS_ERROR
;
261 return ::FLAC__STREAM_DECODER_TELL_STATUS_OK
;
264 ::FLAC__StreamDecoderLengthStatus
StreamDecoder::length_callback(FLAC__uint64
*stream_length
)
266 if(layer_
== LAYER_STREAM
)
267 return ::FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
;
270 return ::FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR
;
272 *stream_length
= (FLAC__uint64
)flacfilesize_
;
273 return ::FLAC__STREAM_DECODER_LENGTH_STATUS_OK
;
276 bool StreamDecoder::eof_callback()
278 if(layer_
== LAYER_STREAM
)
284 return (bool)feof(file_
);
287 ::FLAC__StreamDecoderWriteStatus
StreamDecoder::write_callback(const ::FLAC__Frame
*frame
, const FLAC__int32
* const buffer
[])
291 return common_write_callback_(frame
);
294 void StreamDecoder::metadata_callback(const ::FLAC__StreamMetadata
*metadata
)
296 common_metadata_callback_(metadata
);
299 void StreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status
)
301 common_error_callback_(status
);
304 bool StreamDecoder::test_respond(bool is_ogg
)
306 ::FLAC__StreamDecoderInitStatus init_status
;
308 if(!set_md5_checking(true)) {
309 printf("FAILED at set_md5_checking(), returned false\n");
313 printf("testing init%s()... ", is_ogg
? "_ogg":"");
314 init_status
= is_ogg
? init_ogg() : init();
315 if(init_status
!= ::FLAC__STREAM_DECODER_INIT_STATUS_OK
)
316 return die_s_(0, this);
319 current_metadata_number_
= 0;
321 if(fseeko(file_
, 0, SEEK_SET
) < 0) {
322 printf("FAILED rewinding input, errno = %d\n", errno
);
326 printf("testing process_until_end_of_stream()... ");
327 if(!process_until_end_of_stream()) {
328 State state
= get_state();
329 printf("FAILED, returned false, state = %u (%s)\n", (uint32_t)((::FLAC__StreamDecoderState
)state
), state
.as_cstring());
334 printf("testing finish()... ");
336 State state
= get_state();
337 printf("FAILED, returned false, state = %u (%s)\n", (uint32_t)((::FLAC__StreamDecoderState
)state
), state
.as_cstring());
345 class FileDecoder
: public FLAC::Decoder::File
, public DecoderCommon
{
347 FileDecoder(Layer layer
): FLAC::Decoder::File(), DecoderCommon(layer
) { }
350 // from FLAC::Decoder::Stream
351 ::FLAC__StreamDecoderWriteStatus
write_callback(const ::FLAC__Frame
*frame
, const FLAC__int32
* const buffer
[]);
352 void metadata_callback(const ::FLAC__StreamMetadata
*metadata
);
353 void error_callback(::FLAC__StreamDecoderErrorStatus status
);
355 bool test_respond(bool is_ogg
);
358 ::FLAC__StreamDecoderWriteStatus
FileDecoder::write_callback(const ::FLAC__Frame
*frame
, const FLAC__int32
* const buffer
[])
361 return common_write_callback_(frame
);
364 void FileDecoder::metadata_callback(const ::FLAC__StreamMetadata
*metadata
)
366 common_metadata_callback_(metadata
);
369 void FileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status
)
371 common_error_callback_(status
);
374 bool FileDecoder::test_respond(bool is_ogg
)
376 ::FLAC__StreamDecoderInitStatus init_status
;
378 if(!set_md5_checking(true)) {
379 printf("FAILED at set_md5_checking(), returned false\n");
386 printf("opening %sFLAC file... ", is_ogg
? "Ogg ":"");
387 FILE *file
= ::flac_fopen(flacfilename(is_ogg
), "rb");
389 printf("ERROR (%s)\n", strerror(errno
));
394 printf("testing init%s()... ", is_ogg
? "_ogg":"");
395 init_status
= is_ogg
? init_ogg(file
) : init(file
);
399 printf("testing init%s()... ", is_ogg
? "_ogg":"");
400 init_status
= is_ogg
? init_ogg(flacfilename(is_ogg
)) : init(flacfilename(is_ogg
));
403 die_("internal error 001");
406 if(init_status
!= ::FLAC__STREAM_DECODER_INIT_STATUS_OK
)
407 return die_s_(0, this);
410 current_metadata_number_
= 0;
412 printf("testing process_until_end_of_stream()... ");
413 if(!process_until_end_of_stream()) {
414 State state
= get_state();
415 printf("FAILED, returned false, state = %u (%s)\n", (uint32_t)((::FLAC__StreamDecoderState
)state
), state
.as_cstring());
420 printf("testing finish()... ");
422 State state
= get_state();
423 printf("FAILED, returned false, state = %u (%s)\n", (uint32_t)((::FLAC__StreamDecoderState
)state
), state
.as_cstring());
432 static FLAC::Decoder::Stream
*new_by_layer(Layer layer
)
434 if(layer
< LAYER_FILE
)
435 return new StreamDecoder(layer
);
437 return new FileDecoder(layer
);
440 static bool test_stream_decoder(Layer layer
, bool is_ogg
)
442 FLAC::Decoder::Stream
*decoder
;
443 ::FLAC__StreamDecoderInitStatus init_status
;
446 printf("\n+++ libFLAC++ unit test: FLAC::Decoder::%s (layer: %s, format: %s)\n\n", layer
<LAYER_FILE
? "Stream":"File", LayerString
[layer
], is_ogg
? "Ogg FLAC" : "FLAC");
449 // test new -> delete
451 printf("allocating decoder instance... ");
452 decoder
= new_by_layer(layer
);
454 printf("FAILED, new returned NULL\n");
459 printf("testing is_valid()... ");
460 if(!decoder
->is_valid()) {
461 printf("FAILED, returned false\n");
467 printf("freeing decoder instance... ");
472 // test new -> init -> delete
474 printf("allocating decoder instance... ");
475 decoder
= new_by_layer(layer
);
477 printf("FAILED, new returned NULL\n");
482 printf("testing is_valid()... ");
483 if(!decoder
->is_valid()) {
484 printf("FAILED, returned false\n");
490 printf("testing init%s()... ", is_ogg
? "_ogg":"");
493 case LAYER_SEEKABLE_STREAM
:
494 dynamic_cast<StreamDecoder
*>(decoder
)->file_
= stdin
;
495 init_status
= is_ogg
? decoder
->init_ogg() : decoder
->init();
498 init_status
= is_ogg
?
499 dynamic_cast<FLAC::Decoder::File
*>(decoder
)->init_ogg(stdin
) :
500 dynamic_cast<FLAC::Decoder::File
*>(decoder
)->init(stdin
);
503 init_status
= is_ogg
?
504 dynamic_cast<FLAC::Decoder::File
*>(decoder
)->init_ogg(flacfilename(is_ogg
)) :
505 dynamic_cast<FLAC::Decoder::File
*>(decoder
)->init(flacfilename(is_ogg
));
508 die_("internal error 006");
512 if(init_status
!= ::FLAC__STREAM_DECODER_INIT_STATUS_OK
)
513 return die_s_(0, decoder
);
516 printf("freeing decoder instance... ");
524 expected_metadata_sequence_
[num_expected_
++] = &streaminfo_
;
526 printf("allocating decoder instance... ");
527 decoder
= new_by_layer(layer
);
529 printf("FAILED, new returned NULL\n");
534 printf("testing is_valid()... ");
535 if(!decoder
->is_valid()) {
536 printf("FAILED, returned false\n");
543 printf("testing set_ogg_serial_number()... ");
544 if(!decoder
->set_ogg_serial_number(file_utils__ogg_serial_number
))
545 return die_s_("returned false", decoder
);
549 if(!decoder
->set_md5_checking(true)) {
550 printf("FAILED at set_md5_checking(), returned false\n");
556 case LAYER_SEEKABLE_STREAM
:
557 printf("opening %sFLAC file... ", is_ogg
? "Ogg ":"");
558 dynamic_cast<StreamDecoder
*>(decoder
)->file_
= ::flac_fopen(flacfilename(is_ogg
), "rb");
559 if(0 == dynamic_cast<StreamDecoder
*>(decoder
)->file_
) {
560 printf("ERROR (%s)\n", strerror(errno
));
565 printf("testing init%s()... ", is_ogg
? "_ogg":"");
566 init_status
= is_ogg
? decoder
->init_ogg() : decoder
->init();
570 printf("opening FLAC file... ");
571 FILE *file
= ::flac_fopen(flacfilename(is_ogg
), "rb");
573 printf("ERROR (%s)\n", strerror(errno
));
578 printf("testing init%s()... ", is_ogg
? "_ogg":"");
579 init_status
= is_ogg
?
580 dynamic_cast<FLAC::Decoder::File
*>(decoder
)->init_ogg(file
) :
581 dynamic_cast<FLAC::Decoder::File
*>(decoder
)->init(file
);
585 printf("testing init%s()... ", is_ogg
? "_ogg":"");
586 init_status
= is_ogg
?
587 dynamic_cast<FLAC::Decoder::File
*>(decoder
)->init_ogg(flacfilename(is_ogg
)) :
588 dynamic_cast<FLAC::Decoder::File
*>(decoder
)->init(flacfilename(is_ogg
));
591 die_("internal error 009");
594 if(init_status
!= ::FLAC__STREAM_DECODER_INIT_STATUS_OK
)
595 return die_s_(0, decoder
);
598 printf("testing get_state()... ");
599 FLAC::Decoder::Stream::State state
= decoder
->get_state();
600 printf("returned state = %u (%s)... OK\n", (uint32_t)((::FLAC__StreamDecoderState
)state
), state
.as_cstring());
602 dynamic_cast<DecoderCommon
*>(decoder
)->current_metadata_number_
= 0;
603 dynamic_cast<DecoderCommon
*>(decoder
)->ignore_errors_
= false;
604 dynamic_cast<DecoderCommon
*>(decoder
)->error_occurred_
= false;
606 printf("testing get_md5_checking()... ");
607 if(!decoder
->get_md5_checking()) {
608 printf("FAILED, returned false, expected true\n");
613 printf("testing process_until_end_of_metadata()... ");
614 if(!decoder
->process_until_end_of_metadata())
615 return die_s_("returned false", decoder
);
618 printf("testing process_single()... ");
619 if(!decoder
->process_single())
620 return die_s_("returned false", decoder
);
623 printf("testing skip_single_frame()... ");
624 if(!decoder
->skip_single_frame())
625 return die_s_("returned false", decoder
);
628 if(layer
< LAYER_FILE
) {
629 printf("testing flush()... ");
630 if(!decoder
->flush())
631 return die_s_("returned false", decoder
);
634 dynamic_cast<DecoderCommon
*>(decoder
)->ignore_errors_
= true;
635 printf("testing process_single()... ");
636 if(!decoder
->process_single())
637 return die_s_("returned false", decoder
);
639 dynamic_cast<DecoderCommon
*>(decoder
)->ignore_errors_
= false;
642 expect
= (layer
!= LAYER_STREAM
);
643 printf("testing seek_absolute()... ");
644 if(decoder
->seek_absolute(0) != expect
)
645 return die_s_(expect
? "returned false" : "returned true", decoder
);
648 printf("testing process_until_end_of_stream()... ");
649 if(!decoder
->process_until_end_of_stream())
650 return die_s_("returned false", decoder
);
653 expect
= (layer
!= LAYER_STREAM
);
654 printf("testing seek_absolute()... ");
655 if(decoder
->seek_absolute(0) != expect
)
656 return die_s_(expect
? "returned false" : "returned true", decoder
);
659 printf("testing get_channels()... ");
661 uint32_t channels
= decoder
->get_channels();
662 if(channels
!= streaminfo_
.data
.stream_info
.channels
) {
663 printf("FAILED, returned %u, expected %u\n", channels
, streaminfo_
.data
.stream_info
.channels
);
669 printf("testing get_bits_per_sample()... ");
671 uint32_t bits_per_sample
= decoder
->get_bits_per_sample();
672 if(bits_per_sample
!= streaminfo_
.data
.stream_info
.bits_per_sample
) {
673 printf("FAILED, returned %u, expected %u\n", bits_per_sample
, streaminfo_
.data
.stream_info
.bits_per_sample
);
679 printf("testing get_sample_rate()... ");
681 uint32_t sample_rate
= decoder
->get_sample_rate();
682 if(sample_rate
!= streaminfo_
.data
.stream_info
.sample_rate
) {
683 printf("FAILED, returned %u, expected %u\n", sample_rate
, streaminfo_
.data
.stream_info
.sample_rate
);
689 printf("testing get_blocksize()... ");
691 uint32_t blocksize
= decoder
->get_blocksize();
692 /* value could be anything since we're at the last block, so accept any reasonable answer */
693 printf("returned %u... %s\n", blocksize
, blocksize
>0? "OK" : "FAILED");
698 printf("testing get_channel_assignment()... ");
700 ::FLAC__ChannelAssignment ca
= decoder
->get_channel_assignment();
701 printf("returned %u (%s)... OK\n", (uint32_t)ca
, ::FLAC__ChannelAssignmentString
[ca
]);
704 if(layer
< LAYER_FILE
) {
705 printf("testing reset()... ");
706 if(!decoder
->reset())
707 return die_s_("returned false", decoder
);
710 if(layer
== LAYER_STREAM
) {
711 /* after a reset() we have to rewind the input ourselves */
712 printf("rewinding input... ");
713 if(fseeko(dynamic_cast<StreamDecoder
*>(decoder
)->file_
, 0, SEEK_SET
) < 0) {
714 printf("FAILED, errno = %d\n", errno
);
720 dynamic_cast<DecoderCommon
*>(decoder
)->current_metadata_number_
= 0;
722 printf("testing process_until_end_of_stream()... ");
723 if(!decoder
->process_until_end_of_stream())
724 return die_s_("returned false", decoder
);
728 printf("testing finish()... ");
729 if(!decoder
->finish()) {
730 state
= decoder
->get_state();
731 printf("FAILED, returned false, state = %u (%s)\n", (uint32_t)((::FLAC__StreamDecoderState
)state
), state
.as_cstring());
740 printf("testing set_metadata_respond_all()... ");
741 if(!decoder
->set_metadata_respond_all()) {
742 printf("FAILED, returned false\n");
748 if(is_ogg
) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
749 expected_metadata_sequence_
[num_expected_
++] = &streaminfo_
;
750 expected_metadata_sequence_
[num_expected_
++] = &vorbiscomment_
;
751 expected_metadata_sequence_
[num_expected_
++] = &padding_
;
752 expected_metadata_sequence_
[num_expected_
++] = &seektable_
;
753 expected_metadata_sequence_
[num_expected_
++] = &application1_
;
754 expected_metadata_sequence_
[num_expected_
++] = &application2_
;
755 expected_metadata_sequence_
[num_expected_
++] = &cuesheet_
;
756 expected_metadata_sequence_
[num_expected_
++] = &picture_
;
757 expected_metadata_sequence_
[num_expected_
++] = &unknown_
;
760 expected_metadata_sequence_
[num_expected_
++] = &streaminfo_
;
761 expected_metadata_sequence_
[num_expected_
++] = &padding_
;
762 expected_metadata_sequence_
[num_expected_
++] = &seektable_
;
763 expected_metadata_sequence_
[num_expected_
++] = &application1_
;
764 expected_metadata_sequence_
[num_expected_
++] = &application2_
;
765 expected_metadata_sequence_
[num_expected_
++] = &vorbiscomment_
;
766 expected_metadata_sequence_
[num_expected_
++] = &cuesheet_
;
767 expected_metadata_sequence_
[num_expected_
++] = &picture_
;
768 expected_metadata_sequence_
[num_expected_
++] = &unknown_
;
771 if(!(layer
< LAYER_FILE
? dynamic_cast<StreamDecoder
*>(decoder
)->test_respond(is_ogg
) : dynamic_cast<FileDecoder
*>(decoder
)->test_respond(is_ogg
)))
778 printf("testing set_metadata_ignore_all()... ");
779 if(!decoder
->set_metadata_ignore_all()) {
780 printf("FAILED, returned false\n");
787 if(!(layer
< LAYER_FILE
? dynamic_cast<StreamDecoder
*>(decoder
)->test_respond(is_ogg
) : dynamic_cast<FileDecoder
*>(decoder
)->test_respond(is_ogg
)))
791 * respond all, ignore VORBIS_COMMENT
794 printf("testing set_metadata_respond_all()... ");
795 if(!decoder
->set_metadata_respond_all()) {
796 printf("FAILED, returned false\n");
801 printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
802 if(!decoder
->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT
)) {
803 printf("FAILED, returned false\n");
809 expected_metadata_sequence_
[num_expected_
++] = &streaminfo_
;
810 expected_metadata_sequence_
[num_expected_
++] = &padding_
;
811 expected_metadata_sequence_
[num_expected_
++] = &seektable_
;
812 expected_metadata_sequence_
[num_expected_
++] = &application1_
;
813 expected_metadata_sequence_
[num_expected_
++] = &application2_
;
814 expected_metadata_sequence_
[num_expected_
++] = &cuesheet_
;
815 expected_metadata_sequence_
[num_expected_
++] = &picture_
;
816 expected_metadata_sequence_
[num_expected_
++] = &unknown_
;
818 if(!(layer
< LAYER_FILE
? dynamic_cast<StreamDecoder
*>(decoder
)->test_respond(is_ogg
) : dynamic_cast<FileDecoder
*>(decoder
)->test_respond(is_ogg
)))
822 * respond all, ignore APPLICATION
825 printf("testing set_metadata_respond_all()... ");
826 if(!decoder
->set_metadata_respond_all()) {
827 printf("FAILED, returned false\n");
832 printf("testing set_metadata_ignore(APPLICATION)... ");
833 if(!decoder
->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION
)) {
834 printf("FAILED, returned false\n");
840 if(is_ogg
) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
841 expected_metadata_sequence_
[num_expected_
++] = &streaminfo_
;
842 expected_metadata_sequence_
[num_expected_
++] = &vorbiscomment_
;
843 expected_metadata_sequence_
[num_expected_
++] = &padding_
;
844 expected_metadata_sequence_
[num_expected_
++] = &seektable_
;
845 expected_metadata_sequence_
[num_expected_
++] = &cuesheet_
;
846 expected_metadata_sequence_
[num_expected_
++] = &picture_
;
847 expected_metadata_sequence_
[num_expected_
++] = &unknown_
;
850 expected_metadata_sequence_
[num_expected_
++] = &streaminfo_
;
851 expected_metadata_sequence_
[num_expected_
++] = &padding_
;
852 expected_metadata_sequence_
[num_expected_
++] = &seektable_
;
853 expected_metadata_sequence_
[num_expected_
++] = &vorbiscomment_
;
854 expected_metadata_sequence_
[num_expected_
++] = &cuesheet_
;
855 expected_metadata_sequence_
[num_expected_
++] = &picture_
;
856 expected_metadata_sequence_
[num_expected_
++] = &unknown_
;
859 if(!(layer
< LAYER_FILE
? dynamic_cast<StreamDecoder
*>(decoder
)->test_respond(is_ogg
) : dynamic_cast<FileDecoder
*>(decoder
)->test_respond(is_ogg
)))
863 * respond all, ignore APPLICATION id of app#1
866 printf("testing set_metadata_respond_all()... ");
867 if(!decoder
->set_metadata_respond_all()) {
868 printf("FAILED, returned false\n");
873 printf("testing set_metadata_ignore_application(of app block #1)... ");
874 if(!decoder
->set_metadata_ignore_application(application1_
.data
.application
.id
)) {
875 printf("FAILED, returned false\n");
881 if(is_ogg
) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
882 expected_metadata_sequence_
[num_expected_
++] = &streaminfo_
;
883 expected_metadata_sequence_
[num_expected_
++] = &vorbiscomment_
;
884 expected_metadata_sequence_
[num_expected_
++] = &padding_
;
885 expected_metadata_sequence_
[num_expected_
++] = &seektable_
;
886 expected_metadata_sequence_
[num_expected_
++] = &application2_
;
887 expected_metadata_sequence_
[num_expected_
++] = &cuesheet_
;
888 expected_metadata_sequence_
[num_expected_
++] = &picture_
;
889 expected_metadata_sequence_
[num_expected_
++] = &unknown_
;
892 expected_metadata_sequence_
[num_expected_
++] = &streaminfo_
;
893 expected_metadata_sequence_
[num_expected_
++] = &padding_
;
894 expected_metadata_sequence_
[num_expected_
++] = &seektable_
;
895 expected_metadata_sequence_
[num_expected_
++] = &application2_
;
896 expected_metadata_sequence_
[num_expected_
++] = &vorbiscomment_
;
897 expected_metadata_sequence_
[num_expected_
++] = &cuesheet_
;
898 expected_metadata_sequence_
[num_expected_
++] = &picture_
;
899 expected_metadata_sequence_
[num_expected_
++] = &unknown_
;
902 if(!(layer
< LAYER_FILE
? dynamic_cast<StreamDecoder
*>(decoder
)->test_respond(is_ogg
) : dynamic_cast<FileDecoder
*>(decoder
)->test_respond(is_ogg
)))
906 * respond all, ignore APPLICATION id of app#1 & app#2
909 printf("testing set_metadata_respond_all()... ");
910 if(!decoder
->set_metadata_respond_all()) {
911 printf("FAILED, returned false\n");
916 printf("testing set_metadata_ignore_application(of app block #1)... ");
917 if(!decoder
->set_metadata_ignore_application(application1_
.data
.application
.id
)) {
918 printf("FAILED, returned false\n");
923 printf("testing set_metadata_ignore_application(of app block #2)... ");
924 if(!decoder
->set_metadata_ignore_application(application2_
.data
.application
.id
)) {
925 printf("FAILED, returned false\n");
931 if(is_ogg
) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
932 expected_metadata_sequence_
[num_expected_
++] = &streaminfo_
;
933 expected_metadata_sequence_
[num_expected_
++] = &vorbiscomment_
;
934 expected_metadata_sequence_
[num_expected_
++] = &padding_
;
935 expected_metadata_sequence_
[num_expected_
++] = &seektable_
;
936 expected_metadata_sequence_
[num_expected_
++] = &cuesheet_
;
937 expected_metadata_sequence_
[num_expected_
++] = &picture_
;
938 expected_metadata_sequence_
[num_expected_
++] = &unknown_
;
941 expected_metadata_sequence_
[num_expected_
++] = &streaminfo_
;
942 expected_metadata_sequence_
[num_expected_
++] = &padding_
;
943 expected_metadata_sequence_
[num_expected_
++] = &seektable_
;
944 expected_metadata_sequence_
[num_expected_
++] = &vorbiscomment_
;
945 expected_metadata_sequence_
[num_expected_
++] = &cuesheet_
;
946 expected_metadata_sequence_
[num_expected_
++] = &picture_
;
947 expected_metadata_sequence_
[num_expected_
++] = &unknown_
;
950 if(!(layer
< LAYER_FILE
? dynamic_cast<StreamDecoder
*>(decoder
)->test_respond(is_ogg
) : dynamic_cast<FileDecoder
*>(decoder
)->test_respond(is_ogg
)))
954 * ignore all, respond VORBIS_COMMENT
957 printf("testing set_metadata_ignore_all()... ");
958 if(!decoder
->set_metadata_ignore_all()) {
959 printf("FAILED, returned false\n");
964 printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
965 if(!decoder
->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT
)) {
966 printf("FAILED, returned false\n");
972 expected_metadata_sequence_
[num_expected_
++] = &vorbiscomment_
;
974 if(!(layer
< LAYER_FILE
? dynamic_cast<StreamDecoder
*>(decoder
)->test_respond(is_ogg
) : dynamic_cast<FileDecoder
*>(decoder
)->test_respond(is_ogg
)))
978 * ignore all, respond APPLICATION
981 printf("testing set_metadata_ignore_all()... ");
982 if(!decoder
->set_metadata_ignore_all()) {
983 printf("FAILED, returned false\n");
988 printf("testing set_metadata_respond(APPLICATION)... ");
989 if(!decoder
->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION
)) {
990 printf("FAILED, returned false\n");
996 expected_metadata_sequence_
[num_expected_
++] = &application1_
;
997 expected_metadata_sequence_
[num_expected_
++] = &application2_
;
999 if(!(layer
< LAYER_FILE
? dynamic_cast<StreamDecoder
*>(decoder
)->test_respond(is_ogg
) : dynamic_cast<FileDecoder
*>(decoder
)->test_respond(is_ogg
)))
1003 * ignore all, respond APPLICATION id of app#1
1006 printf("testing set_metadata_ignore_all()... ");
1007 if(!decoder
->set_metadata_ignore_all()) {
1008 printf("FAILED, returned false\n");
1013 printf("testing set_metadata_respond_application(of app block #1)... ");
1014 if(!decoder
->set_metadata_respond_application(application1_
.data
.application
.id
)) {
1015 printf("FAILED, returned false\n");
1021 expected_metadata_sequence_
[num_expected_
++] = &application1_
;
1023 if(!(layer
< LAYER_FILE
? dynamic_cast<StreamDecoder
*>(decoder
)->test_respond(is_ogg
) : dynamic_cast<FileDecoder
*>(decoder
)->test_respond(is_ogg
)))
1027 * ignore all, respond APPLICATION id of app#1 & app#2
1030 printf("testing set_metadata_ignore_all()... ");
1031 if(!decoder
->set_metadata_ignore_all()) {
1032 printf("FAILED, returned false\n");
1037 printf("testing set_metadata_respond_application(of app block #1)... ");
1038 if(!decoder
->set_metadata_respond_application(application1_
.data
.application
.id
)) {
1039 printf("FAILED, returned false\n");
1044 printf("testing set_metadata_respond_application(of app block #2)... ");
1045 if(!decoder
->set_metadata_respond_application(application2_
.data
.application
.id
)) {
1046 printf("FAILED, returned false\n");
1052 expected_metadata_sequence_
[num_expected_
++] = &application1_
;
1053 expected_metadata_sequence_
[num_expected_
++] = &application2_
;
1055 if(!(layer
< LAYER_FILE
? dynamic_cast<StreamDecoder
*>(decoder
)->test_respond(is_ogg
) : dynamic_cast<FileDecoder
*>(decoder
)->test_respond(is_ogg
)))
1059 * respond all, ignore APPLICATION, respond APPLICATION id of app#1
1062 printf("testing set_metadata_respond_all()... ");
1063 if(!decoder
->set_metadata_respond_all()) {
1064 printf("FAILED, returned false\n");
1069 printf("testing set_metadata_ignore(APPLICATION)... ");
1070 if(!decoder
->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION
)) {
1071 printf("FAILED, returned false\n");
1076 printf("testing set_metadata_respond_application(of app block #1)... ");
1077 if(!decoder
->set_metadata_respond_application(application1_
.data
.application
.id
)) {
1078 printf("FAILED, returned false\n");
1084 if(is_ogg
) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
1085 expected_metadata_sequence_
[num_expected_
++] = &streaminfo_
;
1086 expected_metadata_sequence_
[num_expected_
++] = &vorbiscomment_
;
1087 expected_metadata_sequence_
[num_expected_
++] = &padding_
;
1088 expected_metadata_sequence_
[num_expected_
++] = &seektable_
;
1089 expected_metadata_sequence_
[num_expected_
++] = &application1_
;
1090 expected_metadata_sequence_
[num_expected_
++] = &cuesheet_
;
1091 expected_metadata_sequence_
[num_expected_
++] = &picture_
;
1092 expected_metadata_sequence_
[num_expected_
++] = &unknown_
;
1095 expected_metadata_sequence_
[num_expected_
++] = &streaminfo_
;
1096 expected_metadata_sequence_
[num_expected_
++] = &padding_
;
1097 expected_metadata_sequence_
[num_expected_
++] = &seektable_
;
1098 expected_metadata_sequence_
[num_expected_
++] = &application1_
;
1099 expected_metadata_sequence_
[num_expected_
++] = &vorbiscomment_
;
1100 expected_metadata_sequence_
[num_expected_
++] = &cuesheet_
;
1101 expected_metadata_sequence_
[num_expected_
++] = &picture_
;
1102 expected_metadata_sequence_
[num_expected_
++] = &unknown_
;
1105 if(!(layer
< LAYER_FILE
? dynamic_cast<StreamDecoder
*>(decoder
)->test_respond(is_ogg
) : dynamic_cast<FileDecoder
*>(decoder
)->test_respond(is_ogg
)))
1109 * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
1112 printf("testing set_metadata_ignore_all()... ");
1113 if(!decoder
->set_metadata_ignore_all()) {
1114 printf("FAILED, returned false\n");
1119 printf("testing set_metadata_respond(APPLICATION)... ");
1120 if(!decoder
->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION
)) {
1121 printf("FAILED, returned false\n");
1126 printf("testing set_metadata_ignore_application(of app block #1)... ");
1127 if(!decoder
->set_metadata_ignore_application(application1_
.data
.application
.id
)) {
1128 printf("FAILED, returned false\n");
1134 expected_metadata_sequence_
[num_expected_
++] = &application2_
;
1136 if(!(layer
< LAYER_FILE
? dynamic_cast<StreamDecoder
*>(decoder
)->test_respond(is_ogg
) : dynamic_cast<FileDecoder
*>(decoder
)->test_respond(is_ogg
)))
1139 if(layer
< LAYER_FILE
) /* for LAYER_FILE, FLAC__stream_decoder_finish() closes the file */
1140 ::fclose(dynamic_cast<StreamDecoder
*>(decoder
)->file_
);
1142 printf("freeing decoder instance... ");
1146 printf("\nPASSED!\n");
1151 bool test_decoders()
1153 FLAC__bool is_ogg
= false;
1156 init_metadata_blocks_();
1158 if(!generate_file_(is_ogg
))
1161 if(!test_stream_decoder(LAYER_STREAM
, is_ogg
))
1164 if(!test_stream_decoder(LAYER_SEEKABLE_STREAM
, is_ogg
))
1167 if(!test_stream_decoder(LAYER_FILE
, is_ogg
))
1170 if(!test_stream_decoder(LAYER_FILENAME
, is_ogg
))
1173 (void) grabbag__file_remove_file(flacfilename(is_ogg
));
1175 free_metadata_blocks_();
1177 if(!FLAC_API_SUPPORTS_OGG_FLAC
|| is_ogg
)