1 /* test_libFLAC - Unit tester for libFLAC
2 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008 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.
23 #include "FLAC/assert.h"
24 #include "FLAC/metadata.h"
25 #include "test_libs_common/metadata_utils.h"
28 #include <stdlib.h> /* for malloc() */
29 #include <string.h> /* for memcmp() */
31 static FLAC__byte *make_dummydata_(FLAC__byte *dummydata, unsigned len)
35 if(0 == (ret = (FLAC__byte*)malloc(len))) {
36 printf("FAILED, malloc error\n");
40 memcpy(ret, dummydata, len);
45 static FLAC__bool compare_track_(const FLAC__StreamMetadata_CueSheet_Track *from, const FLAC__StreamMetadata_CueSheet_Track *to)
49 if(from->offset != to->offset) {
51 printf("FAILED, track offset mismatch, expected %I64u, got %I64u\n", to->offset, from->offset);
53 printf("FAILED, track offset mismatch, expected %llu, got %llu\n", (unsigned long long)to->offset, (unsigned long long)from->offset);
57 if(from->number != to->number) {
58 printf("FAILED, track number mismatch, expected %u, got %u\n", (unsigned)to->number, (unsigned)from->number);
61 if(0 != strcmp(from->isrc, to->isrc)) {
62 printf("FAILED, track number mismatch, expected %s, got %s\n", to->isrc, from->isrc);
65 if(from->type != to->type) {
66 printf("FAILED, track type mismatch, expected %u, got %u\n", (unsigned)to->type, (unsigned)from->type);
69 if(from->pre_emphasis != to->pre_emphasis) {
70 printf("FAILED, track pre_emphasis mismatch, expected %u, got %u\n", (unsigned)to->pre_emphasis, (unsigned)from->pre_emphasis);
73 if(from->num_indices != to->num_indices) {
74 printf("FAILED, track num_indices mismatch, expected %u, got %u\n", (unsigned)to->num_indices, (unsigned)from->num_indices);
77 if(0 == to->indices || 0 == from->indices) {
78 if(to->indices != from->indices) {
79 printf("FAILED, track indices mismatch\n");
84 for(i = 0; i < to->num_indices; i++) {
85 if(from->indices[i].offset != to->indices[i].offset) {
87 printf("FAILED, track indices[%u].offset mismatch, expected %I64u, got %I64u\n", i, to->indices[i].offset, from->indices[i].offset);
89 printf("FAILED, track indices[%u].offset mismatch, expected %llu, got %llu\n", i, (unsigned long long)to->indices[i].offset, (unsigned long long)from->indices[i].offset);
93 if(from->indices[i].number != to->indices[i].number) {
94 printf("FAILED, track indices[%u].number mismatch, expected %u, got %u\n", i, (unsigned)to->indices[i].number, (unsigned)from->indices[i].number);
103 static FLAC__bool compare_seekpoint_array_(const FLAC__StreamMetadata_SeekPoint *from, const FLAC__StreamMetadata_SeekPoint *to, unsigned n)
107 FLAC__ASSERT(0 != from);
108 FLAC__ASSERT(0 != to);
110 for(i = 0; i < n; i++) {
111 if(from[i].sample_number != to[i].sample_number) {
113 printf("FAILED, point[%u].sample_number mismatch, expected %I64u, got %I64u\n", i, to[i].sample_number, from[i].sample_number);
115 printf("FAILED, point[%u].sample_number mismatch, expected %llu, got %llu\n", i, (unsigned long long)to[i].sample_number, (unsigned long long)from[i].sample_number);
119 if(from[i].stream_offset != to[i].stream_offset) {
121 printf("FAILED, point[%u].stream_offset mismatch, expected %I64u, got %I64u\n", i, to[i].stream_offset, from[i].stream_offset);
123 printf("FAILED, point[%u].stream_offset mismatch, expected %llu, got %llu\n", i, (unsigned long long)to[i].stream_offset, (unsigned long long)from[i].stream_offset);
127 if(from[i].frame_samples != to[i].frame_samples) {
128 printf("FAILED, point[%u].frame_samples mismatch, expected %u, got %u\n", i, to[i].frame_samples, from[i].frame_samples);
136 static FLAC__bool check_seektable_(const FLAC__StreamMetadata *block, unsigned num_points, const FLAC__StreamMetadata_SeekPoint *array)
138 const unsigned expected_length = num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
140 if(block->length != expected_length) {
141 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
144 if(block->data.seek_table.num_points != num_points) {
145 printf("FAILED, expected %u point, got %u\n", num_points, block->data.seek_table.num_points);
149 if(0 != block->data.seek_table.points) {
150 printf("FAILED, 'points' pointer is not null\n");
155 if(!compare_seekpoint_array_(block->data.seek_table.points, array, num_points))
163 static void entry_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, const char *field)
165 entry->length = strlen(field);
166 entry->entry = (FLAC__byte*)malloc(entry->length+1);
167 FLAC__ASSERT(0 != entry->entry);
168 memcpy(entry->entry, field, entry->length);
169 entry->entry[entry->length] = '\0';
172 static void entry_clone_(FLAC__StreamMetadata_VorbisComment_Entry *entry)
174 FLAC__byte *x = (FLAC__byte*)malloc(entry->length+1);
175 FLAC__ASSERT(0 != x);
176 memcpy(x, entry->entry, entry->length);
177 x[entry->length] = '\0';
181 static void vc_calc_len_(FLAC__StreamMetadata *block)
183 const FLAC__StreamMetadata_VorbisComment *vc = &block->data.vorbis_comment;
186 block->length = FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
187 block->length += vc->vendor_string.length;
188 block->length += FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8;
189 for(i = 0; i < vc->num_comments; i++) {
190 block->length += FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
191 block->length += vc->comments[i].length;
195 static void vc_resize_(FLAC__StreamMetadata *block, unsigned num)
197 FLAC__StreamMetadata_VorbisComment *vc = &block->data.vorbis_comment;
199 if(vc->num_comments != 0) {
200 FLAC__ASSERT(0 != vc->comments);
201 if(num < vc->num_comments) {
203 for(i = num; i < vc->num_comments; i++) {
204 if(0 != vc->comments[i].entry)
205 free(vc->comments[i].entry);
210 if(0 != vc->comments) {
216 vc->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)realloc(vc->comments, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*num);
217 FLAC__ASSERT(0 != vc->comments);
218 if(num > vc->num_comments)
219 memset(vc->comments+vc->num_comments, 0, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(num-vc->num_comments));
222 vc->num_comments = num;
226 static int vc_find_from_(FLAC__StreamMetadata *block, const char *name, unsigned start)
228 const unsigned n = strlen(name);
230 for(i = start; i < block->data.vorbis_comment.num_comments; i++) {
231 const FLAC__StreamMetadata_VorbisComment_Entry *entry = &block->data.vorbis_comment.comments[i];
232 if(entry->length > n && 0 == strncmp((const char *)entry->entry, name, n) && entry->entry[n] == '=')
238 static void vc_set_vs_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, const char *field)
240 if(0 != block->data.vorbis_comment.vendor_string.entry)
241 free(block->data.vorbis_comment.vendor_string.entry);
242 entry_new_(entry, field);
243 block->data.vorbis_comment.vendor_string = *entry;
247 static void vc_set_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, unsigned pos, const char *field)
249 if(0 != block->data.vorbis_comment.comments[pos].entry)
250 free(block->data.vorbis_comment.comments[pos].entry);
251 entry_new_(entry, field);
252 block->data.vorbis_comment.comments[pos] = *entry;
256 static void vc_insert_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, unsigned pos, const char *field)
258 vc_resize_(block, block->data.vorbis_comment.num_comments+1);
259 memmove(&block->data.vorbis_comment.comments[pos+1], &block->data.vorbis_comment.comments[pos], sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(block->data.vorbis_comment.num_comments-1-pos));
260 memset(&block->data.vorbis_comment.comments[pos], 0, sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
261 vc_set_new_(entry, block, pos, field);
265 static void vc_delete_(FLAC__StreamMetadata *block, unsigned pos)
267 if(0 != block->data.vorbis_comment.comments[pos].entry)
268 free(block->data.vorbis_comment.comments[pos].entry);
269 memmove(&block->data.vorbis_comment.comments[pos], &block->data.vorbis_comment.comments[pos+1], sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(block->data.vorbis_comment.num_comments-pos-1));
270 block->data.vorbis_comment.comments[block->data.vorbis_comment.num_comments-1].entry = 0;
271 block->data.vorbis_comment.comments[block->data.vorbis_comment.num_comments-1].length = 0;
272 vc_resize_(block, block->data.vorbis_comment.num_comments-1);
276 static void vc_replace_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, const char *field, FLAC__bool all)
279 char field_name[256];
280 const char *eq = strchr(field, '=');
281 FLAC__ASSERT(eq>field && (unsigned)(eq-field) < sizeof(field_name));
282 memcpy(field_name, field, eq-field);
283 field_name[eq-field]='\0';
285 index = vc_find_from_(block, field_name, 0);
287 vc_insert_new_(entry, block, block->data.vorbis_comment.num_comments, field);
289 vc_set_new_(entry, block, (unsigned)index, field);
291 for(index = index+1; index >= 0 && (unsigned)index < block->data.vorbis_comment.num_comments; )
292 if((index = vc_find_from_(block, field_name, (unsigned)index)) >= 0)
293 vc_delete_(block, (unsigned)index);
300 static void track_new_(FLAC__StreamMetadata_CueSheet_Track *track, FLAC__uint64 offset, FLAC__byte number, const char *isrc, FLAC__bool data, FLAC__bool pre_em)
302 track->offset = offset;
303 track->number = number;
304 memcpy(track->isrc, isrc, sizeof(track->isrc));
306 track->pre_emphasis = pre_em;
307 track->num_indices = 0;
311 static void track_clone_(FLAC__StreamMetadata_CueSheet_Track *track)
313 if(track->num_indices > 0) {
314 size_t bytes = sizeof(FLAC__StreamMetadata_CueSheet_Index) * track->num_indices;
315 FLAC__StreamMetadata_CueSheet_Index *x = (FLAC__StreamMetadata_CueSheet_Index*)malloc(bytes);
316 FLAC__ASSERT(0 != x);
317 memcpy(x, track->indices, bytes);
322 static void cs_calc_len_(FLAC__StreamMetadata *block)
324 const FLAC__StreamMetadata_CueSheet *cs = &block->data.cue_sheet;
328 FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
329 FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
330 FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN +
331 FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
332 FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
334 block->length += cs->num_tracks * (
335 FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN +
336 FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN +
337 FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN +
338 FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN +
339 FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN +
340 FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN +
341 FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN
343 for(i = 0; i < cs->num_tracks; i++) {
344 block->length += cs->tracks[i].num_indices * (
345 FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN +
346 FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN +
347 FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN
352 static void tr_resize_(FLAC__StreamMetadata *block, unsigned track_num, unsigned num)
354 FLAC__StreamMetadata_CueSheet_Track *tr;
356 FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
358 tr = &block->data.cue_sheet.tracks[track_num];
360 if(tr->num_indices != 0) {
361 FLAC__ASSERT(0 != tr->indices);
364 if(0 != tr->indices) {
370 tr->indices = (FLAC__StreamMetadata_CueSheet_Index*)realloc(tr->indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)*num);
371 FLAC__ASSERT(0 != tr->indices);
372 if(num > tr->num_indices)
373 memset(tr->indices+tr->num_indices, 0, sizeof(FLAC__StreamMetadata_CueSheet_Index)*(num-tr->num_indices));
376 tr->num_indices = num;
380 static void tr_set_new_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos, FLAC__StreamMetadata_CueSheet_Index index)
382 FLAC__StreamMetadata_CueSheet_Track *tr;
384 FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
386 tr = &block->data.cue_sheet.tracks[track_num];
388 FLAC__ASSERT(pos < tr->num_indices);
390 tr->indices[pos] = index;
395 static void tr_insert_new_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos, FLAC__StreamMetadata_CueSheet_Index index)
397 FLAC__StreamMetadata_CueSheet_Track *tr;
399 FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
401 tr = &block->data.cue_sheet.tracks[track_num];
403 FLAC__ASSERT(pos <= tr->num_indices);
405 tr_resize_(block, track_num, tr->num_indices+1);
406 memmove(&tr->indices[pos+1], &tr->indices[pos], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(tr->num_indices-1-pos));
407 tr_set_new_(block, track_num, pos, index);
411 static void tr_delete_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos)
413 FLAC__StreamMetadata_CueSheet_Track *tr;
415 FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
417 tr = &block->data.cue_sheet.tracks[track_num];
419 FLAC__ASSERT(pos <= tr->num_indices);
421 memmove(&tr->indices[pos], &tr->indices[pos+1], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(tr->num_indices-pos-1));
422 tr_resize_(block, track_num, tr->num_indices-1);
426 static void cs_resize_(FLAC__StreamMetadata *block, unsigned num)
428 FLAC__StreamMetadata_CueSheet *cs = &block->data.cue_sheet;
430 if(cs->num_tracks != 0) {
431 FLAC__ASSERT(0 != cs->tracks);
432 if(num < cs->num_tracks) {
434 for(i = num; i < cs->num_tracks; i++) {
435 if(0 != cs->tracks[i].indices)
436 free(cs->tracks[i].indices);
441 if(0 != cs->tracks) {
447 cs->tracks = (FLAC__StreamMetadata_CueSheet_Track*)realloc(cs->tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)*num);
448 FLAC__ASSERT(0 != cs->tracks);
449 if(num > cs->num_tracks)
450 memset(cs->tracks+cs->num_tracks, 0, sizeof(FLAC__StreamMetadata_CueSheet_Track)*(num-cs->num_tracks));
453 cs->num_tracks = num;
457 static void cs_set_new_(FLAC__StreamMetadata_CueSheet_Track *track, FLAC__StreamMetadata *block, unsigned pos, FLAC__uint64 offset, FLAC__byte number, const char *isrc, FLAC__bool data, FLAC__bool pre_em)
459 track_new_(track, offset, number, isrc, data, pre_em);
460 block->data.cue_sheet.tracks[pos] = *track;
464 static void cs_insert_new_(FLAC__StreamMetadata_CueSheet_Track *track, FLAC__StreamMetadata *block, unsigned pos, FLAC__uint64 offset, FLAC__byte number, const char *isrc, FLAC__bool data, FLAC__bool pre_em)
466 cs_resize_(block, block->data.cue_sheet.num_tracks+1);
467 memmove(&block->data.cue_sheet.tracks[pos+1], &block->data.cue_sheet.tracks[pos], sizeof(FLAC__StreamMetadata_CueSheet_Track)*(block->data.cue_sheet.num_tracks-1-pos));
468 cs_set_new_(track, block, pos, offset, number, isrc, data, pre_em);
472 static void cs_delete_(FLAC__StreamMetadata *block, unsigned pos)
474 if(0 != block->data.cue_sheet.tracks[pos].indices)
475 free(block->data.cue_sheet.tracks[pos].indices);
476 memmove(&block->data.cue_sheet.tracks[pos], &block->data.cue_sheet.tracks[pos+1], sizeof(FLAC__StreamMetadata_CueSheet_Track)*(block->data.cue_sheet.num_tracks-pos-1));
477 block->data.cue_sheet.tracks[block->data.cue_sheet.num_tracks-1].indices = 0;
478 block->data.cue_sheet.tracks[block->data.cue_sheet.num_tracks-1].num_indices = 0;
479 cs_resize_(block, block->data.cue_sheet.num_tracks-1);
483 static void pi_set_mime_type(FLAC__StreamMetadata *block, const char *s)
485 if(block->data.picture.mime_type) {
486 block->length -= strlen(block->data.picture.mime_type);
487 free(block->data.picture.mime_type);
489 block->data.picture.mime_type = strdup(s);
490 FLAC__ASSERT(block->data.picture.mime_type);
491 block->length += strlen(block->data.picture.mime_type);
494 static void pi_set_description(FLAC__StreamMetadata *block, const FLAC__byte *s)
496 if(block->data.picture.description) {
497 block->length -= strlen((const char *)block->data.picture.description);
498 free(block->data.picture.description);
500 block->data.picture.description = (FLAC__byte*)strdup((const char *)s);
501 FLAC__ASSERT(block->data.picture.description);
502 block->length += strlen((const char *)block->data.picture.description);
505 static void pi_set_data(FLAC__StreamMetadata *block, const FLAC__byte *data, FLAC__uint32 len)
507 if(block->data.picture.data) {
508 block->length -= block->data.picture.data_length;
509 free(block->data.picture.data);
511 block->data.picture.data = (FLAC__byte*)strdup((const char *)data);
512 FLAC__ASSERT(block->data.picture.data);
513 block->data.picture.data_length = len;
514 block->length += len;
517 FLAC__bool test_metadata_object(void)
519 FLAC__StreamMetadata *block, *blockcopy, *vorbiscomment, *cuesheet, *picture;
520 FLAC__StreamMetadata_SeekPoint seekpoint_array[14];
521 FLAC__StreamMetadata_VorbisComment_Entry entry;
522 FLAC__StreamMetadata_CueSheet_Index index;
523 FLAC__StreamMetadata_CueSheet_Track track;
524 unsigned i, expected_length, seekpoints;
526 static FLAC__byte dummydata[4] = { 'a', 'b', 'c', 'd' };
528 printf("\n+++ libFLAC unit test: metadata objects\n\n");
531 printf("testing STREAMINFO\n");
533 printf("testing FLAC__metadata_object_new()... ");
534 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_STREAMINFO);
536 printf("FAILED, returned NULL\n");
539 expected_length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
540 if(block->length != expected_length) {
541 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
546 printf("testing FLAC__metadata_object_clone()... ");
547 blockcopy = FLAC__metadata_object_clone(block);
549 printf("FAILED, returned NULL\n");
552 if(!mutils__compare_block(block, blockcopy))
556 printf("testing FLAC__metadata_object_delete()... ");
557 FLAC__metadata_object_delete(blockcopy);
558 FLAC__metadata_object_delete(block);
562 printf("testing PADDING\n");
564 printf("testing FLAC__metadata_object_new()... ");
565 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING);
567 printf("FAILED, returned NULL\n");
571 if(block->length != expected_length) {
572 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
577 printf("testing FLAC__metadata_object_clone()... ");
578 blockcopy = FLAC__metadata_object_clone(block);
580 printf("FAILED, returned NULL\n");
583 if(!mutils__compare_block(block, blockcopy))
587 printf("testing FLAC__metadata_object_delete()... ");
588 FLAC__metadata_object_delete(blockcopy);
589 FLAC__metadata_object_delete(block);
593 printf("testing APPLICATION\n");
595 printf("testing FLAC__metadata_object_new()... ");
596 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION);
598 printf("FAILED, returned NULL\n");
601 expected_length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
602 if(block->length != expected_length) {
603 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
608 printf("testing FLAC__metadata_object_clone()... ");
609 blockcopy = FLAC__metadata_object_clone(block);
611 printf("FAILED, returned NULL\n");
614 if(!mutils__compare_block(block, blockcopy))
618 printf("testing FLAC__metadata_object_delete()... ");
619 FLAC__metadata_object_delete(blockcopy);
622 printf("testing FLAC__metadata_object_application_set_data(copy)... ");
623 if(!FLAC__metadata_object_application_set_data(block, dummydata, sizeof(dummydata), true/*copy*/)) {
624 printf("FAILED, returned false\n");
627 expected_length = (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) + sizeof(dummydata);
628 if(block->length != expected_length) {
629 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
632 if(0 != memcmp(block->data.application.data, dummydata, sizeof(dummydata))) {
633 printf("FAILED, data mismatch\n");
638 printf("testing FLAC__metadata_object_clone()... ");
639 blockcopy = FLAC__metadata_object_clone(block);
641 printf("FAILED, returned NULL\n");
644 if(!mutils__compare_block(block, blockcopy))
648 printf("testing FLAC__metadata_object_delete()... ");
649 FLAC__metadata_object_delete(blockcopy);
652 printf("testing FLAC__metadata_object_application_set_data(own)... ");
653 if(!FLAC__metadata_object_application_set_data(block, make_dummydata_(dummydata, sizeof(dummydata)), sizeof(dummydata), false/*own*/)) {
654 printf("FAILED, returned false\n");
657 expected_length = (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) + sizeof(dummydata);
658 if(block->length != expected_length) {
659 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
662 if(0 != memcmp(block->data.application.data, dummydata, sizeof(dummydata))) {
663 printf("FAILED, data mismatch\n");
668 printf("testing FLAC__metadata_object_clone()... ");
669 blockcopy = FLAC__metadata_object_clone(block);
671 printf("FAILED, returned NULL\n");
674 if(!mutils__compare_block(block, blockcopy))
678 printf("testing FLAC__metadata_object_delete()... ");
679 FLAC__metadata_object_delete(blockcopy);
680 FLAC__metadata_object_delete(block);
684 printf("testing SEEKTABLE\n");
686 for(i = 0; i < sizeof(seekpoint_array) / sizeof(FLAC__StreamMetadata_SeekPoint); i++) {
687 seekpoint_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
688 seekpoint_array[i].stream_offset = 0;
689 seekpoint_array[i].frame_samples = 0;
693 printf("testing FLAC__metadata_object_new()... ");
694 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE);
696 printf("FAILED, returned NULL\n");
699 if(!check_seektable_(block, seekpoints, 0))
702 printf("testing FLAC__metadata_object_clone()... ");
703 blockcopy = FLAC__metadata_object_clone(block);
705 printf("FAILED, returned NULL\n");
708 if(!mutils__compare_block(block, blockcopy))
712 printf("testing FLAC__metadata_object_delete()... ");
713 FLAC__metadata_object_delete(blockcopy);
717 printf("testing FLAC__metadata_object_seektable_resize_points(grow to %u)...", seekpoints);
718 if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
719 printf("FAILED, returned false\n");
722 if(!check_seektable_(block, seekpoints, seekpoint_array))
726 printf("testing FLAC__metadata_object_seektable_resize_points(shrink to %u)...", seekpoints);
727 if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
728 printf("FAILED, returned false\n");
731 if(!check_seektable_(block, seekpoints, seekpoint_array))
734 printf("testing FLAC__metadata_object_seektable_is_legal()...");
735 if(!FLAC__metadata_object_seektable_is_legal(block)) {
736 printf("FAILED, returned false\n");
742 printf("testing FLAC__metadata_object_seektable_resize_points(shrink to %u)...", seekpoints);
743 if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
744 printf("FAILED, returned false\n");
747 if(!check_seektable_(block, seekpoints, 0))
751 printf("testing FLAC__metadata_object_seektable_insert_point() on empty array...");
752 if(!FLAC__metadata_object_seektable_insert_point(block, 0, seekpoint_array[0])) {
753 printf("FAILED, returned false\n");
756 if(!check_seektable_(block, seekpoints, seekpoint_array))
759 seekpoint_array[0].sample_number = 1;
761 printf("testing FLAC__metadata_object_seektable_insert_point() on beginning of non-empty array...");
762 if(!FLAC__metadata_object_seektable_insert_point(block, 0, seekpoint_array[0])) {
763 printf("FAILED, returned false\n");
766 if(!check_seektable_(block, seekpoints, seekpoint_array))
769 seekpoint_array[1].sample_number = 2;
771 printf("testing FLAC__metadata_object_seektable_insert_point() on middle of non-empty array...");
772 if(!FLAC__metadata_object_seektable_insert_point(block, 1, seekpoint_array[1])) {
773 printf("FAILED, returned false\n");
776 if(!check_seektable_(block, seekpoints, seekpoint_array))
779 seekpoint_array[3].sample_number = 3;
781 printf("testing FLAC__metadata_object_seektable_insert_point() on end of non-empty array...");
782 if(!FLAC__metadata_object_seektable_insert_point(block, 3, seekpoint_array[3])) {
783 printf("FAILED, returned false\n");
786 if(!check_seektable_(block, seekpoints, seekpoint_array))
789 printf("testing FLAC__metadata_object_clone()... ");
790 blockcopy = FLAC__metadata_object_clone(block);
792 printf("FAILED, returned NULL\n");
795 if(!mutils__compare_block(block, blockcopy))
799 printf("testing FLAC__metadata_object_delete()... ");
800 FLAC__metadata_object_delete(blockcopy);
803 seekpoint_array[2].sample_number = seekpoint_array[3].sample_number;
805 printf("testing FLAC__metadata_object_seektable_delete_point() on middle of array...");
806 if(!FLAC__metadata_object_seektable_delete_point(block, 2)) {
807 printf("FAILED, returned false\n");
810 if(!check_seektable_(block, seekpoints, seekpoint_array))
814 printf("testing FLAC__metadata_object_seektable_delete_point() on end of array...");
815 if(!FLAC__metadata_object_seektable_delete_point(block, 2)) {
816 printf("FAILED, returned false\n");
819 if(!check_seektable_(block, seekpoints, seekpoint_array))
823 printf("testing FLAC__metadata_object_seektable_delete_point() on beginning of array...");
824 if(!FLAC__metadata_object_seektable_delete_point(block, 0)) {
825 printf("FAILED, returned false\n");
828 if(!check_seektable_(block, seekpoints, seekpoint_array+1))
831 printf("testing FLAC__metadata_object_seektable_set_point()...");
832 FLAC__metadata_object_seektable_set_point(block, 0, seekpoint_array[0]);
833 if(!check_seektable_(block, seekpoints, seekpoint_array))
836 printf("testing FLAC__metadata_object_delete()... ");
837 FLAC__metadata_object_delete(block);
840 /* seektable template functions */
842 for(i = 0; i < sizeof(seekpoint_array) / sizeof(FLAC__StreamMetadata_SeekPoint); i++) {
843 seekpoint_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
844 seekpoint_array[i].stream_offset = 0;
845 seekpoint_array[i].frame_samples = 0;
849 printf("testing FLAC__metadata_object_new()... ");
850 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE);
852 printf("FAILED, returned NULL\n");
855 if(!check_seektable_(block, seekpoints, 0))
859 printf("testing FLAC__metadata_object_seekpoint_template_append_placeholders()... ");
860 if(!FLAC__metadata_object_seektable_template_append_placeholders(block, 2)) {
861 printf("FAILED, returned false\n");
864 if(!check_seektable_(block, seekpoints, seekpoint_array))
867 seekpoint_array[seekpoints++].sample_number = 7;
868 printf("testing FLAC__metadata_object_seekpoint_template_append_point()... ");
869 if(!FLAC__metadata_object_seektable_template_append_point(block, 7)) {
870 printf("FAILED, returned false\n");
873 if(!check_seektable_(block, seekpoints, seekpoint_array))
877 FLAC__uint64 nums[2] = { 3, 7 };
878 seekpoint_array[seekpoints++].sample_number = nums[0];
879 seekpoint_array[seekpoints++].sample_number = nums[1];
880 printf("testing FLAC__metadata_object_seekpoint_template_append_points()... ");
881 if(!FLAC__metadata_object_seektable_template_append_points(block, nums, sizeof(nums)/sizeof(FLAC__uint64))) {
882 printf("FAILED, returned false\n");
885 if(!check_seektable_(block, seekpoints, seekpoint_array))
889 seekpoint_array[seekpoints++].sample_number = 0;
890 seekpoint_array[seekpoints++].sample_number = 10;
891 seekpoint_array[seekpoints++].sample_number = 20;
892 printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points()... ");
893 if(!FLAC__metadata_object_seektable_template_append_spaced_points(block, 3, 30)) {
894 printf("FAILED, returned false\n");
897 if(!check_seektable_(block, seekpoints, seekpoint_array))
901 seekpoint_array[0].sample_number = 0;
902 seekpoint_array[1].sample_number = 3;
903 seekpoint_array[2].sample_number = 7;
904 seekpoint_array[3].sample_number = 10;
905 seekpoint_array[4].sample_number = 20;
906 seekpoint_array[5].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
907 seekpoint_array[6].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
908 printf("testing FLAC__metadata_object_seekpoint_template_sort(compact=true)... ");
909 if(!FLAC__metadata_object_seektable_template_sort(block, /*compact=*/true)) {
910 printf("FAILED, returned false\n");
913 if(!FLAC__metadata_object_seektable_is_legal(block)) {
914 printf("FAILED, seek table is illegal\n");
917 if(!check_seektable_(block, seekpoints, seekpoint_array))
920 printf("testing FLAC__metadata_object_seekpoint_template_sort(compact=false)... ");
921 if(!FLAC__metadata_object_seektable_template_sort(block, /*compact=*/false)) {
922 printf("FAILED, returned false\n");
925 if(!FLAC__metadata_object_seektable_is_legal(block)) {
926 printf("FAILED, seek table is illegal\n");
929 if(!check_seektable_(block, seekpoints, seekpoint_array))
932 seekpoint_array[seekpoints++].sample_number = 0;
933 seekpoint_array[seekpoints++].sample_number = 10;
934 seekpoint_array[seekpoints++].sample_number = 20;
935 printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points_by_samples()... ");
936 if(!FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(block, 10, 30)) {
937 printf("FAILED, returned false\n");
940 if(!check_seektable_(block, seekpoints, seekpoint_array))
943 seekpoint_array[seekpoints++].sample_number = 0;
944 seekpoint_array[seekpoints++].sample_number = 11;
945 seekpoint_array[seekpoints++].sample_number = 22;
946 printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points_by_samples()... ");
947 if(!FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(block, 11, 30)) {
948 printf("FAILED, returned false\n");
951 if(!check_seektable_(block, seekpoints, seekpoint_array))
954 printf("testing FLAC__metadata_object_delete()... ");
955 FLAC__metadata_object_delete(block);
959 printf("testing VORBIS_COMMENT\n");
962 FLAC__StreamMetadata_VorbisComment_Entry entry_;
963 char *field_name, *field_value;
965 printf("testing FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair()... ");
966 if(!FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(&entry_, "name", "value")) {
967 printf("FAILED, returned false\n");
970 if(strcmp((const char *)entry_.entry, "name=value")) {
971 printf("FAILED, field mismatch\n");
976 printf("testing FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair()... ");
977 if(!FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair(entry_, &field_name, &field_value)) {
978 printf("FAILED, returned false\n");
981 if(strcmp(field_name, "name")) {
982 printf("FAILED, field name mismatch\n");
985 if(strcmp(field_value, "value")) {
986 printf("FAILED, field value mismatch\n");
991 printf("testing FLAC__metadata_object_vorbiscomment_entry_matches()... ");
992 if(!FLAC__metadata_object_vorbiscomment_entry_matches(entry_, field_name, strlen(field_name))) {
993 printf("FAILED, expected true, returned false\n");
998 printf("testing FLAC__metadata_object_vorbiscomment_entry_matches()... ");
999 if(FLAC__metadata_object_vorbiscomment_entry_matches(entry_, "blah", strlen("blah"))) {
1000 printf("FAILED, expected false, returned true\n");
1010 printf("testing FLAC__metadata_object_new()... ");
1011 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
1013 printf("FAILED, returned NULL\n");
1016 expected_length = (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + strlen(FLAC__VENDOR_STRING) + FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN/8);
1017 if(block->length != expected_length) {
1018 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
1023 printf("testing FLAC__metadata_object_clone()... ");
1024 vorbiscomment = FLAC__metadata_object_clone(block);
1025 if(0 == vorbiscomment) {
1026 printf("FAILED, returned NULL\n");
1029 if(!mutils__compare_block(vorbiscomment, block))
1033 vc_resize_(vorbiscomment, 2);
1034 printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(grow to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
1035 if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
1036 printf("FAILED, returned false\n");
1039 if(!mutils__compare_block(vorbiscomment, block))
1043 vc_resize_(vorbiscomment, 1);
1044 printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
1045 if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
1046 printf("FAILED, returned false\n");
1049 if(!mutils__compare_block(vorbiscomment, block))
1053 vc_resize_(vorbiscomment, 0);
1054 printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
1055 if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
1056 printf("FAILED, returned false\n");
1059 if(!mutils__compare_block(vorbiscomment, block))
1063 printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on empty array...");
1064 vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
1065 if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
1066 printf("FAILED, returned false\n");
1069 if(!mutils__compare_block(vorbiscomment, block))
1073 printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on non-empty array...");
1074 vc_insert_new_(&entry, vorbiscomment, 1, "name2=field2");
1075 if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
1076 printf("FAILED, returned false\n");
1079 if(!mutils__compare_block(vorbiscomment, block))
1083 vc_resize_(vorbiscomment, 0);
1084 printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
1085 if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
1086 printf("FAILED, returned false\n");
1089 if(!mutils__compare_block(vorbiscomment, block))
1093 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on empty array...");
1094 vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
1095 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/true)) {
1096 printf("FAILED, returned false\n");
1099 if(!mutils__compare_block(vorbiscomment, block))
1103 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on beginning of non-empty array...");
1104 vc_insert_new_(&entry, vorbiscomment, 0, "name2=field2");
1105 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/true)) {
1106 printf("FAILED, returned false\n");
1109 if(!mutils__compare_block(vorbiscomment, block))
1113 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on middle of non-empty array...");
1114 vc_insert_new_(&entry, vorbiscomment, 1, "name3=field3");
1115 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 1, entry, /*copy=*/true)) {
1116 printf("FAILED, returned false\n");
1119 if(!mutils__compare_block(vorbiscomment, block))
1123 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array...");
1124 vc_insert_new_(&entry, vorbiscomment, 3, "name4=field4");
1125 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 3, entry, /*copy=*/true)) {
1126 printf("FAILED, returned false\n");
1129 if(!mutils__compare_block(vorbiscomment, block))
1133 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array...");
1134 vc_insert_new_(&entry, vorbiscomment, 4, "name3=field3dup1");
1135 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 4, entry, /*copy=*/true)) {
1136 printf("FAILED, returned false\n");
1139 if(!mutils__compare_block(vorbiscomment, block))
1143 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array...");
1144 vc_insert_new_(&entry, vorbiscomment, 5, "name3=field3dup1");
1145 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 5, entry, /*copy=*/true)) {
1146 printf("FAILED, returned false\n");
1149 if(!mutils__compare_block(vorbiscomment, block))
1153 printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()...");
1154 if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0, "name3")) != 1) {
1155 printf("FAILED, expected 1, got %d\n", j);
1160 printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()...");
1161 if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, j+1, "name3")) != 4) {
1162 printf("FAILED, expected 4, got %d\n", j);
1167 printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()...");
1168 if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, j+1, "name3")) != 5) {
1169 printf("FAILED, expected 5, got %d\n", j);
1174 printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()...");
1175 if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0, "name2")) != 0) {
1176 printf("FAILED, expected 0, got %d\n", j);
1181 printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()...");
1182 if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, j+1, "name2")) != -1) {
1183 printf("FAILED, expected -1, got %d\n", j);
1188 printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()...");
1189 if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0, "blah")) != -1) {
1190 printf("FAILED, expected -1, got %d\n", j);
1195 printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(first, copy)...");
1196 vc_replace_new_(&entry, vorbiscomment, "name3=field3new1", /*all=*/false);
1197 if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/false, /*copy=*/true)) {
1198 printf("FAILED, returned false\n");
1201 if(!mutils__compare_block(vorbiscomment, block))
1203 if(block->data.vorbis_comment.num_comments != 6) {
1204 printf("FAILED, expected 6 comments, got %u\n", block->data.vorbis_comment.num_comments);
1209 printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(all, copy)...");
1210 vc_replace_new_(&entry, vorbiscomment, "name3=field3new2", /*all=*/true);
1211 if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/true, /*copy=*/true)) {
1212 printf("FAILED, returned false\n");
1215 if(!mutils__compare_block(vorbiscomment, block))
1217 if(block->data.vorbis_comment.num_comments != 4) {
1218 printf("FAILED, expected 4 comments, got %u\n", block->data.vorbis_comment.num_comments);
1223 printf("testing FLAC__metadata_object_clone()... ");
1224 blockcopy = FLAC__metadata_object_clone(block);
1225 if(0 == blockcopy) {
1226 printf("FAILED, returned NULL\n");
1229 if(!mutils__compare_block(block, blockcopy))
1233 printf("testing FLAC__metadata_object_delete()... ");
1234 FLAC__metadata_object_delete(blockcopy);
1237 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on middle of array...");
1238 vc_delete_(vorbiscomment, 2);
1239 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
1240 printf("FAILED, returned false\n");
1243 if(!mutils__compare_block(vorbiscomment, block))
1247 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on end of array...");
1248 vc_delete_(vorbiscomment, 2);
1249 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
1250 printf("FAILED, returned false\n");
1253 if(!mutils__compare_block(vorbiscomment, block))
1257 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on beginning of array...");
1258 vc_delete_(vorbiscomment, 0);
1259 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 0)) {
1260 printf("FAILED, returned false\n");
1263 if(!mutils__compare_block(vorbiscomment, block))
1267 printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on non-empty array...");
1268 vc_insert_new_(&entry, vorbiscomment, 1, "rem0=val0");
1269 if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
1270 printf("FAILED, returned false\n");
1273 if(!mutils__compare_block(vorbiscomment, block))
1277 printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on non-empty array...");
1278 vc_insert_new_(&entry, vorbiscomment, 2, "rem0=val1");
1279 if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
1280 printf("FAILED, returned false\n");
1283 if(!mutils__compare_block(vorbiscomment, block))
1287 printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on non-empty array...");
1288 vc_insert_new_(&entry, vorbiscomment, 3, "rem0=val2");
1289 if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
1290 printf("FAILED, returned false\n");
1293 if(!mutils__compare_block(vorbiscomment, block))
1297 printf("testing FLAC__metadata_object_vorbiscomment_remove_entry_matching(\"blah\")...");
1298 if((j = FLAC__metadata_object_vorbiscomment_remove_entry_matching(block, "blah")) != 0) {
1299 printf("FAILED, expected 0, got %d\n", j);
1302 if(block->data.vorbis_comment.num_comments != 4) {
1303 printf("FAILED, expected 4 comments, got %u\n", block->data.vorbis_comment.num_comments);
1306 if(!mutils__compare_block(vorbiscomment, block))
1310 printf("testing FLAC__metadata_object_vorbiscomment_remove_entry_matching(\"rem0\")...");
1311 vc_delete_(vorbiscomment, 1);
1312 if((j = FLAC__metadata_object_vorbiscomment_remove_entry_matching(block, "rem0")) != 1) {
1313 printf("FAILED, expected 1, got %d\n", j);
1316 if(block->data.vorbis_comment.num_comments != 3) {
1317 printf("FAILED, expected 3 comments, got %u\n", block->data.vorbis_comment.num_comments);
1320 if(!mutils__compare_block(vorbiscomment, block))
1324 printf("testing FLAC__metadata_object_vorbiscomment_remove_entries_matching(\"blah\")...");
1325 if((j = FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, "blah")) != 0) {
1326 printf("FAILED, expected 0, got %d\n", j);
1329 if(block->data.vorbis_comment.num_comments != 3) {
1330 printf("FAILED, expected 3 comments, got %u\n", block->data.vorbis_comment.num_comments);
1333 if(!mutils__compare_block(vorbiscomment, block))
1337 printf("testing FLAC__metadata_object_vorbiscomment_remove_entries_matching(\"rem0\")...");
1338 vc_delete_(vorbiscomment, 1);
1339 vc_delete_(vorbiscomment, 1);
1340 if((j = FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, "rem0")) != 2) {
1341 printf("FAILED, expected 2, got %d\n", j);
1344 if(block->data.vorbis_comment.num_comments != 1) {
1345 printf("FAILED, expected 1 comments, got %u\n", block->data.vorbis_comment.num_comments);
1348 if(!mutils__compare_block(vorbiscomment, block))
1352 printf("testing FLAC__metadata_object_vorbiscomment_set_comment(copy)...");
1353 vc_set_new_(&entry, vorbiscomment, 0, "name5=field5");
1354 FLAC__metadata_object_vorbiscomment_set_comment(block, 0, entry, /*copy=*/true);
1355 if(!mutils__compare_block(vorbiscomment, block))
1359 printf("testing FLAC__metadata_object_vorbiscomment_set_vendor_string(copy)...");
1360 vc_set_vs_new_(&entry, vorbiscomment, "name6=field6");
1361 FLAC__metadata_object_vorbiscomment_set_vendor_string(block, entry, /*copy=*/true);
1362 if(!mutils__compare_block(vorbiscomment, block))
1366 printf("testing FLAC__metadata_object_delete()... ");
1367 FLAC__metadata_object_delete(vorbiscomment);
1368 FLAC__metadata_object_delete(block);
1372 printf("testing FLAC__metadata_object_new()... ");
1373 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
1375 printf("FAILED, returned NULL\n");
1380 printf("testing FLAC__metadata_object_clone()... ");
1381 vorbiscomment = FLAC__metadata_object_clone(block);
1382 if(0 == vorbiscomment) {
1383 printf("FAILED, returned NULL\n");
1386 if(!mutils__compare_block(vorbiscomment, block))
1390 printf("testing FLAC__metadata_object_vorbiscomment_append_comment(own) on empty array...");
1391 vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
1392 entry_clone_(&entry);
1393 if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/false)) {
1394 printf("FAILED, returned false\n");
1397 if(!mutils__compare_block(vorbiscomment, block))
1401 printf("testing FLAC__metadata_object_vorbiscomment_append_comment(own) on non-empty array...");
1402 vc_insert_new_(&entry, vorbiscomment, 1, "name2=field2");
1403 entry_clone_(&entry);
1404 if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/false)) {
1405 printf("FAILED, returned false\n");
1408 if(!mutils__compare_block(vorbiscomment, block))
1412 printf("testing FLAC__metadata_object_delete()... ");
1413 FLAC__metadata_object_delete(vorbiscomment);
1414 FLAC__metadata_object_delete(block);
1417 printf("testing FLAC__metadata_object_new()... ");
1418 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
1420 printf("FAILED, returned NULL\n");
1425 printf("testing FLAC__metadata_object_clone()... ");
1426 vorbiscomment = FLAC__metadata_object_clone(block);
1427 if(0 == vorbiscomment) {
1428 printf("FAILED, returned NULL\n");
1431 if(!mutils__compare_block(vorbiscomment, block))
1435 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on empty array...");
1436 vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
1437 entry_clone_(&entry);
1438 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/false)) {
1439 printf("FAILED, returned false\n");
1442 if(!mutils__compare_block(vorbiscomment, block))
1446 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on beginning of non-empty array...");
1447 vc_insert_new_(&entry, vorbiscomment, 0, "name2=field2");
1448 entry_clone_(&entry);
1449 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/false)) {
1450 printf("FAILED, returned false\n");
1453 if(!mutils__compare_block(vorbiscomment, block))
1457 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on middle of non-empty array...");
1458 vc_insert_new_(&entry, vorbiscomment, 1, "name3=field3");
1459 entry_clone_(&entry);
1460 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 1, entry, /*copy=*/false)) {
1461 printf("FAILED, returned false\n");
1464 if(!mutils__compare_block(vorbiscomment, block))
1468 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on end of non-empty array...");
1469 vc_insert_new_(&entry, vorbiscomment, 3, "name4=field4");
1470 entry_clone_(&entry);
1471 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 3, entry, /*copy=*/false)) {
1472 printf("FAILED, returned false\n");
1475 if(!mutils__compare_block(vorbiscomment, block))
1479 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on end of non-empty array...");
1480 vc_insert_new_(&entry, vorbiscomment, 4, "name3=field3dup1");
1481 entry_clone_(&entry);
1482 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 4, entry, /*copy=*/false)) {
1483 printf("FAILED, returned false\n");
1486 if(!mutils__compare_block(vorbiscomment, block))
1490 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on end of non-empty array...");
1491 vc_insert_new_(&entry, vorbiscomment, 5, "name3=field3dup1");
1492 entry_clone_(&entry);
1493 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 5, entry, /*copy=*/false)) {
1494 printf("FAILED, returned false\n");
1497 if(!mutils__compare_block(vorbiscomment, block))
1501 printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(first, own)...");
1502 vc_replace_new_(&entry, vorbiscomment, "name3=field3new1", /*all=*/false);
1503 entry_clone_(&entry);
1504 if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/false, /*copy=*/false)) {
1505 printf("FAILED, returned false\n");
1508 if(!mutils__compare_block(vorbiscomment, block))
1510 if(block->data.vorbis_comment.num_comments != 6) {
1511 printf("FAILED, expected 6 comments, got %u\n", block->data.vorbis_comment.num_comments);
1516 printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(all, own)...");
1517 vc_replace_new_(&entry, vorbiscomment, "name3=field3new2", /*all=*/true);
1518 entry_clone_(&entry);
1519 if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/true, /*copy=*/false)) {
1520 printf("FAILED, returned false\n");
1523 if(!mutils__compare_block(vorbiscomment, block))
1525 if(block->data.vorbis_comment.num_comments != 4) {
1526 printf("FAILED, expected 4 comments, got %u\n", block->data.vorbis_comment.num_comments);
1531 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on middle of array...");
1532 vc_delete_(vorbiscomment, 2);
1533 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
1534 printf("FAILED, returned false\n");
1537 if(!mutils__compare_block(vorbiscomment, block))
1541 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on end of array...");
1542 vc_delete_(vorbiscomment, 2);
1543 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
1544 printf("FAILED, returned false\n");
1547 if(!mutils__compare_block(vorbiscomment, block))
1551 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on beginning of array...");
1552 vc_delete_(vorbiscomment, 0);
1553 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 0)) {
1554 printf("FAILED, returned false\n");
1557 if(!mutils__compare_block(vorbiscomment, block))
1561 printf("testing FLAC__metadata_object_vorbiscomment_set_comment(own)...");
1562 vc_set_new_(&entry, vorbiscomment, 0, "name5=field5");
1563 entry_clone_(&entry);
1564 FLAC__metadata_object_vorbiscomment_set_comment(block, 0, entry, /*copy=*/false);
1565 if(!mutils__compare_block(vorbiscomment, block))
1569 printf("testing FLAC__metadata_object_vorbiscomment_set_vendor_string(own)...");
1570 vc_set_vs_new_(&entry, vorbiscomment, "name6=field6");
1571 entry_clone_(&entry);
1572 FLAC__metadata_object_vorbiscomment_set_vendor_string(block, entry, /*copy=*/false);
1573 if(!mutils__compare_block(vorbiscomment, block))
1577 printf("testing FLAC__metadata_object_delete()... ");
1578 FLAC__metadata_object_delete(vorbiscomment);
1579 FLAC__metadata_object_delete(block);
1583 printf("testing CUESHEET\n");
1586 FLAC__StreamMetadata_CueSheet_Track *track_, *trackcopy_;
1588 printf("testing FLAC__metadata_object_cuesheet_track_new()... ");
1589 track_ = FLAC__metadata_object_cuesheet_track_new();
1591 printf("FAILED, returned NULL\n");
1596 printf("testing FLAC__metadata_object_cuesheet_track_clone()... ");
1597 trackcopy_ = FLAC__metadata_object_cuesheet_track_clone(track_);
1598 if(0 == trackcopy_) {
1599 printf("FAILED, returned NULL\n");
1602 if(!compare_track_(trackcopy_, track_))
1606 printf("testing FLAC__metadata_object_cuesheet_track_delete()... ");
1607 FLAC__metadata_object_cuesheet_track_delete(trackcopy_);
1608 FLAC__metadata_object_cuesheet_track_delete(track_);
1613 printf("testing FLAC__metadata_object_new()... ");
1614 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET);
1616 printf("FAILED, returned NULL\n");
1620 FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
1621 FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
1622 FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN +
1623 FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
1624 FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
1626 if(block->length != expected_length) {
1627 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
1632 printf("testing FLAC__metadata_object_clone()... ");
1633 cuesheet = FLAC__metadata_object_clone(block);
1635 printf("FAILED, returned NULL\n");
1638 if(!mutils__compare_block(cuesheet, block))
1642 cs_resize_(cuesheet, 2);
1643 printf("testing FLAC__metadata_object_cuesheet_resize_tracks(grow to %u)...", cuesheet->data.cue_sheet.num_tracks);
1644 if(!FLAC__metadata_object_cuesheet_resize_tracks(block, cuesheet->data.cue_sheet.num_tracks)) {
1645 printf("FAILED, returned false\n");
1648 if(!mutils__compare_block(cuesheet, block))
1652 cs_resize_(cuesheet, 1);
1653 printf("testing FLAC__metadata_object_cuesheet_resize_tracks(shrink to %u)...", cuesheet->data.cue_sheet.num_tracks);
1654 if(!FLAC__metadata_object_cuesheet_resize_tracks(block, cuesheet->data.cue_sheet.num_tracks)) {
1655 printf("FAILED, returned false\n");
1658 if(!mutils__compare_block(cuesheet, block))
1662 cs_resize_(cuesheet, 0);
1663 printf("testing FLAC__metadata_object_cuesheet_resize_tracks(shrink to %u)...", cuesheet->data.cue_sheet.num_tracks);
1664 if(!FLAC__metadata_object_cuesheet_resize_tracks(block, cuesheet->data.cue_sheet.num_tracks)) {
1665 printf("FAILED, returned false\n");
1668 if(!mutils__compare_block(cuesheet, block))
1672 printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on empty array...");
1673 cs_insert_new_(&track, cuesheet, 0, 0, 1, "ABCDE1234567", false, false);
1674 if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/true)) {
1675 printf("FAILED, returned false\n");
1678 if(!mutils__compare_block(cuesheet, block))
1682 printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on beginning of non-empty array...");
1683 cs_insert_new_(&track, cuesheet, 0, 10, 2, "BBCDE1234567", false, false);
1684 if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/true)) {
1685 printf("FAILED, returned false\n");
1688 if(!mutils__compare_block(cuesheet, block))
1692 printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on middle of non-empty array...");
1693 cs_insert_new_(&track, cuesheet, 1, 20, 3, "CBCDE1234567", false, false);
1694 if(!FLAC__metadata_object_cuesheet_insert_track(block, 1, &track, /*copy=*/true)) {
1695 printf("FAILED, returned false\n");
1698 if(!mutils__compare_block(cuesheet, block))
1702 printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on end of non-empty array...");
1703 cs_insert_new_(&track, cuesheet, 3, 30, 4, "DBCDE1234567", false, false);
1704 if(!FLAC__metadata_object_cuesheet_insert_track(block, 3, &track, /*copy=*/true)) {
1705 printf("FAILED, returned false\n");
1708 if(!mutils__compare_block(cuesheet, block))
1712 printf("testing FLAC__metadata_object_cuesheet_insert_blank_track() on end of non-empty array...");
1713 cs_insert_new_(&track, cuesheet, 4, 0, 0, "\0\0\0\0\0\0\0\0\0\0\0\0", false, false);
1714 if(!FLAC__metadata_object_cuesheet_insert_blank_track(block, 4)) {
1715 printf("FAILED, returned false\n");
1718 if(!mutils__compare_block(cuesheet, block))
1722 printf("testing FLAC__metadata_object_clone()... ");
1723 blockcopy = FLAC__metadata_object_clone(block);
1724 if(0 == blockcopy) {
1725 printf("FAILED, returned NULL\n");
1728 if(!mutils__compare_block(block, blockcopy))
1732 printf("testing FLAC__metadata_object_delete()... ");
1733 FLAC__metadata_object_delete(blockcopy);
1736 printf("testing FLAC__metadata_object_cuesheet_delete_track() on end of array...");
1737 cs_delete_(cuesheet, 4);
1738 if(!FLAC__metadata_object_cuesheet_delete_track(block, 4)) {
1739 printf("FAILED, returned false\n");
1742 if(!mutils__compare_block(cuesheet, block))
1746 printf("testing FLAC__metadata_object_cuesheet_delete_track() on middle of array...");
1747 cs_delete_(cuesheet, 2);
1748 if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1749 printf("FAILED, returned false\n");
1752 if(!mutils__compare_block(cuesheet, block))
1756 printf("testing FLAC__metadata_object_cuesheet_delete_track() on end of array...");
1757 cs_delete_(cuesheet, 2);
1758 if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1759 printf("FAILED, returned false\n");
1762 if(!mutils__compare_block(cuesheet, block))
1766 printf("testing FLAC__metadata_object_cuesheet_delete_track() on beginning of array...");
1767 cs_delete_(cuesheet, 0);
1768 if(!FLAC__metadata_object_cuesheet_delete_track(block, 0)) {
1769 printf("FAILED, returned false\n");
1772 if(!mutils__compare_block(cuesheet, block))
1776 printf("testing FLAC__metadata_object_cuesheet_set_track(copy)...");
1777 cs_set_new_(&track, cuesheet, 0, 40, 5, "EBCDE1234567", false, false);
1778 FLAC__metadata_object_cuesheet_set_track(block, 0, &track, /*copy=*/true);
1779 if(!mutils__compare_block(cuesheet, block))
1783 tr_resize_(cuesheet, 0, 2);
1784 printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(grow to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices);
1785 if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) {
1786 printf("FAILED, returned false\n");
1789 if(!mutils__compare_block(cuesheet, block))
1793 tr_resize_(cuesheet, 0, 1);
1794 printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(shrink to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices);
1795 if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) {
1796 printf("FAILED, returned false\n");
1799 if(!mutils__compare_block(cuesheet, block))
1803 tr_resize_(cuesheet, 0, 0);
1804 printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(shrink to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices);
1805 if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) {
1806 printf("FAILED, returned false\n");
1809 if(!mutils__compare_block(cuesheet, block))
1815 printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on empty array...");
1816 tr_insert_new_(cuesheet, 0, 0, index);
1817 if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 0, index)) {
1818 printf("FAILED, returned false\n");
1821 if(!mutils__compare_block(cuesheet, block))
1827 printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on beginning of non-empty array...");
1828 tr_insert_new_(cuesheet, 0, 0, index);
1829 if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 0, index)) {
1830 printf("FAILED, returned false\n");
1833 if(!mutils__compare_block(cuesheet, block))
1839 printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on middle of non-empty array...");
1840 tr_insert_new_(cuesheet, 0, 1, index);
1841 if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 1, index)) {
1842 printf("FAILED, returned false\n");
1845 if(!mutils__compare_block(cuesheet, block))
1851 printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on end of non-empty array...");
1852 tr_insert_new_(cuesheet, 0, 3, index);
1853 if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 3, index)) {
1854 printf("FAILED, returned false\n");
1857 if(!mutils__compare_block(cuesheet, block))
1863 printf("testing FLAC__metadata_object_cuesheet_track_insert_blank_index() on end of non-empty array...");
1864 tr_insert_new_(cuesheet, 0, 4, index);
1865 if(!FLAC__metadata_object_cuesheet_track_insert_blank_index(block, 0, 4)) {
1866 printf("FAILED, returned false\n");
1869 if(!mutils__compare_block(cuesheet, block))
1873 printf("testing FLAC__metadata_object_clone()... ");
1874 blockcopy = FLAC__metadata_object_clone(block);
1875 if(0 == blockcopy) {
1876 printf("FAILED, returned NULL\n");
1879 if(!mutils__compare_block(block, blockcopy))
1883 printf("testing FLAC__metadata_object_delete()... ");
1884 FLAC__metadata_object_delete(blockcopy);
1887 printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on end of array...");
1888 tr_delete_(cuesheet, 0, 4);
1889 if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 4)) {
1890 printf("FAILED, returned false\n");
1893 if(!mutils__compare_block(cuesheet, block))
1897 printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on middle of array...");
1898 tr_delete_(cuesheet, 0, 2);
1899 if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 2)) {
1900 printf("FAILED, returned false\n");
1903 if(!mutils__compare_block(cuesheet, block))
1907 printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on end of array...");
1908 tr_delete_(cuesheet, 0, 2);
1909 if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 2)) {
1910 printf("FAILED, returned false\n");
1913 if(!mutils__compare_block(cuesheet, block))
1917 printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on beginning of array...");
1918 tr_delete_(cuesheet, 0, 0);
1919 if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 0)) {
1920 printf("FAILED, returned false\n");
1923 if(!mutils__compare_block(cuesheet, block))
1927 printf("testing FLAC__metadata_object_delete()... ");
1928 FLAC__metadata_object_delete(cuesheet);
1929 FLAC__metadata_object_delete(block);
1933 printf("testing FLAC__metadata_object_new()... ");
1934 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET);
1936 printf("FAILED, returned NULL\n");
1941 printf("testing FLAC__metadata_object_clone()... ");
1942 cuesheet = FLAC__metadata_object_clone(block);
1944 printf("FAILED, returned NULL\n");
1947 if(!mutils__compare_block(cuesheet, block))
1951 printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on empty array...");
1952 cs_insert_new_(&track, cuesheet, 0, 60, 7, "GBCDE1234567", false, false);
1953 track_clone_(&track);
1954 if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/false)) {
1955 printf("FAILED, returned false\n");
1958 if(!mutils__compare_block(cuesheet, block))
1962 printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on beginning of non-empty array...");
1963 cs_insert_new_(&track, cuesheet, 0, 70, 8, "HBCDE1234567", false, false);
1964 track_clone_(&track);
1965 if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/false)) {
1966 printf("FAILED, returned false\n");
1969 if(!mutils__compare_block(cuesheet, block))
1973 printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on middle of non-empty array...");
1974 cs_insert_new_(&track, cuesheet, 1, 80, 9, "IBCDE1234567", false, false);
1975 track_clone_(&track);
1976 if(!FLAC__metadata_object_cuesheet_insert_track(block, 1, &track, /*copy=*/false)) {
1977 printf("FAILED, returned false\n");
1980 if(!mutils__compare_block(cuesheet, block))
1984 printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on end of non-empty array...");
1985 cs_insert_new_(&track, cuesheet, 3, 90, 10, "JBCDE1234567", false, false);
1986 track_clone_(&track);
1987 if(!FLAC__metadata_object_cuesheet_insert_track(block, 3, &track, /*copy=*/false)) {
1988 printf("FAILED, returned false\n");
1991 if(!mutils__compare_block(cuesheet, block))
1995 printf("testing FLAC__metadata_object_cuesheet_delete_track() on middle of array...");
1996 cs_delete_(cuesheet, 2);
1997 if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1998 printf("FAILED, returned false\n");
2001 if(!mutils__compare_block(cuesheet, block))
2005 printf("testing FLAC__metadata_object_cuesheet_delete_track() on end of array...");
2006 cs_delete_(cuesheet, 2);
2007 if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
2008 printf("FAILED, returned false\n");
2011 if(!mutils__compare_block(cuesheet, block))
2015 printf("testing FLAC__metadata_object_cuesheet_delete_track() on beginning of array...");
2016 cs_delete_(cuesheet, 0);
2017 if(!FLAC__metadata_object_cuesheet_delete_track(block, 0)) {
2018 printf("FAILED, returned false\n");
2021 if(!mutils__compare_block(cuesheet, block))
2025 printf("testing FLAC__metadata_object_cuesheet_set_track(own)...");
2026 cs_set_new_(&track, cuesheet, 0, 100, 11, "KBCDE1234567", false, false);
2027 track_clone_(&track);
2028 FLAC__metadata_object_cuesheet_set_track(block, 0, &track, /*copy=*/false);
2029 if(!mutils__compare_block(cuesheet, block))
2033 printf("testing FLAC__metadata_object_cuesheet_is_legal()...");
2035 const char *violation;
2036 if(FLAC__metadata_object_cuesheet_is_legal(block, /*check_cd_da_subset=*/true, &violation)) {
2037 printf("FAILED, returned true when expecting false\n");
2040 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2043 printf("testing FLAC__metadata_object_delete()... ");
2044 FLAC__metadata_object_delete(cuesheet);
2045 FLAC__metadata_object_delete(block);
2049 printf("testing PICTURE\n");
2051 printf("testing FLAC__metadata_object_new()... ");
2052 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PICTURE);
2054 printf("FAILED, returned NULL\n");
2058 FLAC__STREAM_METADATA_PICTURE_TYPE_LEN +
2059 FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN +
2060 FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN +
2061 FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN +
2062 FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN +
2063 FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN +
2064 FLAC__STREAM_METADATA_PICTURE_COLORS_LEN +
2065 FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN
2067 if(block->length != expected_length) {
2068 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
2073 printf("testing FLAC__metadata_object_clone()... ");
2074 picture = FLAC__metadata_object_clone(block);
2076 printf("FAILED, returned NULL\n");
2079 if(!mutils__compare_block(picture, block))
2083 pi_set_mime_type(picture, "image/png\t");
2084 printf("testing FLAC__metadata_object_picture_set_mime_type(copy)...");
2085 if(!FLAC__metadata_object_picture_set_mime_type(block, "image/png\t", /*copy=*/true)) {
2086 printf("FAILED, returned false\n");
2089 if(!mutils__compare_block(picture, block))
2093 printf("testing FLAC__metadata_object_picture_is_legal()...");
2095 const char *violation;
2096 if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
2097 printf("FAILED, returned true when expecting false\n");
2100 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2103 pi_set_mime_type(picture, "image/png");
2104 printf("testing FLAC__metadata_object_picture_set_mime_type(copy)...");
2105 if(!FLAC__metadata_object_picture_set_mime_type(block, "image/png", /*copy=*/true)) {
2106 printf("FAILED, returned false\n");
2109 if(!mutils__compare_block(picture, block))
2113 printf("testing FLAC__metadata_object_picture_is_legal()...");
2115 const char *violation;
2116 if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
2117 printf("FAILED, returned false, violation=\"%s\"\n", violation);
2123 pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION\xff");
2124 printf("testing FLAC__metadata_object_picture_set_description(copy)...");
2125 if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)"DESCRIPTION\xff", /*copy=*/true)) {
2126 printf("FAILED, returned false\n");
2129 if(!mutils__compare_block(picture, block))
2133 printf("testing FLAC__metadata_object_picture_is_legal()...");
2135 const char *violation;
2136 if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
2137 printf("FAILED, returned true when expecting false\n");
2140 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2143 pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION");
2144 printf("testing FLAC__metadata_object_picture_set_description(copy)...");
2145 if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)"DESCRIPTION", /*copy=*/true)) {
2146 printf("FAILED, returned false\n");
2149 if(!mutils__compare_block(picture, block))
2153 printf("testing FLAC__metadata_object_picture_is_legal()...");
2155 const char *violation;
2156 if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
2157 printf("FAILED, returned false, violation=\"%s\"\n", violation);
2164 pi_set_data(picture, (const FLAC__byte*)"PNGDATA", strlen("PNGDATA"));
2165 printf("testing FLAC__metadata_object_picture_set_data(copy)...");
2166 if(!FLAC__metadata_object_picture_set_data(block, (FLAC__byte*)"PNGDATA", strlen("PNGDATA"), /*copy=*/true)) {
2167 printf("FAILED, returned false\n");
2170 if(!mutils__compare_block(picture, block))
2174 printf("testing FLAC__metadata_object_clone()... ");
2175 blockcopy = FLAC__metadata_object_clone(block);
2176 if(0 == blockcopy) {
2177 printf("FAILED, returned NULL\n");
2180 if(!mutils__compare_block(block, blockcopy))
2184 printf("testing FLAC__metadata_object_delete()... ");
2185 FLAC__metadata_object_delete(blockcopy);
2188 pi_set_mime_type(picture, "image/png\t");
2189 printf("testing FLAC__metadata_object_picture_set_mime_type(own)...");
2190 if(!FLAC__metadata_object_picture_set_mime_type(block, strdup("image/png\t"), /*copy=*/false)) {
2191 printf("FAILED, returned false\n");
2194 if(!mutils__compare_block(picture, block))
2198 printf("testing FLAC__metadata_object_picture_is_legal()...");
2200 const char *violation;
2201 if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
2202 printf("FAILED, returned true when expecting false\n");
2205 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2208 pi_set_mime_type(picture, "image/png");
2209 printf("testing FLAC__metadata_object_picture_set_mime_type(own)...");
2210 if(!FLAC__metadata_object_picture_set_mime_type(block, strdup("image/png"), /*copy=*/false)) {
2211 printf("FAILED, returned false\n");
2214 if(!mutils__compare_block(picture, block))
2218 printf("testing FLAC__metadata_object_picture_is_legal()...");
2220 const char *violation;
2221 if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
2222 printf("FAILED, returned false, violation=\"%s\"\n", violation);
2228 pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION\xff");
2229 printf("testing FLAC__metadata_object_picture_set_description(own)...");
2230 if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)strdup("DESCRIPTION\xff"), /*copy=*/false)) {
2231 printf("FAILED, returned false\n");
2234 if(!mutils__compare_block(picture, block))
2238 printf("testing FLAC__metadata_object_picture_is_legal()...");
2240 const char *violation;
2241 if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
2242 printf("FAILED, returned true when expecting false\n");
2245 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2248 pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION");
2249 printf("testing FLAC__metadata_object_picture_set_description(own)...");
2250 if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)strdup("DESCRIPTION"), /*copy=*/false)) {
2251 printf("FAILED, returned false\n");
2254 if(!mutils__compare_block(picture, block))
2258 printf("testing FLAC__metadata_object_picture_is_legal()...");
2260 const char *violation;
2261 if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
2262 printf("FAILED, returned false, violation=\"%s\"\n", violation);
2268 pi_set_data(picture, (const FLAC__byte*)"PNGDATA", strlen("PNGDATA"));
2269 printf("testing FLAC__metadata_object_picture_set_data(own)...");
2270 if(!FLAC__metadata_object_picture_set_data(block, (FLAC__byte*)strdup("PNGDATA"), strlen("PNGDATA"), /*copy=*/false)) {
2271 printf("FAILED, returned false\n");
2274 if(!mutils__compare_block(picture, block))
2278 printf("testing FLAC__metadata_object_clone()... ");
2279 blockcopy = FLAC__metadata_object_clone(block);
2280 if(0 == blockcopy) {
2281 printf("FAILED, returned NULL\n");
2284 if(!mutils__compare_block(block, blockcopy))
2288 printf("testing FLAC__metadata_object_delete()... ");
2289 FLAC__metadata_object_delete(blockcopy);
2292 printf("testing FLAC__metadata_object_delete()... ");
2293 FLAC__metadata_object_delete(picture);
2294 FLAC__metadata_object_delete(block);