1 /* test_libFLAC - Unit tester for libFLAC
2 * Copyright (C) 2002,2003 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.
19 #include "FLAC/assert.h"
20 #include "FLAC/metadata.h"
21 #include "metadata_utils.h"
23 #include <stdlib.h> /* for malloc() */
24 #include <string.h> /* for memcmp() */
26 static FLAC__byte *make_dummydata_(FLAC__byte *dummydata, unsigned len)
30 if(0 == (ret = (FLAC__byte*)malloc(len))) {
31 printf("FAILED, malloc error\n");
35 memcpy(ret, dummydata, len);
40 static FLAC__bool compare_track_(const FLAC__StreamMetadata_CueSheet_Track *from, const FLAC__StreamMetadata_CueSheet_Track *to)
44 if(from->offset != to->offset) {
45 printf("FAILED, track offset mismatch, expected %llu, got %llu\n", to->offset, from->offset);
48 if(from->number != to->number) {
49 printf("FAILED, track number mismatch, expected %u, got %u\n", (unsigned)to->number, (unsigned)from->number);
52 if(0 != strcmp(from->isrc, to->isrc)) {
53 printf("FAILED, track number mismatch, expected %s, got %s\n", to->isrc, from->isrc);
56 if(from->type != to->type) {
57 printf("FAILED, track type mismatch, expected %u, got %u\n", (unsigned)to->type, (unsigned)from->type);
60 if(from->pre_emphasis != to->pre_emphasis) {
61 printf("FAILED, track pre_emphasis mismatch, expected %u, got %u\n", (unsigned)to->pre_emphasis, (unsigned)from->pre_emphasis);
64 if(from->num_indices != to->num_indices) {
65 printf("FAILED, track num_indices mismatch, expected %u, got %u\n", (unsigned)to->num_indices, (unsigned)from->num_indices);
68 if(0 == to->indices || 0 == from->indices) {
69 if(to->indices != from->indices) {
70 printf("FAILED, track indices mismatch\n");
75 for(i = 0; i < to->num_indices; i++) {
76 if(from->indices[i].offset != to->indices[i].offset) {
77 printf("FAILED, track indices[%u].offset mismatch, expected %llu, got %llu\n", i, to->indices[i].offset, from->indices[i].offset);
80 if(from->indices[i].number != to->indices[i].number) {
81 printf("FAILED, track indices[%u].number mismatch, expected %u, got %u\n", i, (unsigned)to->indices[i].number, (unsigned)from->indices[i].number);
90 static FLAC__bool compare_seekpoint_array_(const FLAC__StreamMetadata_SeekPoint *from, const FLAC__StreamMetadata_SeekPoint *to, unsigned n)
94 FLAC__ASSERT(0 != from);
95 FLAC__ASSERT(0 != to);
97 for(i = 0; i < n; i++) {
98 if(from[i].sample_number != to[i].sample_number) {
99 printf("FAILED, point[%u].sample_number mismatch, expected %llu, got %llu\n", i, to[i].sample_number, from[i].sample_number);
102 if(from[i].stream_offset != to[i].stream_offset) {
103 printf("FAILED, point[%u].stream_offset mismatch, expected %llu, got %llu\n", i, to[i].stream_offset, from[i].stream_offset);
106 if(from[i].frame_samples != to[i].frame_samples) {
107 printf("FAILED, point[%u].frame_samples mismatch, expected %u, got %u\n", i, to[i].frame_samples, from[i].frame_samples);
115 static FLAC__bool check_seektable_(const FLAC__StreamMetadata *block, unsigned num_points, const FLAC__StreamMetadata_SeekPoint *array)
117 const unsigned expected_length = num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
119 if(block->length != expected_length) {
120 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
123 if(block->data.seek_table.num_points != num_points) {
124 printf("FAILED, expected %u point, got %u\n", num_points, block->data.seek_table.num_points);
128 if(0 != block->data.seek_table.points) {
129 printf("FAILED, 'points' pointer is not null\n");
134 if(!compare_seekpoint_array_(block->data.seek_table.points, array, num_points))
142 static void entry_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, const char *field)
144 entry->length = strlen(field);
145 entry->entry = (FLAC__byte*)malloc(entry->length);
146 FLAC__ASSERT(0 != entry->entry);
147 memcpy(entry->entry, field, entry->length);
150 static void entry_clone_(FLAC__StreamMetadata_VorbisComment_Entry *entry)
152 FLAC__byte *x = (FLAC__byte*)malloc(entry->length);
153 FLAC__ASSERT(0 != x);
154 memcpy(x, entry->entry, entry->length);
158 static void vc_calc_len_(FLAC__StreamMetadata *block)
160 const FLAC__StreamMetadata_VorbisComment *vc = &block->data.vorbis_comment;
163 block->length = FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
164 block->length += vc->vendor_string.length;
165 block->length += FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8;
166 for(i = 0; i < vc->num_comments; i++) {
167 block->length += FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
168 block->length += vc->comments[i].length;
172 static void vc_resize_(FLAC__StreamMetadata *block, unsigned num)
174 FLAC__StreamMetadata_VorbisComment *vc = &block->data.vorbis_comment;
176 if(vc->num_comments != 0) {
177 FLAC__ASSERT(0 != vc->comments);
178 if(num < vc->num_comments) {
180 for(i = num; i < vc->num_comments; i++) {
181 if(0 != vc->comments[i].entry)
182 free(vc->comments[i].entry);
187 if(0 != vc->comments) {
193 vc->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)realloc(vc->comments, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*num);
194 FLAC__ASSERT(0 != vc->comments);
195 if(num > vc->num_comments)
196 memset(vc->comments+vc->num_comments, 0, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(num-vc->num_comments));
199 vc->num_comments = num;
203 static void vc_set_vs_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, const char *field)
205 if(0 != block->data.vorbis_comment.vendor_string.entry)
206 free(block->data.vorbis_comment.vendor_string.entry);
207 entry_new_(entry, field);
208 block->data.vorbis_comment.vendor_string = *entry;
212 static void vc_set_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, unsigned pos, const char *field)
214 if(0 != block->data.vorbis_comment.comments[pos].entry)
215 free(block->data.vorbis_comment.comments[pos].entry);
216 entry_new_(entry, field);
217 block->data.vorbis_comment.comments[pos] = *entry;
221 static void vc_insert_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, unsigned pos, const char *field)
223 vc_resize_(block, block->data.vorbis_comment.num_comments+1);
224 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));
225 memset(&block->data.vorbis_comment.comments[pos], 0, sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
226 vc_set_new_(entry, block, pos, field);
230 static void vc_delete_(FLAC__StreamMetadata *block, unsigned pos)
232 if(0 != block->data.vorbis_comment.comments[pos].entry)
233 free(block->data.vorbis_comment.comments[pos].entry);
234 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));
235 block->data.vorbis_comment.comments[block->data.vorbis_comment.num_comments-1].entry = 0;
236 block->data.vorbis_comment.comments[block->data.vorbis_comment.num_comments-1].length = 0;
237 vc_resize_(block, block->data.vorbis_comment.num_comments-1);
241 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)
243 track->offset = offset;
244 track->number = number;
245 memcpy(track->isrc, isrc, sizeof(track->isrc));
247 track->pre_emphasis = pre_em;
248 track->num_indices = 0;
252 static void track_clone_(FLAC__StreamMetadata_CueSheet_Track *track)
254 if(track->num_indices > 0) {
255 size_t bytes = sizeof(FLAC__StreamMetadata_CueSheet_Index) * track->num_indices;
256 FLAC__StreamMetadata_CueSheet_Index *x = (FLAC__StreamMetadata_CueSheet_Index*)malloc(bytes);
257 FLAC__ASSERT(0 != x);
258 memcpy(x, track->indices, bytes);
263 static void cs_calc_len_(FLAC__StreamMetadata *block)
265 const FLAC__StreamMetadata_CueSheet *cs = &block->data.cue_sheet;
269 FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
270 FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
271 FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN +
272 FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
273 FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
275 block->length += cs->num_tracks * (
276 FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN +
277 FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN +
278 FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN +
279 FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN +
280 FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN +
281 FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN +
282 FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN
284 for(i = 0; i < cs->num_tracks; i++) {
285 block->length += cs->tracks[i].num_indices * (
286 FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN +
287 FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN +
288 FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN
293 static void tr_resize_(FLAC__StreamMetadata *block, unsigned track_num, unsigned num)
295 FLAC__StreamMetadata_CueSheet_Track *tr;
297 FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
299 tr = &block->data.cue_sheet.tracks[track_num];
301 if(tr->num_indices != 0) {
302 FLAC__ASSERT(0 != tr->indices);
305 if(0 != tr->indices) {
311 tr->indices = (FLAC__StreamMetadata_CueSheet_Index*)realloc(tr->indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)*num);
312 FLAC__ASSERT(0 != tr->indices);
313 if(num > tr->num_indices)
314 memset(tr->indices+tr->num_indices, 0, sizeof(FLAC__StreamMetadata_CueSheet_Index)*(num-tr->num_indices));
317 tr->num_indices = num;
321 static void tr_set_new_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos, FLAC__StreamMetadata_CueSheet_Index index)
323 FLAC__StreamMetadata_CueSheet_Track *tr;
325 FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
327 tr = &block->data.cue_sheet.tracks[track_num];
329 FLAC__ASSERT(pos < tr->num_indices);
331 tr->indices[pos] = index;
336 static void tr_insert_new_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos, FLAC__StreamMetadata_CueSheet_Index index)
338 FLAC__StreamMetadata_CueSheet_Track *tr;
340 FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
342 tr = &block->data.cue_sheet.tracks[track_num];
344 FLAC__ASSERT(pos <= tr->num_indices);
346 tr_resize_(block, track_num, tr->num_indices+1);
347 memmove(&tr->indices[pos+1], &tr->indices[pos], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(tr->num_indices-1-pos));
348 tr_set_new_(block, track_num, pos, index);
352 static void tr_delete_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos)
354 FLAC__StreamMetadata_CueSheet_Track *tr;
356 FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
358 tr = &block->data.cue_sheet.tracks[track_num];
360 FLAC__ASSERT(pos <= tr->num_indices);
362 memmove(&tr->indices[pos], &tr->indices[pos+1], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(tr->num_indices-pos-1));
363 tr_resize_(block, track_num, tr->num_indices-1);
367 static void cs_resize_(FLAC__StreamMetadata *block, unsigned num)
369 FLAC__StreamMetadata_CueSheet *cs = &block->data.cue_sheet;
371 if(cs->num_tracks != 0) {
372 FLAC__ASSERT(0 != cs->tracks);
373 if(num < cs->num_tracks) {
375 for(i = num; i < cs->num_tracks; i++) {
376 if(0 != cs->tracks[i].indices)
377 free(cs->tracks[i].indices);
382 if(0 != cs->tracks) {
388 cs->tracks = (FLAC__StreamMetadata_CueSheet_Track*)realloc(cs->tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)*num);
389 FLAC__ASSERT(0 != cs->tracks);
390 if(num > cs->num_tracks)
391 memset(cs->tracks+cs->num_tracks, 0, sizeof(FLAC__StreamMetadata_CueSheet_Track)*(num-cs->num_tracks));
394 cs->num_tracks = num;
398 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)
400 track_new_(track, offset, number, isrc, data, pre_em);
401 block->data.cue_sheet.tracks[pos] = *track;
405 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)
407 cs_resize_(block, block->data.cue_sheet.num_tracks+1);
408 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));
409 cs_set_new_(track, block, pos, offset, number, isrc, data, pre_em);
413 static void cs_delete_(FLAC__StreamMetadata *block, unsigned pos)
415 if(0 != block->data.cue_sheet.tracks[pos].indices)
416 free(block->data.cue_sheet.tracks[pos].indices);
417 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));
418 block->data.cue_sheet.tracks[block->data.cue_sheet.num_tracks-1].indices = 0;
419 block->data.cue_sheet.tracks[block->data.cue_sheet.num_tracks-1].num_indices = 0;
420 cs_resize_(block, block->data.cue_sheet.num_tracks-1);
425 FLAC__bool test_metadata_object()
427 FLAC__StreamMetadata *block, *blockcopy, *vorbiscomment, *cuesheet;
428 FLAC__StreamMetadata_SeekPoint seekpoint_array[8];
429 FLAC__StreamMetadata_VorbisComment_Entry entry;
430 FLAC__StreamMetadata_CueSheet_Index index;
431 FLAC__StreamMetadata_CueSheet_Track track;
432 unsigned i, expected_length, seekpoints;
433 static FLAC__byte dummydata[4] = { 'a', 'b', 'c', 'd' };
435 printf("\n+++ libFLAC unit test: metadata objects\n\n");
438 printf("testing STREAMINFO\n");
440 printf("testing FLAC__metadata_object_new()... ");
441 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_STREAMINFO);
443 printf("FAILED, returned NULL\n");
446 expected_length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
447 if(block->length != expected_length) {
448 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
453 printf("testing FLAC__metadata_object_clone()... ");
454 blockcopy = FLAC__metadata_object_clone(block);
456 printf("FAILED, returned NULL\n");
459 if(!mutils__compare_block(block, blockcopy))
463 printf("testing FLAC__metadata_object_delete()... ");
464 FLAC__metadata_object_delete(blockcopy);
465 FLAC__metadata_object_delete(block);
469 printf("testing PADDING\n");
471 printf("testing FLAC__metadata_object_new()... ");
472 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING);
474 printf("FAILED, returned NULL\n");
478 if(block->length != expected_length) {
479 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
484 printf("testing FLAC__metadata_object_clone()... ");
485 blockcopy = FLAC__metadata_object_clone(block);
487 printf("FAILED, returned NULL\n");
490 if(!mutils__compare_block(block, blockcopy))
494 printf("testing FLAC__metadata_object_delete()... ");
495 FLAC__metadata_object_delete(blockcopy);
496 FLAC__metadata_object_delete(block);
500 printf("testing APPLICATION\n");
502 printf("testing FLAC__metadata_object_new()... ");
503 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION);
505 printf("FAILED, returned NULL\n");
508 expected_length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
509 if(block->length != expected_length) {
510 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
515 printf("testing FLAC__metadata_object_clone()... ");
516 blockcopy = FLAC__metadata_object_clone(block);
518 printf("FAILED, returned NULL\n");
521 if(!mutils__compare_block(block, blockcopy))
525 printf("testing FLAC__metadata_object_delete()... ");
526 FLAC__metadata_object_delete(blockcopy);
529 printf("testing FLAC__metadata_object_application_set_data(copy)... ");
530 if(!FLAC__metadata_object_application_set_data(block, dummydata, sizeof(dummydata), true/*copy*/)) {
531 printf("FAILED, returned false\n");
534 expected_length = (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) + sizeof(dummydata);
535 if(block->length != expected_length) {
536 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
539 if(0 != memcmp(block->data.application.data, dummydata, sizeof(dummydata))) {
540 printf("FAILED, data mismatch\n");
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);
559 printf("testing FLAC__metadata_object_application_set_data(own)... ");
560 if(!FLAC__metadata_object_application_set_data(block, make_dummydata_(dummydata, sizeof(dummydata)), sizeof(dummydata), false/*own*/)) {
561 printf("FAILED, returned false\n");
564 expected_length = (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) + sizeof(dummydata);
565 if(block->length != expected_length) {
566 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
569 if(0 != memcmp(block->data.application.data, dummydata, sizeof(dummydata))) {
570 printf("FAILED, data mismatch\n");
575 printf("testing FLAC__metadata_object_clone()... ");
576 blockcopy = FLAC__metadata_object_clone(block);
578 printf("FAILED, returned NULL\n");
581 if(!mutils__compare_block(block, blockcopy))
585 printf("testing FLAC__metadata_object_delete()... ");
586 FLAC__metadata_object_delete(blockcopy);
587 FLAC__metadata_object_delete(block);
591 printf("testing SEEKTABLE\n");
593 for(i = 0; i < sizeof(seekpoint_array) / sizeof(FLAC__StreamMetadata_SeekPoint); i++) {
594 seekpoint_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
595 seekpoint_array[i].stream_offset = 0;
596 seekpoint_array[i].frame_samples = 0;
600 printf("testing FLAC__metadata_object_new()... ");
601 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE);
603 printf("FAILED, returned NULL\n");
606 if(!check_seektable_(block, seekpoints, 0))
609 printf("testing FLAC__metadata_object_clone()... ");
610 blockcopy = FLAC__metadata_object_clone(block);
612 printf("FAILED, returned NULL\n");
615 if(!mutils__compare_block(block, blockcopy))
619 printf("testing FLAC__metadata_object_delete()... ");
620 FLAC__metadata_object_delete(blockcopy);
624 printf("testing FLAC__metadata_object_seektable_resize_points(grow to %u)...", seekpoints);
625 if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
626 printf("FAILED, returned false\n");
629 if(!check_seektable_(block, seekpoints, seekpoint_array))
633 printf("testing FLAC__metadata_object_seektable_resize_points(shrink to %u)...", seekpoints);
634 if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
635 printf("FAILED, returned false\n");
638 if(!check_seektable_(block, seekpoints, seekpoint_array))
641 printf("testing FLAC__metadata_object_seektable_is_legal()...");
642 if(!FLAC__metadata_object_seektable_is_legal(block)) {
643 printf("FAILED, returned false\n");
649 printf("testing FLAC__metadata_object_seektable_resize_points(shrink to %u)...", seekpoints);
650 if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
651 printf("FAILED, returned false\n");
654 if(!check_seektable_(block, seekpoints, 0))
658 printf("testing FLAC__metadata_object_seektable_insert_point() on empty array...");
659 if(!FLAC__metadata_object_seektable_insert_point(block, 0, seekpoint_array[0])) {
660 printf("FAILED, returned false\n");
663 if(!check_seektable_(block, seekpoints, seekpoint_array))
666 seekpoint_array[0].sample_number = 1;
668 printf("testing FLAC__metadata_object_seektable_insert_point() on beginning of non-empty array...");
669 if(!FLAC__metadata_object_seektable_insert_point(block, 0, seekpoint_array[0])) {
670 printf("FAILED, returned false\n");
673 if(!check_seektable_(block, seekpoints, seekpoint_array))
676 seekpoint_array[1].sample_number = 2;
678 printf("testing FLAC__metadata_object_seektable_insert_point() on middle of non-empty array...");
679 if(!FLAC__metadata_object_seektable_insert_point(block, 1, seekpoint_array[1])) {
680 printf("FAILED, returned false\n");
683 if(!check_seektable_(block, seekpoints, seekpoint_array))
686 seekpoint_array[3].sample_number = 3;
688 printf("testing FLAC__metadata_object_seektable_insert_point() on end of non-empty array...");
689 if(!FLAC__metadata_object_seektable_insert_point(block, 3, seekpoint_array[3])) {
690 printf("FAILED, returned false\n");
693 if(!check_seektable_(block, seekpoints, seekpoint_array))
696 printf("testing FLAC__metadata_object_clone()... ");
697 blockcopy = FLAC__metadata_object_clone(block);
699 printf("FAILED, returned NULL\n");
702 if(!mutils__compare_block(block, blockcopy))
706 printf("testing FLAC__metadata_object_delete()... ");
707 FLAC__metadata_object_delete(blockcopy);
710 seekpoint_array[2].sample_number = seekpoint_array[3].sample_number;
712 printf("testing FLAC__metadata_object_seektable_delete_point() on middle of array...");
713 if(!FLAC__metadata_object_seektable_delete_point(block, 2)) {
714 printf("FAILED, returned false\n");
717 if(!check_seektable_(block, seekpoints, seekpoint_array))
721 printf("testing FLAC__metadata_object_seektable_delete_point() on end of array...");
722 if(!FLAC__metadata_object_seektable_delete_point(block, 2)) {
723 printf("FAILED, returned false\n");
726 if(!check_seektable_(block, seekpoints, seekpoint_array))
730 printf("testing FLAC__metadata_object_seektable_delete_point() on beginning of array...");
731 if(!FLAC__metadata_object_seektable_delete_point(block, 0)) {
732 printf("FAILED, returned false\n");
735 if(!check_seektable_(block, seekpoints, seekpoint_array+1))
738 printf("testing FLAC__metadata_object_seektable_set_point()...");
739 FLAC__metadata_object_seektable_set_point(block, 0, seekpoint_array[0]);
740 if(!check_seektable_(block, seekpoints, seekpoint_array))
743 printf("testing FLAC__metadata_object_delete()... ");
744 FLAC__metadata_object_delete(block);
747 /* seektable template functions */
749 for(i = 0; i < sizeof(seekpoint_array) / sizeof(FLAC__StreamMetadata_SeekPoint); i++) {
750 seekpoint_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
751 seekpoint_array[i].stream_offset = 0;
752 seekpoint_array[i].frame_samples = 0;
756 printf("testing FLAC__metadata_object_new()... ");
757 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE);
759 printf("FAILED, returned NULL\n");
762 if(!check_seektable_(block, seekpoints, 0))
766 printf("testing FLAC__metadata_object_seekpoint_template_append_placeholders()... ");
767 if(!FLAC__metadata_object_seektable_template_append_placeholders(block, 2)) {
768 printf("FAILED, returned false\n");
771 if(!check_seektable_(block, seekpoints, seekpoint_array))
774 seekpoint_array[seekpoints++].sample_number = 7;
775 printf("testing FLAC__metadata_object_seekpoint_template_append_point()... ");
776 if(!FLAC__metadata_object_seektable_template_append_point(block, 7)) {
777 printf("FAILED, returned false\n");
780 if(!check_seektable_(block, seekpoints, seekpoint_array))
784 FLAC__uint64 nums[2] = { 3, 7 };
785 seekpoint_array[seekpoints++].sample_number = nums[0];
786 seekpoint_array[seekpoints++].sample_number = nums[1];
787 printf("testing FLAC__metadata_object_seekpoint_template_append_points()... ");
788 if(!FLAC__metadata_object_seektable_template_append_points(block, nums, sizeof(nums)/sizeof(FLAC__uint64))) {
789 printf("FAILED, returned false\n");
792 if(!check_seektable_(block, seekpoints, seekpoint_array))
796 seekpoint_array[seekpoints++].sample_number = 0;
797 seekpoint_array[seekpoints++].sample_number = 10;
798 seekpoint_array[seekpoints++].sample_number = 20;
799 printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points()... ");
800 if(!FLAC__metadata_object_seektable_template_append_spaced_points(block, 3, 30)) {
801 printf("FAILED, returned false\n");
804 if(!check_seektable_(block, seekpoints, seekpoint_array))
808 seekpoint_array[0].sample_number = 0;
809 seekpoint_array[1].sample_number = 3;
810 seekpoint_array[2].sample_number = 7;
811 seekpoint_array[3].sample_number = 10;
812 seekpoint_array[4].sample_number = 20;
813 seekpoint_array[5].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
814 seekpoint_array[6].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
815 printf("testing FLAC__metadata_object_seekpoint_template_sort(compact=true)... ");
816 if(!FLAC__metadata_object_seektable_template_sort(block, /*compact=*/true)) {
817 printf("FAILED, returned false\n");
820 if(!FLAC__metadata_object_seektable_is_legal(block)) {
821 printf("FAILED, seek table is illegal\n");
824 if(!check_seektable_(block, seekpoints, seekpoint_array))
827 printf("testing FLAC__metadata_object_seekpoint_template_sort(compact=false)... ");
828 if(!FLAC__metadata_object_seektable_template_sort(block, /*compact=*/false)) {
829 printf("FAILED, returned false\n");
832 if(!FLAC__metadata_object_seektable_is_legal(block)) {
833 printf("FAILED, seek table is illegal\n");
836 if(!check_seektable_(block, seekpoints, seekpoint_array))
839 printf("testing FLAC__metadata_object_delete()... ");
840 FLAC__metadata_object_delete(block);
844 printf("testing VORBIS_COMMENT\n");
846 printf("testing FLAC__metadata_object_new()... ");
847 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
849 printf("FAILED, returned NULL\n");
852 expected_length = (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + strlen(FLAC__VENDOR_STRING) + FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN/8);
853 if(block->length != expected_length) {
854 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
859 printf("testing FLAC__metadata_object_clone()... ");
860 vorbiscomment = FLAC__metadata_object_clone(block);
861 if(0 == vorbiscomment) {
862 printf("FAILED, returned NULL\n");
865 if(!mutils__compare_block(vorbiscomment, block))
869 vc_resize_(vorbiscomment, 2);
870 printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(grow to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
871 if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
872 printf("FAILED, returned false\n");
875 if(!mutils__compare_block(vorbiscomment, block))
879 vc_resize_(vorbiscomment, 1);
880 printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
881 if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
882 printf("FAILED, returned false\n");
885 if(!mutils__compare_block(vorbiscomment, block))
889 vc_resize_(vorbiscomment, 0);
890 printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
891 if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
892 printf("FAILED, returned false\n");
895 if(!mutils__compare_block(vorbiscomment, block))
899 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on empty array...");
900 vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
901 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/true)) {
902 printf("FAILED, returned false\n");
905 if(!mutils__compare_block(vorbiscomment, block))
909 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on beginning of non-empty array...");
910 vc_insert_new_(&entry, vorbiscomment, 0, "name2=field2");
911 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/true)) {
912 printf("FAILED, returned false\n");
915 if(!mutils__compare_block(vorbiscomment, block))
919 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on middle of non-empty array...");
920 vc_insert_new_(&entry, vorbiscomment, 1, "name3=field3");
921 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 1, entry, /*copy=*/true)) {
922 printf("FAILED, returned false\n");
925 if(!mutils__compare_block(vorbiscomment, block))
929 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array...");
930 vc_insert_new_(&entry, vorbiscomment, 3, "name4=field4");
931 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 3, entry, /*copy=*/true)) {
932 printf("FAILED, returned false\n");
935 if(!mutils__compare_block(vorbiscomment, block))
939 printf("testing FLAC__metadata_object_clone()... ");
940 blockcopy = FLAC__metadata_object_clone(block);
942 printf("FAILED, returned NULL\n");
945 if(!mutils__compare_block(block, blockcopy))
949 printf("testing FLAC__metadata_object_delete()... ");
950 FLAC__metadata_object_delete(blockcopy);
953 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on middle of array...");
954 vc_delete_(vorbiscomment, 2);
955 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
956 printf("FAILED, returned false\n");
959 if(!mutils__compare_block(vorbiscomment, block))
963 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on end of array...");
964 vc_delete_(vorbiscomment, 2);
965 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
966 printf("FAILED, returned false\n");
969 if(!mutils__compare_block(vorbiscomment, block))
973 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on beginning of array...");
974 vc_delete_(vorbiscomment, 0);
975 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 0)) {
976 printf("FAILED, returned false\n");
979 if(!mutils__compare_block(vorbiscomment, block))
983 printf("testing FLAC__metadata_object_vorbiscomment_set_comment(copy)...");
984 vc_set_new_(&entry, vorbiscomment, 0, "name5=field5");
985 FLAC__metadata_object_vorbiscomment_set_comment(block, 0, entry, /*copy=*/true);
986 if(!mutils__compare_block(vorbiscomment, block))
990 printf("testing FLAC__metadata_object_vorbiscomment_set_vendor_string(copy)...");
991 vc_set_vs_new_(&entry, vorbiscomment, "name6=field6");
992 FLAC__metadata_object_vorbiscomment_set_vendor_string(block, entry, /*copy=*/true);
993 if(!mutils__compare_block(vorbiscomment, block))
997 printf("testing FLAC__metadata_object_delete()... ");
998 FLAC__metadata_object_delete(vorbiscomment);
999 FLAC__metadata_object_delete(block);
1003 printf("testing FLAC__metadata_object_new()... ");
1004 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
1006 printf("FAILED, returned NULL\n");
1011 printf("testing FLAC__metadata_object_clone()... ");
1012 vorbiscomment = FLAC__metadata_object_clone(block);
1013 if(0 == vorbiscomment) {
1014 printf("FAILED, returned NULL\n");
1017 if(!mutils__compare_block(vorbiscomment, block))
1021 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on empty array...");
1022 vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
1023 entry_clone_(&entry);
1024 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/false)) {
1025 printf("FAILED, returned false\n");
1028 if(!mutils__compare_block(vorbiscomment, block))
1032 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on beginning of non-empty array...");
1033 vc_insert_new_(&entry, vorbiscomment, 0, "name2=field2");
1034 entry_clone_(&entry);
1035 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/false)) {
1036 printf("FAILED, returned false\n");
1039 if(!mutils__compare_block(vorbiscomment, block))
1043 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on middle of non-empty array...");
1044 vc_insert_new_(&entry, vorbiscomment, 1, "name3=field3");
1045 entry_clone_(&entry);
1046 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 1, entry, /*copy=*/false)) {
1047 printf("FAILED, returned false\n");
1050 if(!mutils__compare_block(vorbiscomment, block))
1054 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on end of non-empty array...");
1055 vc_insert_new_(&entry, vorbiscomment, 3, "name4=field4");
1056 entry_clone_(&entry);
1057 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 3, entry, /*copy=*/false)) {
1058 printf("FAILED, returned false\n");
1061 if(!mutils__compare_block(vorbiscomment, block))
1065 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on middle of array...");
1066 vc_delete_(vorbiscomment, 2);
1067 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
1068 printf("FAILED, returned false\n");
1071 if(!mutils__compare_block(vorbiscomment, block))
1075 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on end of array...");
1076 vc_delete_(vorbiscomment, 2);
1077 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
1078 printf("FAILED, returned false\n");
1081 if(!mutils__compare_block(vorbiscomment, block))
1085 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on beginning of array...");
1086 vc_delete_(vorbiscomment, 0);
1087 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 0)) {
1088 printf("FAILED, returned false\n");
1091 if(!mutils__compare_block(vorbiscomment, block))
1095 printf("testing FLAC__metadata_object_vorbiscomment_set_comment(own)...");
1096 vc_set_new_(&entry, vorbiscomment, 0, "name5=field5");
1097 entry_clone_(&entry);
1098 FLAC__metadata_object_vorbiscomment_set_comment(block, 0, entry, /*copy=*/false);
1099 if(!mutils__compare_block(vorbiscomment, block))
1103 printf("testing FLAC__metadata_object_vorbiscomment_set_vendor_string(own)...");
1104 vc_set_vs_new_(&entry, vorbiscomment, "name6=field6");
1105 entry_clone_(&entry);
1106 FLAC__metadata_object_vorbiscomment_set_vendor_string(block, entry, /*copy=*/false);
1107 if(!mutils__compare_block(vorbiscomment, block))
1111 printf("testing FLAC__metadata_object_delete()... ");
1112 FLAC__metadata_object_delete(vorbiscomment);
1113 FLAC__metadata_object_delete(block);
1118 printf("testing CUESHEET\n");
1121 FLAC__StreamMetadata_CueSheet_Track *track_, *trackcopy_;
1123 printf("testing FLAC__metadata_object_cuesheet_track_new()... ");
1124 track_ = FLAC__metadata_object_cuesheet_track_new();
1126 printf("FAILED, returned NULL\n");
1131 printf("testing FLAC__metadata_object_cuesheet_track_clone()... ");
1132 trackcopy_ = FLAC__metadata_object_cuesheet_track_clone(track_);
1133 if(0 == trackcopy_) {
1134 printf("FAILED, returned NULL\n");
1137 if(!compare_track_(trackcopy_, track_))
1141 printf("testing FLAC__metadata_object_cuesheet_track_delete()... ");
1142 FLAC__metadata_object_cuesheet_track_delete(trackcopy_);
1143 FLAC__metadata_object_cuesheet_track_delete(track_);
1148 printf("testing FLAC__metadata_object_new()... ");
1149 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET);
1151 printf("FAILED, returned NULL\n");
1155 FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
1156 FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
1157 FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN +
1158 FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
1159 FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
1161 if(block->length != expected_length) {
1162 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
1167 printf("testing FLAC__metadata_object_clone()... ");
1168 cuesheet = FLAC__metadata_object_clone(block);
1170 printf("FAILED, returned NULL\n");
1173 if(!mutils__compare_block(cuesheet, block))
1177 cs_resize_(cuesheet, 2);
1178 printf("testing FLAC__metadata_object_cuesheet_resize_tracks(grow to %u)...", cuesheet->data.cue_sheet.num_tracks);
1179 if(!FLAC__metadata_object_cuesheet_resize_tracks(block, cuesheet->data.cue_sheet.num_tracks)) {
1180 printf("FAILED, returned false\n");
1183 if(!mutils__compare_block(cuesheet, block))
1187 cs_resize_(cuesheet, 1);
1188 printf("testing FLAC__metadata_object_cuesheet_resize_tracks(shrink to %u)...", cuesheet->data.cue_sheet.num_tracks);
1189 if(!FLAC__metadata_object_cuesheet_resize_tracks(block, cuesheet->data.cue_sheet.num_tracks)) {
1190 printf("FAILED, returned false\n");
1193 if(!mutils__compare_block(cuesheet, block))
1197 cs_resize_(cuesheet, 0);
1198 printf("testing FLAC__metadata_object_cuesheet_resize_tracks(shrink to %u)...", cuesheet->data.cue_sheet.num_tracks);
1199 if(!FLAC__metadata_object_cuesheet_resize_tracks(block, cuesheet->data.cue_sheet.num_tracks)) {
1200 printf("FAILED, returned false\n");
1203 if(!mutils__compare_block(cuesheet, block))
1207 printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on empty array...");
1208 cs_insert_new_(&track, cuesheet, 0, 0, 1, "ABCDE1234567", false, false);
1209 if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/true)) {
1210 printf("FAILED, returned false\n");
1213 if(!mutils__compare_block(cuesheet, block))
1217 printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on beginning of non-empty array...");
1218 cs_insert_new_(&track, cuesheet, 0, 10, 2, "BBCDE1234567", false, false);
1219 if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/true)) {
1220 printf("FAILED, returned false\n");
1223 if(!mutils__compare_block(cuesheet, block))
1227 printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on middle of non-empty array...");
1228 cs_insert_new_(&track, cuesheet, 1, 20, 3, "CBCDE1234567", false, false);
1229 if(!FLAC__metadata_object_cuesheet_insert_track(block, 1, &track, /*copy=*/true)) {
1230 printf("FAILED, returned false\n");
1233 if(!mutils__compare_block(cuesheet, block))
1237 printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on end of non-empty array...");
1238 cs_insert_new_(&track, cuesheet, 3, 30, 4, "DBCDE1234567", false, false);
1239 if(!FLAC__metadata_object_cuesheet_insert_track(block, 3, &track, /*copy=*/true)) {
1240 printf("FAILED, returned false\n");
1243 if(!mutils__compare_block(cuesheet, block))
1247 printf("testing FLAC__metadata_object_cuesheet_insert_blank_track() on end of non-empty array...");
1248 cs_insert_new_(&track, cuesheet, 4, 0, 0, "\0\0\0\0\0\0\0\0\0\0\0\0", false, false);
1249 if(!FLAC__metadata_object_cuesheet_insert_blank_track(block, 4)) {
1250 printf("FAILED, returned false\n");
1253 if(!mutils__compare_block(cuesheet, block))
1257 printf("testing FLAC__metadata_object_clone()... ");
1258 blockcopy = FLAC__metadata_object_clone(block);
1259 if(0 == blockcopy) {
1260 printf("FAILED, returned NULL\n");
1263 if(!mutils__compare_block(block, blockcopy))
1267 printf("testing FLAC__metadata_object_delete()... ");
1268 FLAC__metadata_object_delete(blockcopy);
1271 printf("testing FLAC__metadata_object_cuesheet_delete_track() on end of array...");
1272 cs_delete_(cuesheet, 4);
1273 if(!FLAC__metadata_object_cuesheet_delete_track(block, 4)) {
1274 printf("FAILED, returned false\n");
1277 if(!mutils__compare_block(cuesheet, block))
1281 printf("testing FLAC__metadata_object_cuesheet_delete_track() on middle of array...");
1282 cs_delete_(cuesheet, 2);
1283 if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1284 printf("FAILED, returned false\n");
1287 if(!mutils__compare_block(cuesheet, block))
1291 printf("testing FLAC__metadata_object_cuesheet_delete_track() on end of array...");
1292 cs_delete_(cuesheet, 2);
1293 if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1294 printf("FAILED, returned false\n");
1297 if(!mutils__compare_block(cuesheet, block))
1301 printf("testing FLAC__metadata_object_cuesheet_delete_track() on beginning of array...");
1302 cs_delete_(cuesheet, 0);
1303 if(!FLAC__metadata_object_cuesheet_delete_track(block, 0)) {
1304 printf("FAILED, returned false\n");
1307 if(!mutils__compare_block(cuesheet, block))
1311 printf("testing FLAC__metadata_object_cuesheet_set_track(copy)...");
1312 cs_set_new_(&track, cuesheet, 0, 40, 5, "EBCDE1234567", false, false);
1313 FLAC__metadata_object_cuesheet_set_track(block, 0, &track, /*copy=*/true);
1314 if(!mutils__compare_block(cuesheet, block))
1318 tr_resize_(cuesheet, 0, 2);
1319 printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(grow to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices);
1320 if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) {
1321 printf("FAILED, returned false\n");
1324 if(!mutils__compare_block(cuesheet, block))
1328 tr_resize_(cuesheet, 0, 1);
1329 printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(shrink to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices);
1330 if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) {
1331 printf("FAILED, returned false\n");
1334 if(!mutils__compare_block(cuesheet, block))
1338 tr_resize_(cuesheet, 0, 0);
1339 printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(shrink to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices);
1340 if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) {
1341 printf("FAILED, returned false\n");
1344 if(!mutils__compare_block(cuesheet, block))
1350 printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on empty array...");
1351 tr_insert_new_(cuesheet, 0, 0, index);
1352 if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 0, index)) {
1353 printf("FAILED, returned false\n");
1356 if(!mutils__compare_block(cuesheet, block))
1362 printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on beginning of non-empty array...");
1363 tr_insert_new_(cuesheet, 0, 0, index);
1364 if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 0, index)) {
1365 printf("FAILED, returned false\n");
1368 if(!mutils__compare_block(cuesheet, block))
1374 printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on middle of non-empty array...");
1375 tr_insert_new_(cuesheet, 0, 1, index);
1376 if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 1, index)) {
1377 printf("FAILED, returned false\n");
1380 if(!mutils__compare_block(cuesheet, block))
1386 printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on end of non-empty array...");
1387 tr_insert_new_(cuesheet, 0, 3, index);
1388 if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 3, index)) {
1389 printf("FAILED, returned false\n");
1392 if(!mutils__compare_block(cuesheet, block))
1398 printf("testing FLAC__metadata_object_cuesheet_track_insert_blank_index() on end of non-empty array...");
1399 tr_insert_new_(cuesheet, 0, 4, index);
1400 if(!FLAC__metadata_object_cuesheet_track_insert_blank_index(block, 0, 4)) {
1401 printf("FAILED, returned false\n");
1404 if(!mutils__compare_block(cuesheet, block))
1408 printf("testing FLAC__metadata_object_clone()... ");
1409 blockcopy = FLAC__metadata_object_clone(block);
1410 if(0 == blockcopy) {
1411 printf("FAILED, returned NULL\n");
1414 if(!mutils__compare_block(block, blockcopy))
1418 printf("testing FLAC__metadata_object_delete()... ");
1419 FLAC__metadata_object_delete(blockcopy);
1422 printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on end of array...");
1423 tr_delete_(cuesheet, 0, 4);
1424 if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 4)) {
1425 printf("FAILED, returned false\n");
1428 if(!mutils__compare_block(cuesheet, block))
1432 printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on middle of array...");
1433 tr_delete_(cuesheet, 0, 2);
1434 if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 2)) {
1435 printf("FAILED, returned false\n");
1438 if(!mutils__compare_block(cuesheet, block))
1442 printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on end of array...");
1443 tr_delete_(cuesheet, 0, 2);
1444 if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 2)) {
1445 printf("FAILED, returned false\n");
1448 if(!mutils__compare_block(cuesheet, block))
1452 printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on beginning of array...");
1453 tr_delete_(cuesheet, 0, 0);
1454 if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 0)) {
1455 printf("FAILED, returned false\n");
1458 if(!mutils__compare_block(cuesheet, block))
1462 printf("testing FLAC__metadata_object_delete()... ");
1463 FLAC__metadata_object_delete(cuesheet);
1464 FLAC__metadata_object_delete(block);
1468 printf("testing FLAC__metadata_object_new()... ");
1469 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET);
1471 printf("FAILED, returned NULL\n");
1476 printf("testing FLAC__metadata_object_clone()... ");
1477 cuesheet = FLAC__metadata_object_clone(block);
1479 printf("FAILED, returned NULL\n");
1482 if(!mutils__compare_block(cuesheet, block))
1486 printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on empty array...");
1487 cs_insert_new_(&track, cuesheet, 0, 60, 7, "GBCDE1234567", false, false);
1488 track_clone_(&track);
1489 if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/false)) {
1490 printf("FAILED, returned false\n");
1493 if(!mutils__compare_block(cuesheet, block))
1497 printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on beginning of non-empty array...");
1498 cs_insert_new_(&track, cuesheet, 0, 70, 8, "HBCDE1234567", false, false);
1499 track_clone_(&track);
1500 if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/false)) {
1501 printf("FAILED, returned false\n");
1504 if(!mutils__compare_block(cuesheet, block))
1508 printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on middle of non-empty array...");
1509 cs_insert_new_(&track, cuesheet, 1, 80, 9, "IBCDE1234567", false, false);
1510 track_clone_(&track);
1511 if(!FLAC__metadata_object_cuesheet_insert_track(block, 1, &track, /*copy=*/false)) {
1512 printf("FAILED, returned false\n");
1515 if(!mutils__compare_block(cuesheet, block))
1519 printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on end of non-empty array...");
1520 cs_insert_new_(&track, cuesheet, 3, 90, 10, "JBCDE1234567", false, false);
1521 track_clone_(&track);
1522 if(!FLAC__metadata_object_cuesheet_insert_track(block, 3, &track, /*copy=*/false)) {
1523 printf("FAILED, returned false\n");
1526 if(!mutils__compare_block(cuesheet, block))
1530 printf("testing FLAC__metadata_object_cuesheet_delete_track() on middle of array...");
1531 cs_delete_(cuesheet, 2);
1532 if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1533 printf("FAILED, returned false\n");
1536 if(!mutils__compare_block(cuesheet, block))
1540 printf("testing FLAC__metadata_object_cuesheet_delete_track() on end of array...");
1541 cs_delete_(cuesheet, 2);
1542 if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1543 printf("FAILED, returned false\n");
1546 if(!mutils__compare_block(cuesheet, block))
1550 printf("testing FLAC__metadata_object_cuesheet_delete_track() on beginning of array...");
1551 cs_delete_(cuesheet, 0);
1552 if(!FLAC__metadata_object_cuesheet_delete_track(block, 0)) {
1553 printf("FAILED, returned false\n");
1556 if(!mutils__compare_block(cuesheet, block))
1560 printf("testing FLAC__metadata_object_cuesheet_set_track(own)...");
1561 cs_set_new_(&track, cuesheet, 0, 100, 11, "KBCDE1234567", false, false);
1562 track_clone_(&track);
1563 FLAC__metadata_object_cuesheet_set_track(block, 0, &track, /*copy=*/false);
1564 if(!mutils__compare_block(cuesheet, block))
1568 printf("testing FLAC__metadata_object_cuesheet_is_legal()...");
1570 const char *violation;
1571 if(FLAC__metadata_object_cuesheet_is_legal(block, /*check_cd_da_subset=*/true, &violation)) {
1572 printf("FAILED, returned true when expecting false\n");
1575 printf("returned false as expected, violation=\"%s\" OK\n", violation);
1578 printf("testing FLAC__metadata_object_delete()... ");
1579 FLAC__metadata_object_delete(cuesheet);
1580 FLAC__metadata_object_delete(block);