Commit 587f491b authored by Josh Coalson's avatar Josh Coalson
Browse files

finish CUESHEET tests

parent a0d5454f
......@@ -39,8 +39,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_, cuesheet_;
static FLAC__StreamMetadata *expected_metadata_sequence_[7];
static unsigned num_expected_;
static const char *flacfilename_ = "metadata.flac";
static unsigned flacfilesize_;
......@@ -184,6 +184,60 @@ static void init_metadata_blocks_()
vorbiscomment_.data.vorbis_comment.comments[1].length = 0;
vorbiscomment_.data.vorbis_comment.comments[1].entry = 0;
}
cuesheet_.is_last = true;
cuesheet_.type = FLAC__METADATA_TYPE_CUESHEET;
cuesheet_.length =
/* cuesheet guts */
(
FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
) / 8 +
/* 2 tracks */
2 * (
FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN +
FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN +
FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN +
FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN +
FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN +
FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN +
FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN
) / 8 +
/* 3 index points */
3 * (
FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN +
FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN +
FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN
) / 8
;
memset(cuesheet_.data.cue_sheet.media_catalog_number, 0, sizeof(cuesheet_.data.cue_sheet.media_catalog_number));
cuesheet_.data.cue_sheet.media_catalog_number[0] = 'j';
cuesheet_.data.cue_sheet.media_catalog_number[1] = 'C';
cuesheet_.data.cue_sheet.lead_in = 159;
cuesheet_.data.cue_sheet.num_tracks = 2;
cuesheet_.data.cue_sheet.tracks = malloc_or_die_(cuesheet_.data.cue_sheet.num_tracks * sizeof(FLAC__StreamMetadata_CueSheet_Track));
cuesheet_.data.cue_sheet.tracks[0].offset = 1;
cuesheet_.data.cue_sheet.tracks[0].number = 1;
memcpy(cuesheet_.data.cue_sheet.tracks[0].isrc, "ACBDE1234567", sizeof(cuesheet_.data.cue_sheet.tracks[0].isrc));
cuesheet_.data.cue_sheet.tracks[0].type = 0;
cuesheet_.data.cue_sheet.tracks[0].pre_emphasis = 1;
cuesheet_.data.cue_sheet.tracks[0].num_indices = 2;
cuesheet_.data.cue_sheet.tracks[0].indices = malloc_or_die_(cuesheet_.data.cue_sheet.tracks[0].num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index));
cuesheet_.data.cue_sheet.tracks[0].indices[0].offset = 0;
cuesheet_.data.cue_sheet.tracks[0].indices[0].number = 0;
cuesheet_.data.cue_sheet.tracks[0].indices[1].offset = 1234567890;
cuesheet_.data.cue_sheet.tracks[0].indices[1].number = 1;
cuesheet_.data.cue_sheet.tracks[1].offset = 12345678901;
cuesheet_.data.cue_sheet.tracks[1].number = 2;
memcpy(cuesheet_.data.cue_sheet.tracks[1].isrc, "ACBDE7654321", sizeof(cuesheet_.data.cue_sheet.tracks[1].isrc));
cuesheet_.data.cue_sheet.tracks[1].type = 1;
cuesheet_.data.cue_sheet.tracks[1].pre_emphasis = 0;
cuesheet_.data.cue_sheet.tracks[1].num_indices = 1;
cuesheet_.data.cue_sheet.tracks[1].indices = malloc_or_die_(cuesheet_.data.cue_sheet.tracks[1].num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index));
cuesheet_.data.cue_sheet.tracks[1].indices[0].offset = 0;
cuesheet_.data.cue_sheet.tracks[1].indices[0].number = 1;
}
static void free_metadata_blocks_()
......@@ -193,6 +247,9 @@ static void free_metadata_blocks_()
free(vorbiscomment_.data.vorbis_comment.vendor_string.entry);
free(vorbiscomment_.data.vorbis_comment.comments[0].entry);
free(vorbiscomment_.data.vorbis_comment.comments);
free(cuesheet_.data.cue_sheet.tracks[0].indices);
free(cuesheet_.data.cue_sheet.tracks[1].indices);
free(cuesheet_.data.cue_sheet.tracks);
}
static FLAC__bool generate_file_()
......@@ -204,7 +261,8 @@ static FLAC__bool generate_file_()
expected_metadata_sequence_[2] = &application1_;
expected_metadata_sequence_[3] = &application2_;
expected_metadata_sequence_[4] = &vorbiscomment_;
num_expected_ = 5;
expected_metadata_sequence_[5] = &cuesheet_;
num_expected_ = 6;
if(!file_utils__generate_flacfile(flacfilename_, &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
return die_("creating the encoded file");
......@@ -564,6 +622,7 @@ static FLAC__bool test_stream_decoder()
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
......@@ -602,6 +661,7 @@ static FLAC__bool test_stream_decoder()
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
......@@ -625,6 +685,7 @@ static FLAC__bool test_stream_decoder()
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
......@@ -649,6 +710,7 @@ static FLAC__bool test_stream_decoder()
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
......@@ -677,6 +739,7 @@ static FLAC__bool test_stream_decoder()
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
......@@ -793,6 +856,7 @@ static FLAC__bool test_stream_decoder()
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
......@@ -830,6 +894,7 @@ static FLAC__bool test_stream_decoder()
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
printf("testing FLAC__stream_decoder_delete()... ");
FLAC__stream_decoder_delete(decoder);
......@@ -1259,6 +1324,7 @@ static FLAC__bool test_seekable_stream_decoder()
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
if(!seekable_stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
......@@ -1297,6 +1363,7 @@ static FLAC__bool test_seekable_stream_decoder()
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
if(!seekable_stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
......@@ -1320,6 +1387,7 @@ static FLAC__bool test_seekable_stream_decoder()
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
if(!seekable_stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
......@@ -1344,6 +1412,7 @@ static FLAC__bool test_seekable_stream_decoder()
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
if(!seekable_stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
......@@ -1372,6 +1441,7 @@ static FLAC__bool test_seekable_stream_decoder()
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
if(!seekable_stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
......@@ -1488,6 +1558,7 @@ static FLAC__bool test_seekable_stream_decoder()
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
if(!seekable_stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
......@@ -1525,6 +1596,7 @@ static FLAC__bool test_seekable_stream_decoder()
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
printf("testing FLAC__seekable_stream_decoder_delete()... ");
FLAC__seekable_stream_decoder_delete(decoder);
......@@ -1785,6 +1857,7 @@ static FLAC__bool test_file_decoder()
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
if(!file_decoder_test_respond_(decoder, &decoder_client_data))
return false;
......@@ -1823,6 +1896,7 @@ static FLAC__bool test_file_decoder()
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
if(!file_decoder_test_respond_(decoder, &decoder_client_data))
return false;
......@@ -1846,6 +1920,7 @@ static FLAC__bool test_file_decoder()
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
if(!file_decoder_test_respond_(decoder, &decoder_client_data))
return false;
......@@ -1870,6 +1945,7 @@ static FLAC__bool test_file_decoder()
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
if(!file_decoder_test_respond_(decoder, &decoder_client_data))
return false;
......@@ -1898,6 +1974,7 @@ static FLAC__bool test_file_decoder()
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
if(!file_decoder_test_respond_(decoder, &decoder_client_data))
return false;
......@@ -2014,6 +2091,7 @@ static FLAC__bool test_file_decoder()
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
if(!file_decoder_test_respond_(decoder, &decoder_client_data))
return false;
......@@ -2051,6 +2129,7 @@ static FLAC__bool test_file_decoder()
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
printf("testing FLAC__file_decoder_delete()... ");
FLAC__file_decoder_delete(decoder);
......
......@@ -27,9 +27,9 @@
#include <stdlib.h>
#include <string.h>
static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_;
static FLAC__StreamMetadata *metadata_sequence_[] = { &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_ };
static const unsigned num_metadata_ = 5;
static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_;
static FLAC__StreamMetadata *metadata_sequence_[] = { &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_ };
static const unsigned num_metadata_ = 6;
static const char *flacfilename_ = "metadata.flac";
static FLAC__bool die_s_(const char *msg, const FLAC__StreamEncoder *encoder)
......@@ -161,7 +161,7 @@ static void init_metadata_blocks_()
memcpy(application2_.data.application.id, "\x76\x54\x32\x10", 4);
application2_.data.application.data = 0;
vorbiscomment_.is_last = true;
vorbiscomment_.is_last = false;
vorbiscomment_.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
vorbiscomment_.length = (4 + 8) + 4 + (4 + 5) + (4 + 0);
vorbiscomment_.data.vorbis_comment.vendor_string.length = 8;
......@@ -174,6 +174,60 @@ static void init_metadata_blocks_()
memcpy(vorbiscomment_.data.vorbis_comment.comments[0].entry, "ab=cd", 5);
vorbiscomment_.data.vorbis_comment.comments[1].length = 0;
vorbiscomment_.data.vorbis_comment.comments[1].entry = 0;
cuesheet_.is_last = true;
cuesheet_.type = FLAC__METADATA_TYPE_CUESHEET;
cuesheet_.length =
/* cuesheet guts */
(
FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
) / 8 +
/* 2 tracks */
2 * (
FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN +
FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN +
FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN +
FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN +
FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN +
FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN +
FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN
) / 8 +
/* 3 index points */
3 * (
FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN +
FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN +
FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN
) / 8
;
memset(cuesheet_.data.cue_sheet.media_catalog_number, 0, sizeof(cuesheet_.data.cue_sheet.media_catalog_number));
cuesheet_.data.cue_sheet.media_catalog_number[0] = 'j';
cuesheet_.data.cue_sheet.media_catalog_number[1] = 'C';
cuesheet_.data.cue_sheet.lead_in = 159;
cuesheet_.data.cue_sheet.num_tracks = 2;
cuesheet_.data.cue_sheet.tracks = malloc_or_die_(cuesheet_.data.cue_sheet.num_tracks * sizeof(FLAC__StreamMetadata_CueSheet_Track));
cuesheet_.data.cue_sheet.tracks[0].offset = 1;
cuesheet_.data.cue_sheet.tracks[0].number = 1;
memcpy(cuesheet_.data.cue_sheet.tracks[0].isrc, "ACBDE1234567", sizeof(cuesheet_.data.cue_sheet.tracks[0].isrc));
cuesheet_.data.cue_sheet.tracks[0].type = 0;
cuesheet_.data.cue_sheet.tracks[0].pre_emphasis = 1;
cuesheet_.data.cue_sheet.tracks[0].num_indices = 2;
cuesheet_.data.cue_sheet.tracks[0].indices = malloc_or_die_(cuesheet_.data.cue_sheet.tracks[0].num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index));
cuesheet_.data.cue_sheet.tracks[0].indices[0].offset = 0;
cuesheet_.data.cue_sheet.tracks[0].indices[0].number = 0;
cuesheet_.data.cue_sheet.tracks[0].indices[1].offset = 1234567890;
cuesheet_.data.cue_sheet.tracks[0].indices[1].number = 1;
cuesheet_.data.cue_sheet.tracks[1].offset = 12345678901;
cuesheet_.data.cue_sheet.tracks[1].number = 2;
memcpy(cuesheet_.data.cue_sheet.tracks[1].isrc, "ACBDE7654321", sizeof(cuesheet_.data.cue_sheet.tracks[1].isrc));
cuesheet_.data.cue_sheet.tracks[1].type = 1;
cuesheet_.data.cue_sheet.tracks[1].pre_emphasis = 0;
cuesheet_.data.cue_sheet.tracks[1].num_indices = 1;
cuesheet_.data.cue_sheet.tracks[1].indices = malloc_or_die_(cuesheet_.data.cue_sheet.tracks[1].num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index));
cuesheet_.data.cue_sheet.tracks[1].indices[0].offset = 0;
cuesheet_.data.cue_sheet.tracks[1].indices[0].number = 1;
}
static void free_metadata_blocks_()
......@@ -183,6 +237,9 @@ static void free_metadata_blocks_()
free(vorbiscomment_.data.vorbis_comment.vendor_string.entry);
free(vorbiscomment_.data.vorbis_comment.comments[0].entry);
free(vorbiscomment_.data.vorbis_comment.comments);
free(cuesheet_.data.cue_sheet.tracks[0].indices);
free(cuesheet_.data.cue_sheet.tracks[1].indices);
free(cuesheet_.data.cue_sheet.tracks);
}
static FLAC__StreamEncoderWriteStatus stream_encoder_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
......
......@@ -37,6 +37,56 @@ static FLAC__byte *make_dummydata_(FLAC__byte *dummydata, unsigned len)
return ret;
}
static FLAC__bool compare_track_(const FLAC__StreamMetadata_CueSheet_Track *from, const FLAC__StreamMetadata_CueSheet_Track *to)
{
unsigned i;
if(from->offset != to->offset) {
printf("FAILED, track offset mismatch, expected %llu, got %llu\n", to->offset, from->offset);
return false;
}
if(from->number != to->number) {
printf("FAILED, track number mismatch, expected %u, got %u\n", (unsigned)to->number, (unsigned)from->number);
return false;
}
if(0 != strcmp(from->isrc, to->isrc)) {
printf("FAILED, track number mismatch, expected %s, got %s\n", to->isrc, from->isrc);
return false;
}
if(from->type != to->type) {
printf("FAILED, track type mismatch, expected %u, got %u\n", (unsigned)to->type, (unsigned)from->type);
return false;
}
if(from->pre_emphasis != to->pre_emphasis) {
printf("FAILED, track pre_emphasis mismatch, expected %u, got %u\n", (unsigned)to->pre_emphasis, (unsigned)from->pre_emphasis);
return false;
}
if(from->num_indices != to->num_indices) {
printf("FAILED, track num_indices mismatch, expected %u, got %u\n", (unsigned)to->num_indices, (unsigned)from->num_indices);
return false;
}
if(0 == to->indices || 0 == from->indices) {
if(to->indices != from->indices) {
printf("FAILED, track indices mismatch\n");
return false;
}
}
else {
for(i = 0; i < to->num_indices; i++) {
if(from->indices[i].offset != to->indices[i].offset) {
printf("FAILED, track indices[%u].offset mismatch, expected %llu, got %llu\n", i, to->indices[i].offset, from->indices[i].offset);
return false;
}
if(from->indices[i].number != to->indices[i].number) {
printf("FAILED, track indices[%u].number mismatch, expected %u, got %u\n", i, (unsigned)to->indices[i].number, (unsigned)from->indices[i].number);
return false;
}
}
}
return true;
}
static FLAC__bool compare_seekpoint_array_(const FLAC__StreamMetadata_SeekPoint *from, const FLAC__StreamMetadata_SeekPoint *to, unsigned n)
{
unsigned i;
......@@ -213,6 +263,7 @@ static void cs_calc_len_(FLAC__StreamMetadata *block)
block->length = (
FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
) / 8;
block->length += cs->num_tracks * (
......@@ -233,6 +284,80 @@ static void cs_calc_len_(FLAC__StreamMetadata *block)
}
}
static void tr_resize_(FLAC__StreamMetadata *block, unsigned track_num, unsigned num)
{
FLAC__StreamMetadata_CueSheet_Track *tr;
FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
tr = &block->data.cue_sheet.tracks[track_num];
if(tr->num_indices != 0) {
FLAC__ASSERT(0 != tr->indices);
}
if(num == 0) {
if(0 != tr->indices) {
free(tr->indices);
tr->indices = 0;
}
}
else {
tr->indices = (FLAC__StreamMetadata_CueSheet_Index*)realloc(tr->indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)*num);
FLAC__ASSERT(0 != tr->indices);
if(num > tr->num_indices)
memset(tr->indices+tr->num_indices, 0, sizeof(FLAC__StreamMetadata_CueSheet_Index)*(num-tr->num_indices));
}
tr->num_indices = num;
cs_calc_len_(block);
}
static void tr_set_new_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos, FLAC__StreamMetadata_CueSheet_Index index)
{
FLAC__StreamMetadata_CueSheet_Track *tr;
FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
tr = &block->data.cue_sheet.tracks[track_num];
FLAC__ASSERT(pos < tr->num_indices);
tr->indices[pos] = index;
cs_calc_len_(block);
}
static void tr_insert_new_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos, FLAC__StreamMetadata_CueSheet_Index index)
{
FLAC__StreamMetadata_CueSheet_Track *tr;
FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
tr = &block->data.cue_sheet.tracks[track_num];
FLAC__ASSERT(pos <= tr->num_indices);
tr_resize_(block, track_num, tr->num_indices+1);
memmove(&tr->indices[pos+1], &tr->indices[pos], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(tr->num_indices-1-pos));
tr_set_new_(block, track_num, pos, index);
cs_calc_len_(block);
}
static void tr_delete_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos)
{
FLAC__StreamMetadata_CueSheet_Track *tr;
FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
tr = &block->data.cue_sheet.tracks[track_num];
FLAC__ASSERT(pos <= tr->num_indices);
memmove(&tr->indices[pos], &tr->indices[pos+1], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(tr->num_indices-pos-1));
tr_resize_(block, track_num, tr->num_indices-1);
cs_calc_len_(block);
}
static void cs_resize_(FLAC__StreamMetadata *block, unsigned num)
{
FLAC__StreamMetadata_CueSheet *cs = &block->data.cue_sheet;
......@@ -296,6 +421,7 @@ FLAC__bool test_metadata_object()
FLAC__StreamMetadata *block, *blockcopy, *vorbiscomment, *cuesheet;
FLAC__StreamMetadata_SeekPoint seekpoint_array[8];
FLAC__StreamMetadata_VorbisComment_Entry entry;
FLAC__StreamMetadata_CueSheet_Index index;
FLAC__StreamMetadata_CueSheet_Track track;
unsigned i, expected_length, seekpoints;
static FLAC__byte dummydata[4] = { 'a', 'b', 'c', 'd' };
......@@ -982,8 +1108,37 @@ FLAC__bool test_metadata_object()
printf("OK\n");
printf("testing CUESHEET\n");
{
FLAC__StreamMetadata_CueSheet_Track *track_, *trackcopy_;
printf("testing FLAC__metadata_object_cuesheet_track_new()... ");
track_ = FLAC__metadata_object_cuesheet_track_new();
if(0 == track_) {
printf("FAILED, returned NULL\n");
return false;
}
printf("OK\n");
printf("testing FLAC__metadata_object_cuesheet_track_clone()... ");
trackcopy_ = FLAC__metadata_object_cuesheet_track_clone(track_);
if(0 == trackcopy_) {
printf("FAILED, returned NULL\n");
return false;
}
if(!compare_track_(trackcopy_, track_))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_cuesheet_track_delete()... ");
FLAC__metadata_object_cuesheet_track_delete(trackcopy_);
FLAC__metadata_object_cuesheet_track_delete(track_);
printf("OK\n");
}
printf("testing FLAC__metadata_object_new()... ");
block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET);
if(0 == block) {
......@@ -993,6 +1148,7 @@ FLAC__bool test_metadata_object()
expected_length = (
FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
) / 8;
if(block->length != expected_length) {
......@@ -1043,7 +1199,7 @@ FLAC__bool test_metadata_object()
printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on empty array...");
cs_insert_new_(&track, cuesheet, 0, 0, 1, "ABCDE1234567", false, false);
if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, track, /*copy=*/true)) {
if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/true)) {
printf("FAILED, returned false\n");
return false;
}
......@@ -1053,7 +1209,7 @@ FLAC__bool test_metadata_object()
printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on beginning of non-empty array...");
cs_insert_new_(&track, cuesheet, 0, 10, 2, "BBCDE1234567", false, false);
if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, track, /*copy=*/true)) {
if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/true)) {
printf("FAILED, returned false\n");
return false;
}
......@@ -1063,7 +1219,7 @@ FLAC__bool test_metadata_object()
printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on middle of non-empty array...");
cs_insert_new_(&track, cuesheet, 1, 20, 3, "CBCDE1234567", false, false);
if(!FLAC__metadata_object_cuesheet_insert_track(block, 1, track, /*copy=*/true)) {
if(!FLAC__metadata_object_cuesheet_insert_track(block, 1, &track, /*copy=*/true)) {
printf("FAILED, returned false\n");
return false;
}
......@@ -1073,7 +1229,7 @@ FLAC__bool test_metadata_object()
printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on end of non-empty array...");
cs_insert_new_(&track, cuesheet, 3, 30, 4, "DBCDE1234567", false, false);
if(!FLAC__metadata_object_cuesheet_insert_track(block, 3, track, /*copy=*/true)) {
if(!FLAC__metadata_object_cuesheet_insert_track(block, 3, &track, /*copy=*/true)) {
printf("FAILED, returned false\n");
return false;
}
......@@ -1127,12 +1283,132 @@ FLAC__bool test_metadata_object()
printf("testing FLAC__metadata_object_cuesheet_set_track(copy)...");
cs_set_new_(&track, cuesheet, 0, 40, 5, "EBCDE1234567", false, false);
FLAC__metadata_object_cuesheet_set_track(block, 0, track, /*copy=*/true);
FLAC__metadata_object_cuesheet_set_track(block, 0, &track, /*copy=*/true);
if(!compare_block_(cuesheet, block))
return false;
printf("OK\n");
/*@@@@ track index function tests here*/
tr_resize_(cuesheet, 0, 2);
printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(grow to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices);
if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) {
printf("FAILED, returned false\n");
return false;
}
if(!compare_block_(cuesheet, block))
return false;
printf("OK\n");
tr_resize_(cuesheet, 0, 1);
printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(shrink to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices);