additions to metadata object api: more vorbiscomment functions, trailing-null on vorbis comment field values enforced everywhere

This commit is contained in:
Josh Coalson
2004-12-30 00:59:30 +00:00
parent 8ddf7fb278
commit def597ee59
20 changed files with 984 additions and 122 deletions

View File

@@ -120,16 +120,16 @@ static void init_metadata_blocks_()
vorbiscomment_.type = ::FLAC__METADATA_TYPE_VORBIS_COMMENT;
vorbiscomment_.length = (4 + 5) + 4 + (4 + 12) + (4 + 12);
vorbiscomment_.data.vorbis_comment.vendor_string.length = 5;
vorbiscomment_.data.vorbis_comment.vendor_string.entry = (FLAC__byte*)malloc_or_die_(5);
memcpy(vorbiscomment_.data.vorbis_comment.vendor_string.entry, "name0", 5);
vorbiscomment_.data.vorbis_comment.vendor_string.entry = (FLAC__byte*)malloc_or_die_(5+1);
memcpy(vorbiscomment_.data.vorbis_comment.vendor_string.entry, "name0", 5+1);
vorbiscomment_.data.vorbis_comment.num_comments = 2;
vorbiscomment_.data.vorbis_comment.comments = (::FLAC__StreamMetadata_VorbisComment_Entry*)malloc_or_die_(vorbiscomment_.data.vorbis_comment.num_comments * sizeof(::FLAC__StreamMetadata_VorbisComment_Entry));
vorbiscomment_.data.vorbis_comment.comments[0].length = 12;
vorbiscomment_.data.vorbis_comment.comments[0].entry = (FLAC__byte*)malloc_or_die_(12);
memcpy(vorbiscomment_.data.vorbis_comment.comments[0].entry, "name2=value2", 12);
vorbiscomment_.data.vorbis_comment.comments[0].entry = (FLAC__byte*)malloc_or_die_(12+1);
memcpy(vorbiscomment_.data.vorbis_comment.comments[0].entry, "name2=value2", 12+1);
vorbiscomment_.data.vorbis_comment.comments[1].length = 12;
vorbiscomment_.data.vorbis_comment.comments[1].entry = (FLAC__byte*)malloc_or_die_(12);
memcpy(vorbiscomment_.data.vorbis_comment.comments[1].entry, "name3=value3", 12);
vorbiscomment_.data.vorbis_comment.comments[1].entry = (FLAC__byte*)malloc_or_die_(12+1);
memcpy(vorbiscomment_.data.vorbis_comment.comments[1].entry, "name3=value3", 12+1);
cuesheet_.is_last = true;
cuesheet_.type = ::FLAC__METADATA_TYPE_CUESHEET;
@@ -795,12 +795,32 @@ bool test_metadata_object_vorbiscomment()
return die_("!is_valid()");
printf("OK\n");
{
printf("testing Entry::Entry(const char *field)... ");
FLAC::Metadata::VorbisComment::Entry entry2z("name2=value2");
if(!entry2z.is_valid())
return die_("!is_valid()");
if(strcmp(entry2.get_field(), entry2z.get_field()))
return die_("bad value");
printf("OK\n");
}
printf("testing Entry::Entry(const char *field_name, const char *field_value, unsigned field_value_length)... ");
FLAC::Metadata::VorbisComment::Entry entry3("name3", "value3", strlen("value3"));
if(!entry3.is_valid())
return die_("!is_valid()");
printf("OK\n");
{
printf("testing Entry::Entry(const char *field_name, const char *field_value)... ");
FLAC::Metadata::VorbisComment::Entry entry3z("name3", "value3");
if(!entry3z.is_valid())
return die_("!is_valid()");
if(strcmp(entry3.get_field(), entry3z.get_field()))
return die_("bad value");
printf("OK\n");
}
printf("testing Entry::Entry(const Entry &entry)... ");
{
FLAC::Metadata::VorbisComment::Entry entry2copy(entry2);
@@ -867,7 +887,7 @@ bool test_metadata_object_vorbiscomment()
return die_("entry mismatch");
printf("OK\n");
printf("testing Entry::set_field_value()... ");
printf("testing Entry::set_field_value(const char *field_value, unsigned field_value_length)... ");
if(!entry1.set_field_value("value1", strlen("value1")))
return die_("returned false");
if(0 != memcmp(entry1.get_field_value(), "value1", strlen("value1")))
@@ -876,7 +896,16 @@ bool test_metadata_object_vorbiscomment()
return die_("entry mismatch");
printf("OK\n");
printf("testing Entry::set_field()... ");
printf("testing Entry::set_field_value(const char *field_value)... ");
if(!entry1.set_field_value("value1"))
return die_("returned false");
if(0 != memcmp(entry1.get_field_value(), "value1", strlen("value1")))
return die_("value mismatch");
if(0 != memcmp(entry1.get_field(), "name1=value1", strlen("name1=value1")))
return die_("entry mismatch");
printf("OK\n");
printf("testing Entry::set_field(const char *field, unsigned field_length)... ");
if(!entry1.set_field("name0=value0", strlen("name0=value0")))
return die_("returned false");
if(0 != memcmp(entry1.get_field_name(), "name0", strlen("name0")))
@@ -887,6 +916,17 @@ bool test_metadata_object_vorbiscomment()
return die_("entry mismatch");
printf("OK\n");
printf("testing Entry::set_field(const char *field)... ");
if(!entry1.set_field("name0=value0"))
return die_("returned false");
if(0 != memcmp(entry1.get_field_name(), "name0", strlen("name0")))
return die_("value mismatch");
if(0 != memcmp(entry1.get_field_value(), "value0", strlen("value0")))
return die_("value mismatch");
if(0 != memcmp(entry1.get_field(), "name0=value0", strlen("name0=value0")))
return die_("entry mismatch");
printf("OK\n");
printf("PASSED\n\n");
@@ -989,6 +1029,44 @@ bool test_metadata_object_vorbiscomment()
return die_("value mismatch");
printf("OK\n");
printf("testing VorbisComment::append_comment()... +\n");
printf(" VorbisComment::get_comment()... ");
if(!block.append_comment(entry3))
return die_("returned false");
if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[1].length)
return die_("length mismatch");
if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[1].entry, vorbiscomment_.data.vorbis_comment.comments[1].length))
return die_("value mismatch");
printf("OK\n");
printf("testing VorbisComment::append_comment()... +\n");
printf(" VorbisComment::get_comment()... ");
if(!block.append_comment(entry2))
return die_("returned false");
if(block.get_comment(1).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[0].length)
return die_("length mismatch");
if(0 != memcmp(block.get_comment(1).get_field(), vorbiscomment_.data.vorbis_comment.comments[0].entry, vorbiscomment_.data.vorbis_comment.comments[0].length))
return die_("value mismatch");
printf("OK\n");
printf("testing VorbisComment::delete_comment()... +\n");
printf(" VorbisComment::get_comment()... ");
if(!block.delete_comment(0))
return die_("returned false");
if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[0].length)
return die_("length[0] mismatch");
if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[0].entry, vorbiscomment_.data.vorbis_comment.comments[0].length))
return die_("value[0] mismatch");
printf("OK\n");
printf("testing VorbisComment::delete_comment()... +\n");
printf(" VorbisComment::get_comment()... ");
if(!block.delete_comment(0))
return die_("returned false");
if(block.get_num_comments() != 0)
return die_("block mismatch, expected num_comments = 0");
printf("OK\n");
printf("testing VorbisComment::insert_comment()... +\n");
printf(" VorbisComment::get_comment()... ");
if(!block.insert_comment(0, entry3))