1 /* test_libFLAC - Unit tester for libFLAC
2 * Copyright (C) 2002,2003,2004,2005,2006,2007 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"
27 #include <stdlib.h> /* for malloc() */
28 #include <string.h> /* for memcmp() */
30 static FLAC__byte *make_dummydata_(FLAC__byte *dummydata, unsigned len)
34 if(0 == (ret = (FLAC__byte*)malloc(len))) {
35 printf("FAILED, malloc error\n");
39 memcpy(ret, dummydata, len);
44 static FLAC__bool compare_track_(const FLAC__StreamMetadata_CueSheet_Track *from, const FLAC__StreamMetadata_CueSheet_Track *to)
48 if(from->offset != to->offset) {
50 printf("FAILED, track offset mismatch, expected %I64u, got %I64u\n", to->offset, from->offset);
52 printf("FAILED, track offset mismatch, expected %llu, got %llu\n", (unsigned long long)to->offset, (unsigned long long)from->offset);
56 if(from->number != to->number) {
57 printf("FAILED, track number mismatch, expected %u, got %u\n", (unsigned)to->number, (unsigned)from->number);
60 if(0 != strcmp(from->isrc, to->isrc)) {
61 printf("FAILED, track number mismatch, expected %s, got %s\n", to->isrc, from->isrc);
64 if(from->type != to->type) {
65 printf("FAILED, track type mismatch, expected %u, got %u\n", (unsigned)to->type, (unsigned)from->type);
68 if(from->pre_emphasis != to->pre_emphasis) {
69 printf("FAILED, track pre_emphasis mismatch, expected %u, got %u\n", (unsigned)to->pre_emphasis, (unsigned)from->pre_emphasis);
72 if(from->num_indices != to->num_indices) {
73 printf("FAILED, track num_indices mismatch, expected %u, got %u\n", (unsigned)to->num_indices, (unsigned)from->num_indices);
76 if(0 == to->indices || 0 == from->indices) {
77 if(to->indices != from->indices) {
78 printf("FAILED, track indices mismatch\n");
83 for(i = 0; i < to->num_indices; i++) {
84 if(from->indices[i].offset != to->indices[i].offset) {
86 printf("FAILED, track indices[%u].offset mismatch, expected %I64u, got %I64u\n", i, to->indices[i].offset, from->indices[i].offset);
88 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);
92 if(from->indices[i].number != to->indices[i].number) {
93 printf("FAILED, track indices[%u].number mismatch, expected %u, got %u\n", i, (unsigned)to->indices[i].number, (unsigned)from->indices[i].number);
102 static FLAC__bool compare_seekpoint_array_(const FLAC__StreamMetadata_SeekPoint *from, const FLAC__StreamMetadata_SeekPoint *to, unsigned n)
106 FLAC__ASSERT(0 != from);
107 FLAC__ASSERT(0 != to);
109 for(i = 0; i < n; i++) {
110 if(from[i].sample_number != to[i].sample_number) {
112 printf("FAILED, point[%u].sample_number mismatch, expected %I64u, got %I64u\n", i, to[i].sample_number, from[i].sample_number);
114 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);
118 if(from[i].stream_offset != to[i].stream_offset) {
120 printf("FAILED, point[%u].stream_offset mismatch, expected %I64u, got %I64u\n", i, to[i].stream_offset, from[i].stream_offset);
122 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);
126 if(from[i].frame_samples != to[i].frame_samples) {
127 printf("FAILED, point[%u].frame_samples mismatch, expected %u, got %u\n", i, to[i].frame_samples, from[i].frame_samples);
135 static FLAC__bool check_seektable_(const FLAC__StreamMetadata *block, unsigned num_points, const FLAC__StreamMetadata_SeekPoint *array)
137 const unsigned expected_length = num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
139 if(block->length != expected_length) {
140 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
143 if(block->data.seek_table.num_points != num_points) {
144 printf("FAILED, expected %u point, got %u\n", num_points, block->data.seek_table.num_points);
148 if(0 != block->data.seek_table.points) {
149 printf("FAILED, 'points' pointer is not null\n");
154 if(!compare_seekpoint_array_(block->data.seek_table.points, array, num_points))
162 static void entry_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, const char *field)
164 entry->length = strlen(field);
165 entry->entry = (FLAC__byte*)malloc(entry->length+1);
166 FLAC__ASSERT(0 != entry->entry);
167 memcpy(entry->entry, field, entry->length);
168 entry->entry[entry->length] = '\0';
171 static void entry_clone_(FLAC__StreamMetadata_VorbisComment_Entry *entry)
173 FLAC__byte *x = (FLAC__byte*)malloc(entry->length+1);
174 FLAC__ASSERT(0 != x);
175 memcpy(x, entry->entry, entry->length);
176 x[entry->length] = '\0';
180 static void vc_calc_len_(FLAC__StreamMetadata *block)
182 const FLAC__StreamMetadata_VorbisComment *vc = &block->data.vorbis_comment;
185 block->length = FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
186 block->length += vc->vendor_string.length;
187 block->length += FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8;
188 for(i = 0; i < vc->num_comments; i++) {
189 block->length += FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
190 block->length += vc->comments[i].length;
194 static void vc_resize_(FLAC__StreamMetadata *block, unsigned num)
196 FLAC__StreamMetadata_VorbisComment *vc = &block->data.vorbis_comment;
198 if(vc->num_comments != 0) {
199 FLAC__ASSERT(0 != vc->comments);
200 if(num < vc->num_comments) {
202 for(i = num; i < vc->num_comments; i++) {
203 if(0 != vc->comments[i].entry)
204 free(vc->comments[i].entry);
209 if(0 != vc->comments) {
215 vc->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)realloc(vc->comments, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*num);
216 FLAC__ASSERT(0 != vc->comments);
217 if(num > vc->num_comments)
218 memset(vc->comments+vc->num_comments, 0, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(num-vc->num_comments));
221 vc->num_comments = num;
225 static int vc_find_from_(FLAC__StreamMetadata *block, const char *name, unsigned start)
227 const unsigned n = strlen(name);
229 for(i = start; i < block->data.vorbis_comment.num_comments; i++) {
230 const FLAC__StreamMetadata_VorbisComment_Entry *entry = &block->data.vorbis_comment.comments[i];
231 if(entry->length > n && 0 == strncmp((const char *)entry->entry, name, n) && entry->entry[n] == '=')
237 static void vc_set_vs_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, const char *field)
239 if(0 != block->data.vorbis_comment.vendor_string.entry)
240 free(block->data.vorbis_comment.vendor_string.entry);
241 entry_new_(entry, field);
242 block->data.vorbis_comment.vendor_string = *entry;
246 static void vc_set_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, unsigned pos, const char *field)
248 if(0 != block->data.vorbis_comment.comments[pos].entry)
249 free(block->data.vorbis_comment.comments[pos].entry);
250 entry_new_(entry, field);
251 block->data.vorbis_comment.comments[pos] = *entry;
255 static void vc_insert_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, unsigned pos, const char *field)
257 vc_resize_(block, block->data.vorbis_comment.num_comments+1);
258 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));
259 memset(&block->data.vorbis_comment.comments[pos], 0, sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
260 vc_set_new_(entry, block, pos, field);
264 static void vc_delete_(FLAC__StreamMetadata *block, unsigned pos)
266 if(0 != block->data.vorbis_comment.comments[pos].entry)
267 free(block->data.vorbis_comment.comments[pos].entry);
268 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));
269 block->data.vorbis_comment.comments[block->data.vorbis_comment.num_comments-1].entry = 0;
270 block->data.vorbis_comment.comments[block->data.vorbis_comment.num_comments-1].length = 0;
271 vc_resize_(block, block->data.vorbis_comment.num_comments-1);
275 static void vc_replace_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, const char *field, FLAC__bool all)
278 char field_name[256];
279 const char *eq = strchr(field, '=');
280 FLAC__ASSERT(eq>field && (unsigned)(eq-field) < sizeof(field_name));
281 memcpy(field_name, field, eq-field);
282 field_name[eq-field]='\0';
284 index = vc_find_from_(block, field_name, 0);
286 vc_insert_new_(entry, block, block->data.vorbis_comment.num_comments, field);
288 vc_set_new_(entry, block, (unsigned)index, field);
290 for(index = index+1; index >= 0 && (unsigned)index < block->data.vorbis_comment.num_comments; )
291 if((index = vc_find_from_(block, field_name, (unsigned)index)) >= 0)
292 vc_delete_(block, (unsigned)index);
299 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)
301 track->offset = offset;
302 track->number = number;
303 memcpy(track->isrc, isrc, sizeof(track->isrc));
305 track->pre_emphasis = pre_em;
306 track->num_indices = 0;
310 static void track_clone_(FLAC__StreamMetadata_CueSheet_Track *track)
312 if(track->num_indices > 0) {
313 size_t bytes = sizeof(FLAC__StreamMetadata_CueSheet_Index) * track->num_indices;
314 FLAC__StreamMetadata_CueSheet_Index *x = (FLAC__StreamMetadata_CueSheet_Index*)malloc(bytes);
315 FLAC__ASSERT(0 != x);
316 memcpy(x, track->indices, bytes);
321 static void cs_calc_len_(FLAC__StreamMetadata *block)
323 const FLAC__StreamMetadata_CueSheet *cs = &block->data.cue_sheet;
327 FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
328 FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
329 FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN +
330 FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
331 FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
333 block->length += cs->num_tracks * (
334 FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN +
335 FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN +
336 FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN +
337 FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN +
338 FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN +
339 FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN +
340 FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN
342 for(i = 0; i < cs->num_tracks; i++) {
343 block->length += cs->tracks[i].num_indices * (
344 FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN +
345 FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN +
346 FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN
351 static void tr_resize_(FLAC__StreamMetadata *block, unsigned track_num, unsigned num)
353 FLAC__StreamMetadata_CueSheet_Track *tr;
355 FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
357 tr = &block->data.cue_sheet.tracks[track_num];
359 if(tr->num_indices != 0) {
360 FLAC__ASSERT(0 != tr->indices);
363 if(0 != tr->indices) {
369 tr->indices = (FLAC__StreamMetadata_CueSheet_Index*)realloc(tr->indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)*num);
370 FLAC__ASSERT(0 != tr->indices);
371 if(num > tr->num_indices)
372 memset(tr->indices+tr->num_indices, 0, sizeof(FLAC__StreamMetadata_CueSheet_Index)*(num-tr->num_indices));
375 tr->num_indices = num;
379 static void tr_set_new_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos, FLAC__StreamMetadata_CueSheet_Index index)
381 FLAC__StreamMetadata_CueSheet_Track *tr;
383 FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
385 tr = &block->data.cue_sheet.tracks[track_num];
387 FLAC__ASSERT(pos < tr->num_indices);
389 tr->indices[pos] = index;
394 static void tr_insert_new_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos, FLAC__StreamMetadata_CueSheet_Index index)
396 FLAC__StreamMetadata_CueSheet_Track *tr;
398 FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
400 tr = &block->data.cue_sheet.tracks[track_num];
402 FLAC__ASSERT(pos <= tr->num_indices);
404 tr_resize_(block, track_num, tr->num_indices+1);
405 memmove(&tr->indices[pos+1], &tr->indices[pos], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(tr->num_indices-1-pos));
406 tr_set_new_(block, track_num, pos, index);
410 static void tr_delete_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos)
412 FLAC__StreamMetadata_CueSheet_Track *tr;
414 FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
416 tr = &block->data.cue_sheet.tracks[track_num];
418 FLAC__ASSERT(pos <= tr->num_indices);
420 memmove(&tr->indices[pos], &tr->indices[pos+1], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(tr->num_indices-pos-1));
421 tr_resize_(block, track_num, tr->num_indices-1);
425 static void cs_resize_(FLAC__StreamMetadata *block, unsigned num)
427 FLAC__StreamMetadata_CueSheet *cs = &block->data.cue_sheet;
429 if(cs->num_tracks != 0) {
430 FLAC__ASSERT(0 != cs->tracks);
431 if(num < cs->num_tracks) {
433 for(i = num; i < cs->num_tracks; i++) {
434 if(0 != cs->tracks[i].indices)
435 free(cs->tracks[i].indices);
440 if(0 != cs->tracks) {
446 cs->tracks = (FLAC__StreamMetadata_CueSheet_Track*)realloc(cs->tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)*num);
447 FLAC__ASSERT(0 != cs->tracks);
448 if(num > cs->num_tracks)
449 memset(cs->tracks+cs->num_tracks, 0, sizeof(FLAC__StreamMetadata_CueSheet_Track)*(num-cs->num_tracks));
452 cs->num_tracks = num;
456 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)
458 track_new_(track, offset, number, isrc, data, pre_em);
459 block->data.cue_sheet.tracks[pos] = *track;
463 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)
465 cs_resize_(block, block->data.cue_sheet.num_tracks+1);
466 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));
467 cs_set_new_(track, block, pos, offset, number, isrc, data, pre_em);
471 static void cs_delete_(FLAC__StreamMetadata *block, unsigned pos)
473 if(0 != block->data.cue_sheet.tracks[pos].indices)
474 free(block->data.cue_sheet.tracks[pos].indices);
475 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));
476 block->data.cue_sheet.tracks[block->data.cue_sheet.num_tracks-1].indices = 0;
477 block->data.cue_sheet.tracks[block->data.cue_sheet.num_tracks-1].num_indices = 0;
478 cs_resize_(block, block->data.cue_sheet.num_tracks-1);
482 static void pi_set_mime_type(FLAC__StreamMetadata *block, const char *s)
484 if(block->data.picture.mime_type) {
485 block->length -= strlen(block->data.picture.mime_type);
486 free(block->data.picture.mime_type);
488 block->data.picture.mime_type = strdup(s);
489 FLAC__ASSERT(block->data.picture.mime_type);
490 block->length += strlen(block->data.picture.mime_type);
493 static void pi_set_description(FLAC__StreamMetadata *block, const FLAC__byte *s)
495 if(block->data.picture.description) {
496 block->length -= strlen((const char *)block->data.picture.description);
497 free(block->data.picture.description);
499 block->data.picture.description = (FLAC__byte*)strdup((const char *)s);
500 FLAC__ASSERT(block->data.picture.description);
501 block->length += strlen((const char *)block->data.picture.description);
504 static void pi_set_data(FLAC__StreamMetadata *block, const FLAC__byte *data, FLAC__uint32 len)
506 if(block->data.picture.data) {
507 block->length -= block->data.picture.data_length;
508 free(block->data.picture.data);
510 block->data.picture.data = (FLAC__byte*)strdup((const char *)data);
511 FLAC__ASSERT(block->data.picture.data);
512 block->data.picture.data_length = len;
513 block->length += len;
516 FLAC__bool test_metadata_object(void)
518 FLAC__StreamMetadata *block, *blockcopy, *vorbiscomment, *cuesheet, *picture;
519 FLAC__StreamMetadata_SeekPoint seekpoint_array[14];
520 FLAC__StreamMetadata_VorbisComment_Entry entry;
521 FLAC__StreamMetadata_CueSheet_Index index;
522 FLAC__StreamMetadata_CueSheet_Track track;
523 unsigned i, expected_length, seekpoints;
525 static FLAC__byte dummydata[4] = { 'a', 'b', 'c', 'd' };
527 printf("\n+++ libFLAC unit test: metadata objects\n\n");
530 printf("testing STREAMINFO\n");
532 printf("testing FLAC__metadata_object_new()... ");
533 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_STREAMINFO);
535 printf("FAILED, returned NULL\n");
538 expected_length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
539 if(block->length != expected_length) {
540 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
545 printf("testing FLAC__metadata_object_clone()... ");
546 blockcopy = FLAC__metadata_object_clone(block);
548 printf("FAILED, returned NULL\n");
551 if(!mutils__compare_block(block, blockcopy))
555 printf("testing FLAC__metadata_object_delete()... ");
556 FLAC__metadata_object_delete(blockcopy);
557 FLAC__metadata_object_delete(block);
561 printf("testing PADDING\n");
563 printf("testing FLAC__metadata_object_new()... ");
564 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING);
566 printf("FAILED, returned NULL\n");
570 if(block->length != expected_length) {
571 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
576 printf("testing FLAC__metadata_object_clone()... ");
577 blockcopy = FLAC__metadata_object_clone(block);
579 printf("FAILED, returned NULL\n");
582 if(!mutils__compare_block(block, blockcopy))
586 printf("testing FLAC__metadata_object_delete()... ");
587 FLAC__metadata_object_delete(blockcopy);
588 FLAC__metadata_object_delete(block);
592 printf("testing APPLICATION\n");
594 printf("testing FLAC__metadata_object_new()... ");
595 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION);
597 printf("FAILED, returned NULL\n");
600 expected_length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
601 if(block->length != expected_length) {
602 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
607 printf("testing FLAC__metadata_object_clone()... ");
608 blockcopy = FLAC__metadata_object_clone(block);
610 printf("FAILED, returned NULL\n");
613 if(!mutils__compare_block(block, blockcopy))
617 printf("testing FLAC__metadata_object_delete()... ");
618 FLAC__metadata_object_delete(blockcopy);
621 printf("testing FLAC__metadata_object_application_set_data(copy)... ");
622 if(!FLAC__metadata_object_application_set_data(block, dummydata, sizeof(dummydata), true/*copy*/)) {
623 printf("FAILED, returned false\n");
626 expected_length = (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) + sizeof(dummydata);
627 if(block->length != expected_length) {
628 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
631 if(0 != memcmp(block->data.application.data, dummydata, sizeof(dummydata))) {
632 printf("FAILED, data mismatch\n");
637 printf("testing FLAC__metadata_object_clone()... ");
638 blockcopy = FLAC__metadata_object_clone(block);
640 printf("FAILED, returned NULL\n");
643 if(!mutils__compare_block(block, blockcopy))
647 printf("testing FLAC__metadata_object_delete()... ");
648 FLAC__metadata_object_delete(blockcopy);
651 printf("testing FLAC__metadata_object_application_set_data(own)... ");
652 if(!FLAC__metadata_object_application_set_data(block, make_dummydata_(dummydata, sizeof(dummydata)), sizeof(dummydata), false/*own*/)) {
653 printf("FAILED, returned false\n");
656 expected_length = (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) + sizeof(dummydata);
657 if(block->length != expected_length) {
658 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
661 if(0 != memcmp(block->data.application.data, dummydata, sizeof(dummydata))) {
662 printf("FAILED, data mismatch\n");
667 printf("testing FLAC__metadata_object_clone()... ");
668 blockcopy = FLAC__metadata_object_clone(block);
670 printf("FAILED, returned NULL\n");
673 if(!mutils__compare_block(block, blockcopy))
677 printf("testing FLAC__metadata_object_delete()... ");
678 FLAC__metadata_object_delete(blockcopy);
679 FLAC__metadata_object_delete(block);
683 printf("testing SEEKTABLE\n");
685 for(i = 0; i < sizeof(seekpoint_array) / sizeof(FLAC__StreamMetadata_SeekPoint); i++) {
686 seekpoint_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
687 seekpoint_array[i].stream_offset = 0;
688 seekpoint_array[i].frame_samples = 0;
692 printf("testing FLAC__metadata_object_new()... ");
693 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE);
695 printf("FAILED, returned NULL\n");
698 if(!check_seektable_(block, seekpoints, 0))
701 printf("testing FLAC__metadata_object_clone()... ");
702 blockcopy = FLAC__metadata_object_clone(block);
704 printf("FAILED, returned NULL\n");
707 if(!mutils__compare_block(block, blockcopy))
711 printf("testing FLAC__metadata_object_delete()... ");
712 FLAC__metadata_object_delete(blockcopy);
716 printf("testing FLAC__metadata_object_seektable_resize_points(grow to %u)...", seekpoints);
717 if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
718 printf("FAILED, returned false\n");
721 if(!check_seektable_(block, seekpoints, seekpoint_array))
725 printf("testing FLAC__metadata_object_seektable_resize_points(shrink to %u)...", seekpoints);
726 if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
727 printf("FAILED, returned false\n");
730 if(!check_seektable_(block, seekpoints, seekpoint_array))
733 printf("testing FLAC__metadata_object_seektable_is_legal()...");
734 if(!FLAC__metadata_object_seektable_is_legal(block)) {
735 printf("FAILED, returned false\n");
741 printf("testing FLAC__metadata_object_seektable_resize_points(shrink to %u)...", seekpoints);
742 if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
743 printf("FAILED, returned false\n");
746 if(!check_seektable_(block, seekpoints, 0))
750 printf("testing FLAC__metadata_object_seektable_insert_point() on empty array...");
751 if(!FLAC__metadata_object_seektable_insert_point(block, 0, seekpoint_array[0])) {
752 printf("FAILED, returned false\n");
755 if(!check_seektable_(block, seekpoints, seekpoint_array))
758 seekpoint_array[0].sample_number = 1;
760 printf("testing FLAC__metadata_object_seektable_insert_point() on beginning of non-empty array...");
761 if(!FLAC__metadata_object_seektable_insert_point(block, 0, seekpoint_array[0])) {
762 printf("FAILED, returned false\n");
765 if(!check_seektable_(block, seekpoints, seekpoint_array))
768 seekpoint_array[1].sample_number = 2;
770 printf("testing FLAC__metadata_object_seektable_insert_point() on middle of non-empty array...");
771 if(!FLAC__metadata_object_seektable_insert_point(block, 1, seekpoint_array[1])) {
772 printf("FAILED, returned false\n");
775 if(!check_seektable_(block, seekpoints, seekpoint_array))
778 seekpoint_array[3].sample_number = 3;
780 printf("testing FLAC__metadata_object_seektable_insert_point() on end of non-empty array...");
781 if(!FLAC__metadata_object_seektable_insert_point(block, 3, seekpoint_array[3])) {
782 printf("FAILED, returned false\n");
785 if(!check_seektable_(block, seekpoints, seekpoint_array))
788 printf("testing FLAC__metadata_object_clone()... ");
789 blockcopy = FLAC__metadata_object_clone(block);
791 printf("FAILED, returned NULL\n");
794 if(!mutils__compare_block(block, blockcopy))
798 printf("testing FLAC__metadata_object_delete()... ");
799 FLAC__metadata_object_delete(blockcopy);
802 seekpoint_array[2].sample_number = seekpoint_array[3].sample_number;
804 printf("testing FLAC__metadata_object_seektable_delete_point() on middle of array...");
805 if(!FLAC__metadata_object_seektable_delete_point(block, 2)) {
806 printf("FAILED, returned false\n");
809 if(!check_seektable_(block, seekpoints, seekpoint_array))
813 printf("testing FLAC__metadata_object_seektable_delete_point() on end of array...");
814 if(!FLAC__metadata_object_seektable_delete_point(block, 2)) {
815 printf("FAILED, returned false\n");
818 if(!check_seektable_(block, seekpoints, seekpoint_array))
822 printf("testing FLAC__metadata_object_seektable_delete_point() on beginning of array...");
823 if(!FLAC__metadata_object_seektable_delete_point(block, 0)) {
824 printf("FAILED, returned false\n");
827 if(!check_seektable_(block, seekpoints, seekpoint_array+1))
830 printf("testing FLAC__metadata_object_seektable_set_point()...");
831 FLAC__metadata_object_seektable_set_point(block, 0, seekpoint_array[0]);
832 if(!check_seektable_(block, seekpoints, seekpoint_array))
835 printf("testing FLAC__metadata_object_delete()... ");
836 FLAC__metadata_object_delete(block);
839 /* seektable template functions */
841 for(i = 0; i < sizeof(seekpoint_array) / sizeof(FLAC__StreamMetadata_SeekPoint); i++) {
842 seekpoint_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
843 seekpoint_array[i].stream_offset = 0;
844 seekpoint_array[i].frame_samples = 0;
848 printf("testing FLAC__metadata_object_new()... ");
849 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE);
851 printf("FAILED, returned NULL\n");
854 if(!check_seektable_(block, seekpoints, 0))
858 printf("testing FLAC__metadata_object_seekpoint_template_append_placeholders()... ");
859 if(!FLAC__metadata_object_seektable_template_append_placeholders(block, 2)) {
860 printf("FAILED, returned false\n");
863 if(!check_seektable_(block, seekpoints, seekpoint_array))
866 seekpoint_array[seekpoints++].sample_number = 7;
867 printf("testing FLAC__metadata_object_seekpoint_template_append_point()... ");
868 if(!FLAC__metadata_object_seektable_template_append_point(block, 7)) {
869 printf("FAILED, returned false\n");
872 if(!check_seektable_(block, seekpoints, seekpoint_array))
876 FLAC__uint64 nums[2] = { 3, 7 };
877 seekpoint_array[seekpoints++].sample_number = nums[0];
878 seekpoint_array[seekpoints++].sample_number = nums[1];
879 printf("testing FLAC__metadata_object_seekpoint_template_append_points()... ");
880 if(!FLAC__metadata_object_seektable_template_append_points(block, nums, sizeof(nums)/sizeof(FLAC__uint64))) {
881 printf("FAILED, returned false\n");
884 if(!check_seektable_(block, seekpoints, seekpoint_array))
888 seekpoint_array[seekpoints++].sample_number = 0;
889 seekpoint_array[seekpoints++].sample_number = 10;
890 seekpoint_array[seekpoints++].sample_number = 20;
891 printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points()... ");
892 if(!FLAC__metadata_object_seektable_template_append_spaced_points(block, 3, 30)) {
893 printf("FAILED, returned false\n");
896 if(!check_seektable_(block, seekpoints, seekpoint_array))
900 seekpoint_array[0].sample_number = 0;
901 seekpoint_array[1].sample_number = 3;
902 seekpoint_array[2].sample_number = 7;
903 seekpoint_array[3].sample_number = 10;
904 seekpoint_array[4].sample_number = 20;
905 seekpoint_array[5].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
906 seekpoint_array[6].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
907 printf("testing FLAC__metadata_object_seekpoint_template_sort(compact=true)... ");
908 if(!FLAC__metadata_object_seektable_template_sort(block, /*compact=*/true)) {
909 printf("FAILED, returned false\n");
912 if(!FLAC__metadata_object_seektable_is_legal(block)) {
913 printf("FAILED, seek table is illegal\n");
916 if(!check_seektable_(block, seekpoints, seekpoint_array))
919 printf("testing FLAC__metadata_object_seekpoint_template_sort(compact=false)... ");
920 if(!FLAC__metadata_object_seektable_template_sort(block, /*compact=*/false)) {
921 printf("FAILED, returned false\n");
924 if(!FLAC__metadata_object_seektable_is_legal(block)) {
925 printf("FAILED, seek table is illegal\n");
928 if(!check_seektable_(block, seekpoints, seekpoint_array))
931 seekpoint_array[seekpoints++].sample_number = 0;
932 seekpoint_array[seekpoints++].sample_number = 10;
933 seekpoint_array[seekpoints++].sample_number = 20;
934 printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points_by_samples()... ");
935 if(!FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(block, 10, 30)) {
936 printf("FAILED, returned false\n");
939 if(!check_seektable_(block, seekpoints, seekpoint_array))
942 seekpoint_array[seekpoints++].sample_number = 0;
943 seekpoint_array[seekpoints++].sample_number = 11;
944 seekpoint_array[seekpoints++].sample_number = 22;
945 printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points_by_samples()... ");
946 if(!FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(block, 11, 30)) {
947 printf("FAILED, returned false\n");
950 if(!check_seektable_(block, seekpoints, seekpoint_array))
953 printf("testing FLAC__metadata_object_delete()... ");
954 FLAC__metadata_object_delete(block);
958 printf("testing VORBIS_COMMENT\n");
961 FLAC__StreamMetadata_VorbisComment_Entry entry_;
962 char *field_name, *field_value;
964 printf("testing FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair()... ");
965 if(!FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(&entry_, "name", "value")) {
966 printf("FAILED, returned false\n");
969 if(strcmp((const char *)entry_.entry, "name=value")) {
970 printf("FAILED, field mismatch\n");
975 printf("testing FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair()... ");
976 if(!FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair(entry_, &field_name, &field_value)) {
977 printf("FAILED, returned false\n");
980 if(strcmp(field_name, "name")) {
981 printf("FAILED, field name mismatch\n");
984 if(strcmp(field_value, "value")) {
985 printf("FAILED, field value mismatch\n");
990 printf("testing FLAC__metadata_object_vorbiscomment_entry_matches()... ");
991 if(!FLAC__metadata_object_vorbiscomment_entry_matches(entry_, field_name, strlen(field_name))) {
992 printf("FAILED, expected true, returned false\n");
997 printf("testing FLAC__metadata_object_vorbiscomment_entry_matches()... ");
998 if(FLAC__metadata_object_vorbiscomment_entry_matches(entry_, "blah", strlen("blah"))) {
999 printf("FAILED, expected false, returned true\n");
1009 printf("testing FLAC__metadata_object_new()... ");
1010 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
1012 printf("FAILED, returned NULL\n");
1015 expected_length = (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + strlen(FLAC__VENDOR_STRING) + FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN/8);
1016 if(block->length != expected_length) {
1017 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
1022 printf("testing FLAC__metadata_object_clone()... ");
1023 vorbiscomment = FLAC__metadata_object_clone(block);
1024 if(0 == vorbiscomment) {
1025 printf("FAILED, returned NULL\n");
1028 if(!mutils__compare_block(vorbiscomment, block))
1032 vc_resize_(vorbiscomment, 2);
1033 printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(grow to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
1034 if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
1035 printf("FAILED, returned false\n");
1038 if(!mutils__compare_block(vorbiscomment, block))
1042 vc_resize_(vorbiscomment, 1);
1043 printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
1044 if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
1045 printf("FAILED, returned false\n");
1048 if(!mutils__compare_block(vorbiscomment, block))
1052 vc_resize_(vorbiscomment, 0);
1053 printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
1054 if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
1055 printf("FAILED, returned false\n");
1058 if(!mutils__compare_block(vorbiscomment, block))
1062 printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on empty array...");
1063 vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
1064 if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
1065 printf("FAILED, returned false\n");
1068 if(!mutils__compare_block(vorbiscomment, block))
1072 printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on non-empty array...");
1073 vc_insert_new_(&entry, vorbiscomment, 1, "name2=field2");
1074 if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
1075 printf("FAILED, returned false\n");
1078 if(!mutils__compare_block(vorbiscomment, block))
1082 vc_resize_(vorbiscomment, 0);
1083 printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
1084 if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
1085 printf("FAILED, returned false\n");
1088 if(!mutils__compare_block(vorbiscomment, block))
1092 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on empty array...");
1093 vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
1094 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/true)) {
1095 printf("FAILED, returned false\n");
1098 if(!mutils__compare_block(vorbiscomment, block))
1102 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on beginning of non-empty array...");
1103 vc_insert_new_(&entry, vorbiscomment, 0, "name2=field2");
1104 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/true)) {
1105 printf("FAILED, returned false\n");
1108 if(!mutils__compare_block(vorbiscomment, block))
1112 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on middle of non-empty array...");
1113 vc_insert_new_(&entry, vorbiscomment, 1, "name3=field3");
1114 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 1, entry, /*copy=*/true)) {
1115 printf("FAILED, returned false\n");
1118 if(!mutils__compare_block(vorbiscomment, block))
1122 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array...");
1123 vc_insert_new_(&entry, vorbiscomment, 3, "name4=field4");
1124 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 3, entry, /*copy=*/true)) {
1125 printf("FAILED, returned false\n");
1128 if(!mutils__compare_block(vorbiscomment, block))
1132 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array...");
1133 vc_insert_new_(&entry, vorbiscomment, 4, "name3=field3dup1");
1134 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 4, entry, /*copy=*/true)) {
1135 printf("FAILED, returned false\n");
1138 if(!mutils__compare_block(vorbiscomment, block))
1142 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array...");
1143 vc_insert_new_(&entry, vorbiscomment, 5, "name3=field3dup1");
1144 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 5, entry, /*copy=*/true)) {
1145 printf("FAILED, returned false\n");
1148 if(!mutils__compare_block(vorbiscomment, block))
1152 printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()...");
1153 if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0, "name3")) != 1) {
1154 printf("FAILED, expected 1, 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, j+1, "name3")) != 4) {
1161 printf("FAILED, expected 4, 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, "name3")) != 5) {
1168 printf("FAILED, expected 5, 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, "name2")) != 0) {
1175 printf("FAILED, expected 0, got %d\n", j);
1180 printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()...");
1181 if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, j+1, "name2")) != -1) {
1182 printf("FAILED, expected -1, got %d\n", j);
1187 printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()...");
1188 if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0, "blah")) != -1) {
1189 printf("FAILED, expected -1, got %d\n", j);
1194 printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(first, copy)...");
1195 vc_replace_new_(&entry, vorbiscomment, "name3=field3new1", /*all=*/false);
1196 if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/false, /*copy=*/true)) {
1197 printf("FAILED, returned false\n");
1200 if(!mutils__compare_block(vorbiscomment, block))
1202 if(block->data.vorbis_comment.num_comments != 6) {
1203 printf("FAILED, expected 6 comments, got %u\n", block->data.vorbis_comment.num_comments);
1208 printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(all, copy)...");
1209 vc_replace_new_(&entry, vorbiscomment, "name3=field3new2", /*all=*/true);
1210 if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/true, /*copy=*/true)) {
1211 printf("FAILED, returned false\n");
1214 if(!mutils__compare_block(vorbiscomment, block))
1216 if(block->data.vorbis_comment.num_comments != 4) {
1217 printf("FAILED, expected 4 comments, got %u\n", block->data.vorbis_comment.num_comments);
1222 printf("testing FLAC__metadata_object_clone()... ");
1223 blockcopy = FLAC__metadata_object_clone(block);
1224 if(0 == blockcopy) {
1225 printf("FAILED, returned NULL\n");
1228 if(!mutils__compare_block(block, blockcopy))
1232 printf("testing FLAC__metadata_object_delete()... ");
1233 FLAC__metadata_object_delete(blockcopy);
1236 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on middle of array...");
1237 vc_delete_(vorbiscomment, 2);
1238 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
1239 printf("FAILED, returned false\n");
1242 if(!mutils__compare_block(vorbiscomment, block))
1246 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on end of array...");
1247 vc_delete_(vorbiscomment, 2);
1248 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
1249 printf("FAILED, returned false\n");
1252 if(!mutils__compare_block(vorbiscomment, block))
1256 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on beginning of array...");
1257 vc_delete_(vorbiscomment, 0);
1258 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 0)) {
1259 printf("FAILED, returned false\n");
1262 if(!mutils__compare_block(vorbiscomment, block))
1266 printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on non-empty array...");
1267 vc_insert_new_(&entry, vorbiscomment, 1, "rem0=val0");
1268 if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
1269 printf("FAILED, returned false\n");
1272 if(!mutils__compare_block(vorbiscomment, block))
1276 printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on non-empty array...");
1277 vc_insert_new_(&entry, vorbiscomment, 2, "rem0=val1");
1278 if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
1279 printf("FAILED, returned false\n");
1282 if(!mutils__compare_block(vorbiscomment, block))
1286 printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on non-empty array...");
1287 vc_insert_new_(&entry, vorbiscomment, 3, "rem0=val2");
1288 if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
1289 printf("FAILED, returned false\n");
1292 if(!mutils__compare_block(vorbiscomment, block))
1296 printf("testing FLAC__metadata_object_vorbiscomment_remove_entry_matching(\"blah\")...");
1297 if((j = FLAC__metadata_object_vorbiscomment_remove_entry_matching(block, "blah")) != 0) {
1298 printf("FAILED, expected 0, got %d\n", j);
1301 if(block->data.vorbis_comment.num_comments != 4) {
1302 printf("FAILED, expected 4 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_entry_matching(\"rem0\")...");
1310 vc_delete_(vorbiscomment, 1);
1311 if((j = FLAC__metadata_object_vorbiscomment_remove_entry_matching(block, "rem0")) != 1) {
1312 printf("FAILED, expected 1, got %d\n", j);
1315 if(block->data.vorbis_comment.num_comments != 3) {
1316 printf("FAILED, expected 3 comments, got %u\n", block->data.vorbis_comment.num_comments);
1319 if(!mutils__compare_block(vorbiscomment, block))
1323 printf("testing FLAC__metadata_object_vorbiscomment_remove_entries_matching(\"blah\")...");
1324 if((j = FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, "blah")) != 0) {
1325 printf("FAILED, expected 0, got %d\n", j);
1328 if(block->data.vorbis_comment.num_comments != 3) {
1329 printf("FAILED, expected 3 comments, got %u\n", block->data.vorbis_comment.num_comments);
1332 if(!mutils__compare_block(vorbiscomment, block))
1336 printf("testing FLAC__metadata_object_vorbiscomment_remove_entries_matching(\"rem0\")...");
1337 vc_delete_(vorbiscomment, 1);
1338 vc_delete_(vorbiscomment, 1);
1339 if((j = FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, "rem0")) != 2) {
1340 printf("FAILED, expected 2, got %d\n", j);
1343 if(block->data.vorbis_comment.num_comments != 1) {
1344 printf("FAILED, expected 1 comments, got %u\n", block->data.vorbis_comment.num_comments);
1347 if(!mutils__compare_block(vorbiscomment, block))
1351 printf("testing FLAC__metadata_object_vorbiscomment_set_comment(copy)...");
1352 vc_set_new_(&entry, vorbiscomment, 0, "name5=field5");
1353 FLAC__metadata_object_vorbiscomment_set_comment(block, 0, entry, /*copy=*/true);
1354 if(!mutils__compare_block(vorbiscomment, block))
1358 printf("testing FLAC__metadata_object_vorbiscomment_set_vendor_string(copy)...");
1359 vc_set_vs_new_(&entry, vorbiscomment, "name6=field6");
1360 FLAC__metadata_object_vorbiscomment_set_vendor_string(block, entry, /*copy=*/true);
1361 if(!mutils__compare_block(vorbiscomment, block))
1365 printf("testing FLAC__metadata_object_delete()... ");
1366 FLAC__metadata_object_delete(vorbiscomment);
1367 FLAC__metadata_object_delete(block);
1371 printf("testing FLAC__metadata_object_new()... ");
1372 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
1374 printf("FAILED, returned NULL\n");
1379 printf("testing FLAC__metadata_object_clone()... ");
1380 vorbiscomment = FLAC__metadata_object_clone(block);
1381 if(0 == vorbiscomment) {
1382 printf("FAILED, returned NULL\n");
1385 if(!mutils__compare_block(vorbiscomment, block))
1389 printf("testing FLAC__metadata_object_vorbiscomment_append_comment(own) on empty array...");
1390 vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
1391 entry_clone_(&entry);
1392 if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/false)) {
1393 printf("FAILED, returned false\n");
1396 if(!mutils__compare_block(vorbiscomment, block))
1400 printf("testing FLAC__metadata_object_vorbiscomment_append_comment(own) on non-empty array...");
1401 vc_insert_new_(&entry, vorbiscomment, 1, "name2=field2");
1402 entry_clone_(&entry);
1403 if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/false)) {
1404 printf("FAILED, returned false\n");
1407 if(!mutils__compare_block(vorbiscomment, block))
1411 printf("testing FLAC__metadata_object_delete()... ");
1412 FLAC__metadata_object_delete(vorbiscomment);
1413 FLAC__metadata_object_delete(block);
1416 printf("testing FLAC__metadata_object_new()... ");
1417 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
1419 printf("FAILED, returned NULL\n");
1424 printf("testing FLAC__metadata_object_clone()... ");
1425 vorbiscomment = FLAC__metadata_object_clone(block);
1426 if(0 == vorbiscomment) {
1427 printf("FAILED, returned NULL\n");
1430 if(!mutils__compare_block(vorbiscomment, block))
1434 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on empty array...");
1435 vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
1436 entry_clone_(&entry);
1437 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/false)) {
1438 printf("FAILED, returned false\n");
1441 if(!mutils__compare_block(vorbiscomment, block))
1445 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on beginning of non-empty array...");
1446 vc_insert_new_(&entry, vorbiscomment, 0, "name2=field2");
1447 entry_clone_(&entry);
1448 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/false)) {
1449 printf("FAILED, returned false\n");
1452 if(!mutils__compare_block(vorbiscomment, block))
1456 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on middle of non-empty array...");
1457 vc_insert_new_(&entry, vorbiscomment, 1, "name3=field3");
1458 entry_clone_(&entry);
1459 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 1, entry, /*copy=*/false)) {
1460 printf("FAILED, returned false\n");
1463 if(!mutils__compare_block(vorbiscomment, block))
1467 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on end of non-empty array...");
1468 vc_insert_new_(&entry, vorbiscomment, 3, "name4=field4");
1469 entry_clone_(&entry);
1470 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 3, entry, /*copy=*/false)) {
1471 printf("FAILED, returned false\n");
1474 if(!mutils__compare_block(vorbiscomment, block))
1478 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on end of non-empty array...");
1479 vc_insert_new_(&entry, vorbiscomment, 4, "name3=field3dup1");
1480 entry_clone_(&entry);
1481 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 4, entry, /*copy=*/false)) {
1482 printf("FAILED, returned false\n");
1485 if(!mutils__compare_block(vorbiscomment, block))
1489 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on end of non-empty array...");
1490 vc_insert_new_(&entry, vorbiscomment, 5, "name3=field3dup1");
1491 entry_clone_(&entry);
1492 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 5, entry, /*copy=*/false)) {
1493 printf("FAILED, returned false\n");
1496 if(!mutils__compare_block(vorbiscomment, block))
1500 printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(first, own)...");
1501 vc_replace_new_(&entry, vorbiscomment, "name3=field3new1", /*all=*/false);
1502 entry_clone_(&entry);
1503 if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/false, /*copy=*/false)) {
1504 printf("FAILED, returned false\n");
1507 if(!mutils__compare_block(vorbiscomment, block))
1509 if(block->data.vorbis_comment.num_comments != 6) {
1510 printf("FAILED, expected 6 comments, got %u\n", block->data.vorbis_comment.num_comments);
1515 printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(all, own)...");
1516 vc_replace_new_(&entry, vorbiscomment, "name3=field3new2", /*all=*/true);
1517 entry_clone_(&entry);
1518 if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/true, /*copy=*/false)) {
1519 printf("FAILED, returned false\n");
1522 if(!mutils__compare_block(vorbiscomment, block))
1524 if(block->data.vorbis_comment.num_comments != 4) {
1525 printf("FAILED, expected 4 comments, got %u\n", block->data.vorbis_comment.num_comments);
1530 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on middle of array...");
1531 vc_delete_(vorbiscomment, 2);
1532 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
1533 printf("FAILED, returned false\n");
1536 if(!mutils__compare_block(vorbiscomment, block))
1540 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on end of array...");
1541 vc_delete_(vorbiscomment, 2);
1542 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
1543 printf("FAILED, returned false\n");
1546 if(!mutils__compare_block(vorbiscomment, block))
1550 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on beginning of array...");
1551 vc_delete_(vorbiscomment, 0);
1552 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 0)) {
1553 printf("FAILED, returned false\n");
1556 if(!mutils__compare_block(vorbiscomment, block))
1560 printf("testing FLAC__metadata_object_vorbiscomment_set_comment(own)...");
1561 vc_set_new_(&entry, vorbiscomment, 0, "name5=field5");
1562 entry_clone_(&entry);
1563 FLAC__metadata_object_vorbiscomment_set_comment(block, 0, entry, /*copy=*/false);
1564 if(!mutils__compare_block(vorbiscomment, block))
1568 printf("testing FLAC__metadata_object_vorbiscomment_set_vendor_string(own)...");
1569 vc_set_vs_new_(&entry, vorbiscomment, "name6=field6");
1570 entry_clone_(&entry);
1571 FLAC__metadata_object_vorbiscomment_set_vendor_string(block, entry, /*copy=*/false);
1572 if(!mutils__compare_block(vorbiscomment, block))
1576 printf("testing FLAC__metadata_object_delete()... ");
1577 FLAC__metadata_object_delete(vorbiscomment);
1578 FLAC__metadata_object_delete(block);
1582 printf("testing CUESHEET\n");
1585 FLAC__StreamMetadata_CueSheet_Track *track_, *trackcopy_;
1587 printf("testing FLAC__metadata_object_cuesheet_track_new()... ");
1588 track_ = FLAC__metadata_object_cuesheet_track_new();
1590 printf("FAILED, returned NULL\n");
1595 printf("testing FLAC__metadata_object_cuesheet_track_clone()... ");
1596 trackcopy_ = FLAC__metadata_object_cuesheet_track_clone(track_);
1597 if(0 == trackcopy_) {
1598 printf("FAILED, returned NULL\n");
1601 if(!compare_track_(trackcopy_, track_))
1605 printf("testing FLAC__metadata_object_cuesheet_track_delete()... ");
1606 FLAC__metadata_object_cuesheet_track_delete(trackcopy_);
1607 FLAC__metadata_object_cuesheet_track_delete(track_);
1612 printf("testing FLAC__metadata_object_new()... ");
1613 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET);
1615 printf("FAILED, returned NULL\n");
1619 FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
1620 FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
1621 FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN +
1622 FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
1623 FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
1625 if(block->length != expected_length) {
1626 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
1631 printf("testing FLAC__metadata_object_clone()... ");
1632 cuesheet = FLAC__metadata_object_clone(block);
1634 printf("FAILED, returned NULL\n");
1637 if(!mutils__compare_block(cuesheet, block))
1641 cs_resize_(cuesheet, 2);
1642 printf("testing FLAC__metadata_object_cuesheet_resize_tracks(grow to %u)...", cuesheet->data.cue_sheet.num_tracks);
1643 if(!FLAC__metadata_object_cuesheet_resize_tracks(block, cuesheet->data.cue_sheet.num_tracks)) {
1644 printf("FAILED, returned false\n");
1647 if(!mutils__compare_block(cuesheet, block))
1651 cs_resize_(cuesheet, 1);
1652 printf("testing FLAC__metadata_object_cuesheet_resize_tracks(shrink to %u)...", cuesheet->data.cue_sheet.num_tracks);
1653 if(!FLAC__metadata_object_cuesheet_resize_tracks(block, cuesheet->data.cue_sheet.num_tracks)) {
1654 printf("FAILED, returned false\n");
1657 if(!mutils__compare_block(cuesheet, block))
1661 cs_resize_(cuesheet, 0);
1662 printf("testing FLAC__metadata_object_cuesheet_resize_tracks(shrink to %u)...", cuesheet->data.cue_sheet.num_tracks);
1663 if(!FLAC__metadata_object_cuesheet_resize_tracks(block, cuesheet->data.cue_sheet.num_tracks)) {
1664 printf("FAILED, returned false\n");
1667 if(!mutils__compare_block(cuesheet, block))
1671 printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on empty array...");
1672 cs_insert_new_(&track, cuesheet, 0, 0, 1, "ABCDE1234567", false, false);
1673 if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/true)) {
1674 printf("FAILED, returned false\n");
1677 if(!mutils__compare_block(cuesheet, block))
1681 printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on beginning of non-empty array...");
1682 cs_insert_new_(&track, cuesheet, 0, 10, 2, "BBCDE1234567", false, false);
1683 if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/true)) {
1684 printf("FAILED, returned false\n");
1687 if(!mutils__compare_block(cuesheet, block))
1691 printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on middle of non-empty array...");
1692 cs_insert_new_(&track, cuesheet, 1, 20, 3, "CBCDE1234567", false, false);
1693 if(!FLAC__metadata_object_cuesheet_insert_track(block, 1, &track, /*copy=*/true)) {
1694 printf("FAILED, returned false\n");
1697 if(!mutils__compare_block(cuesheet, block))
1701 printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on end of non-empty array...");
1702 cs_insert_new_(&track, cuesheet, 3, 30, 4, "DBCDE1234567", false, false);
1703 if(!FLAC__metadata_object_cuesheet_insert_track(block, 3, &track, /*copy=*/true)) {
1704 printf("FAILED, returned false\n");
1707 if(!mutils__compare_block(cuesheet, block))
1711 printf("testing FLAC__metadata_object_cuesheet_insert_blank_track() on end of non-empty array...");
1712 cs_insert_new_(&track, cuesheet, 4, 0, 0, "\0\0\0\0\0\0\0\0\0\0\0\0", false, false);
1713 if(!FLAC__metadata_object_cuesheet_insert_blank_track(block, 4)) {
1714 printf("FAILED, returned false\n");
1717 if(!mutils__compare_block(cuesheet, block))
1721 printf("testing FLAC__metadata_object_clone()... ");
1722 blockcopy = FLAC__metadata_object_clone(block);
1723 if(0 == blockcopy) {
1724 printf("FAILED, returned NULL\n");
1727 if(!mutils__compare_block(block, blockcopy))
1731 printf("testing FLAC__metadata_object_delete()... ");
1732 FLAC__metadata_object_delete(blockcopy);
1735 printf("testing FLAC__metadata_object_cuesheet_delete_track() on end of array...");
1736 cs_delete_(cuesheet, 4);
1737 if(!FLAC__metadata_object_cuesheet_delete_track(block, 4)) {
1738 printf("FAILED, returned false\n");
1741 if(!mutils__compare_block(cuesheet, block))
1745 printf("testing FLAC__metadata_object_cuesheet_delete_track() on middle of array...");
1746 cs_delete_(cuesheet, 2);
1747 if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1748 printf("FAILED, returned false\n");
1751 if(!mutils__compare_block(cuesheet, block))
1755 printf("testing FLAC__metadata_object_cuesheet_delete_track() on end of array...");
1756 cs_delete_(cuesheet, 2);
1757 if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1758 printf("FAILED, returned false\n");
1761 if(!mutils__compare_block(cuesheet, block))
1765 printf("testing FLAC__metadata_object_cuesheet_delete_track() on beginning of array...");
1766 cs_delete_(cuesheet, 0);
1767 if(!FLAC__metadata_object_cuesheet_delete_track(block, 0)) {
1768 printf("FAILED, returned false\n");
1771 if(!mutils__compare_block(cuesheet, block))
1775 printf("testing FLAC__metadata_object_cuesheet_set_track(copy)...");
1776 cs_set_new_(&track, cuesheet, 0, 40, 5, "EBCDE1234567", false, false);
1777 FLAC__metadata_object_cuesheet_set_track(block, 0, &track, /*copy=*/true);
1778 if(!mutils__compare_block(cuesheet, block))
1782 tr_resize_(cuesheet, 0, 2);
1783 printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(grow to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices);
1784 if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) {
1785 printf("FAILED, returned false\n");
1788 if(!mutils__compare_block(cuesheet, block))
1792 tr_resize_(cuesheet, 0, 1);
1793 printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(shrink to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices);
1794 if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) {
1795 printf("FAILED, returned false\n");
1798 if(!mutils__compare_block(cuesheet, block))
1802 tr_resize_(cuesheet, 0, 0);
1803 printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(shrink to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices);
1804 if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) {
1805 printf("FAILED, returned false\n");
1808 if(!mutils__compare_block(cuesheet, block))
1814 printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on empty array...");
1815 tr_insert_new_(cuesheet, 0, 0, index);
1816 if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 0, index)) {
1817 printf("FAILED, returned false\n");
1820 if(!mutils__compare_block(cuesheet, block))
1826 printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on beginning of non-empty array...");
1827 tr_insert_new_(cuesheet, 0, 0, index);
1828 if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 0, index)) {
1829 printf("FAILED, returned false\n");
1832 if(!mutils__compare_block(cuesheet, block))
1838 printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on middle of non-empty array...");
1839 tr_insert_new_(cuesheet, 0, 1, index);
1840 if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 1, index)) {
1841 printf("FAILED, returned false\n");
1844 if(!mutils__compare_block(cuesheet, block))
1850 printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on end of non-empty array...");
1851 tr_insert_new_(cuesheet, 0, 3, index);
1852 if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 3, index)) {
1853 printf("FAILED, returned false\n");
1856 if(!mutils__compare_block(cuesheet, block))
1862 printf("testing FLAC__metadata_object_cuesheet_track_insert_blank_index() on end of non-empty array...");
1863 tr_insert_new_(cuesheet, 0, 4, index);
1864 if(!FLAC__metadata_object_cuesheet_track_insert_blank_index(block, 0, 4)) {
1865 printf("FAILED, returned false\n");
1868 if(!mutils__compare_block(cuesheet, block))
1872 printf("testing FLAC__metadata_object_clone()... ");
1873 blockcopy = FLAC__metadata_object_clone(block);
1874 if(0 == blockcopy) {
1875 printf("FAILED, returned NULL\n");
1878 if(!mutils__compare_block(block, blockcopy))
1882 printf("testing FLAC__metadata_object_delete()... ");
1883 FLAC__metadata_object_delete(blockcopy);
1886 printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on end of array...");
1887 tr_delete_(cuesheet, 0, 4);
1888 if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 4)) {
1889 printf("FAILED, returned false\n");
1892 if(!mutils__compare_block(cuesheet, block))
1896 printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on middle of array...");
1897 tr_delete_(cuesheet, 0, 2);
1898 if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 2)) {
1899 printf("FAILED, returned false\n");
1902 if(!mutils__compare_block(cuesheet, block))
1906 printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on end of array...");
1907 tr_delete_(cuesheet, 0, 2);
1908 if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 2)) {
1909 printf("FAILED, returned false\n");
1912 if(!mutils__compare_block(cuesheet, block))
1916 printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on beginning of array...");
1917 tr_delete_(cuesheet, 0, 0);
1918 if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 0)) {
1919 printf("FAILED, returned false\n");
1922 if(!mutils__compare_block(cuesheet, block))
1926 printf("testing FLAC__metadata_object_delete()... ");
1927 FLAC__metadata_object_delete(cuesheet);
1928 FLAC__metadata_object_delete(block);
1932 printf("testing FLAC__metadata_object_new()... ");
1933 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET);
1935 printf("FAILED, returned NULL\n");
1940 printf("testing FLAC__metadata_object_clone()... ");
1941 cuesheet = FLAC__metadata_object_clone(block);
1943 printf("FAILED, returned NULL\n");
1946 if(!mutils__compare_block(cuesheet, block))
1950 printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on empty array...");
1951 cs_insert_new_(&track, cuesheet, 0, 60, 7, "GBCDE1234567", false, false);
1952 track_clone_(&track);
1953 if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/false)) {
1954 printf("FAILED, returned false\n");
1957 if(!mutils__compare_block(cuesheet, block))
1961 printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on beginning of non-empty array...");
1962 cs_insert_new_(&track, cuesheet, 0, 70, 8, "HBCDE1234567", false, false);
1963 track_clone_(&track);
1964 if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/false)) {
1965 printf("FAILED, returned false\n");
1968 if(!mutils__compare_block(cuesheet, block))
1972 printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on middle of non-empty array...");
1973 cs_insert_new_(&track, cuesheet, 1, 80, 9, "IBCDE1234567", false, false);
1974 track_clone_(&track);
1975 if(!FLAC__metadata_object_cuesheet_insert_track(block, 1, &track, /*copy=*/false)) {
1976 printf("FAILED, returned false\n");
1979 if(!mutils__compare_block(cuesheet, block))
1983 printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on end of non-empty array...");
1984 cs_insert_new_(&track, cuesheet, 3, 90, 10, "JBCDE1234567", false, false);
1985 track_clone_(&track);
1986 if(!FLAC__metadata_object_cuesheet_insert_track(block, 3, &track, /*copy=*/false)) {
1987 printf("FAILED, returned false\n");
1990 if(!mutils__compare_block(cuesheet, block))
1994 printf("testing FLAC__metadata_object_cuesheet_delete_track() on middle of array...");
1995 cs_delete_(cuesheet, 2);
1996 if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1997 printf("FAILED, returned false\n");
2000 if(!mutils__compare_block(cuesheet, block))
2004 printf("testing FLAC__metadata_object_cuesheet_delete_track() on end of array...");
2005 cs_delete_(cuesheet, 2);
2006 if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
2007 printf("FAILED, returned false\n");
2010 if(!mutils__compare_block(cuesheet, block))
2014 printf("testing FLAC__metadata_object_cuesheet_delete_track() on beginning of array...");
2015 cs_delete_(cuesheet, 0);
2016 if(!FLAC__metadata_object_cuesheet_delete_track(block, 0)) {
2017 printf("FAILED, returned false\n");
2020 if(!mutils__compare_block(cuesheet, block))
2024 printf("testing FLAC__metadata_object_cuesheet_set_track(own)...");
2025 cs_set_new_(&track, cuesheet, 0, 100, 11, "KBCDE1234567", false, false);
2026 track_clone_(&track);
2027 FLAC__metadata_object_cuesheet_set_track(block, 0, &track, /*copy=*/false);
2028 if(!mutils__compare_block(cuesheet, block))
2032 printf("testing FLAC__metadata_object_cuesheet_is_legal()...");
2034 const char *violation;
2035 if(FLAC__metadata_object_cuesheet_is_legal(block, /*check_cd_da_subset=*/true, &violation)) {
2036 printf("FAILED, returned true when expecting false\n");
2039 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2042 printf("testing FLAC__metadata_object_delete()... ");
2043 FLAC__metadata_object_delete(cuesheet);
2044 FLAC__metadata_object_delete(block);
2048 printf("testing PICTURE\n");
2050 printf("testing FLAC__metadata_object_new()... ");
2051 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PICTURE);
2053 printf("FAILED, returned NULL\n");
2057 FLAC__STREAM_METADATA_PICTURE_TYPE_LEN +
2058 FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN +
2059 FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN +
2060 FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN +
2061 FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN +
2062 FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN +
2063 FLAC__STREAM_METADATA_PICTURE_COLORS_LEN +
2064 FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN
2066 if(block->length != expected_length) {
2067 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
2072 printf("testing FLAC__metadata_object_clone()... ");
2073 picture = FLAC__metadata_object_clone(block);
2075 printf("FAILED, returned NULL\n");
2078 if(!mutils__compare_block(picture, block))
2082 pi_set_mime_type(picture, "image/png\t");
2083 printf("testing FLAC__metadata_object_picture_set_mime_type(copy)...");
2084 if(!FLAC__metadata_object_picture_set_mime_type(block, "image/png\t", /*copy=*/true)) {
2085 printf("FAILED, returned false\n");
2088 if(!mutils__compare_block(picture, block))
2092 printf("testing FLAC__metadata_object_picture_is_legal()...");
2094 const char *violation;
2095 if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
2096 printf("FAILED, returned true when expecting false\n");
2099 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2102 pi_set_mime_type(picture, "image/png");
2103 printf("testing FLAC__metadata_object_picture_set_mime_type(copy)...");
2104 if(!FLAC__metadata_object_picture_set_mime_type(block, "image/png", /*copy=*/true)) {
2105 printf("FAILED, returned false\n");
2108 if(!mutils__compare_block(picture, block))
2112 printf("testing FLAC__metadata_object_picture_is_legal()...");
2114 const char *violation;
2115 if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
2116 printf("FAILED, returned false, violation=\"%s\"\n", violation);
2122 pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION\xff");
2123 printf("testing FLAC__metadata_object_picture_set_description(copy)...");
2124 if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)"DESCRIPTION\xff", /*copy=*/true)) {
2125 printf("FAILED, returned false\n");
2128 if(!mutils__compare_block(picture, block))
2132 printf("testing FLAC__metadata_object_picture_is_legal()...");
2134 const char *violation;
2135 if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
2136 printf("FAILED, returned true when expecting false\n");
2139 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2142 pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION");
2143 printf("testing FLAC__metadata_object_picture_set_description(copy)...");
2144 if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)"DESCRIPTION", /*copy=*/true)) {
2145 printf("FAILED, returned false\n");
2148 if(!mutils__compare_block(picture, block))
2152 printf("testing FLAC__metadata_object_picture_is_legal()...");
2154 const char *violation;
2155 if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
2156 printf("FAILED, returned false, violation=\"%s\"\n", violation);
2163 pi_set_data(picture, (const FLAC__byte*)"PNGDATA", strlen("PNGDATA"));
2164 printf("testing FLAC__metadata_object_picture_set_data(copy)...");
2165 if(!FLAC__metadata_object_picture_set_data(block, (FLAC__byte*)"PNGDATA", strlen("PNGDATA"), /*copy=*/true)) {
2166 printf("FAILED, returned false\n");
2169 if(!mutils__compare_block(picture, block))
2173 printf("testing FLAC__metadata_object_clone()... ");
2174 blockcopy = FLAC__metadata_object_clone(block);
2175 if(0 == blockcopy) {
2176 printf("FAILED, returned NULL\n");
2179 if(!mutils__compare_block(block, blockcopy))
2183 printf("testing FLAC__metadata_object_delete()... ");
2184 FLAC__metadata_object_delete(blockcopy);
2187 pi_set_mime_type(picture, "image/png\t");
2188 printf("testing FLAC__metadata_object_picture_set_mime_type(own)...");
2189 if(!FLAC__metadata_object_picture_set_mime_type(block, strdup("image/png\t"), /*copy=*/false)) {
2190 printf("FAILED, returned false\n");
2193 if(!mutils__compare_block(picture, block))
2197 printf("testing FLAC__metadata_object_picture_is_legal()...");
2199 const char *violation;
2200 if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
2201 printf("FAILED, returned true when expecting false\n");
2204 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2207 pi_set_mime_type(picture, "image/png");
2208 printf("testing FLAC__metadata_object_picture_set_mime_type(own)...");
2209 if(!FLAC__metadata_object_picture_set_mime_type(block, strdup("image/png"), /*copy=*/false)) {
2210 printf("FAILED, returned false\n");
2213 if(!mutils__compare_block(picture, block))
2217 printf("testing FLAC__metadata_object_picture_is_legal()...");
2219 const char *violation;
2220 if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
2221 printf("FAILED, returned false, violation=\"%s\"\n", violation);
2227 pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION\xff");
2228 printf("testing FLAC__metadata_object_picture_set_description(own)...");
2229 if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)strdup("DESCRIPTION\xff"), /*copy=*/false)) {
2230 printf("FAILED, returned false\n");
2233 if(!mutils__compare_block(picture, block))
2237 printf("testing FLAC__metadata_object_picture_is_legal()...");
2239 const char *violation;
2240 if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
2241 printf("FAILED, returned true when expecting false\n");
2244 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2247 pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION");
2248 printf("testing FLAC__metadata_object_picture_set_description(own)...");
2249 if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)strdup("DESCRIPTION"), /*copy=*/false)) {
2250 printf("FAILED, returned false\n");
2253 if(!mutils__compare_block(picture, block))
2257 printf("testing FLAC__metadata_object_picture_is_legal()...");
2259 const char *violation;
2260 if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
2261 printf("FAILED, returned false, violation=\"%s\"\n", violation);
2267 pi_set_data(picture, (const FLAC__byte*)"PNGDATA", strlen("PNGDATA"));
2268 printf("testing FLAC__metadata_object_picture_set_data(own)...");
2269 if(!FLAC__metadata_object_picture_set_data(block, (FLAC__byte*)strdup("PNGDATA"), strlen("PNGDATA"), /*copy=*/false)) {
2270 printf("FAILED, returned false\n");
2273 if(!mutils__compare_block(picture, block))
2277 printf("testing FLAC__metadata_object_clone()... ");
2278 blockcopy = FLAC__metadata_object_clone(block);
2279 if(0 == blockcopy) {
2280 printf("FAILED, returned NULL\n");
2283 if(!mutils__compare_block(block, blockcopy))
2287 printf("testing FLAC__metadata_object_delete()... ");
2288 FLAC__metadata_object_delete(blockcopy);
2291 printf("testing FLAC__metadata_object_delete()... ");
2292 FLAC__metadata_object_delete(picture);
2293 FLAC__metadata_object_delete(block);