1 /* test_libFLAC - Unit tester for libFLAC
2 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 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"
26 #include "share/compat.h"
29 #include <stdlib.h> /* for malloc() */
30 #include <string.h> /* for memcmp() */
32 static FLAC__byte *make_dummydata_(FLAC__byte *dummydata, unsigned len)
36 if(0 == (ret = malloc(len))) {
37 printf("FAILED, malloc error\n");
41 memcpy(ret, dummydata, len);
46 static FLAC__bool compare_track_(const FLAC__StreamMetadata_CueSheet_Track *from, const FLAC__StreamMetadata_CueSheet_Track *to)
50 if(from->offset != to->offset) {
51 printf("FAILED, track offset mismatch, expected %" PRIu64 ", got %" PRIu64 "\n", to->offset, from->offset);
54 if(from->number != to->number) {
55 printf("FAILED, track number mismatch, expected %u, got %u\n", (unsigned)to->number, (unsigned)from->number);
58 if(0 != strcmp(from->isrc, to->isrc)) {
59 printf("FAILED, track number mismatch, expected %s, got %s\n", to->isrc, from->isrc);
62 if(from->type != to->type) {
63 printf("FAILED, track type mismatch, expected %u, got %u\n", (unsigned)to->type, (unsigned)from->type);
66 if(from->pre_emphasis != to->pre_emphasis) {
67 printf("FAILED, track pre_emphasis mismatch, expected %u, got %u\n", (unsigned)to->pre_emphasis, (unsigned)from->pre_emphasis);
70 if(from->num_indices != to->num_indices) {
71 printf("FAILED, track num_indices mismatch, expected %u, got %u\n", (unsigned)to->num_indices, (unsigned)from->num_indices);
74 if(0 == to->indices || 0 == from->indices) {
75 if(to->indices != from->indices) {
76 printf("FAILED, track indices mismatch\n");
81 for(i = 0; i < to->num_indices; i++) {
82 if(from->indices[i].offset != to->indices[i].offset) {
83 printf("FAILED, track indices[%u].offset mismatch, expected %" PRIu64 ", got %" PRIu64 "\n", i, to->indices[i].offset, from->indices[i].offset);
86 if(from->indices[i].number != to->indices[i].number) {
87 printf("FAILED, track indices[%u].number mismatch, expected %u, got %u\n", i, (unsigned)to->indices[i].number, (unsigned)from->indices[i].number);
96 static FLAC__bool compare_seekpoint_array_(const FLAC__StreamMetadata_SeekPoint *from, const FLAC__StreamMetadata_SeekPoint *to, unsigned n)
100 FLAC__ASSERT(0 != from);
101 FLAC__ASSERT(0 != to);
103 for(i = 0; i < n; i++) {
104 if(from[i].sample_number != to[i].sample_number) {
105 printf("FAILED, point[%u].sample_number mismatch, expected %" PRIu64 ", got %" PRIu64 "\n", i, to[i].sample_number, from[i].sample_number);
108 if(from[i].stream_offset != to[i].stream_offset) {
109 printf("FAILED, point[%u].stream_offset mismatch, expected %" PRIu64 ", got %" PRIu64 "\n", i, to[i].stream_offset, from[i].stream_offset);
112 if(from[i].frame_samples != to[i].frame_samples) {
113 printf("FAILED, point[%u].frame_samples mismatch, expected %u, got %u\n", i, to[i].frame_samples, from[i].frame_samples);
121 static FLAC__bool check_seektable_(const FLAC__StreamMetadata *block, unsigned num_points, const FLAC__StreamMetadata_SeekPoint *array)
123 const unsigned expected_length = num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
125 if(block->length != expected_length) {
126 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
129 if(block->data.seek_table.num_points != num_points) {
130 printf("FAILED, expected %u point, got %u\n", num_points, block->data.seek_table.num_points);
134 if(0 != block->data.seek_table.points) {
135 printf("FAILED, 'points' pointer is not null\n");
140 if(!compare_seekpoint_array_(block->data.seek_table.points, array, num_points))
148 static void entry_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, const char *field)
150 entry->length = strlen(field);
151 entry->entry = malloc(entry->length+1);
152 FLAC__ASSERT(0 != entry->entry);
153 memcpy(entry->entry, field, entry->length);
154 entry->entry[entry->length] = '\0';
157 static void entry_clone_(FLAC__StreamMetadata_VorbisComment_Entry *entry)
159 FLAC__byte *x = malloc(entry->length+1);
160 FLAC__ASSERT(0 != x);
161 memcpy(x, entry->entry, entry->length);
162 x[entry->length] = '\0';
166 static void vc_calc_len_(FLAC__StreamMetadata *block)
168 const FLAC__StreamMetadata_VorbisComment *vc = &block->data.vorbis_comment;
171 block->length = FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
172 block->length += vc->vendor_string.length;
173 block->length += FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8;
174 for(i = 0; i < vc->num_comments; i++) {
175 block->length += FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
176 block->length += vc->comments[i].length;
180 static void vc_resize_(FLAC__StreamMetadata *block, unsigned num)
182 FLAC__StreamMetadata_VorbisComment *vc = &block->data.vorbis_comment;
184 if(vc->num_comments != 0) {
185 FLAC__ASSERT(0 != vc->comments);
186 if(num < vc->num_comments) {
188 for(i = num; i < vc->num_comments; i++) {
189 if(0 != vc->comments[i].entry)
190 free(vc->comments[i].entry);
195 if(0 != vc->comments) {
201 vc->comments = realloc(vc->comments, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*num);
202 FLAC__ASSERT(0 != vc->comments);
203 if(num > vc->num_comments)
204 memset(vc->comments+vc->num_comments, 0, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(num-vc->num_comments));
207 vc->num_comments = num;
211 static int vc_find_from_(FLAC__StreamMetadata *block, const char *name, unsigned start)
213 const unsigned n = strlen(name);
215 for(i = start; i < block->data.vorbis_comment.num_comments; i++) {
216 const FLAC__StreamMetadata_VorbisComment_Entry *entry = &block->data.vorbis_comment.comments[i];
217 if(entry->length > n && 0 == strncmp((const char *)entry->entry, name, n) && entry->entry[n] == '=')
223 static void vc_set_vs_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, const char *field)
225 if(0 != block->data.vorbis_comment.vendor_string.entry)
226 free(block->data.vorbis_comment.vendor_string.entry);
227 entry_new_(entry, field);
228 block->data.vorbis_comment.vendor_string = *entry;
232 static void vc_set_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, unsigned pos, const char *field)
234 if(0 != block->data.vorbis_comment.comments[pos].entry)
235 free(block->data.vorbis_comment.comments[pos].entry);
236 entry_new_(entry, field);
237 block->data.vorbis_comment.comments[pos] = *entry;
241 static void vc_insert_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, unsigned pos, const char *field)
243 vc_resize_(block, block->data.vorbis_comment.num_comments+1);
244 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));
245 memset(&block->data.vorbis_comment.comments[pos], 0, sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
246 vc_set_new_(entry, block, pos, field);
250 static void vc_delete_(FLAC__StreamMetadata *block, unsigned pos)
252 if(0 != block->data.vorbis_comment.comments[pos].entry)
253 free(block->data.vorbis_comment.comments[pos].entry);
254 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));
255 block->data.vorbis_comment.comments[block->data.vorbis_comment.num_comments-1].entry = 0;
256 block->data.vorbis_comment.comments[block->data.vorbis_comment.num_comments-1].length = 0;
257 vc_resize_(block, block->data.vorbis_comment.num_comments-1);
261 static void vc_replace_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, const char *field, FLAC__bool all)
264 char field_name[256];
265 const char *eq = strchr(field, '=');
266 FLAC__ASSERT(eq>field && (unsigned)(eq-field) < sizeof(field_name));
267 memcpy(field_name, field, eq-field);
268 field_name[eq-field]='\0';
270 index = vc_find_from_(block, field_name, 0);
272 vc_insert_new_(entry, block, block->data.vorbis_comment.num_comments, field);
274 vc_set_new_(entry, block, (unsigned)index, field);
276 for(index = index+1; index >= 0 && (unsigned)index < block->data.vorbis_comment.num_comments; )
277 if((index = vc_find_from_(block, field_name, (unsigned)index)) >= 0)
278 vc_delete_(block, (unsigned)index);
285 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)
287 track->offset = offset;
288 track->number = number;
289 memcpy(track->isrc, isrc, sizeof(track->isrc));
291 track->pre_emphasis = pre_em;
292 track->num_indices = 0;
296 static void track_clone_(FLAC__StreamMetadata_CueSheet_Track *track)
298 if(track->num_indices > 0) {
299 size_t bytes = sizeof(FLAC__StreamMetadata_CueSheet_Index) * track->num_indices;
300 FLAC__StreamMetadata_CueSheet_Index *x = malloc(bytes);
301 FLAC__ASSERT(0 != x);
302 memcpy(x, track->indices, bytes);
307 static void cs_calc_len_(FLAC__StreamMetadata *block)
309 const FLAC__StreamMetadata_CueSheet *cs = &block->data.cue_sheet;
313 FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
314 FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
315 FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN +
316 FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
317 FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
319 block->length += cs->num_tracks * (
320 FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN +
321 FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN +
322 FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN +
323 FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN +
324 FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN +
325 FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN +
326 FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN
328 for(i = 0; i < cs->num_tracks; i++) {
329 block->length += cs->tracks[i].num_indices * (
330 FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN +
331 FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN +
332 FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN
337 static void tr_resize_(FLAC__StreamMetadata *block, unsigned track_num, unsigned num)
339 FLAC__StreamMetadata_CueSheet_Track *tr;
341 FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
343 tr = &block->data.cue_sheet.tracks[track_num];
345 if(tr->num_indices != 0) {
346 FLAC__ASSERT(0 != tr->indices);
349 if(0 != tr->indices) {
355 tr->indices = realloc(tr->indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)*num);
356 FLAC__ASSERT(0 != tr->indices);
357 if(num > tr->num_indices)
358 memset(tr->indices+tr->num_indices, 0, sizeof(FLAC__StreamMetadata_CueSheet_Index)*(num-tr->num_indices));
361 tr->num_indices = num;
365 static void tr_set_new_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos, FLAC__StreamMetadata_CueSheet_Index index)
367 FLAC__StreamMetadata_CueSheet_Track *tr;
369 FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
371 tr = &block->data.cue_sheet.tracks[track_num];
373 FLAC__ASSERT(pos < tr->num_indices);
375 tr->indices[pos] = index;
380 static void tr_insert_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_resize_(block, track_num, tr->num_indices+1);
391 memmove(&tr->indices[pos+1], &tr->indices[pos], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(tr->num_indices-1-pos));
392 tr_set_new_(block, track_num, pos, index);
396 static void tr_delete_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos)
398 FLAC__StreamMetadata_CueSheet_Track *tr;
400 FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
402 tr = &block->data.cue_sheet.tracks[track_num];
404 FLAC__ASSERT(pos <= tr->num_indices);
406 memmove(&tr->indices[pos], &tr->indices[pos+1], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(tr->num_indices-pos-1));
407 tr_resize_(block, track_num, tr->num_indices-1);
411 static void cs_resize_(FLAC__StreamMetadata *block, unsigned num)
413 FLAC__StreamMetadata_CueSheet *cs = &block->data.cue_sheet;
415 if(cs->num_tracks != 0) {
416 FLAC__ASSERT(0 != cs->tracks);
417 if(num < cs->num_tracks) {
419 for(i = num; i < cs->num_tracks; i++) {
420 if(0 != cs->tracks[i].indices)
421 free(cs->tracks[i].indices);
426 if(0 != cs->tracks) {
432 cs->tracks = realloc(cs->tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)*num);
433 FLAC__ASSERT(0 != cs->tracks);
434 if(num > cs->num_tracks)
435 memset(cs->tracks+cs->num_tracks, 0, sizeof(FLAC__StreamMetadata_CueSheet_Track)*(num-cs->num_tracks));
438 cs->num_tracks = num;
442 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)
444 track_new_(track, offset, number, isrc, data, pre_em);
445 block->data.cue_sheet.tracks[pos] = *track;
449 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)
451 cs_resize_(block, block->data.cue_sheet.num_tracks+1);
452 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));
453 cs_set_new_(track, block, pos, offset, number, isrc, data, pre_em);
457 static void cs_delete_(FLAC__StreamMetadata *block, unsigned pos)
459 if(0 != block->data.cue_sheet.tracks[pos].indices)
460 free(block->data.cue_sheet.tracks[pos].indices);
461 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));
462 block->data.cue_sheet.tracks[block->data.cue_sheet.num_tracks-1].indices = 0;
463 block->data.cue_sheet.tracks[block->data.cue_sheet.num_tracks-1].num_indices = 0;
464 cs_resize_(block, block->data.cue_sheet.num_tracks-1);
468 static void pi_set_mime_type(FLAC__StreamMetadata *block, const char *s)
470 if(block->data.picture.mime_type) {
471 block->length -= strlen(block->data.picture.mime_type);
472 free(block->data.picture.mime_type);
474 block->data.picture.mime_type = strdup(s);
475 FLAC__ASSERT(block->data.picture.mime_type);
476 block->length += strlen(block->data.picture.mime_type);
479 static void pi_set_description(FLAC__StreamMetadata *block, const FLAC__byte *s)
481 if(block->data.picture.description) {
482 block->length -= strlen((const char *)block->data.picture.description);
483 free(block->data.picture.description);
485 block->data.picture.description = (FLAC__byte*)strdup((const char *)s);
486 FLAC__ASSERT(block->data.picture.description);
487 block->length += strlen((const char *)block->data.picture.description);
490 static void pi_set_data(FLAC__StreamMetadata *block, const FLAC__byte *data, FLAC__uint32 len)
492 if(block->data.picture.data) {
493 block->length -= block->data.picture.data_length;
494 free(block->data.picture.data);
496 block->data.picture.data = (FLAC__byte*)strdup((const char *)data);
497 FLAC__ASSERT(block->data.picture.data);
498 block->data.picture.data_length = len;
499 block->length += len;
502 FLAC__bool test_metadata_object(void)
504 FLAC__StreamMetadata *block, *blockcopy, *vorbiscomment, *cuesheet, *picture;
505 FLAC__StreamMetadata_SeekPoint seekpoint_array[14];
506 FLAC__StreamMetadata_VorbisComment_Entry entry;
507 FLAC__StreamMetadata_CueSheet_Index index;
508 FLAC__StreamMetadata_CueSheet_Track track;
509 unsigned i, expected_length, seekpoints;
511 static FLAC__byte dummydata[4] = { 'a', 'b', 'c', 'd' };
513 printf("\n+++ libFLAC unit test: metadata objects\n\n");
516 printf("testing STREAMINFO\n");
518 printf("testing FLAC__metadata_object_new()... ");
519 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_STREAMINFO);
521 printf("FAILED, returned NULL\n");
524 expected_length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
525 if(block->length != expected_length) {
526 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
531 printf("testing FLAC__metadata_object_clone()... ");
532 blockcopy = FLAC__metadata_object_clone(block);
534 printf("FAILED, returned NULL\n");
537 if(!mutils__compare_block(block, blockcopy))
541 printf("testing FLAC__metadata_object_delete()... ");
542 FLAC__metadata_object_delete(blockcopy);
543 FLAC__metadata_object_delete(block);
547 printf("testing PADDING\n");
549 printf("testing FLAC__metadata_object_new()... ");
550 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING);
552 printf("FAILED, returned NULL\n");
556 if(block->length != expected_length) {
557 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
562 printf("testing FLAC__metadata_object_clone()... ");
563 blockcopy = FLAC__metadata_object_clone(block);
565 printf("FAILED, returned NULL\n");
568 if(!mutils__compare_block(block, blockcopy))
572 printf("testing FLAC__metadata_object_delete()... ");
573 FLAC__metadata_object_delete(blockcopy);
574 FLAC__metadata_object_delete(block);
578 printf("testing APPLICATION\n");
580 printf("testing FLAC__metadata_object_new()... ");
581 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION);
583 printf("FAILED, returned NULL\n");
586 expected_length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
587 if(block->length != expected_length) {
588 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
593 printf("testing FLAC__metadata_object_clone()... ");
594 blockcopy = FLAC__metadata_object_clone(block);
596 printf("FAILED, returned NULL\n");
599 if(!mutils__compare_block(block, blockcopy))
603 printf("testing FLAC__metadata_object_delete()... ");
604 FLAC__metadata_object_delete(blockcopy);
607 printf("testing FLAC__metadata_object_application_set_data(copy)... ");
608 if(!FLAC__metadata_object_application_set_data(block, dummydata, sizeof(dummydata), true/*copy*/)) {
609 printf("FAILED, returned false\n");
612 expected_length = (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) + sizeof(dummydata);
613 if(block->length != expected_length) {
614 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
617 if(0 != memcmp(block->data.application.data, dummydata, sizeof(dummydata))) {
618 printf("FAILED, data mismatch\n");
623 printf("testing FLAC__metadata_object_clone()... ");
624 blockcopy = FLAC__metadata_object_clone(block);
626 printf("FAILED, returned NULL\n");
629 if(!mutils__compare_block(block, blockcopy))
633 printf("testing FLAC__metadata_object_delete()... ");
634 FLAC__metadata_object_delete(blockcopy);
637 printf("testing FLAC__metadata_object_application_set_data(own)... ");
638 if(!FLAC__metadata_object_application_set_data(block, make_dummydata_(dummydata, sizeof(dummydata)), sizeof(dummydata), false/*own*/)) {
639 printf("FAILED, returned false\n");
642 expected_length = (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) + sizeof(dummydata);
643 if(block->length != expected_length) {
644 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
647 if(0 != memcmp(block->data.application.data, dummydata, sizeof(dummydata))) {
648 printf("FAILED, data mismatch\n");
653 printf("testing FLAC__metadata_object_clone()... ");
654 blockcopy = FLAC__metadata_object_clone(block);
656 printf("FAILED, returned NULL\n");
659 if(!mutils__compare_block(block, blockcopy))
663 printf("testing FLAC__metadata_object_delete()... ");
664 FLAC__metadata_object_delete(blockcopy);
665 FLAC__metadata_object_delete(block);
669 printf("testing SEEKTABLE\n");
671 for(i = 0; i < sizeof(seekpoint_array) / sizeof(FLAC__StreamMetadata_SeekPoint); i++) {
672 seekpoint_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
673 seekpoint_array[i].stream_offset = 0;
674 seekpoint_array[i].frame_samples = 0;
678 printf("testing FLAC__metadata_object_new()... ");
679 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE);
681 printf("FAILED, returned NULL\n");
684 if(!check_seektable_(block, seekpoints, 0))
687 printf("testing FLAC__metadata_object_clone()... ");
688 blockcopy = FLAC__metadata_object_clone(block);
690 printf("FAILED, returned NULL\n");
693 if(!mutils__compare_block(block, blockcopy))
697 printf("testing FLAC__metadata_object_delete()... ");
698 FLAC__metadata_object_delete(blockcopy);
702 printf("testing FLAC__metadata_object_seektable_resize_points(grow to %u)...", seekpoints);
703 if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
704 printf("FAILED, returned false\n");
707 if(!check_seektable_(block, seekpoints, seekpoint_array))
711 printf("testing FLAC__metadata_object_seektable_resize_points(shrink to %u)...", seekpoints);
712 if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
713 printf("FAILED, returned false\n");
716 if(!check_seektable_(block, seekpoints, seekpoint_array))
719 printf("testing FLAC__metadata_object_seektable_is_legal()...");
720 if(!FLAC__metadata_object_seektable_is_legal(block)) {
721 printf("FAILED, returned false\n");
727 printf("testing FLAC__metadata_object_seektable_resize_points(shrink to %u)...", seekpoints);
728 if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
729 printf("FAILED, returned false\n");
732 if(!check_seektable_(block, seekpoints, 0))
736 printf("testing FLAC__metadata_object_seektable_insert_point() on empty array...");
737 if(!FLAC__metadata_object_seektable_insert_point(block, 0, seekpoint_array[0])) {
738 printf("FAILED, returned false\n");
741 if(!check_seektable_(block, seekpoints, seekpoint_array))
744 seekpoint_array[0].sample_number = 1;
746 printf("testing FLAC__metadata_object_seektable_insert_point() on beginning of non-empty array...");
747 if(!FLAC__metadata_object_seektable_insert_point(block, 0, seekpoint_array[0])) {
748 printf("FAILED, returned false\n");
751 if(!check_seektable_(block, seekpoints, seekpoint_array))
754 seekpoint_array[1].sample_number = 2;
756 printf("testing FLAC__metadata_object_seektable_insert_point() on middle of non-empty array...");
757 if(!FLAC__metadata_object_seektable_insert_point(block, 1, seekpoint_array[1])) {
758 printf("FAILED, returned false\n");
761 if(!check_seektable_(block, seekpoints, seekpoint_array))
764 seekpoint_array[3].sample_number = 3;
766 printf("testing FLAC__metadata_object_seektable_insert_point() on end of non-empty array...");
767 if(!FLAC__metadata_object_seektable_insert_point(block, 3, seekpoint_array[3])) {
768 printf("FAILED, returned false\n");
771 if(!check_seektable_(block, seekpoints, seekpoint_array))
774 printf("testing FLAC__metadata_object_clone()... ");
775 blockcopy = FLAC__metadata_object_clone(block);
777 printf("FAILED, returned NULL\n");
780 if(!mutils__compare_block(block, blockcopy))
784 printf("testing FLAC__metadata_object_delete()... ");
785 FLAC__metadata_object_delete(blockcopy);
788 seekpoint_array[2].sample_number = seekpoint_array[3].sample_number;
790 printf("testing FLAC__metadata_object_seektable_delete_point() on middle of array...");
791 if(!FLAC__metadata_object_seektable_delete_point(block, 2)) {
792 printf("FAILED, returned false\n");
795 if(!check_seektable_(block, seekpoints, seekpoint_array))
799 printf("testing FLAC__metadata_object_seektable_delete_point() on end of array...");
800 if(!FLAC__metadata_object_seektable_delete_point(block, 2)) {
801 printf("FAILED, returned false\n");
804 if(!check_seektable_(block, seekpoints, seekpoint_array))
808 printf("testing FLAC__metadata_object_seektable_delete_point() on beginning of array...");
809 if(!FLAC__metadata_object_seektable_delete_point(block, 0)) {
810 printf("FAILED, returned false\n");
813 if(!check_seektable_(block, seekpoints, seekpoint_array+1))
816 printf("testing FLAC__metadata_object_seektable_set_point()...");
817 FLAC__metadata_object_seektable_set_point(block, 0, seekpoint_array[0]);
818 if(!check_seektable_(block, seekpoints, seekpoint_array))
821 printf("testing FLAC__metadata_object_delete()... ");
822 FLAC__metadata_object_delete(block);
825 /* seektable template functions */
827 for(i = 0; i < sizeof(seekpoint_array) / sizeof(FLAC__StreamMetadata_SeekPoint); i++) {
828 seekpoint_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
829 seekpoint_array[i].stream_offset = 0;
830 seekpoint_array[i].frame_samples = 0;
834 printf("testing FLAC__metadata_object_new()... ");
835 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE);
837 printf("FAILED, returned NULL\n");
840 if(!check_seektable_(block, seekpoints, 0))
844 printf("testing FLAC__metadata_object_seekpoint_template_append_placeholders()... ");
845 if(!FLAC__metadata_object_seektable_template_append_placeholders(block, 2)) {
846 printf("FAILED, returned false\n");
849 if(!check_seektable_(block, seekpoints, seekpoint_array))
852 seekpoint_array[seekpoints++].sample_number = 7;
853 printf("testing FLAC__metadata_object_seekpoint_template_append_point()... ");
854 if(!FLAC__metadata_object_seektable_template_append_point(block, 7)) {
855 printf("FAILED, returned false\n");
858 if(!check_seektable_(block, seekpoints, seekpoint_array))
862 FLAC__uint64 nums[2] = { 3, 7 };
863 seekpoint_array[seekpoints++].sample_number = nums[0];
864 seekpoint_array[seekpoints++].sample_number = nums[1];
865 printf("testing FLAC__metadata_object_seekpoint_template_append_points()... ");
866 if(!FLAC__metadata_object_seektable_template_append_points(block, nums, sizeof(nums)/sizeof(FLAC__uint64))) {
867 printf("FAILED, returned false\n");
870 if(!check_seektable_(block, seekpoints, seekpoint_array))
874 seekpoint_array[seekpoints++].sample_number = 0;
875 seekpoint_array[seekpoints++].sample_number = 10;
876 seekpoint_array[seekpoints++].sample_number = 20;
877 printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points()... ");
878 if(!FLAC__metadata_object_seektable_template_append_spaced_points(block, 3, 30)) {
879 printf("FAILED, returned false\n");
882 if(!check_seektable_(block, seekpoints, seekpoint_array))
886 seekpoint_array[0].sample_number = 0;
887 seekpoint_array[1].sample_number = 3;
888 seekpoint_array[2].sample_number = 7;
889 seekpoint_array[3].sample_number = 10;
890 seekpoint_array[4].sample_number = 20;
891 seekpoint_array[5].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
892 seekpoint_array[6].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
893 printf("testing FLAC__metadata_object_seekpoint_template_sort(compact=true)... ");
894 if(!FLAC__metadata_object_seektable_template_sort(block, /*compact=*/true)) {
895 printf("FAILED, returned false\n");
898 if(!FLAC__metadata_object_seektable_is_legal(block)) {
899 printf("FAILED, seek table is illegal\n");
902 if(!check_seektable_(block, seekpoints, seekpoint_array))
905 printf("testing FLAC__metadata_object_seekpoint_template_sort(compact=false)... ");
906 if(!FLAC__metadata_object_seektable_template_sort(block, /*compact=*/false)) {
907 printf("FAILED, returned false\n");
910 if(!FLAC__metadata_object_seektable_is_legal(block)) {
911 printf("FAILED, seek table is illegal\n");
914 if(!check_seektable_(block, seekpoints, seekpoint_array))
917 seekpoint_array[seekpoints++].sample_number = 0;
918 seekpoint_array[seekpoints++].sample_number = 10;
919 seekpoint_array[seekpoints++].sample_number = 20;
920 printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points_by_samples()... ");
921 if(!FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(block, 10, 30)) {
922 printf("FAILED, returned false\n");
925 if(!check_seektable_(block, seekpoints, seekpoint_array))
928 seekpoint_array[seekpoints++].sample_number = 0;
929 seekpoint_array[seekpoints++].sample_number = 11;
930 seekpoint_array[seekpoints++].sample_number = 22;
931 printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points_by_samples()... ");
932 if(!FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(block, 11, 30)) {
933 printf("FAILED, returned false\n");
936 if(!check_seektable_(block, seekpoints, seekpoint_array))
939 printf("testing FLAC__metadata_object_delete()... ");
940 FLAC__metadata_object_delete(block);
944 printf("testing VORBIS_COMMENT\n");
947 FLAC__StreamMetadata_VorbisComment_Entry entry_;
948 char *field_name, *field_value;
950 printf("testing FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair()... ");
951 if(!FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(&entry_, "name", "value")) {
952 printf("FAILED, returned false\n");
955 if(strcmp((const char *)entry_.entry, "name=value")) {
956 printf("FAILED, field mismatch\n");
961 printf("testing FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair()... ");
962 if(!FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair(entry_, &field_name, &field_value)) {
963 printf("FAILED, returned false\n");
966 if(strcmp(field_name, "name")) {
967 printf("FAILED, field name mismatch\n");
970 if(strcmp(field_value, "value")) {
971 printf("FAILED, field value mismatch\n");
976 printf("testing FLAC__metadata_object_vorbiscomment_entry_matches()... ");
977 if(!FLAC__metadata_object_vorbiscomment_entry_matches(entry_, field_name, strlen(field_name))) {
978 printf("FAILED, expected true, returned false\n");
983 printf("testing FLAC__metadata_object_vorbiscomment_entry_matches()... ");
984 if(FLAC__metadata_object_vorbiscomment_entry_matches(entry_, "blah", strlen("blah"))) {
985 printf("FAILED, expected false, returned true\n");
995 printf("testing FLAC__metadata_object_new()... ");
996 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
998 printf("FAILED, returned NULL\n");
1001 expected_length = (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + strlen(FLAC__VENDOR_STRING) + FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN/8);
1002 if(block->length != expected_length) {
1003 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
1008 printf("testing FLAC__metadata_object_clone()... ");
1009 vorbiscomment = FLAC__metadata_object_clone(block);
1010 if(0 == vorbiscomment) {
1011 printf("FAILED, returned NULL\n");
1014 if(!mutils__compare_block(vorbiscomment, block))
1018 vc_resize_(vorbiscomment, 2);
1019 printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(grow to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
1020 if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
1021 printf("FAILED, returned false\n");
1024 if(!mutils__compare_block(vorbiscomment, block))
1028 vc_resize_(vorbiscomment, 1);
1029 printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
1030 if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
1031 printf("FAILED, returned false\n");
1034 if(!mutils__compare_block(vorbiscomment, block))
1038 vc_resize_(vorbiscomment, 0);
1039 printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
1040 if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
1041 printf("FAILED, returned false\n");
1044 if(!mutils__compare_block(vorbiscomment, block))
1048 printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on empty array...");
1049 vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
1050 if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
1051 printf("FAILED, returned false\n");
1054 if(!mutils__compare_block(vorbiscomment, block))
1058 printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on non-empty array...");
1059 vc_insert_new_(&entry, vorbiscomment, 1, "name2=field2");
1060 if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
1061 printf("FAILED, returned false\n");
1064 if(!mutils__compare_block(vorbiscomment, block))
1068 vc_resize_(vorbiscomment, 0);
1069 printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
1070 if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
1071 printf("FAILED, returned false\n");
1074 if(!mutils__compare_block(vorbiscomment, block))
1078 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on empty array...");
1079 vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
1080 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/true)) {
1081 printf("FAILED, returned false\n");
1084 if(!mutils__compare_block(vorbiscomment, block))
1088 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on beginning of non-empty array...");
1089 vc_insert_new_(&entry, vorbiscomment, 0, "name2=field2");
1090 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/true)) {
1091 printf("FAILED, returned false\n");
1094 if(!mutils__compare_block(vorbiscomment, block))
1098 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on middle of non-empty array...");
1099 vc_insert_new_(&entry, vorbiscomment, 1, "name3=field3");
1100 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 1, entry, /*copy=*/true)) {
1101 printf("FAILED, returned false\n");
1104 if(!mutils__compare_block(vorbiscomment, block))
1108 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array...");
1109 vc_insert_new_(&entry, vorbiscomment, 3, "name4=field4");
1110 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 3, entry, /*copy=*/true)) {
1111 printf("FAILED, returned false\n");
1114 if(!mutils__compare_block(vorbiscomment, block))
1118 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array...");
1119 vc_insert_new_(&entry, vorbiscomment, 4, "name3=field3dup1");
1120 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 4, entry, /*copy=*/true)) {
1121 printf("FAILED, returned false\n");
1124 if(!mutils__compare_block(vorbiscomment, block))
1128 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array...");
1129 vc_insert_new_(&entry, vorbiscomment, 5, "name3=field3dup1");
1130 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 5, entry, /*copy=*/true)) {
1131 printf("FAILED, returned false\n");
1134 if(!mutils__compare_block(vorbiscomment, block))
1138 printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()...");
1139 if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0, "name3")) != 1) {
1140 printf("FAILED, expected 1, got %d\n", j);
1145 printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()...");
1146 if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, j+1, "name3")) != 4) {
1147 printf("FAILED, expected 4, got %d\n", j);
1152 printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()...");
1153 if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, j+1, "name3")) != 5) {
1154 printf("FAILED, expected 5, got %d\n", j);
1159 printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()...");
1160 if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0, "name2")) != 0) {
1161 printf("FAILED, expected 0, got %d\n", j);
1166 printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()...");
1167 if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, j+1, "name2")) != -1) {
1168 printf("FAILED, expected -1, got %d\n", j);
1173 printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()...");
1174 if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0, "blah")) != -1) {
1175 printf("FAILED, expected -1, got %d\n", j);
1180 printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(first, copy)...");
1181 vc_replace_new_(&entry, vorbiscomment, "name3=field3new1", /*all=*/false);
1182 if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/false, /*copy=*/true)) {
1183 printf("FAILED, returned false\n");
1186 if(!mutils__compare_block(vorbiscomment, block))
1188 if(block->data.vorbis_comment.num_comments != 6) {
1189 printf("FAILED, expected 6 comments, got %u\n", block->data.vorbis_comment.num_comments);
1194 printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(all, copy)...");
1195 vc_replace_new_(&entry, vorbiscomment, "name3=field3new2", /*all=*/true);
1196 if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/true, /*copy=*/true)) {
1197 printf("FAILED, returned false\n");
1200 if(!mutils__compare_block(vorbiscomment, block))
1202 if(block->data.vorbis_comment.num_comments != 4) {
1203 printf("FAILED, expected 4 comments, got %u\n", block->data.vorbis_comment.num_comments);
1208 printf("testing FLAC__metadata_object_clone()... ");
1209 blockcopy = FLAC__metadata_object_clone(block);
1210 if(0 == blockcopy) {
1211 printf("FAILED, returned NULL\n");
1214 if(!mutils__compare_block(block, blockcopy))
1218 printf("testing FLAC__metadata_object_delete()... ");
1219 FLAC__metadata_object_delete(blockcopy);
1222 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on middle of array...");
1223 vc_delete_(vorbiscomment, 2);
1224 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
1225 printf("FAILED, returned false\n");
1228 if(!mutils__compare_block(vorbiscomment, block))
1232 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on end of array...");
1233 vc_delete_(vorbiscomment, 2);
1234 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
1235 printf("FAILED, returned false\n");
1238 if(!mutils__compare_block(vorbiscomment, block))
1242 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on beginning of array...");
1243 vc_delete_(vorbiscomment, 0);
1244 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 0)) {
1245 printf("FAILED, returned false\n");
1248 if(!mutils__compare_block(vorbiscomment, block))
1252 printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on non-empty array...");
1253 vc_insert_new_(&entry, vorbiscomment, 1, "rem0=val0");
1254 if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
1255 printf("FAILED, returned false\n");
1258 if(!mutils__compare_block(vorbiscomment, block))
1262 printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on non-empty array...");
1263 vc_insert_new_(&entry, vorbiscomment, 2, "rem0=val1");
1264 if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
1265 printf("FAILED, returned false\n");
1268 if(!mutils__compare_block(vorbiscomment, block))
1272 printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on non-empty array...");
1273 vc_insert_new_(&entry, vorbiscomment, 3, "rem0=val2");
1274 if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
1275 printf("FAILED, returned false\n");
1278 if(!mutils__compare_block(vorbiscomment, block))
1282 printf("testing FLAC__metadata_object_vorbiscomment_remove_entry_matching(\"blah\")...");
1283 if((j = FLAC__metadata_object_vorbiscomment_remove_entry_matching(block, "blah")) != 0) {
1284 printf("FAILED, expected 0, got %d\n", j);
1287 if(block->data.vorbis_comment.num_comments != 4) {
1288 printf("FAILED, expected 4 comments, got %u\n", block->data.vorbis_comment.num_comments);
1291 if(!mutils__compare_block(vorbiscomment, block))
1295 printf("testing FLAC__metadata_object_vorbiscomment_remove_entry_matching(\"rem0\")...");
1296 vc_delete_(vorbiscomment, 1);
1297 if((j = FLAC__metadata_object_vorbiscomment_remove_entry_matching(block, "rem0")) != 1) {
1298 printf("FAILED, expected 1, got %d\n", j);
1301 if(block->data.vorbis_comment.num_comments != 3) {
1302 printf("FAILED, expected 3 comments, got %u\n", block->data.vorbis_comment.num_comments);
1305 if(!mutils__compare_block(vorbiscomment, block))
1309 printf("testing FLAC__metadata_object_vorbiscomment_remove_entries_matching(\"blah\")...");
1310 if((j = FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, "blah")) != 0) {
1311 printf("FAILED, expected 0, got %d\n", j);
1314 if(block->data.vorbis_comment.num_comments != 3) {
1315 printf("FAILED, expected 3 comments, got %u\n", block->data.vorbis_comment.num_comments);
1318 if(!mutils__compare_block(vorbiscomment, block))
1322 printf("testing FLAC__metadata_object_vorbiscomment_remove_entries_matching(\"rem0\")...");
1323 vc_delete_(vorbiscomment, 1);
1324 vc_delete_(vorbiscomment, 1);
1325 if((j = FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, "rem0")) != 2) {
1326 printf("FAILED, expected 2, got %d\n", j);
1329 if(block->data.vorbis_comment.num_comments != 1) {
1330 printf("FAILED, expected 1 comments, got %u\n", block->data.vorbis_comment.num_comments);
1333 if(!mutils__compare_block(vorbiscomment, block))
1337 printf("testing FLAC__metadata_object_vorbiscomment_set_comment(copy)...");
1338 vc_set_new_(&entry, vorbiscomment, 0, "name5=field5");
1339 FLAC__metadata_object_vorbiscomment_set_comment(block, 0, entry, /*copy=*/true);
1340 if(!mutils__compare_block(vorbiscomment, block))
1344 printf("testing FLAC__metadata_object_vorbiscomment_set_vendor_string(copy)...");
1345 vc_set_vs_new_(&entry, vorbiscomment, "name6=field6");
1346 FLAC__metadata_object_vorbiscomment_set_vendor_string(block, entry, /*copy=*/true);
1347 if(!mutils__compare_block(vorbiscomment, block))
1351 printf("testing FLAC__metadata_object_delete()... ");
1352 FLAC__metadata_object_delete(vorbiscomment);
1353 FLAC__metadata_object_delete(block);
1357 printf("testing FLAC__metadata_object_new()... ");
1358 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
1360 printf("FAILED, returned NULL\n");
1365 printf("testing FLAC__metadata_object_clone()... ");
1366 vorbiscomment = FLAC__metadata_object_clone(block);
1367 if(0 == vorbiscomment) {
1368 printf("FAILED, returned NULL\n");
1371 if(!mutils__compare_block(vorbiscomment, block))
1375 printf("testing FLAC__metadata_object_vorbiscomment_append_comment(own) on empty array...");
1376 vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
1377 entry_clone_(&entry);
1378 if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/false)) {
1379 printf("FAILED, returned false\n");
1382 if(!mutils__compare_block(vorbiscomment, block))
1386 printf("testing FLAC__metadata_object_vorbiscomment_append_comment(own) on non-empty array...");
1387 vc_insert_new_(&entry, vorbiscomment, 1, "name2=field2");
1388 entry_clone_(&entry);
1389 if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/false)) {
1390 printf("FAILED, returned false\n");
1393 if(!mutils__compare_block(vorbiscomment, block))
1397 printf("testing FLAC__metadata_object_delete()... ");
1398 FLAC__metadata_object_delete(vorbiscomment);
1399 FLAC__metadata_object_delete(block);
1402 printf("testing FLAC__metadata_object_new()... ");
1403 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
1405 printf("FAILED, returned NULL\n");
1410 printf("testing FLAC__metadata_object_clone()... ");
1411 vorbiscomment = FLAC__metadata_object_clone(block);
1412 if(0 == vorbiscomment) {
1413 printf("FAILED, returned NULL\n");
1416 if(!mutils__compare_block(vorbiscomment, block))
1420 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on empty array...");
1421 vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
1422 entry_clone_(&entry);
1423 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/false)) {
1424 printf("FAILED, returned false\n");
1427 if(!mutils__compare_block(vorbiscomment, block))
1431 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on beginning of non-empty array...");
1432 vc_insert_new_(&entry, vorbiscomment, 0, "name2=field2");
1433 entry_clone_(&entry);
1434 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/false)) {
1435 printf("FAILED, returned false\n");
1438 if(!mutils__compare_block(vorbiscomment, block))
1442 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on middle of non-empty array...");
1443 vc_insert_new_(&entry, vorbiscomment, 1, "name3=field3");
1444 entry_clone_(&entry);
1445 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 1, entry, /*copy=*/false)) {
1446 printf("FAILED, returned false\n");
1449 if(!mutils__compare_block(vorbiscomment, block))
1453 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on end of non-empty array...");
1454 vc_insert_new_(&entry, vorbiscomment, 3, "name4=field4");
1455 entry_clone_(&entry);
1456 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 3, entry, /*copy=*/false)) {
1457 printf("FAILED, returned false\n");
1460 if(!mutils__compare_block(vorbiscomment, block))
1464 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on end of non-empty array...");
1465 vc_insert_new_(&entry, vorbiscomment, 4, "name3=field3dup1");
1466 entry_clone_(&entry);
1467 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 4, entry, /*copy=*/false)) {
1468 printf("FAILED, returned false\n");
1471 if(!mutils__compare_block(vorbiscomment, block))
1475 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on end of non-empty array...");
1476 vc_insert_new_(&entry, vorbiscomment, 5, "name3=field3dup1");
1477 entry_clone_(&entry);
1478 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 5, entry, /*copy=*/false)) {
1479 printf("FAILED, returned false\n");
1482 if(!mutils__compare_block(vorbiscomment, block))
1486 printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(first, own)...");
1487 vc_replace_new_(&entry, vorbiscomment, "name3=field3new1", /*all=*/false);
1488 entry_clone_(&entry);
1489 if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/false, /*copy=*/false)) {
1490 printf("FAILED, returned false\n");
1493 if(!mutils__compare_block(vorbiscomment, block))
1495 if(block->data.vorbis_comment.num_comments != 6) {
1496 printf("FAILED, expected 6 comments, got %u\n", block->data.vorbis_comment.num_comments);
1501 printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(all, own)...");
1502 vc_replace_new_(&entry, vorbiscomment, "name3=field3new2", /*all=*/true);
1503 entry_clone_(&entry);
1504 if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/true, /*copy=*/false)) {
1505 printf("FAILED, returned false\n");
1508 if(!mutils__compare_block(vorbiscomment, block))
1510 if(block->data.vorbis_comment.num_comments != 4) {
1511 printf("FAILED, expected 4 comments, got %u\n", block->data.vorbis_comment.num_comments);
1516 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on middle of array...");
1517 vc_delete_(vorbiscomment, 2);
1518 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
1519 printf("FAILED, returned false\n");
1522 if(!mutils__compare_block(vorbiscomment, block))
1526 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on end of array...");
1527 vc_delete_(vorbiscomment, 2);
1528 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
1529 printf("FAILED, returned false\n");
1532 if(!mutils__compare_block(vorbiscomment, block))
1536 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on beginning of array...");
1537 vc_delete_(vorbiscomment, 0);
1538 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 0)) {
1539 printf("FAILED, returned false\n");
1542 if(!mutils__compare_block(vorbiscomment, block))
1546 printf("testing FLAC__metadata_object_vorbiscomment_set_comment(own)...");
1547 vc_set_new_(&entry, vorbiscomment, 0, "name5=field5");
1548 entry_clone_(&entry);
1549 FLAC__metadata_object_vorbiscomment_set_comment(block, 0, entry, /*copy=*/false);
1550 if(!mutils__compare_block(vorbiscomment, block))
1554 printf("testing FLAC__metadata_object_vorbiscomment_set_vendor_string(own)...");
1555 vc_set_vs_new_(&entry, vorbiscomment, "name6=field6");
1556 entry_clone_(&entry);
1557 FLAC__metadata_object_vorbiscomment_set_vendor_string(block, entry, /*copy=*/false);
1558 if(!mutils__compare_block(vorbiscomment, block))
1562 printf("testing FLAC__metadata_object_delete()... ");
1563 FLAC__metadata_object_delete(vorbiscomment);
1564 FLAC__metadata_object_delete(block);
1568 printf("testing CUESHEET\n");
1571 FLAC__StreamMetadata_CueSheet_Track *track_, *trackcopy_;
1573 printf("testing FLAC__metadata_object_cuesheet_track_new()... ");
1574 track_ = FLAC__metadata_object_cuesheet_track_new();
1576 printf("FAILED, returned NULL\n");
1581 printf("testing FLAC__metadata_object_cuesheet_track_clone()... ");
1582 trackcopy_ = FLAC__metadata_object_cuesheet_track_clone(track_);
1583 if(0 == trackcopy_) {
1584 printf("FAILED, returned NULL\n");
1587 if(!compare_track_(trackcopy_, track_))
1591 printf("testing FLAC__metadata_object_cuesheet_track_delete()... ");
1592 FLAC__metadata_object_cuesheet_track_delete(trackcopy_);
1593 FLAC__metadata_object_cuesheet_track_delete(track_);
1598 printf("testing FLAC__metadata_object_new()... ");
1599 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET);
1601 printf("FAILED, returned NULL\n");
1605 FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
1606 FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
1607 FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN +
1608 FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
1609 FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
1611 if(block->length != expected_length) {
1612 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
1617 printf("testing FLAC__metadata_object_clone()... ");
1618 cuesheet = FLAC__metadata_object_clone(block);
1620 printf("FAILED, returned NULL\n");
1623 if(!mutils__compare_block(cuesheet, block))
1627 cs_resize_(cuesheet, 2);
1628 printf("testing FLAC__metadata_object_cuesheet_resize_tracks(grow to %u)...", cuesheet->data.cue_sheet.num_tracks);
1629 if(!FLAC__metadata_object_cuesheet_resize_tracks(block, cuesheet->data.cue_sheet.num_tracks)) {
1630 printf("FAILED, returned false\n");
1633 if(!mutils__compare_block(cuesheet, block))
1637 cs_resize_(cuesheet, 1);
1638 printf("testing FLAC__metadata_object_cuesheet_resize_tracks(shrink to %u)...", cuesheet->data.cue_sheet.num_tracks);
1639 if(!FLAC__metadata_object_cuesheet_resize_tracks(block, cuesheet->data.cue_sheet.num_tracks)) {
1640 printf("FAILED, returned false\n");
1643 if(!mutils__compare_block(cuesheet, block))
1647 cs_resize_(cuesheet, 0);
1648 printf("testing FLAC__metadata_object_cuesheet_resize_tracks(shrink to %u)...", cuesheet->data.cue_sheet.num_tracks);
1649 if(!FLAC__metadata_object_cuesheet_resize_tracks(block, cuesheet->data.cue_sheet.num_tracks)) {
1650 printf("FAILED, returned false\n");
1653 if(!mutils__compare_block(cuesheet, block))
1657 printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on empty array...");
1658 cs_insert_new_(&track, cuesheet, 0, 0, 1, "ABCDE1234567", false, false);
1659 if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/true)) {
1660 printf("FAILED, returned false\n");
1663 if(!mutils__compare_block(cuesheet, block))
1667 printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on beginning of non-empty array...");
1668 cs_insert_new_(&track, cuesheet, 0, 10, 2, "BBCDE1234567", false, false);
1669 if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/true)) {
1670 printf("FAILED, returned false\n");
1673 if(!mutils__compare_block(cuesheet, block))
1677 printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on middle of non-empty array...");
1678 cs_insert_new_(&track, cuesheet, 1, 20, 3, "CBCDE1234567", false, false);
1679 if(!FLAC__metadata_object_cuesheet_insert_track(block, 1, &track, /*copy=*/true)) {
1680 printf("FAILED, returned false\n");
1683 if(!mutils__compare_block(cuesheet, block))
1687 printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on end of non-empty array...");
1688 cs_insert_new_(&track, cuesheet, 3, 30, 4, "DBCDE1234567", false, false);
1689 if(!FLAC__metadata_object_cuesheet_insert_track(block, 3, &track, /*copy=*/true)) {
1690 printf("FAILED, returned false\n");
1693 if(!mutils__compare_block(cuesheet, block))
1697 printf("testing FLAC__metadata_object_cuesheet_insert_blank_track() on end of non-empty array...");
1698 cs_insert_new_(&track, cuesheet, 4, 0, 0, "\0\0\0\0\0\0\0\0\0\0\0\0", false, false);
1699 if(!FLAC__metadata_object_cuesheet_insert_blank_track(block, 4)) {
1700 printf("FAILED, returned false\n");
1703 if(!mutils__compare_block(cuesheet, block))
1707 printf("testing FLAC__metadata_object_clone()... ");
1708 blockcopy = FLAC__metadata_object_clone(block);
1709 if(0 == blockcopy) {
1710 printf("FAILED, returned NULL\n");
1713 if(!mutils__compare_block(block, blockcopy))
1717 printf("testing FLAC__metadata_object_delete()... ");
1718 FLAC__metadata_object_delete(blockcopy);
1721 printf("testing FLAC__metadata_object_cuesheet_delete_track() on end of array...");
1722 cs_delete_(cuesheet, 4);
1723 if(!FLAC__metadata_object_cuesheet_delete_track(block, 4)) {
1724 printf("FAILED, returned false\n");
1727 if(!mutils__compare_block(cuesheet, block))
1731 printf("testing FLAC__metadata_object_cuesheet_delete_track() on middle of array...");
1732 cs_delete_(cuesheet, 2);
1733 if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1734 printf("FAILED, returned false\n");
1737 if(!mutils__compare_block(cuesheet, block))
1741 printf("testing FLAC__metadata_object_cuesheet_delete_track() on end of array...");
1742 cs_delete_(cuesheet, 2);
1743 if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1744 printf("FAILED, returned false\n");
1747 if(!mutils__compare_block(cuesheet, block))
1751 printf("testing FLAC__metadata_object_cuesheet_delete_track() on beginning of array...");
1752 cs_delete_(cuesheet, 0);
1753 if(!FLAC__metadata_object_cuesheet_delete_track(block, 0)) {
1754 printf("FAILED, returned false\n");
1757 if(!mutils__compare_block(cuesheet, block))
1761 printf("testing FLAC__metadata_object_cuesheet_set_track(copy)...");
1762 cs_set_new_(&track, cuesheet, 0, 40, 5, "EBCDE1234567", false, false);
1763 FLAC__metadata_object_cuesheet_set_track(block, 0, &track, /*copy=*/true);
1764 if(!mutils__compare_block(cuesheet, block))
1768 tr_resize_(cuesheet, 0, 2);
1769 printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(grow to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices);
1770 if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) {
1771 printf("FAILED, returned false\n");
1774 if(!mutils__compare_block(cuesheet, block))
1778 tr_resize_(cuesheet, 0, 1);
1779 printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(shrink to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices);
1780 if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) {
1781 printf("FAILED, returned false\n");
1784 if(!mutils__compare_block(cuesheet, block))
1788 tr_resize_(cuesheet, 0, 0);
1789 printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(shrink to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices);
1790 if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) {
1791 printf("FAILED, returned false\n");
1794 if(!mutils__compare_block(cuesheet, block))
1800 printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on empty array...");
1801 tr_insert_new_(cuesheet, 0, 0, index);
1802 if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 0, index)) {
1803 printf("FAILED, returned false\n");
1806 if(!mutils__compare_block(cuesheet, block))
1812 printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on beginning of non-empty array...");
1813 tr_insert_new_(cuesheet, 0, 0, index);
1814 if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 0, index)) {
1815 printf("FAILED, returned false\n");
1818 if(!mutils__compare_block(cuesheet, block))
1824 printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on middle of non-empty array...");
1825 tr_insert_new_(cuesheet, 0, 1, index);
1826 if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 1, index)) {
1827 printf("FAILED, returned false\n");
1830 if(!mutils__compare_block(cuesheet, block))
1836 printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on end of non-empty array...");
1837 tr_insert_new_(cuesheet, 0, 3, index);
1838 if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 3, index)) {
1839 printf("FAILED, returned false\n");
1842 if(!mutils__compare_block(cuesheet, block))
1848 printf("testing FLAC__metadata_object_cuesheet_track_insert_blank_index() on end of non-empty array...");
1849 tr_insert_new_(cuesheet, 0, 4, index);
1850 if(!FLAC__metadata_object_cuesheet_track_insert_blank_index(block, 0, 4)) {
1851 printf("FAILED, returned false\n");
1854 if(!mutils__compare_block(cuesheet, block))
1858 printf("testing FLAC__metadata_object_clone()... ");
1859 blockcopy = FLAC__metadata_object_clone(block);
1860 if(0 == blockcopy) {
1861 printf("FAILED, returned NULL\n");
1864 if(!mutils__compare_block(block, blockcopy))
1868 printf("testing FLAC__metadata_object_delete()... ");
1869 FLAC__metadata_object_delete(blockcopy);
1872 printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on end of array...");
1873 tr_delete_(cuesheet, 0, 4);
1874 if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 4)) {
1875 printf("FAILED, returned false\n");
1878 if(!mutils__compare_block(cuesheet, block))
1882 printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on middle of array...");
1883 tr_delete_(cuesheet, 0, 2);
1884 if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 2)) {
1885 printf("FAILED, returned false\n");
1888 if(!mutils__compare_block(cuesheet, block))
1892 printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on end of array...");
1893 tr_delete_(cuesheet, 0, 2);
1894 if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 2)) {
1895 printf("FAILED, returned false\n");
1898 if(!mutils__compare_block(cuesheet, block))
1902 printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on beginning of array...");
1903 tr_delete_(cuesheet, 0, 0);
1904 if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 0)) {
1905 printf("FAILED, returned false\n");
1908 if(!mutils__compare_block(cuesheet, block))
1912 printf("testing FLAC__metadata_object_delete()... ");
1913 FLAC__metadata_object_delete(cuesheet);
1914 FLAC__metadata_object_delete(block);
1918 printf("testing FLAC__metadata_object_new()... ");
1919 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET);
1921 printf("FAILED, returned NULL\n");
1926 printf("testing FLAC__metadata_object_clone()... ");
1927 cuesheet = FLAC__metadata_object_clone(block);
1929 printf("FAILED, returned NULL\n");
1932 if(!mutils__compare_block(cuesheet, block))
1936 printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on empty array...");
1937 cs_insert_new_(&track, cuesheet, 0, 60, 7, "GBCDE1234567", false, false);
1938 track_clone_(&track);
1939 if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/false)) {
1940 printf("FAILED, returned false\n");
1943 if(!mutils__compare_block(cuesheet, block))
1947 printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on beginning of non-empty array...");
1948 cs_insert_new_(&track, cuesheet, 0, 70, 8, "HBCDE1234567", false, false);
1949 track_clone_(&track);
1950 if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/false)) {
1951 printf("FAILED, returned false\n");
1954 if(!mutils__compare_block(cuesheet, block))
1958 printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on middle of non-empty array...");
1959 cs_insert_new_(&track, cuesheet, 1, 80, 9, "IBCDE1234567", false, false);
1960 track_clone_(&track);
1961 if(!FLAC__metadata_object_cuesheet_insert_track(block, 1, &track, /*copy=*/false)) {
1962 printf("FAILED, returned false\n");
1965 if(!mutils__compare_block(cuesheet, block))
1969 printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on end of non-empty array...");
1970 cs_insert_new_(&track, cuesheet, 3, 90, 10, "JBCDE1234567", false, false);
1971 track_clone_(&track);
1972 if(!FLAC__metadata_object_cuesheet_insert_track(block, 3, &track, /*copy=*/false)) {
1973 printf("FAILED, returned false\n");
1976 if(!mutils__compare_block(cuesheet, block))
1980 printf("testing FLAC__metadata_object_cuesheet_delete_track() on middle of array...");
1981 cs_delete_(cuesheet, 2);
1982 if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1983 printf("FAILED, returned false\n");
1986 if(!mutils__compare_block(cuesheet, block))
1990 printf("testing FLAC__metadata_object_cuesheet_delete_track() on end of array...");
1991 cs_delete_(cuesheet, 2);
1992 if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1993 printf("FAILED, returned false\n");
1996 if(!mutils__compare_block(cuesheet, block))
2000 printf("testing FLAC__metadata_object_cuesheet_delete_track() on beginning of array...");
2001 cs_delete_(cuesheet, 0);
2002 if(!FLAC__metadata_object_cuesheet_delete_track(block, 0)) {
2003 printf("FAILED, returned false\n");
2006 if(!mutils__compare_block(cuesheet, block))
2010 printf("testing FLAC__metadata_object_cuesheet_set_track(own)...");
2011 cs_set_new_(&track, cuesheet, 0, 100, 11, "KBCDE1234567", false, false);
2012 track_clone_(&track);
2013 FLAC__metadata_object_cuesheet_set_track(block, 0, &track, /*copy=*/false);
2014 if(!mutils__compare_block(cuesheet, block))
2018 printf("testing FLAC__metadata_object_cuesheet_is_legal()...");
2020 const char *violation;
2021 if(FLAC__metadata_object_cuesheet_is_legal(block, /*check_cd_da_subset=*/true, &violation)) {
2022 printf("FAILED, returned true when expecting false\n");
2025 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2028 printf("testing FLAC__metadata_object_delete()... ");
2029 FLAC__metadata_object_delete(cuesheet);
2030 FLAC__metadata_object_delete(block);
2034 printf("testing PICTURE\n");
2036 printf("testing FLAC__metadata_object_new()... ");
2037 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PICTURE);
2039 printf("FAILED, returned NULL\n");
2043 FLAC__STREAM_METADATA_PICTURE_TYPE_LEN +
2044 FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN +
2045 FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN +
2046 FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN +
2047 FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN +
2048 FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN +
2049 FLAC__STREAM_METADATA_PICTURE_COLORS_LEN +
2050 FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN
2052 if(block->length != expected_length) {
2053 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
2058 printf("testing FLAC__metadata_object_clone()... ");
2059 picture = FLAC__metadata_object_clone(block);
2061 printf("FAILED, returned NULL\n");
2064 if(!mutils__compare_block(picture, block))
2068 pi_set_mime_type(picture, "image/png\t");
2069 printf("testing FLAC__metadata_object_picture_set_mime_type(copy)...");
2070 if(!FLAC__metadata_object_picture_set_mime_type(block, "image/png\t", /*copy=*/true)) {
2071 printf("FAILED, returned false\n");
2074 if(!mutils__compare_block(picture, block))
2078 printf("testing FLAC__metadata_object_picture_is_legal()...");
2080 const char *violation;
2081 if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
2082 printf("FAILED, returned true when expecting false\n");
2085 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2088 pi_set_mime_type(picture, "image/png");
2089 printf("testing FLAC__metadata_object_picture_set_mime_type(copy)...");
2090 if(!FLAC__metadata_object_picture_set_mime_type(block, "image/png", /*copy=*/true)) {
2091 printf("FAILED, returned false\n");
2094 if(!mutils__compare_block(picture, block))
2098 printf("testing FLAC__metadata_object_picture_is_legal()...");
2100 const char *violation;
2101 if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
2102 printf("FAILED, returned false, violation=\"%s\"\n", violation);
2108 pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION\xff");
2109 printf("testing FLAC__metadata_object_picture_set_description(copy)...");
2110 if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)"DESCRIPTION\xff", /*copy=*/true)) {
2111 printf("FAILED, returned false\n");
2114 if(!mutils__compare_block(picture, block))
2118 printf("testing FLAC__metadata_object_picture_is_legal()...");
2120 const char *violation;
2121 if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
2122 printf("FAILED, returned true when expecting false\n");
2125 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2128 pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION");
2129 printf("testing FLAC__metadata_object_picture_set_description(copy)...");
2130 if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)"DESCRIPTION", /*copy=*/true)) {
2131 printf("FAILED, returned false\n");
2134 if(!mutils__compare_block(picture, block))
2138 printf("testing FLAC__metadata_object_picture_is_legal()...");
2140 const char *violation;
2141 if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
2142 printf("FAILED, returned false, violation=\"%s\"\n", violation);
2149 pi_set_data(picture, (const FLAC__byte*)"PNGDATA", strlen("PNGDATA"));
2150 printf("testing FLAC__metadata_object_picture_set_data(copy)...");
2151 if(!FLAC__metadata_object_picture_set_data(block, (FLAC__byte*)"PNGDATA", strlen("PNGDATA"), /*copy=*/true)) {
2152 printf("FAILED, returned false\n");
2155 if(!mutils__compare_block(picture, block))
2159 printf("testing FLAC__metadata_object_clone()... ");
2160 blockcopy = FLAC__metadata_object_clone(block);
2161 if(0 == blockcopy) {
2162 printf("FAILED, returned NULL\n");
2165 if(!mutils__compare_block(block, blockcopy))
2169 printf("testing FLAC__metadata_object_delete()... ");
2170 FLAC__metadata_object_delete(blockcopy);
2173 pi_set_mime_type(picture, "image/png\t");
2174 printf("testing FLAC__metadata_object_picture_set_mime_type(own)...");
2175 if(!FLAC__metadata_object_picture_set_mime_type(block, strdup("image/png\t"), /*copy=*/false)) {
2176 printf("FAILED, returned false\n");
2179 if(!mutils__compare_block(picture, block))
2183 printf("testing FLAC__metadata_object_picture_is_legal()...");
2185 const char *violation;
2186 if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
2187 printf("FAILED, returned true when expecting false\n");
2190 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2193 pi_set_mime_type(picture, "image/png");
2194 printf("testing FLAC__metadata_object_picture_set_mime_type(own)...");
2195 if(!FLAC__metadata_object_picture_set_mime_type(block, strdup("image/png"), /*copy=*/false)) {
2196 printf("FAILED, returned false\n");
2199 if(!mutils__compare_block(picture, block))
2203 printf("testing FLAC__metadata_object_picture_is_legal()...");
2205 const char *violation;
2206 if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
2207 printf("FAILED, returned false, violation=\"%s\"\n", violation);
2213 pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION\xff");
2214 printf("testing FLAC__metadata_object_picture_set_description(own)...");
2215 if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)strdup("DESCRIPTION\xff"), /*copy=*/false)) {
2216 printf("FAILED, returned false\n");
2219 if(!mutils__compare_block(picture, block))
2223 printf("testing FLAC__metadata_object_picture_is_legal()...");
2225 const char *violation;
2226 if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
2227 printf("FAILED, returned true when expecting false\n");
2230 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2233 pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION");
2234 printf("testing FLAC__metadata_object_picture_set_description(own)...");
2235 if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)strdup("DESCRIPTION"), /*copy=*/false)) {
2236 printf("FAILED, returned false\n");
2239 if(!mutils__compare_block(picture, block))
2243 printf("testing FLAC__metadata_object_picture_is_legal()...");
2245 const char *violation;
2246 if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
2247 printf("FAILED, returned false, violation=\"%s\"\n", violation);
2253 pi_set_data(picture, (const FLAC__byte*)"PNGDATA", strlen("PNGDATA"));
2254 printf("testing FLAC__metadata_object_picture_set_data(own)...");
2255 if(!FLAC__metadata_object_picture_set_data(block, (FLAC__byte*)strdup("PNGDATA"), strlen("PNGDATA"), /*copy=*/false)) {
2256 printf("FAILED, returned false\n");
2259 if(!mutils__compare_block(picture, block))
2263 printf("testing FLAC__metadata_object_clone()... ");
2264 blockcopy = FLAC__metadata_object_clone(block);
2265 if(0 == blockcopy) {
2266 printf("FAILED, returned NULL\n");
2269 if(!mutils__compare_block(block, blockcopy))
2273 printf("testing FLAC__metadata_object_delete()... ");
2274 FLAC__metadata_object_delete(blockcopy);
2277 printf("testing FLAC__metadata_object_delete()... ");
2278 FLAC__metadata_object_delete(picture);
2279 FLAC__metadata_object_delete(block);