1
/* test_libOggFLAC++ - Unit tester for libOggFLAC++
2
* Copyright (C) 2002,2003,2004,2005 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 "OggFLAC++/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 *oggflacfilename_ = "metadata.ogg";
42
static unsigned oggflacfilesize_;
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 Ogg 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_;
72
/* WATCHOUT: the encoder should move the VORBIS_COMMENT block to the front, right after STREAMINFO */
74
if(!file_utils__generate_oggflacfile(oggflacfilename_, &oggflacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
75
return die_("creating the encoded file");
84
unsigned current_metadata_number_;
88
DecoderCommon(): file_(0), current_metadata_number_(0), ignore_errors_(false), error_occurred_(false) { }
89
::FLAC__StreamDecoderReadStatus common_read_callback_(FLAC__byte buffer[], unsigned *bytes);
90
::FLAC__StreamDecoderWriteStatus common_write_callback_(const ::FLAC__Frame *frame);
91
void common_metadata_callback_(const ::FLAC__StreamMetadata *metadata);
92
void common_error_callback_(::FLAC__StreamDecoderErrorStatus status);
95
::FLAC__StreamDecoderReadStatus DecoderCommon::common_read_callback_(FLAC__byte buffer[], unsigned *bytes)
98
return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT;
102
return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
104
else if(*bytes > 0) {
105
*bytes = ::fread(buffer, 1, *bytes, file_);
108
return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
110
return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
113
return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
117
return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
120
::FLAC__StreamDecoderWriteStatus DecoderCommon::common_write_callback_(const ::FLAC__Frame *frame)
123
return ::FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
126
(frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) ||
127
(frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0)
129
printf("content... ");
133
return ::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
136
void DecoderCommon::common_metadata_callback_(const ::FLAC__StreamMetadata *metadata)
141
printf("%d... ", current_metadata_number_);
144
if(current_metadata_number_ >= num_expected_) {
145
(void)die_("got more metadata blocks than expected");
146
error_occurred_ = true;
149
if(!::FLAC__metadata_object_is_equal(expected_metadata_sequence_[current_metadata_number_], metadata)) {
150
(void)die_("metadata block mismatch");
151
error_occurred_ = true;
154
current_metadata_number_++;
157
void DecoderCommon::common_error_callback_(::FLAC__StreamDecoderErrorStatus status)
159
if(!ignore_errors_) {
160
printf("ERROR: got error callback: err = %u (%s)\n", (unsigned)status, ::FLAC__StreamDecoderErrorStatusString[status]);
161
error_occurred_ = true;
165
class StreamDecoder : public OggFLAC::Decoder::Stream, public DecoderCommon {
167
StreamDecoder(): OggFLAC::Decoder::Stream(), DecoderCommon() { }
170
// from OggFLAC::Decoder::Stream
171
::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
172
::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
173
void metadata_callback(const ::FLAC__StreamMetadata *metadata);
174
void error_callback(::FLAC__StreamDecoderErrorStatus status);
176
bool die(const char *msg = 0) const;
181
::FLAC__StreamDecoderReadStatus StreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
183
return common_read_callback_(buffer, bytes);
186
::FLAC__StreamDecoderWriteStatus StreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
190
return common_write_callback_(frame);
193
void StreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
195
common_metadata_callback_(metadata);
198
void StreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
200
common_error_callback_(status);
203
bool StreamDecoder::die(const char *msg) const
205
State state = get_state();
208
printf("FAILED, %s", msg);
212
printf(", state = %u (%s)\n", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring());
217
bool StreamDecoder::test_respond()
219
printf("testing init()... ");
220
if(init() != ::OggFLAC__STREAM_DECODER_OK)
224
current_metadata_number_ = 0;
226
if(::fseek(file_, 0, SEEK_SET) < 0) {
227
printf("FAILED rewinding input, errno = %d\n", errno);
231
printf("testing process_until_end_of_stream()... ");
232
if(!process_until_end_of_stream()) {
233
State state = get_state();
234
printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring());
239
printf("testing finish()... ");
246
static bool test_stream_decoder()
248
StreamDecoder *decoder;
250
printf("\n+++ libOggFLAC++ unit test: OggFLAC::Decoder::Stream\n\n");
253
// test new -> delete
255
printf("allocating decoder instance... ");
256
decoder = new StreamDecoder();
258
printf("FAILED, new returned NULL\n");
263
printf("testing is_valid()... ");
264
if(!decoder->is_valid()) {
265
printf("FAILED, returned false\n");
270
printf("freeing decoder instance... ");
275
// test new -> init -> delete
277
printf("allocating decoder instance... ");
278
decoder = new StreamDecoder();
280
printf("FAILED, new returned NULL\n");
285
printf("testing is_valid()... ");
286
if(!decoder->is_valid()) {
287
printf("FAILED, returned false\n");
292
printf("testing init()... ");
293
if(decoder->init() != ::OggFLAC__STREAM_DECODER_OK)
294
return decoder->die();
297
printf("freeing decoder instance... ");
305
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
307
printf("allocating decoder instance... ");
308
decoder = new StreamDecoder();
310
printf("FAILED, new returned NULL\n");
315
printf("testing is_valid()... ");
316
if(!decoder->is_valid()) {
317
printf("FAILED, returned false\n");
322
printf("testing set_serial_number()... ");
323
if(!decoder->set_serial_number(file_utils__serial_number))
324
return decoder->die("returned false");
327
printf("testing init()... ");
328
if(decoder->init() != ::OggFLAC__STREAM_DECODER_OK)
329
return decoder->die();
332
printf("testing get_state()... ");
333
OggFLAC::Decoder::Stream::State state = decoder->get_state();
334
printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring());
336
printf("testing get_FLAC_stream_decoder_state()... ");
337
FLAC::Decoder::Stream::State state_ = decoder->get_FLAC_stream_decoder_state();
338
printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state_), state_.as_cstring());
340
decoder->current_metadata_number_ = 0;
341
decoder->ignore_errors_ = false;
342
decoder->error_occurred_ = false;
344
printf("opening Ogg FLAC file... ");
345
decoder->file_ = ::fopen(oggflacfilename_, "rb");
346
if(0 == decoder->file_) {
352
printf("testing process_until_end_of_metadata()... ");
353
if(!decoder->process_until_end_of_metadata())
354
return decoder->die("returned false");
357
printf("testing process_single()... ");
358
if(!decoder->process_single())
359
return decoder->die("returned false");
362
printf("testing flush()... ");
363
if(!decoder->flush())
364
return decoder->die("returned false");
367
decoder->ignore_errors_ = true;
368
printf("testing process_single()... ");
369
if(!decoder->process_single())
370
return decoder->die("returned false");
372
decoder->ignore_errors_ = false;
374
printf("testing process_until_end_of_stream()... ");
375
if(!decoder->process_until_end_of_stream())
376
return decoder->die("returned false");
379
printf("testing get_channels()... ");
381
unsigned channels = decoder->get_channels();
382
if(channels != streaminfo_.data.stream_info.channels) {
383
printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
389
printf("testing get_bits_per_sample()... ");
391
unsigned bits_per_sample = decoder->get_bits_per_sample();
392
if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
393
printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
399
printf("testing get_sample_rate()... ");
401
unsigned sample_rate = decoder->get_sample_rate();
402
if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
403
printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
409
printf("testing get_blocksize()... ");
411
unsigned blocksize = decoder->get_blocksize();
412
/* value could be anything since we're at the last block, so accept any answer */
413
printf("returned %u... OK\n", blocksize);
416
printf("testing get_channel_assignment()... ");
418
::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
419
printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
422
printf("testing reset()... ");
423
if(!decoder->reset())
424
return decoder->die("returned false");
427
decoder->current_metadata_number_ = 0;
429
printf("rewinding input... ");
430
if(::fseek(decoder->file_, 0, SEEK_SET) < 0) {
431
printf("FAILED, errno = %d\n", errno);
436
printf("testing process_until_end_of_stream()... ");
437
if(!decoder->process_until_end_of_stream())
438
return decoder->die("returned false");
441
printf("testing finish()... ");
449
printf("testing set_metadata_respond_all()... ");
450
if(!decoder->set_metadata_respond_all()) {
451
printf("FAILED, returned false\n");
457
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
458
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
459
expected_metadata_sequence_[num_expected_++] = &padding_;
460
expected_metadata_sequence_[num_expected_++] = &seektable_;
461
expected_metadata_sequence_[num_expected_++] = &application1_;
462
expected_metadata_sequence_[num_expected_++] = &application2_;
463
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
464
expected_metadata_sequence_[num_expected_++] = &unknown_;
466
if(!decoder->test_respond())
473
printf("testing set_metadata_ignore_all()... ");
474
if(!decoder->set_metadata_ignore_all()) {
475
printf("FAILED, returned false\n");
482
if(!decoder->test_respond())
486
* respond all, ignore VORBIS_COMMENT
489
printf("testing set_metadata_respond_all()... ");
490
if(!decoder->set_metadata_respond_all()) {
491
printf("FAILED, returned false\n");
496
printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
497
if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
498
printf("FAILED, returned false\n");
504
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
505
expected_metadata_sequence_[num_expected_++] = &padding_;
506
expected_metadata_sequence_[num_expected_++] = &seektable_;
507
expected_metadata_sequence_[num_expected_++] = &application1_;
508
expected_metadata_sequence_[num_expected_++] = &application2_;
509
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
510
expected_metadata_sequence_[num_expected_++] = &unknown_;
512
if(!decoder->test_respond())
516
* respond all, ignore APPLICATION
519
printf("testing set_metadata_respond_all()... ");
520
if(!decoder->set_metadata_respond_all()) {
521
printf("FAILED, returned false\n");
526
printf("testing set_metadata_ignore(APPLICATION)... ");
527
if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
528
printf("FAILED, returned false\n");
534
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
535
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
536
expected_metadata_sequence_[num_expected_++] = &padding_;
537
expected_metadata_sequence_[num_expected_++] = &seektable_;
538
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
539
expected_metadata_sequence_[num_expected_++] = &unknown_;
541
if(!decoder->test_respond())
545
* respond all, ignore APPLICATION id of app#1
548
printf("testing set_metadata_respond_all()... ");
549
if(!decoder->set_metadata_respond_all()) {
550
printf("FAILED, returned false\n");
555
printf("testing set_metadata_ignore_application(of app block #1)... ");
556
if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
557
printf("FAILED, returned false\n");
563
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
564
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
565
expected_metadata_sequence_[num_expected_++] = &padding_;
566
expected_metadata_sequence_[num_expected_++] = &seektable_;
567
expected_metadata_sequence_[num_expected_++] = &application2_;
568
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
569
expected_metadata_sequence_[num_expected_++] = &unknown_;
571
if(!decoder->test_respond())
575
* respond all, ignore APPLICATION id of app#1 & app#2
578
printf("testing set_metadata_respond_all()... ");
579
if(!decoder->set_metadata_respond_all()) {
580
printf("FAILED, returned false\n");
585
printf("testing set_metadata_ignore_application(of app block #1)... ");
586
if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
587
printf("FAILED, returned false\n");
592
printf("testing set_metadata_ignore_application(of app block #2)... ");
593
if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
594
printf("FAILED, returned false\n");
600
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
601
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
602
expected_metadata_sequence_[num_expected_++] = &padding_;
603
expected_metadata_sequence_[num_expected_++] = &seektable_;
604
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
605
expected_metadata_sequence_[num_expected_++] = &unknown_;
607
if(!decoder->test_respond())
611
* ignore all, respond VORBIS_COMMENT
614
printf("testing set_metadata_ignore_all()... ");
615
if(!decoder->set_metadata_ignore_all()) {
616
printf("FAILED, returned false\n");
621
printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
622
if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
623
printf("FAILED, returned false\n");
629
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
631
if(!decoder->test_respond())
635
* ignore all, respond APPLICATION
638
printf("testing set_metadata_ignore_all()... ");
639
if(!decoder->set_metadata_ignore_all()) {
640
printf("FAILED, returned false\n");
645
printf("testing set_metadata_respond(APPLICATION)... ");
646
if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
647
printf("FAILED, returned false\n");
653
expected_metadata_sequence_[num_expected_++] = &application1_;
654
expected_metadata_sequence_[num_expected_++] = &application2_;
656
if(!decoder->test_respond())
660
* ignore all, respond APPLICATION id of app#1
663
printf("testing set_metadata_ignore_all()... ");
664
if(!decoder->set_metadata_ignore_all()) {
665
printf("FAILED, returned false\n");
670
printf("testing set_metadata_respond_application(of app block #1)... ");
671
if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
672
printf("FAILED, returned false\n");
678
expected_metadata_sequence_[num_expected_++] = &application1_;
680
if(!decoder->test_respond())
684
* ignore all, respond APPLICATION id of app#1 & app#2
687
printf("testing set_metadata_ignore_all()... ");
688
if(!decoder->set_metadata_ignore_all()) {
689
printf("FAILED, returned false\n");
694
printf("testing set_metadata_respond_application(of app block #1)... ");
695
if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
696
printf("FAILED, returned false\n");
701
printf("testing set_metadata_respond_application(of app block #2)... ");
702
if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
703
printf("FAILED, returned false\n");
709
expected_metadata_sequence_[num_expected_++] = &application1_;
710
expected_metadata_sequence_[num_expected_++] = &application2_;
712
if(!decoder->test_respond())
716
* respond all, ignore APPLICATION, respond APPLICATION id of app#1
719
printf("testing set_metadata_respond_all()... ");
720
if(!decoder->set_metadata_respond_all()) {
721
printf("FAILED, returned false\n");
726
printf("testing set_metadata_ignore(APPLICATION)... ");
727
if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
728
printf("FAILED, returned false\n");
733
printf("testing set_metadata_respond_application(of app block #1)... ");
734
if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
735
printf("FAILED, returned false\n");
741
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
742
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
743
expected_metadata_sequence_[num_expected_++] = &padding_;
744
expected_metadata_sequence_[num_expected_++] = &seektable_;
745
expected_metadata_sequence_[num_expected_++] = &application1_;
746
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
747
expected_metadata_sequence_[num_expected_++] = &unknown_;
749
if(!decoder->test_respond())
753
* ignore all, respond APPLICATION, ignore APPLICATION id of app#1
756
printf("testing set_metadata_ignore_all()... ");
757
if(!decoder->set_metadata_ignore_all()) {
758
printf("FAILED, returned false\n");
763
printf("testing set_metadata_respond(APPLICATION)... ");
764
if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
765
printf("FAILED, returned false\n");
770
printf("testing set_metadata_ignore_application(of app block #1)... ");
771
if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
772
printf("FAILED, returned false\n");
778
expected_metadata_sequence_[num_expected_++] = &application2_;
780
if(!decoder->test_respond())
783
/* done, now leave the sequence the way we found it... */
785
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
786
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
787
expected_metadata_sequence_[num_expected_++] = &padding_;
788
expected_metadata_sequence_[num_expected_++] = &seektable_;
789
expected_metadata_sequence_[num_expected_++] = &application1_;
790
expected_metadata_sequence_[num_expected_++] = &application2_;
791
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
792
expected_metadata_sequence_[num_expected_++] = &unknown_;
794
::fclose(decoder->file_);
796
printf("freeing decoder instance... ");
800
printf("\nPASSED!\n");
805
class SeekableStreamDecoder : public OggFLAC::Decoder::SeekableStream, public DecoderCommon {
807
SeekableStreamDecoder(): OggFLAC::Decoder::SeekableStream(), DecoderCommon() { }
808
~SeekableStreamDecoder() { }
810
// from OggFLAC::Decoder::SeekableStream
811
::OggFLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
812
::OggFLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
813
::OggFLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
814
::OggFLAC__SeekableStreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length);
816
::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
817
void metadata_callback(const ::FLAC__StreamMetadata *metadata);
818
void error_callback(::FLAC__StreamDecoderErrorStatus status);
820
bool die(const char *msg = 0) const;
825
::OggFLAC__SeekableStreamDecoderReadStatus SeekableStreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
827
switch(common_read_callback_(buffer, bytes)) {
828
case ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
829
case ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
830
return ::OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
831
case ::FLAC__STREAM_DECODER_READ_STATUS_ABORT:
832
return ::OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
835
return ::OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
839
::OggFLAC__SeekableStreamDecoderSeekStatus SeekableStreamDecoder::seek_callback(FLAC__uint64 absolute_byte_offset)
842
return ::OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
844
if(::fseek(file_, (long)absolute_byte_offset, SEEK_SET) < 0) {
845
error_occurred_ = true;
846
return ::OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
849
return ::OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
852
::OggFLAC__SeekableStreamDecoderTellStatus SeekableStreamDecoder::tell_callback(FLAC__uint64 *absolute_byte_offset)
855
return ::OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
857
long offset = ::ftell(file_);
858
*absolute_byte_offset = (FLAC__uint64)offset;
861
error_occurred_ = true;
862
return ::OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
865
return ::OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;
868
::OggFLAC__SeekableStreamDecoderLengthStatus SeekableStreamDecoder::length_callback(FLAC__uint64 *stream_length)
871
return ::OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR;
873
*stream_length = (FLAC__uint64)oggflacfilesize_;
874
return ::OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;
877
bool SeekableStreamDecoder::eof_callback()
882
return (bool)feof(file_);
885
::FLAC__StreamDecoderWriteStatus SeekableStreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
889
return common_write_callback_(frame);
892
void SeekableStreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
894
common_metadata_callback_(metadata);
897
void SeekableStreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
899
common_error_callback_(status);
902
bool SeekableStreamDecoder::die(const char *msg) const
904
State state = get_state();
907
printf("FAILED, %s", msg);
911
printf(", state = %u (%s)\n", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state), state.as_cstring());
912
if(state == ::OggFLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR) {
913
OggFLAC::Decoder::Stream::State state_ = get_stream_decoder_state();
914
printf(" stream decoder state = %u (%s)\n", (unsigned)((::OggFLAC__StreamDecoderState)state_), state_.as_cstring());
915
if(state_ == ::OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR) {
916
FLAC::Decoder::Stream::State state__ = get_FLAC_stream_decoder_state();
917
printf(" FLAC stream decoder state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state__), state__.as_cstring());
924
bool SeekableStreamDecoder::test_respond()
926
if(!set_md5_checking(true)) {
927
printf("FAILED at set_md5_checking(), returned false\n");
931
printf("testing init()... ");
932
if(init() != ::OggFLAC__SEEKABLE_STREAM_DECODER_OK)
936
current_metadata_number_ = 0;
938
if(::fseek(file_, 0, SEEK_SET) < 0) {
939
printf("FAILED rewinding input, errno = %d\n", errno);
943
printf("testing process_until_end_of_stream()... ");
944
if(!process_until_end_of_stream()) {
945
State state = get_state();
946
printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state), state.as_cstring());
951
printf("testing finish()... ");
958
static bool test_seekable_stream_decoder()
960
SeekableStreamDecoder *decoder;
962
printf("\n+++ libOggFLAC++ unit test: OggFLAC::Decoder::SeekableStream\n\n");
965
// test new -> delete
967
printf("allocating decoder instance... ");
968
decoder = new SeekableStreamDecoder();
970
printf("FAILED, new returned NULL\n");
975
printf("testing is_valid()... ");
976
if(!decoder->is_valid()) {
977
printf("FAILED, returned false\n");
982
printf("freeing decoder instance... ");
987
// test new -> init -> delete
989
printf("allocating decoder instance... ");
990
decoder = new SeekableStreamDecoder();
992
printf("FAILED, new returned NULL\n");
997
printf("testing is_valid()... ");
998
if(!decoder->is_valid()) {
999
printf("FAILED, returned false\n");
1004
printf("testing init()... ");
1005
if(decoder->init() != ::OggFLAC__SEEKABLE_STREAM_DECODER_OK)
1006
return decoder->die();
1009
printf("freeing decoder instance... ");
1014
// test normal usage
1017
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1019
printf("allocating decoder instance... ");
1020
decoder = new SeekableStreamDecoder();
1022
printf("FAILED, new returned NULL\n");
1027
printf("testing is_valid()... ");
1028
if(!decoder->is_valid()) {
1029
printf("FAILED, returned false\n");
1034
printf("testing set_md5_checking()... ");
1035
if(!decoder->set_md5_checking(true)) {
1036
printf("FAILED, returned false\n");
1041
printf("testing set_serial_number()... ");
1042
if(!decoder->set_serial_number(file_utils__serial_number))
1043
return decoder->die("returned false");
1046
printf("testing init()... ");
1047
if(decoder->init() != ::OggFLAC__SEEKABLE_STREAM_DECODER_OK)
1048
return decoder->die();
1051
printf("testing get_state()... ");
1052
OggFLAC::Decoder::SeekableStream::State state = decoder->get_state();
1053
printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state), state.as_cstring());
1055
printf("testing get_stream_decoder_state()... ");
1056
OggFLAC::Decoder::Stream::State state_ = decoder->get_stream_decoder_state();
1057
printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__StreamDecoderState)state_), state_.as_cstring());
1059
printf("testing get_FLAC_stream_decoder_state()... ");
1060
FLAC::Decoder::Stream::State state__ = decoder->get_FLAC_stream_decoder_state();
1061
printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state__), state__.as_cstring());
1063
decoder->current_metadata_number_ = 0;
1064
decoder->ignore_errors_ = false;
1065
decoder->error_occurred_ = false;
1067
printf("opening Ogg FLAC file... ");
1068
decoder->file_ = ::fopen(oggflacfilename_, "rb");
1069
if(0 == decoder->file_) {
1075
printf("testing get_md5_checking()... ");
1076
if(!decoder->get_md5_checking()) {
1077
printf("FAILED, returned false, expected true\n");
1082
printf("testing process_until_end_of_metadata()... ");
1083
if(!decoder->process_until_end_of_metadata())
1084
return decoder->die("returned false");
1087
printf("testing process_single()... ");
1088
if(!decoder->process_single())
1089
return decoder->die("returned false");
1092
printf("testing flush()... ");
1093
if(!decoder->flush())
1094
return decoder->die("returned false");
1097
decoder->ignore_errors_ = true;
1098
printf("testing process_single()... ");
1099
if(!decoder->process_single())
1100
return decoder->die("returned false");
1102
decoder->ignore_errors_ = false;
1104
printf("testing seek_absolute()... ");
1105
if(!decoder->seek_absolute(0))
1106
return decoder->die("returned false");
1109
printf("testing process_until_end_of_stream()... ");
1110
if(!decoder->process_until_end_of_stream())
1111
return decoder->die("returned false");
1114
printf("testing get_channels()... ");
1116
unsigned channels = decoder->get_channels();
1117
if(channels != streaminfo_.data.stream_info.channels) {
1118
printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
1124
printf("testing get_bits_per_sample()... ");
1126
unsigned bits_per_sample = decoder->get_bits_per_sample();
1127
if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
1128
printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
1134
printf("testing get_sample_rate()... ");
1136
unsigned sample_rate = decoder->get_sample_rate();
1137
if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
1138
printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
1144
printf("testing get_blocksize()... ");
1146
unsigned blocksize = decoder->get_blocksize();
1147
/* value could be anything since we're at the last block, so accept any answer */
1148
printf("returned %u... OK\n", blocksize);
1151
printf("testing get_channel_assignment()... ");
1153
::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
1154
printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
1157
printf("testing reset()... ");
1158
if(!decoder->reset())
1159
return decoder->die("returned false");
1162
decoder->current_metadata_number_ = 0;
1164
printf("rewinding input... ");
1165
if(::fseek(decoder->file_, 0, SEEK_SET) < 0) {
1166
printf("FAILED, errno = %d\n", errno);
1171
printf("testing process_until_end_of_stream()... ");
1172
if(!decoder->process_until_end_of_stream())
1173
return decoder->die("returned false");
1176
printf("testing finish()... ");
1184
printf("testing set_metadata_respond_all()... ");
1185
if(!decoder->set_metadata_respond_all()) {
1186
printf("FAILED, returned false\n");
1192
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1193
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1194
expected_metadata_sequence_[num_expected_++] = &padding_;
1195
expected_metadata_sequence_[num_expected_++] = &seektable_;
1196
expected_metadata_sequence_[num_expected_++] = &application1_;
1197
expected_metadata_sequence_[num_expected_++] = &application2_;
1198
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1199
expected_metadata_sequence_[num_expected_++] = &unknown_;
1201
if(!decoder->test_respond())
1208
printf("testing set_metadata_ignore_all()... ");
1209
if(!decoder->set_metadata_ignore_all()) {
1210
printf("FAILED, returned false\n");
1217
if(!decoder->test_respond())
1221
* respond all, ignore VORBIS_COMMENT
1224
printf("testing set_metadata_respond_all()... ");
1225
if(!decoder->set_metadata_respond_all()) {
1226
printf("FAILED, returned false\n");
1231
printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
1232
if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
1233
printf("FAILED, returned false\n");
1239
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1240
expected_metadata_sequence_[num_expected_++] = &padding_;
1241
expected_metadata_sequence_[num_expected_++] = &seektable_;
1242
expected_metadata_sequence_[num_expected_++] = &application1_;
1243
expected_metadata_sequence_[num_expected_++] = &application2_;
1244
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1245
expected_metadata_sequence_[num_expected_++] = &unknown_;
1247
if(!decoder->test_respond())
1251
* respond all, ignore APPLICATION
1254
printf("testing set_metadata_respond_all()... ");
1255
if(!decoder->set_metadata_respond_all()) {
1256
printf("FAILED, returned false\n");
1261
printf("testing set_metadata_ignore(APPLICATION)... ");
1262
if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1263
printf("FAILED, returned false\n");
1269
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1270
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1271
expected_metadata_sequence_[num_expected_++] = &padding_;
1272
expected_metadata_sequence_[num_expected_++] = &seektable_;
1273
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1274
expected_metadata_sequence_[num_expected_++] = &unknown_;
1276
if(!decoder->test_respond())
1280
* respond all, ignore APPLICATION id of app#1
1283
printf("testing set_metadata_respond_all()... ");
1284
if(!decoder->set_metadata_respond_all()) {
1285
printf("FAILED, returned false\n");
1290
printf("testing set_metadata_ignore_application(of app block #1)... ");
1291
if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1292
printf("FAILED, returned false\n");
1298
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1299
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1300
expected_metadata_sequence_[num_expected_++] = &padding_;
1301
expected_metadata_sequence_[num_expected_++] = &seektable_;
1302
expected_metadata_sequence_[num_expected_++] = &application2_;
1303
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1304
expected_metadata_sequence_[num_expected_++] = &unknown_;
1306
if(!decoder->test_respond())
1310
* respond all, ignore APPLICATION id of app#1 & app#2
1313
printf("testing set_metadata_respond_all()... ");
1314
if(!decoder->set_metadata_respond_all()) {
1315
printf("FAILED, returned false\n");
1320
printf("testing set_metadata_ignore_application(of app block #1)... ");
1321
if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1322
printf("FAILED, returned false\n");
1327
printf("testing set_metadata_ignore_application(of app block #2)... ");
1328
if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
1329
printf("FAILED, returned false\n");
1335
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1336
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1337
expected_metadata_sequence_[num_expected_++] = &padding_;
1338
expected_metadata_sequence_[num_expected_++] = &seektable_;
1339
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1340
expected_metadata_sequence_[num_expected_++] = &unknown_;
1342
if(!decoder->test_respond())
1346
* ignore all, respond VORBIS_COMMENT
1349
printf("testing set_metadata_ignore_all()... ");
1350
if(!decoder->set_metadata_ignore_all()) {
1351
printf("FAILED, returned false\n");
1356
printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
1357
if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
1358
printf("FAILED, returned false\n");
1364
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1366
if(!decoder->test_respond())
1370
* ignore all, respond APPLICATION
1373
printf("testing set_metadata_ignore_all()... ");
1374
if(!decoder->set_metadata_ignore_all()) {
1375
printf("FAILED, returned false\n");
1380
printf("testing set_metadata_respond(APPLICATION)... ");
1381
if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
1382
printf("FAILED, returned false\n");
1388
expected_metadata_sequence_[num_expected_++] = &application1_;
1389
expected_metadata_sequence_[num_expected_++] = &application2_;
1391
if(!decoder->test_respond())
1395
* ignore all, respond APPLICATION id of app#1
1398
printf("testing set_metadata_ignore_all()... ");
1399
if(!decoder->set_metadata_ignore_all()) {
1400
printf("FAILED, returned false\n");
1405
printf("testing set_metadata_respond_application(of app block #1)... ");
1406
if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1407
printf("FAILED, returned false\n");
1413
expected_metadata_sequence_[num_expected_++] = &application1_;
1415
if(!decoder->test_respond())
1419
* ignore all, respond APPLICATION id of app#1 & app#2
1422
printf("testing set_metadata_ignore_all()... ");
1423
if(!decoder->set_metadata_ignore_all()) {
1424
printf("FAILED, returned false\n");
1429
printf("testing set_metadata_respond_application(of app block #1)... ");
1430
if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1431
printf("FAILED, returned false\n");
1436
printf("testing set_metadata_respond_application(of app block #2)... ");
1437
if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
1438
printf("FAILED, returned false\n");
1444
expected_metadata_sequence_[num_expected_++] = &application1_;
1445
expected_metadata_sequence_[num_expected_++] = &application2_;
1447
if(!decoder->test_respond())
1451
* respond all, ignore APPLICATION, respond APPLICATION id of app#1
1454
printf("testing set_metadata_respond_all()... ");
1455
if(!decoder->set_metadata_respond_all()) {
1456
printf("FAILED, returned false\n");
1461
printf("testing set_metadata_ignore(APPLICATION)... ");
1462
if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1463
printf("FAILED, returned false\n");
1468
printf("testing set_metadata_respond_application(of app block #1)... ");
1469
if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1470
printf("FAILED, returned false\n");
1476
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1477
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1478
expected_metadata_sequence_[num_expected_++] = &padding_;
1479
expected_metadata_sequence_[num_expected_++] = &seektable_;
1480
expected_metadata_sequence_[num_expected_++] = &application1_;
1481
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1482
expected_metadata_sequence_[num_expected_++] = &unknown_;
1484
if(!decoder->test_respond())
1488
* ignore all, respond APPLICATION, ignore APPLICATION id of app#1
1491
printf("testing set_metadata_ignore_all()... ");
1492
if(!decoder->set_metadata_ignore_all()) {
1493
printf("FAILED, returned false\n");
1498
printf("testing set_metadata_respond(APPLICATION)... ");
1499
if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
1500
printf("FAILED, returned false\n");
1505
printf("testing set_metadata_ignore_application(of app block #1)... ");
1506
if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1507
printf("FAILED, returned false\n");
1513
expected_metadata_sequence_[num_expected_++] = &application2_;
1515
if(!decoder->test_respond())
1518
/* done, now leave the sequence the way we found it... */
1520
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1521
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1522
expected_metadata_sequence_[num_expected_++] = &padding_;
1523
expected_metadata_sequence_[num_expected_++] = &seektable_;
1524
expected_metadata_sequence_[num_expected_++] = &application1_;
1525
expected_metadata_sequence_[num_expected_++] = &application2_;
1526
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1527
expected_metadata_sequence_[num_expected_++] = &unknown_;
1529
::fclose(decoder->file_);
1531
printf("freeing decoder instance... ");
1535
printf("\nPASSED!\n");
1540
class FileDecoder : public OggFLAC::Decoder::File, public DecoderCommon {
1542
FileDecoder(): OggFLAC::Decoder::File(), DecoderCommon() { }
1545
// from OggFLAC::Decoder::File
1546
::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
1547
void metadata_callback(const ::FLAC__StreamMetadata *metadata);
1548
void error_callback(::FLAC__StreamDecoderErrorStatus status);
1550
bool die(const char *msg = 0) const;
1552
bool test_respond();
1555
::FLAC__StreamDecoderWriteStatus FileDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
1558
return common_write_callback_(frame);
1561
void FileDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
1563
common_metadata_callback_(metadata);
1566
void FileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
1568
common_error_callback_(status);
1571
bool FileDecoder::die(const char *msg) const
1573
State state = get_state();
1576
printf("FAILED, %s", msg);
1580
printf(", state = %u (%s)\n", (unsigned)((::OggFLAC__FileDecoderState)state), state.as_cstring());
1581
if(state == ::OggFLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR) {
1582
OggFLAC::Decoder::SeekableStream::State state_ = get_seekable_stream_decoder_state();
1583
printf(" seekable stream decoder state = %u (%s)\n", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state_), state_.as_cstring());
1584
if(state_ == ::OggFLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR) {
1585
OggFLAC::Decoder::Stream::State state__ = get_stream_decoder_state();
1586
printf(" stream decoder state = %u (%s)\n", (unsigned)((::OggFLAC__StreamDecoderState)state__), state__.as_cstring());
1587
if(state__ == ::OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR) {
1588
FLAC::Decoder::Stream::State state___ = get_FLAC_stream_decoder_state();
1589
printf(" FLAC stream decoder state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state___), state___.as_cstring());
1597
bool FileDecoder::test_respond()
1599
if(!set_filename(oggflacfilename_)) {
1600
printf("FAILED at set_filename(), returned false\n");
1604
if(!set_md5_checking(true)) {
1605
printf("FAILED at set_md5_checking(), returned false\n");
1609
printf("testing init()... ");
1610
if(init() != ::OggFLAC__FILE_DECODER_OK)
1614
current_metadata_number_ = 0;
1616
printf("testing process_until_end_of_file()... ");
1617
if(!process_until_end_of_file()) {
1618
State state = get_state();
1619
printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::OggFLAC__FileDecoderState)state), state.as_cstring());
1624
printf("testing finish()... ");
1631
static bool test_file_decoder()
1633
FileDecoder *decoder;
1635
printf("\n+++ libOggFLAC++ unit test: OggFLAC::Decoder::File\n\n");
1638
// test new -> delete
1640
printf("allocating decoder instance... ");
1641
decoder = new FileDecoder();
1643
printf("FAILED, new returned NULL\n");
1648
printf("testing is_valid()... ");
1649
if(!decoder->is_valid()) {
1650
printf("FAILED, returned false\n");
1655
printf("freeing decoder instance... ");
1660
// test new -> init -> delete
1662
printf("allocating decoder instance... ");
1663
decoder = new FileDecoder();
1665
printf("FAILED, new returned NULL\n");
1670
printf("testing is_valid()... ");
1671
if(!decoder->is_valid()) {
1672
printf("FAILED, returned false\n");
1677
printf("testing init()... ");
1678
if(decoder->init() != ::OggFLAC__FILE_DECODER_OK)
1679
return decoder->die();
1682
printf("freeing decoder instance... ");
1687
// test normal usage
1690
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1692
printf("allocating decoder instance... ");
1693
decoder = new FileDecoder();
1695
printf("FAILED, new returned NULL\n");
1700
printf("testing is_valid()... ");
1701
if(!decoder->is_valid()) {
1702
printf("FAILED, returned false\n");
1707
printf("testing set_filename()... ");
1708
if(!decoder->set_filename(oggflacfilename_)) {
1709
printf("FAILED, returned false\n");
1714
printf("testing set_md5_checking()... ");
1715
if(!decoder->set_md5_checking(true)) {
1716
printf("FAILED, returned false\n");
1721
printf("testing set_serial_number()... ");
1722
if(!decoder->set_serial_number(file_utils__serial_number))
1723
return decoder->die("returned false");
1726
printf("testing init()... ");
1727
if(decoder->init() != ::OggFLAC__FILE_DECODER_OK)
1728
return decoder->die();
1731
printf("testing get_state()... ");
1732
OggFLAC::Decoder::File::State state = decoder->get_state();
1733
printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__FileDecoderState)state), state.as_cstring());
1735
printf("testing get_seekable_stream_decoder_state()... ");
1736
OggFLAC::Decoder::SeekableStream::State state_ = decoder->get_seekable_stream_decoder_state();
1737
printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state_), state_.as_cstring());
1739
printf("testing get_stream_decoder_state()... ");
1740
OggFLAC::Decoder::Stream::State state__ = decoder->get_stream_decoder_state();
1741
printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__StreamDecoderState)state__), state__.as_cstring());
1743
printf("testing get_FLAC_stream_decoder_state()... ");
1744
FLAC::Decoder::Stream::State state___ = decoder->get_FLAC_stream_decoder_state();
1745
printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state___), state___.as_cstring());
1747
decoder->current_metadata_number_ = 0;
1748
decoder->ignore_errors_ = false;
1749
decoder->error_occurred_ = false;
1751
printf("testing get_md5_checking()... ");
1752
if(!decoder->get_md5_checking()) {
1753
printf("FAILED, returned false, expected true\n");
1758
printf("testing process_until_end_of_metadata()... ");
1759
if(!decoder->process_until_end_of_metadata())
1760
return decoder->die("returned false");
1763
printf("testing process_single()... ");
1764
if(!decoder->process_single())
1765
return decoder->die("returned false");
1768
printf("testing seek_absolute()... ");
1769
if(!decoder->seek_absolute(0))
1770
return decoder->die("returned false");
1773
printf("testing process_until_end_of_file()... ");
1774
if(!decoder->process_until_end_of_file())
1775
return decoder->die("returned false");
1778
printf("testing get_channels()... ");
1780
unsigned channels = decoder->get_channels();
1781
if(channels != streaminfo_.data.stream_info.channels) {
1782
printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
1788
printf("testing get_bits_per_sample()... ");
1790
unsigned bits_per_sample = decoder->get_bits_per_sample();
1791
if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
1792
printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
1798
printf("testing get_sample_rate()... ");
1800
unsigned sample_rate = decoder->get_sample_rate();
1801
if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
1802
printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
1808
printf("testing get_blocksize()... ");
1810
unsigned blocksize = decoder->get_blocksize();
1811
/* value could be anything since we're at the last block, so accept any answer */
1812
printf("returned %u... OK\n", blocksize);
1815
printf("testing get_channel_assignment()... ");
1817
::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
1818
printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
1821
printf("testing finish()... ");
1829
printf("testing set_metadata_respond_all()... ");
1830
if(!decoder->set_metadata_respond_all()) {
1831
printf("FAILED, returned false\n");
1837
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1838
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1839
expected_metadata_sequence_[num_expected_++] = &padding_;
1840
expected_metadata_sequence_[num_expected_++] = &seektable_;
1841
expected_metadata_sequence_[num_expected_++] = &application1_;
1842
expected_metadata_sequence_[num_expected_++] = &application2_;
1843
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1844
expected_metadata_sequence_[num_expected_++] = &unknown_;
1846
if(!decoder->test_respond())
1853
printf("testing set_metadata_ignore_all()... ");
1854
if(!decoder->set_metadata_ignore_all()) {
1855
printf("FAILED, returned false\n");
1862
if(!decoder->test_respond())
1866
* respond all, ignore VORBIS_COMMENT
1869
printf("testing set_metadata_respond_all()... ");
1870
if(!decoder->set_metadata_respond_all()) {
1871
printf("FAILED, returned false\n");
1876
printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
1877
if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
1878
printf("FAILED, returned false\n");
1884
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1885
expected_metadata_sequence_[num_expected_++] = &padding_;
1886
expected_metadata_sequence_[num_expected_++] = &seektable_;
1887
expected_metadata_sequence_[num_expected_++] = &application1_;
1888
expected_metadata_sequence_[num_expected_++] = &application2_;
1889
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1890
expected_metadata_sequence_[num_expected_++] = &unknown_;
1892
if(!decoder->test_respond())
1896
* respond all, ignore APPLICATION
1899
printf("testing set_metadata_respond_all()... ");
1900
if(!decoder->set_metadata_respond_all()) {
1901
printf("FAILED, returned false\n");
1906
printf("testing set_metadata_ignore(APPLICATION)... ");
1907
if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1908
printf("FAILED, returned false\n");
1914
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1915
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1916
expected_metadata_sequence_[num_expected_++] = &padding_;
1917
expected_metadata_sequence_[num_expected_++] = &seektable_;
1918
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1919
expected_metadata_sequence_[num_expected_++] = &unknown_;
1921
if(!decoder->test_respond())
1925
* respond all, ignore APPLICATION id of app#1
1928
printf("testing set_metadata_respond_all()... ");
1929
if(!decoder->set_metadata_respond_all()) {
1930
printf("FAILED, returned false\n");
1935
printf("testing set_metadata_ignore_application(of app block #1)... ");
1936
if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1937
printf("FAILED, returned false\n");
1943
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1944
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1945
expected_metadata_sequence_[num_expected_++] = &padding_;
1946
expected_metadata_sequence_[num_expected_++] = &seektable_;
1947
expected_metadata_sequence_[num_expected_++] = &application2_;
1948
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1949
expected_metadata_sequence_[num_expected_++] = &unknown_;
1951
if(!decoder->test_respond())
1955
* respond all, ignore APPLICATION id of app#1 & app#2
1958
printf("testing set_metadata_respond_all()... ");
1959
if(!decoder->set_metadata_respond_all()) {
1960
printf("FAILED, returned false\n");
1965
printf("testing set_metadata_ignore_application(of app block #1)... ");
1966
if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1967
printf("FAILED, returned false\n");
1972
printf("testing set_metadata_ignore_application(of app block #2)... ");
1973
if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
1974
printf("FAILED, returned false\n");
1980
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1981
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1982
expected_metadata_sequence_[num_expected_++] = &padding_;
1983
expected_metadata_sequence_[num_expected_++] = &seektable_;
1984
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1985
expected_metadata_sequence_[num_expected_++] = &unknown_;
1987
if(!decoder->test_respond())
1991
* ignore all, respond VORBIS_COMMENT
1994
printf("testing set_metadata_ignore_all()... ");
1995
if(!decoder->set_metadata_ignore_all()) {
1996
printf("FAILED, returned false\n");
2001
printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
2002
if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
2003
printf("FAILED, returned false\n");
2009
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
2011
if(!decoder->test_respond())
2015
* ignore all, respond APPLICATION
2018
printf("testing set_metadata_ignore_all()... ");
2019
if(!decoder->set_metadata_ignore_all()) {
2020
printf("FAILED, returned false\n");
2025
printf("testing set_metadata_respond(APPLICATION)... ");
2026
if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
2027
printf("FAILED, returned false\n");
2033
expected_metadata_sequence_[num_expected_++] = &application1_;
2034
expected_metadata_sequence_[num_expected_++] = &application2_;
2036
if(!decoder->test_respond())
2040
* ignore all, respond APPLICATION id of app#1
2043
printf("testing set_metadata_ignore_all()... ");
2044
if(!decoder->set_metadata_ignore_all()) {
2045
printf("FAILED, returned false\n");
2050
printf("testing set_metadata_respond_application(of app block #1)... ");
2051
if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
2052
printf("FAILED, returned false\n");
2058
expected_metadata_sequence_[num_expected_++] = &application1_;
2060
if(!decoder->test_respond())
2064
* ignore all, respond APPLICATION id of app#1 & app#2
2067
printf("testing set_metadata_ignore_all()... ");
2068
if(!decoder->set_metadata_ignore_all()) {
2069
printf("FAILED, returned false\n");
2074
printf("testing set_metadata_respond_application(of app block #1)... ");
2075
if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
2076
printf("FAILED, returned false\n");
2081
printf("testing set_metadata_respond_application(of app block #2)... ");
2082
if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
2083
printf("FAILED, returned false\n");
2089
expected_metadata_sequence_[num_expected_++] = &application1_;
2090
expected_metadata_sequence_[num_expected_++] = &application2_;
2092
if(!decoder->test_respond())
2096
* respond all, ignore APPLICATION, respond APPLICATION id of app#1
2099
printf("testing set_metadata_respond_all()... ");
2100
if(!decoder->set_metadata_respond_all()) {
2101
printf("FAILED, returned false\n");
2106
printf("testing set_metadata_ignore(APPLICATION)... ");
2107
if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
2108
printf("FAILED, returned false\n");
2113
printf("testing set_metadata_respond_application(of app block #1)... ");
2114
if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
2115
printf("FAILED, returned false\n");
2121
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
2122
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
2123
expected_metadata_sequence_[num_expected_++] = &padding_;
2124
expected_metadata_sequence_[num_expected_++] = &seektable_;
2125
expected_metadata_sequence_[num_expected_++] = &application1_;
2126
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
2127
expected_metadata_sequence_[num_expected_++] = &unknown_;
2129
if(!decoder->test_respond())
2133
* ignore all, respond APPLICATION, ignore APPLICATION id of app#1
2136
printf("testing set_metadata_ignore_all()... ");
2137
if(!decoder->set_metadata_ignore_all()) {
2138
printf("FAILED, returned false\n");
2143
printf("testing set_metadata_respond(APPLICATION)... ");
2144
if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
2145
printf("FAILED, returned false\n");
2150
printf("testing set_metadata_ignore_application(of app block #1)... ");
2151
if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
2152
printf("FAILED, returned false\n");
2158
expected_metadata_sequence_[num_expected_++] = &application2_;
2160
if(!decoder->test_respond())
2163
/* done, now leave the sequence the way we found it... */
2165
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
2166
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
2167
expected_metadata_sequence_[num_expected_++] = &padding_;
2168
expected_metadata_sequence_[num_expected_++] = &seektable_;
2169
expected_metadata_sequence_[num_expected_++] = &application1_;
2170
expected_metadata_sequence_[num_expected_++] = &application2_;
2171
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
2172
expected_metadata_sequence_[num_expected_++] = &unknown_;
2174
printf("freeing decoder instance... ");
2178
printf("\nPASSED!\n");
2183
bool test_decoders()
2185
init_metadata_blocks_();
2187
if(!generate_file_())
2190
if(!test_stream_decoder())
2193
if(!test_seekable_stream_decoder())
2196
if(!test_file_decoder())
2199
(void) grabbag__file_remove_file(oggflacfilename_);
2201
free_metadata_blocks_();