fix bug in stats reporting
[flac.git] / src / test_libFLAC / decoders.c
index a22dbdc..fef757e 100644 (file)
@@ -38,8 +38,8 @@ typedef struct {
 typedef stream_decoder_client_data_struct seekable_stream_decoder_client_data_struct;
 typedef stream_decoder_client_data_struct file_decoder_client_data_struct;
 
-static FLAC__StreamMetaData streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_;
-static FLAC__StreamMetaData *expected_metadata_sequence_[6];
+static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_;
+static FLAC__StreamMetadata *expected_metadata_sequence_[6];
 static unsigned num_expected_;
 static const char *flacfilename_ = "metadata.flac";
 static unsigned flacfilesize_;
@@ -55,9 +55,11 @@ static FLAC__bool die_s_(const char *msg, const FLAC__StreamDecoder *decoder)
        FLAC__StreamDecoderState state = FLAC__stream_decoder_get_state(decoder);
 
        if(msg)
-               printf("FAILED, %s, state = %u (%s)\n", msg, (unsigned)state, FLAC__StreamDecoderStateString[state]);
+               printf("FAILED, %s", msg);
        else
-               printf("FAILED, state = %u (%s)\n", (unsigned)state, FLAC__StreamDecoderStateString[state]);
+               printf("FAILED");
+
+       printf(", state = %u (%s)\n", (unsigned)state, FLAC__StreamDecoderStateString[state]);
 
        return false;
 }
@@ -67,9 +69,15 @@ static FLAC__bool die_ss_(const char *msg, const FLAC__SeekableStreamDecoder *de
        FLAC__SeekableStreamDecoderState state = FLAC__seekable_stream_decoder_get_state(decoder);
 
        if(msg)
-               printf("FAILED, %s, state = %u (%s)\n", msg, (unsigned)state, FLAC__SeekableStreamDecoderStateString[state]);
+               printf("FAILED, %s", msg);
        else
-               printf("FAILED, state = %u (%s)\n", (unsigned)state, FLAC__SeekableStreamDecoderStateString[state]);
+               printf("FAILED");
+
+       printf(", state = %u (%s)\n", (unsigned)state, FLAC__SeekableStreamDecoderStateString[state]);
+       if(state == FLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR) {
+               FLAC__StreamDecoderState state_ = FLAC__seekable_stream_decoder_get_stream_decoder_state(decoder);
+               printf("      stream decoder state = %u (%s)\n", (unsigned)state_, FLAC__StreamDecoderStateString[state_]);
+       }
 
        return false;
 }
@@ -79,9 +87,19 @@ static FLAC__bool die_f_(const char *msg, const FLAC__FileDecoder *decoder)
        FLAC__FileDecoderState state = FLAC__file_decoder_get_state(decoder);
 
        if(msg)
-               printf("FAILED, %s, state = %u (%s)\n", msg, (unsigned)state, FLAC__FileDecoderStateString[state]);
+               printf("FAILED, %s", msg);
        else
-               printf("FAILED, state = %u (%s)\n", (unsigned)state, FLAC__FileDecoderStateString[state]);
+               printf("FAILED");
+
+       printf(", state = %u (%s)\n", (unsigned)state, FLAC__FileDecoderStateString[state]);
+       if(state == FLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR) {
+               FLAC__SeekableStreamDecoderState state_ = FLAC__file_decoder_get_seekable_stream_decoder_state(decoder);
+               printf("      seekable stream decoder state = %u (%s)\n", (unsigned)state, FLAC__SeekableStreamDecoderStateString[state_]);
+               if(state_ == FLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR) {
+                       FLAC__StreamDecoderState state__ = FLAC__file_decoder_get_stream_decoder_state(decoder);
+                       printf("      stream decoder state = %u (%s)\n", (unsigned)state__, FLAC__StreamDecoderStateString[state__]);
+               }
+       }
 
        return false;
 }
@@ -128,7 +146,7 @@ static void init_metadata_blocks_()
     seektable_.type = FLAC__METADATA_TYPE_SEEKTABLE;
        seektable_.data.seek_table.num_points = 2;
     seektable_.length = seektable_.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
-       seektable_.data.seek_table.points = malloc_or_die_(seektable_.data.seek_table.num_points * sizeof(FLAC__StreamMetaData_SeekPoint));
+       seektable_.data.seek_table.points = malloc_or_die_(seektable_.data.seek_table.num_points * sizeof(FLAC__StreamMetadata_SeekPoint));
        seektable_.data.seek_table.points[0].sample_number = 0;
        seektable_.data.seek_table.points[0].stream_offset = 0;
        seektable_.data.seek_table.points[0].frame_samples = streaminfo_.data.stream_info.min_blocksize;
@@ -156,7 +174,7 @@ static void init_metadata_blocks_()
        vorbiscomment_.data.vorbis_comment.vendor_string.entry = malloc_or_die_(8);
        memcpy(vorbiscomment_.data.vorbis_comment.vendor_string.entry, "flac 1.x", 8);
        vorbiscomment_.data.vorbis_comment.num_comments = 2;
-       vorbiscomment_.data.vorbis_comment.comments = malloc_or_die_(vorbiscomment_.data.vorbis_comment.num_comments * sizeof(FLAC__StreamMetaData_VorbisComment_Entry));
+       vorbiscomment_.data.vorbis_comment.comments = malloc_or_die_(vorbiscomment_.data.vorbis_comment.num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
        vorbiscomment_.data.vorbis_comment.comments[0].length = 5;
        vorbiscomment_.data.vorbis_comment.comments[0].entry = malloc_or_die_(5);
        memcpy(vorbiscomment_.data.vorbis_comment.comments[0].entry, "ab=cd", 5);
@@ -248,7 +266,7 @@ static FLAC__StreamDecoderWriteStatus stream_decoder_write_callback_(const FLAC_
        return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
 }
 
-static void stream_decoder_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data)
+static void stream_decoder_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
 {
        stream_decoder_client_data_struct *dcd = (stream_decoder_client_data_struct*)client_data;
 
@@ -324,8 +342,8 @@ static FLAC__bool stream_decoder_test_respond_(FLAC__StreamDecoder *decoder, str
                return false;
        }
 
-       printf("testing FLAC__stream_decoder_process_whole_stream()... ");
-       if(!FLAC__stream_decoder_process_whole_stream(decoder))
+       printf("testing FLAC__stream_decoder_process_until_end_of_stream()... ");
+       if(!FLAC__stream_decoder_process_until_end_of_stream(decoder))
                return die_s_("returned false", decoder);
        printf("OK\n");
 
@@ -342,7 +360,36 @@ static FLAC__bool test_stream_decoder()
        FLAC__StreamDecoderState state;
        stream_decoder_client_data_struct decoder_client_data;
 
-       printf("\n+++ unit test: FLAC__StreamDecoder\n\n");
+       printf("\n+++ libFLAC unit test: FLAC__StreamDecoder\n\n");
+
+       printf("testing FLAC__stream_decoder_new()... ");
+       decoder = FLAC__stream_decoder_new();
+       if(0 == decoder) {
+               printf("FAILED, returned NULL\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__stream_decoder_delete()... ");
+       FLAC__stream_decoder_delete(decoder);
+       printf("OK\n");
+
+       printf("testing FLAC__stream_decoder_new()... ");
+       decoder = FLAC__stream_decoder_new();
+       if(0 == decoder) {
+               printf("FAILED, returned NULL\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__stream_decoder_init()... ");
+       if(FLAC__stream_decoder_init(decoder) == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA)
+               return die_s_(0, decoder);
+       printf("OK\n");
+
+       printf("testing FLAC__stream_decoder_delete()... ");
+       FLAC__stream_decoder_delete(decoder);
+       printf("OK\n");
 
        num_expected_ = 0;
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
@@ -401,13 +448,13 @@ static FLAC__bool test_stream_decoder()
        }
        printf("OK\n");
 
-       printf("testing FLAC__stream_decoder_process_metadata()... ");
-       if(!FLAC__stream_decoder_process_metadata(decoder))
+       printf("testing FLAC__stream_decoder_process_until_end_of_metadata()... ");
+       if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder))
                return die_s_("returned false", decoder);
        printf("OK\n");
 
-       printf("testing FLAC__stream_decoder_process_one_frame()... ");
-       if(!FLAC__stream_decoder_process_one_frame(decoder))
+       printf("testing FLAC__stream_decoder_process_single()... ");
+       if(!FLAC__stream_decoder_process_single(decoder))
                return die_s_("returned false", decoder);
        printf("OK\n");
 
@@ -417,14 +464,14 @@ static FLAC__bool test_stream_decoder()
        printf("OK\n");
 
        decoder_client_data.ignore_errors = true;
-       printf("testing FLAC__stream_decoder_process_one_frame()... ");
-       if(!FLAC__stream_decoder_process_one_frame(decoder))
+       printf("testing FLAC__stream_decoder_process_single()... ");
+       if(!FLAC__stream_decoder_process_single(decoder))
                return die_s_("returned false", decoder);
        printf("OK\n");
        decoder_client_data.ignore_errors = false;
 
-       printf("testing FLAC__stream_decoder_process_remaining_frames()... ");
-       if(!FLAC__stream_decoder_process_remaining_frames(decoder))
+       printf("testing FLAC__stream_decoder_process_until_end_of_stream()... ");
+       if(!FLAC__stream_decoder_process_until_end_of_stream(decoder))
                return die_s_("returned false", decoder);
        printf("OK\n");
 
@@ -488,8 +535,8 @@ static FLAC__bool test_stream_decoder()
        }
        printf("OK\n");
 
-       printf("testing FLAC__stream_decoder_process_whole_stream()... ");
-       if(!FLAC__stream_decoder_process_whole_stream(decoder))
+       printf("testing FLAC__stream_decoder_process_until_end_of_stream()... ");
+       if(!FLAC__stream_decoder_process_until_end_of_stream(decoder))
                return die_s_("returned false", decoder);
        printf("OK\n");
 
@@ -820,7 +867,7 @@ static FLAC__SeekableStreamDecoderSeekStatus seekable_stream_decoder_seek_callba
        if(dcd->error_occurred)
                return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
 
-       if(fseek(dcd->file, absolute_byte_offset, SEEK_SET) < 0) {
+       if(fseek(dcd->file, (long)absolute_byte_offset, SEEK_SET) < 0) {
                dcd->error_occurred = true;
                return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
        }
@@ -895,7 +942,7 @@ static FLAC__StreamDecoderWriteStatus seekable_stream_decoder_write_callback_(co
        return stream_decoder_write_callback_(0, frame, buffer, client_data);
 }
 
-static void seekable_stream_decoder_metadata_callback_(const FLAC__SeekableStreamDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data)
+static void seekable_stream_decoder_metadata_callback_(const FLAC__SeekableStreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
 {
        (void)decoder;
        stream_decoder_metadata_callback_(0, metadata, client_data);
@@ -951,8 +998,8 @@ static FLAC__bool seekable_stream_decoder_test_respond_(FLAC__SeekableStreamDeco
                return false;
        }
 
-       printf("testing FLAC__seekable_stream_decoder_process_whole_stream()... ");
-       if(!FLAC__seekable_stream_decoder_process_whole_stream(decoder))
+       printf("testing FLAC__seekable_stream_decoder_process_until_end_of_stream()... ");
+       if(!FLAC__seekable_stream_decoder_process_until_end_of_stream(decoder))
                return die_ss_("returned false", decoder);
        printf("OK\n");
 
@@ -967,9 +1014,39 @@ static FLAC__bool test_seekable_stream_decoder()
 {
        FLAC__SeekableStreamDecoder *decoder;
        FLAC__SeekableStreamDecoderState state;
+       FLAC__StreamDecoderState sstate;
        seekable_stream_decoder_client_data_struct decoder_client_data;
 
-       printf("\n+++ unit test: FLAC__SeekableStreamDecoder\n\n");
+       printf("\n+++ libFLAC unit test: FLAC__SeekableStreamDecoder\n\n");
+
+       printf("testing FLAC__seekable_stream_decoder_new()... ");
+       decoder = FLAC__seekable_stream_decoder_new();
+       if(0 == decoder) {
+               printf("FAILED, returned NULL\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_decoder_delete()... ");
+       FLAC__seekable_stream_decoder_delete(decoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_decoder_new()... ");
+       decoder = FLAC__seekable_stream_decoder_new();
+       if(0 == decoder) {
+               printf("FAILED, returned NULL\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_decoder_init()... ");
+       if(FLAC__seekable_stream_decoder_init(decoder) == FLAC__SEEKABLE_STREAM_DECODER_OK)
+               return die_ss_(0, decoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_decoder_delete()... ");
+       FLAC__seekable_stream_decoder_delete(decoder);
+       printf("OK\n");
 
        num_expected_ = 0;
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
@@ -1041,6 +1118,10 @@ static FLAC__bool test_seekable_stream_decoder()
        state = FLAC__seekable_stream_decoder_get_state(decoder);
        printf("returned state = %u (%s)... OK\n", state, FLAC__SeekableStreamDecoderStateString[state]);
 
+       printf("testing FLAC__seekable_stream_decoder_get_stream_decoder_state()... ");
+       sstate = FLAC__seekable_stream_decoder_get_stream_decoder_state(decoder);
+       printf("returned state = %u (%s)... OK\n", sstate, FLAC__StreamDecoderStateString[sstate]);
+
        decoder_client_data.current_metadata_number = 0;
        decoder_client_data.ignore_errors = false;
        decoder_client_data.error_occurred = false;
@@ -1060,13 +1141,13 @@ static FLAC__bool test_seekable_stream_decoder()
        }
        printf("OK\n");
 
-       printf("testing FLAC__seekable_stream_decoder_process_metadata()... ");
-       if(!FLAC__seekable_stream_decoder_process_metadata(decoder))
+       printf("testing FLAC__seekable_stream_decoder_process_until_end_of_metadata()... ");
+       if(!FLAC__seekable_stream_decoder_process_until_end_of_metadata(decoder))
                return die_ss_("returned false", decoder);
        printf("OK\n");
 
-       printf("testing FLAC__seekable_stream_decoder_process_one_frame()... ");
-       if(!FLAC__seekable_stream_decoder_process_one_frame(decoder))
+       printf("testing FLAC__seekable_stream_decoder_process_single()... ");
+       if(!FLAC__seekable_stream_decoder_process_single(decoder))
                return die_ss_("returned false", decoder);
        printf("OK\n");
 
@@ -1076,8 +1157,8 @@ static FLAC__bool test_seekable_stream_decoder()
        printf("OK\n");
 
        decoder_client_data.ignore_errors = true;
-       printf("testing FLAC__seekable_stream_decoder_process_one_frame()... ");
-       if(!FLAC__seekable_stream_decoder_process_one_frame(decoder))
+       printf("testing FLAC__seekable_stream_decoder_process_single()... ");
+       if(!FLAC__seekable_stream_decoder_process_single(decoder))
                return die_ss_("returned false", decoder);
        printf("OK\n");
        decoder_client_data.ignore_errors = false;
@@ -1087,8 +1168,8 @@ static FLAC__bool test_seekable_stream_decoder()
                return die_ss_("returned false", decoder);
        printf("OK\n");
 
-       printf("testing FLAC__seekable_stream_decoder_process_remaining_frames()... ");
-       if(!FLAC__seekable_stream_decoder_process_remaining_frames(decoder))
+       printf("testing FLAC__seekable_stream_decoder_process_until_end_of_stream()... ");
+       if(!FLAC__seekable_stream_decoder_process_until_end_of_stream(decoder))
                return die_ss_("returned false", decoder);
        printf("OK\n");
 
@@ -1149,8 +1230,8 @@ static FLAC__bool test_seekable_stream_decoder()
        }
        printf("OK\n");
 
-       printf("testing FLAC__seekable_stream_decoder_process_whole_stream()... ");
-       if(!FLAC__seekable_stream_decoder_process_whole_stream(decoder))
+       printf("testing FLAC__seekable_stream_decoder_process_until_end_of_stream()... ");
+       if(!FLAC__seekable_stream_decoder_process_until_end_of_stream(decoder))
                return die_ss_("returned false", decoder);
        printf("OK\n");
 
@@ -1458,7 +1539,7 @@ static FLAC__StreamDecoderWriteStatus file_decoder_write_callback_(const FLAC__F
        return stream_decoder_write_callback_(0, frame, buffer, client_data);
 }
 
-static void file_decoder_metadata_callback_(const FLAC__FileDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data)
+static void file_decoder_metadata_callback_(const FLAC__FileDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
 {
        (void)decoder;
        stream_decoder_metadata_callback_(0, metadata, client_data);
@@ -1497,8 +1578,8 @@ static FLAC__bool file_decoder_test_respond_(FLAC__FileDecoder *decoder, file_de
 
        dcd->current_metadata_number = 0;
 
-       printf("testing FLAC__file_decoder_process_whole_file()... ");
-       if(!FLAC__file_decoder_process_whole_file(decoder))
+       printf("testing FLAC__file_decoder_process_until_end_of_file()... ");
+       if(!FLAC__file_decoder_process_until_end_of_file(decoder))
                return die_f_("returned false", decoder);
        printf("OK\n");
 
@@ -1513,9 +1594,40 @@ static FLAC__bool test_file_decoder()
 {
        FLAC__FileDecoder *decoder;
        FLAC__FileDecoderState state;
+       FLAC__SeekableStreamDecoderState ssstate;
+       FLAC__StreamDecoderState sstate;
        seekable_stream_decoder_client_data_struct decoder_client_data;
 
-       printf("\n+++ unit test: FLAC__FileDecoder\n\n");
+       printf("\n+++ libFLAC unit test: FLAC__FileDecoder\n\n");
+
+       printf("testing FLAC__file_decoder_new()... ");
+       decoder = FLAC__file_decoder_new();
+       if(0 == decoder) {
+               printf("FAILED, returned NULL\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__file_decoder_delete()... ");
+       FLAC__file_decoder_delete(decoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_decoder_new()... ");
+       decoder = FLAC__file_decoder_new();
+       if(0 == decoder) {
+               printf("FAILED, returned NULL\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__file_decoder_init()... ");
+       if(FLAC__file_decoder_init(decoder) == FLAC__FILE_DECODER_OK)
+               return die_f_(0, decoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_decoder_delete()... ");
+       FLAC__file_decoder_delete(decoder);
+       printf("OK\n");
 
        num_expected_ = 0;
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
@@ -1567,6 +1679,14 @@ static FLAC__bool test_file_decoder()
        state = FLAC__file_decoder_get_state(decoder);
        printf("returned state = %u (%s)... OK\n", state, FLAC__FileDecoderStateString[state]);
 
+       printf("testing FLAC__file_decoder_get_seekable_stream_decoder_state()... ");
+       ssstate = FLAC__file_decoder_get_seekable_stream_decoder_state(decoder);
+       printf("returned state = %u (%s)... OK\n", ssstate, FLAC__SeekableStreamDecoderStateString[ssstate]);
+
+       printf("testing FLAC__file_decoder_get_stream_decoder_state()... ");
+       sstate = FLAC__file_decoder_get_stream_decoder_state(decoder);
+       printf("returned state = %u (%s)... OK\n", sstate, FLAC__StreamDecoderStateString[sstate]);
+
        decoder_client_data.current_metadata_number = 0;
        decoder_client_data.ignore_errors = false;
        decoder_client_data.error_occurred = false;
@@ -1578,13 +1698,13 @@ static FLAC__bool test_file_decoder()
        }
        printf("OK\n");
 
-       printf("testing FLAC__file_decoder_process_metadata()... ");
-       if(!FLAC__file_decoder_process_metadata(decoder))
+       printf("testing FLAC__file_decoder_process_until_end_of_metadata()... ");
+       if(!FLAC__file_decoder_process_until_end_of_metadata(decoder))
                return die_f_("returned false", decoder);
        printf("OK\n");
 
-       printf("testing FLAC__file_decoder_process_one_frame()... ");
-       if(!FLAC__file_decoder_process_one_frame(decoder))
+       printf("testing FLAC__file_decoder_process_single()... ");
+       if(!FLAC__file_decoder_process_single(decoder))
                return die_f_("returned false", decoder);
        printf("OK\n");
 
@@ -1593,8 +1713,8 @@ static FLAC__bool test_file_decoder()
                return die_f_("returned false", decoder);
        printf("OK\n");
 
-       printf("testing FLAC__file_decoder_process_remaining_frames()... ");
-       if(!FLAC__file_decoder_process_remaining_frames(decoder))
+       printf("testing FLAC__file_decoder_process_until_end_of_file()... ");
+       if(!FLAC__file_decoder_process_until_end_of_file(decoder))
                return die_f_("returned false", decoder);
        printf("OK\n");