bump requisite _MSC_VER to <=1600 for fseeko/ftello hack
[flac.git] / src / test_libFLAC / metadata_object.c
1 /* test_libFLAC - Unit tester for libFLAC
2  * Copyright (C) 2002,2003,2004,2005,2006  Josh Coalson
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 #if HAVE_CONFIG_H
20 #  include <config.h>
21 #endif
22
23 #include "FLAC/assert.h"
24 #include "FLAC/metadata.h"
25 #include "test_libs_common/metadata_utils.h"
26 #include <stdio.h>
27 #include <stdlib.h> /* for malloc() */
28 #include <string.h> /* for memcmp() */
29
30 static FLAC__byte *make_dummydata_(FLAC__byte *dummydata, unsigned len)
31 {
32         FLAC__byte *ret;
33
34         if(0 == (ret = (FLAC__byte*)malloc(len))) {
35                 printf("FAILED, malloc error\n");
36                 exit(1);
37         }
38         else
39                 memcpy(ret, dummydata, len);
40
41         return ret;
42 }
43
44 static FLAC__bool compare_track_(const FLAC__StreamMetadata_CueSheet_Track *from, const FLAC__StreamMetadata_CueSheet_Track *to)
45 {
46         unsigned i;
47
48         if(from->offset != to->offset) {
49 #ifdef _MSC_VER
50                 printf("FAILED, track offset mismatch, expected %I64u, got %I64u\n", to->offset, from->offset);
51 #else
52                 printf("FAILED, track offset mismatch, expected %llu, got %llu\n", (unsigned long long)to->offset, (unsigned long long)from->offset);
53 #endif
54                 return false;
55         }
56         if(from->number != to->number) {
57                 printf("FAILED, track number mismatch, expected %u, got %u\n", (unsigned)to->number, (unsigned)from->number);
58                 return false;
59         }
60         if(0 != strcmp(from->isrc, to->isrc)) {
61                 printf("FAILED, track number mismatch, expected %s, got %s\n", to->isrc, from->isrc);
62                 return false;
63         }
64         if(from->type != to->type) {
65                 printf("FAILED, track type mismatch, expected %u, got %u\n", (unsigned)to->type, (unsigned)from->type);
66                 return false;
67         }
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);
70                 return false;
71         }
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);
74                 return false;
75         }
76         if(0 == to->indices || 0 == from->indices) {
77                 if(to->indices != from->indices) {
78                         printf("FAILED, track indices mismatch\n");
79                         return false;
80                 }
81         }
82         else {
83                 for(i = 0; i < to->num_indices; i++) {
84                         if(from->indices[i].offset != to->indices[i].offset) {
85 #ifdef _MSC_VER
86                                 printf("FAILED, track indices[%u].offset mismatch, expected %I64u, got %I64u\n", i, to->indices[i].offset, from->indices[i].offset);
87 #else
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);
89 #endif
90                                 return false;
91                         }
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);
94                                 return false;
95                         }
96                 }
97         }
98
99         return true;
100 }
101
102 static FLAC__bool compare_seekpoint_array_(const FLAC__StreamMetadata_SeekPoint *from, const FLAC__StreamMetadata_SeekPoint *to, unsigned n)
103 {
104         unsigned i;
105
106         FLAC__ASSERT(0 != from);
107         FLAC__ASSERT(0 != to);
108
109         for(i = 0; i < n; i++) {
110                 if(from[i].sample_number != to[i].sample_number) {
111 #ifdef _MSC_VER
112                         printf("FAILED, point[%u].sample_number mismatch, expected %I64u, got %I64u\n", i, to[i].sample_number, from[i].sample_number);
113 #else
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);
115 #endif
116                         return false;
117                 }
118                 if(from[i].stream_offset != to[i].stream_offset) {
119 #ifdef _MSC_VER
120                         printf("FAILED, point[%u].stream_offset mismatch, expected %I64u, got %I64u\n", i, to[i].stream_offset, from[i].stream_offset);
121 #else
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);
123 #endif
124                         return false;
125                 }
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);
128                         return false;
129                 }
130         }
131
132         return true;
133 }
134
135 static FLAC__bool check_seektable_(const FLAC__StreamMetadata *block, unsigned num_points, const FLAC__StreamMetadata_SeekPoint *array)
136 {
137         const unsigned expected_length = num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
138
139         if(block->length != expected_length) {
140                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
141                 return false;
142         }
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);
145                 return false;
146         }
147         if(0 == array) {
148                 if(0 != block->data.seek_table.points) {
149                         printf("FAILED, 'points' pointer is not null\n");
150                         return false;
151                 }
152         }
153         else {
154                 if(!compare_seekpoint_array_(block->data.seek_table.points, array, num_points))
155                         return false;
156         }
157         printf("OK\n");
158
159         return true;
160 }
161
162 static void entry_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, const char *field)
163 {
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';
169 }
170
171 static void entry_clone_(FLAC__StreamMetadata_VorbisComment_Entry *entry)
172 {
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';
177         entry->entry = x;
178 }
179
180 static void vc_calc_len_(FLAC__StreamMetadata *block)
181 {
182         const FLAC__StreamMetadata_VorbisComment *vc = &block->data.vorbis_comment;
183         unsigned i;
184
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;
191         }
192 }
193
194 static void vc_resize_(FLAC__StreamMetadata *block, unsigned num)
195 {
196         FLAC__StreamMetadata_VorbisComment *vc = &block->data.vorbis_comment;
197
198         if(vc->num_comments != 0) {
199                 FLAC__ASSERT(0 != vc->comments);
200                 if(num < vc->num_comments) {
201                         unsigned i;
202                         for(i = num; i < vc->num_comments; i++) {
203                                 if(0 != vc->comments[i].entry)
204                                         free(vc->comments[i].entry);
205                         }
206                 }
207         }
208         if(num == 0) {
209                 if(0 != vc->comments) {
210                         free(vc->comments);
211                         vc->comments = 0;
212                 }
213         }
214         else {
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));
219         }
220
221         vc->num_comments = num;
222         vc_calc_len_(block);
223 }
224
225 static int vc_find_from_(FLAC__StreamMetadata *block, const char *name, unsigned start)
226 {
227         const unsigned n = strlen(name);
228         unsigned i;
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] == '=')
232                         return (int)i;
233         }
234         return -1;
235 }
236
237 static void vc_set_vs_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, const char *field)
238 {
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;
243         vc_calc_len_(block);
244 }
245
246 static void vc_set_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, unsigned pos, const char *field)
247 {
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;
252         vc_calc_len_(block);
253 }
254
255 static void vc_insert_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, unsigned pos, const char *field)
256 {
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);
261         vc_calc_len_(block);
262 }
263
264 static void vc_delete_(FLAC__StreamMetadata *block, unsigned pos)
265 {
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);
272         vc_calc_len_(block);
273 }
274
275 static void vc_replace_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, const char *field, FLAC__bool all)
276 {
277         int index;
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';
283
284         index = vc_find_from_(block, field_name, 0);
285         if(index < 0)
286                 vc_insert_new_(entry, block, block->data.vorbis_comment.num_comments, field);
287         else {
288                 vc_set_new_(entry, block, (unsigned)index, field);
289                 if(all) {
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);
293                 }
294         }
295
296         vc_calc_len_(block);
297 }
298
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)
300 {
301         track->offset = offset;
302         track->number = number;
303         memcpy(track->isrc, isrc, sizeof(track->isrc));
304         track->type = data;
305         track->pre_emphasis = pre_em;
306         track->num_indices = 0;
307         track->indices = 0;
308 }
309
310 static void track_clone_(FLAC__StreamMetadata_CueSheet_Track *track)
311 {
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);
317                 track->indices = x;
318         }
319 }
320
321 static void cs_calc_len_(FLAC__StreamMetadata *block)
322 {
323         const FLAC__StreamMetadata_CueSheet *cs = &block->data.cue_sheet;
324         unsigned i;
325
326         block->length = (
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
332         ) / 8;
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
341         ) / 8;
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
347                 ) / 8;
348         }
349 }
350
351 static void tr_resize_(FLAC__StreamMetadata *block, unsigned track_num, unsigned num)
352 {
353         FLAC__StreamMetadata_CueSheet_Track *tr;
354
355         FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
356
357         tr = &block->data.cue_sheet.tracks[track_num];
358
359         if(tr->num_indices != 0) {
360                 FLAC__ASSERT(0 != tr->indices);
361         }
362         if(num == 0) {
363                 if(0 != tr->indices) {
364                         free(tr->indices);
365                         tr->indices = 0;
366                 }
367         }
368         else {
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));
373         }
374
375         tr->num_indices = num;
376         cs_calc_len_(block);
377 }
378
379 static void tr_set_new_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos, FLAC__StreamMetadata_CueSheet_Index index)
380 {
381         FLAC__StreamMetadata_CueSheet_Track *tr;
382
383         FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
384
385         tr = &block->data.cue_sheet.tracks[track_num];
386
387         FLAC__ASSERT(pos < tr->num_indices);
388
389         tr->indices[pos] = index;
390
391         cs_calc_len_(block);
392 }
393
394 static void tr_insert_new_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos, FLAC__StreamMetadata_CueSheet_Index index)
395 {
396         FLAC__StreamMetadata_CueSheet_Track *tr;
397
398         FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
399
400         tr = &block->data.cue_sheet.tracks[track_num];
401
402         FLAC__ASSERT(pos <= tr->num_indices);
403
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);
407         cs_calc_len_(block);
408 }
409
410 static void tr_delete_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos)
411 {
412         FLAC__StreamMetadata_CueSheet_Track *tr;
413
414         FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
415
416         tr = &block->data.cue_sheet.tracks[track_num];
417
418         FLAC__ASSERT(pos <= tr->num_indices);
419
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);
422         cs_calc_len_(block);
423 }
424
425 static void cs_resize_(FLAC__StreamMetadata *block, unsigned num)
426 {
427         FLAC__StreamMetadata_CueSheet *cs = &block->data.cue_sheet;
428
429         if(cs->num_tracks != 0) {
430                 FLAC__ASSERT(0 != cs->tracks);
431                 if(num < cs->num_tracks) {
432                         unsigned i;
433                         for(i = num; i < cs->num_tracks; i++) {
434                                 if(0 != cs->tracks[i].indices)
435                                         free(cs->tracks[i].indices);
436                         }
437                 }
438         }
439         if(num == 0) {
440                 if(0 != cs->tracks) {
441                         free(cs->tracks);
442                         cs->tracks = 0;
443                 }
444         }
445         else {
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));
450         }
451
452         cs->num_tracks = num;
453         cs_calc_len_(block);
454 }
455
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)
457 {
458         track_new_(track, offset, number, isrc, data, pre_em);
459         block->data.cue_sheet.tracks[pos] = *track;
460         cs_calc_len_(block);
461 }
462
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)
464 {
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);
468         cs_calc_len_(block);
469 }
470
471 static void cs_delete_(FLAC__StreamMetadata *block, unsigned pos)
472 {
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);
479         cs_calc_len_(block);
480 }
481
482 static void pi_set_mime_type(FLAC__StreamMetadata *block, const char *s)
483 {
484         if(block->data.picture.mime_type) {
485                 block->length -= strlen(block->data.picture.mime_type);
486                 free(block->data.picture.mime_type);
487         }
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);
491 }
492
493 static void pi_set_description(FLAC__StreamMetadata *block, const FLAC__byte *s)
494 {
495         if(block->data.picture.description) {
496                 block->length -= strlen((const char *)block->data.picture.description);
497                 free(block->data.picture.description);
498         }
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);
502 }
503
504 static void pi_set_data(FLAC__StreamMetadata *block, const FLAC__byte *data, FLAC__uint32 len)
505 {
506         if(block->data.picture.data) {
507                 block->length -= block->data.picture.data_length;
508                 free(block->data.picture.data);
509         }
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;
514 }
515
516 FLAC__bool test_metadata_object(void)
517 {
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;
524         int j;
525         static FLAC__byte dummydata[4] = { 'a', 'b', 'c', 'd' };
526
527         printf("\n+++ libFLAC unit test: metadata objects\n\n");
528
529
530         printf("testing STREAMINFO\n");
531
532         printf("testing FLAC__metadata_object_new()... ");
533         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_STREAMINFO);
534         if(0 == block) {
535                 printf("FAILED, returned NULL\n");
536                 return false;
537         }
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);
541                 return false;
542         }
543         printf("OK\n");
544
545         printf("testing FLAC__metadata_object_clone()... ");
546         blockcopy = FLAC__metadata_object_clone(block);
547         if(0 == blockcopy) {
548                 printf("FAILED, returned NULL\n");
549                 return false;
550         }
551         if(!mutils__compare_block(block, blockcopy))
552                 return false;
553         printf("OK\n");
554
555         printf("testing FLAC__metadata_object_delete()... ");
556         FLAC__metadata_object_delete(blockcopy);
557         FLAC__metadata_object_delete(block);
558         printf("OK\n");
559
560
561         printf("testing PADDING\n");
562
563         printf("testing FLAC__metadata_object_new()... ");
564         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING);
565         if(0 == block) {
566                 printf("FAILED, returned NULL\n");
567                 return false;
568         }
569         expected_length = 0;
570         if(block->length != expected_length) {
571                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
572                 return false;
573         }
574         printf("OK\n");
575
576         printf("testing FLAC__metadata_object_clone()... ");
577         blockcopy = FLAC__metadata_object_clone(block);
578         if(0 == blockcopy) {
579                 printf("FAILED, returned NULL\n");
580                 return false;
581         }
582         if(!mutils__compare_block(block, blockcopy))
583                 return false;
584         printf("OK\n");
585
586         printf("testing FLAC__metadata_object_delete()... ");
587         FLAC__metadata_object_delete(blockcopy);
588         FLAC__metadata_object_delete(block);
589         printf("OK\n");
590
591
592         printf("testing APPLICATION\n");
593
594         printf("testing FLAC__metadata_object_new()... ");
595         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION);
596         if(0 == block) {
597                 printf("FAILED, returned NULL\n");
598                 return false;
599         }
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);
603                 return false;
604         }
605         printf("OK\n");
606
607         printf("testing FLAC__metadata_object_clone()... ");
608         blockcopy = FLAC__metadata_object_clone(block);
609         if(0 == blockcopy) {
610                 printf("FAILED, returned NULL\n");
611                 return false;
612         }
613         if(!mutils__compare_block(block, blockcopy))
614                 return false;
615         printf("OK\n");
616
617         printf("testing FLAC__metadata_object_delete()... ");
618         FLAC__metadata_object_delete(blockcopy);
619         printf("OK\n");
620
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");
624                 return false;
625         }
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);
629                 return false;
630         }
631         if(0 != memcmp(block->data.application.data, dummydata, sizeof(dummydata))) {
632                 printf("FAILED, data mismatch\n");
633                 return false;
634         }
635         printf("OK\n");
636
637         printf("testing FLAC__metadata_object_clone()... ");
638         blockcopy = FLAC__metadata_object_clone(block);
639         if(0 == blockcopy) {
640                 printf("FAILED, returned NULL\n");
641                 return false;
642         }
643         if(!mutils__compare_block(block, blockcopy))
644                 return false;
645         printf("OK\n");
646
647         printf("testing FLAC__metadata_object_delete()... ");
648         FLAC__metadata_object_delete(blockcopy);
649         printf("OK\n");
650
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");
654                 return false;
655         }
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);
659                 return false;
660         }
661         if(0 != memcmp(block->data.application.data, dummydata, sizeof(dummydata))) {
662                 printf("FAILED, data mismatch\n");
663                 return false;
664         }
665         printf("OK\n");
666
667         printf("testing FLAC__metadata_object_clone()... ");
668         blockcopy = FLAC__metadata_object_clone(block);
669         if(0 == blockcopy) {
670                 printf("FAILED, returned NULL\n");
671                 return false;
672         }
673         if(!mutils__compare_block(block, blockcopy))
674                 return false;
675         printf("OK\n");
676
677         printf("testing FLAC__metadata_object_delete()... ");
678         FLAC__metadata_object_delete(blockcopy);
679         FLAC__metadata_object_delete(block);
680         printf("OK\n");
681
682
683         printf("testing SEEKTABLE\n");
684
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;
689         }
690
691         seekpoints = 0;
692         printf("testing FLAC__metadata_object_new()... ");
693         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE);
694         if(0 == block) {
695                 printf("FAILED, returned NULL\n");
696                 return false;
697         }
698         if(!check_seektable_(block, seekpoints, 0))
699                 return false;
700
701         printf("testing FLAC__metadata_object_clone()... ");
702         blockcopy = FLAC__metadata_object_clone(block);
703         if(0 == blockcopy) {
704                 printf("FAILED, returned NULL\n");
705                 return false;
706         }
707         if(!mutils__compare_block(block, blockcopy))
708                 return false;
709         printf("OK\n");
710
711         printf("testing FLAC__metadata_object_delete()... ");
712         FLAC__metadata_object_delete(blockcopy);
713         printf("OK\n");
714
715         seekpoints = 2;
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");
719                 return false;
720         }
721         if(!check_seektable_(block, seekpoints, seekpoint_array))
722                 return false;
723
724         seekpoints = 1;
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");
728                 return false;
729         }
730         if(!check_seektable_(block, seekpoints, seekpoint_array))
731                 return false;
732
733         printf("testing FLAC__metadata_object_seektable_is_legal()...");
734         if(!FLAC__metadata_object_seektable_is_legal(block)) {
735                 printf("FAILED, returned false\n");
736                 return false;
737         }
738         printf("OK\n");
739
740         seekpoints = 0;
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");
744                 return false;
745         }
746         if(!check_seektable_(block, seekpoints, 0))
747                 return false;
748
749         seekpoints++;
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");
753                 return false;
754         }
755         if(!check_seektable_(block, seekpoints, seekpoint_array))
756                 return false;
757
758         seekpoint_array[0].sample_number = 1;
759         seekpoints++;
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");
763                 return false;
764         }
765         if(!check_seektable_(block, seekpoints, seekpoint_array))
766                 return false;
767
768         seekpoint_array[1].sample_number = 2;
769         seekpoints++;
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");
773                 return false;
774         }
775         if(!check_seektable_(block, seekpoints, seekpoint_array))
776                 return false;
777
778         seekpoint_array[3].sample_number = 3;
779         seekpoints++;
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");
783                 return false;
784         }
785         if(!check_seektable_(block, seekpoints, seekpoint_array))
786                 return false;
787
788         printf("testing FLAC__metadata_object_clone()... ");
789         blockcopy = FLAC__metadata_object_clone(block);
790         if(0 == blockcopy) {
791                 printf("FAILED, returned NULL\n");
792                 return false;
793         }
794         if(!mutils__compare_block(block, blockcopy))
795                 return false;
796         printf("OK\n");
797
798         printf("testing FLAC__metadata_object_delete()... ");
799         FLAC__metadata_object_delete(blockcopy);
800         printf("OK\n");
801
802         seekpoint_array[2].sample_number = seekpoint_array[3].sample_number;
803         seekpoints--;
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");
807                 return false;
808         }
809         if(!check_seektable_(block, seekpoints, seekpoint_array))
810                 return false;
811
812         seekpoints--;
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");
816                 return false;
817         }
818         if(!check_seektable_(block, seekpoints, seekpoint_array))
819                 return false;
820
821         seekpoints--;
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");
825                 return false;
826         }
827         if(!check_seektable_(block, seekpoints, seekpoint_array+1))
828                 return false;
829
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))
833                 return false;
834
835         printf("testing FLAC__metadata_object_delete()... ");
836         FLAC__metadata_object_delete(block);
837         printf("OK\n");
838
839         /* seektable template functions */
840
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;
845         }
846
847         seekpoints = 0;
848         printf("testing FLAC__metadata_object_new()... ");
849         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE);
850         if(0 == block) {
851                 printf("FAILED, returned NULL\n");
852                 return false;
853         }
854         if(!check_seektable_(block, seekpoints, 0))
855                 return false;
856
857         seekpoints += 2;
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");
861                 return false;
862         }
863         if(!check_seektable_(block, seekpoints, seekpoint_array))
864                 return false;
865
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");
870                 return false;
871         }
872         if(!check_seektable_(block, seekpoints, seekpoint_array))
873                 return false;
874
875         {
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");
882                         return false;
883                 }
884                 if(!check_seektable_(block, seekpoints, seekpoint_array))
885                         return false;
886         }
887
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");
894                 return false;
895         }
896         if(!check_seektable_(block, seekpoints, seekpoint_array))
897                 return false;
898
899         seekpoints--;
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");
910                 return false;
911         }
912         if(!FLAC__metadata_object_seektable_is_legal(block)) {
913                 printf("FAILED, seek table is illegal\n");
914                 return false;
915         }
916         if(!check_seektable_(block, seekpoints, seekpoint_array))
917                 return false;
918
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");
922                 return false;
923         }
924         if(!FLAC__metadata_object_seektable_is_legal(block)) {
925                 printf("FAILED, seek table is illegal\n");
926                 return false;
927         }
928         if(!check_seektable_(block, seekpoints, seekpoint_array))
929                 return false;
930
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");
937                 return false;
938         }
939         if(!check_seektable_(block, seekpoints, seekpoint_array))
940                 return false;
941
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");
948                 return false;
949         }
950         if(!check_seektable_(block, seekpoints, seekpoint_array))
951                 return false;
952
953         printf("testing FLAC__metadata_object_delete()... ");
954         FLAC__metadata_object_delete(block);
955         printf("OK\n");
956
957
958         printf("testing VORBIS_COMMENT\n");
959
960         {
961                 FLAC__StreamMetadata_VorbisComment_Entry entry_;
962                 char *field_name, *field_value;
963
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");
967                         return false;
968                 }
969                 if(strcmp((const char *)entry_.entry, "name=value")) {
970                         printf("FAILED, field mismatch\n");
971                         return false;
972                 }
973                 printf("OK\n");
974
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");
978                         return false;
979                 }
980                 if(strcmp(field_name, "name")) {
981                         printf("FAILED, field name mismatch\n");
982                         return false;
983                 }
984                 if(strcmp(field_value, "value")) {
985                         printf("FAILED, field value mismatch\n");
986                         return false;
987                 }
988                 printf("OK\n");
989
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");
993                         return false;
994                 }
995                 printf("OK\n");
996
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");
1000                         return false;
1001                 }
1002                 printf("OK\n");
1003
1004                 free(entry_.entry);
1005                 free(field_name);
1006                 free(field_value);
1007         }
1008
1009         printf("testing FLAC__metadata_object_new()... ");
1010         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
1011         if(0 == block) {
1012                 printf("FAILED, returned NULL\n");
1013                 return false;
1014         }
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);
1018                 return false;
1019         }
1020         printf("OK\n");
1021
1022         printf("testing FLAC__metadata_object_clone()... ");
1023         vorbiscomment = FLAC__metadata_object_clone(block);
1024         if(0 == vorbiscomment) {
1025                 printf("FAILED, returned NULL\n");
1026                 return false;
1027         }
1028         if(!mutils__compare_block(vorbiscomment, block))
1029                 return false;
1030         printf("OK\n");
1031
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");
1036                 return false;
1037         }
1038         if(!mutils__compare_block(vorbiscomment, block))
1039                 return false;
1040         printf("OK\n");
1041
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");
1046                 return false;
1047         }
1048         if(!mutils__compare_block(vorbiscomment, block))
1049                 return false;
1050         printf("OK\n");
1051
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");
1056                 return false;
1057         }
1058         if(!mutils__compare_block(vorbiscomment, block))
1059                 return false;
1060         printf("OK\n");
1061
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");
1066                 return false;
1067         }
1068         if(!mutils__compare_block(vorbiscomment, block))
1069                 return false;
1070         printf("OK\n");
1071
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");
1076                 return false;
1077         }
1078         if(!mutils__compare_block(vorbiscomment, block))
1079                 return false;
1080         printf("OK\n");
1081
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");
1086                 return false;
1087         }
1088         if(!mutils__compare_block(vorbiscomment, block))
1089                 return false;
1090         printf("OK\n");
1091
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");
1096                 return false;
1097         }
1098         if(!mutils__compare_block(vorbiscomment, block))
1099                 return false;
1100         printf("OK\n");
1101
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");
1106                 return false;
1107         }
1108         if(!mutils__compare_block(vorbiscomment, block))
1109                 return false;
1110         printf("OK\n");
1111
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");
1116                 return false;
1117         }
1118         if(!mutils__compare_block(vorbiscomment, block))
1119                 return false;
1120         printf("OK\n");
1121
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");
1126                 return false;
1127         }
1128         if(!mutils__compare_block(vorbiscomment, block))
1129                 return false;
1130         printf("OK\n");
1131
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");
1136                 return false;
1137         }
1138         if(!mutils__compare_block(vorbiscomment, block))
1139                 return false;
1140         printf("OK\n");
1141
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");
1146                 return false;
1147         }
1148         if(!mutils__compare_block(vorbiscomment, block))
1149                 return false;
1150         printf("OK\n");
1151
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);
1155                 return false;
1156         }
1157         printf("OK\n");
1158
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);
1162                 return false;
1163         }
1164         printf("OK\n");
1165
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);
1169                 return false;
1170         }
1171         printf("OK\n");
1172
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);
1176                 return false;
1177         }
1178         printf("OK\n");
1179
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);
1183                 return false;
1184         }
1185         printf("OK\n");
1186
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);
1190                 return false;
1191         }
1192         printf("OK\n");
1193
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");
1198                 return false;
1199         }
1200         if(!mutils__compare_block(vorbiscomment, block))
1201                 return false;
1202         if(block->data.vorbis_comment.num_comments != 6) {
1203                 printf("FAILED, expected 6 comments, got %u\n", block->data.vorbis_comment.num_comments);
1204                 return false;
1205         }
1206         printf("OK\n");
1207
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");
1212                 return false;
1213         }
1214         if(!mutils__compare_block(vorbiscomment, block))
1215                 return false;
1216         if(block->data.vorbis_comment.num_comments != 4) {
1217                 printf("FAILED, expected 4 comments, got %u\n", block->data.vorbis_comment.num_comments);
1218                 return false;
1219         }
1220         printf("OK\n");
1221
1222         printf("testing FLAC__metadata_object_clone()... ");
1223         blockcopy = FLAC__metadata_object_clone(block);
1224         if(0 == blockcopy) {
1225                 printf("FAILED, returned NULL\n");
1226                 return false;
1227         }
1228         if(!mutils__compare_block(block, blockcopy))
1229                 return false;
1230         printf("OK\n");
1231
1232         printf("testing FLAC__metadata_object_delete()... ");
1233         FLAC__metadata_object_delete(blockcopy);
1234         printf("OK\n");
1235
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");
1240                 return false;
1241         }
1242         if(!mutils__compare_block(vorbiscomment, block))
1243                 return false;
1244         printf("OK\n");
1245
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");
1250                 return false;
1251         }
1252         if(!mutils__compare_block(vorbiscomment, block))
1253                 return false;
1254         printf("OK\n");
1255
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");
1260                 return false;
1261         }
1262         if(!mutils__compare_block(vorbiscomment, block))
1263                 return false;
1264         printf("OK\n");
1265
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");
1270                 return false;
1271         }
1272         if(!mutils__compare_block(vorbiscomment, block))
1273                 return false;
1274         printf("OK\n");
1275
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");
1280                 return false;
1281         }
1282         if(!mutils__compare_block(vorbiscomment, block))
1283                 return false;
1284         printf("OK\n");
1285
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");
1290                 return false;
1291         }
1292         if(!mutils__compare_block(vorbiscomment, block))
1293                 return false;
1294         printf("OK\n");
1295
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);
1299                 return false;
1300         }
1301         if(block->data.vorbis_comment.num_comments != 4) {
1302                 printf("FAILED, expected 4 comments, got %u\n", block->data.vorbis_comment.num_comments);
1303                 return false;
1304         }
1305         if(!mutils__compare_block(vorbiscomment, block))
1306                 return false;
1307         printf("OK\n");
1308
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);
1313                 return false;
1314         }
1315         if(block->data.vorbis_comment.num_comments != 3) {
1316                 printf("FAILED, expected 3 comments, got %u\n", block->data.vorbis_comment.num_comments);
1317                 return false;
1318         }
1319         if(!mutils__compare_block(vorbiscomment, block))
1320                 return false;
1321         printf("OK\n");
1322
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);
1326                 return false;
1327         }
1328         if(block->data.vorbis_comment.num_comments != 3) {
1329                 printf("FAILED, expected 3 comments, got %u\n", block->data.vorbis_comment.num_comments);
1330                 return false;
1331         }
1332         if(!mutils__compare_block(vorbiscomment, block))
1333                 return false;
1334         printf("OK\n");
1335
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);
1341                 return false;
1342         }
1343         if(block->data.vorbis_comment.num_comments != 1) {
1344                 printf("FAILED, expected 1 comments, got %u\n", block->data.vorbis_comment.num_comments);
1345                 return false;
1346         }
1347         if(!mutils__compare_block(vorbiscomment, block))
1348                 return false;
1349         printf("OK\n");
1350
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))
1355                 return false;
1356         printf("OK\n");
1357
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))
1362                 return false;
1363         printf("OK\n");
1364
1365         printf("testing FLAC__metadata_object_delete()... ");
1366         FLAC__metadata_object_delete(vorbiscomment);
1367         FLAC__metadata_object_delete(block);
1368         printf("OK\n");
1369
1370
1371         printf("testing FLAC__metadata_object_new()... ");
1372         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
1373         if(0 == block) {
1374                 printf("FAILED, returned NULL\n");
1375                 return false;
1376         }
1377         printf("OK\n");
1378
1379         printf("testing FLAC__metadata_object_clone()... ");
1380         vorbiscomment = FLAC__metadata_object_clone(block);
1381         if(0 == vorbiscomment) {
1382                 printf("FAILED, returned NULL\n");
1383                 return false;
1384         }
1385         if(!mutils__compare_block(vorbiscomment, block))
1386                 return false;
1387         printf("OK\n");
1388
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");
1394                 return false;
1395         }
1396         if(!mutils__compare_block(vorbiscomment, block))
1397                 return false;
1398         printf("OK\n");
1399
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");
1405                 return false;
1406         }
1407         if(!mutils__compare_block(vorbiscomment, block))
1408                 return false;
1409         printf("OK\n");
1410
1411         printf("testing FLAC__metadata_object_delete()... ");
1412         FLAC__metadata_object_delete(vorbiscomment);
1413         FLAC__metadata_object_delete(block);
1414         printf("OK\n");
1415
1416         printf("testing FLAC__metadata_object_new()... ");
1417         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
1418         if(0 == block) {
1419                 printf("FAILED, returned NULL\n");
1420                 return false;
1421         }
1422         printf("OK\n");
1423
1424         printf("testing FLAC__metadata_object_clone()... ");
1425         vorbiscomment = FLAC__metadata_object_clone(block);
1426         if(0 == vorbiscomment) {
1427                 printf("FAILED, returned NULL\n");
1428                 return false;
1429         }
1430         if(!mutils__compare_block(vorbiscomment, block))
1431                 return false;
1432         printf("OK\n");
1433
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");
1439                 return false;
1440         }
1441         if(!mutils__compare_block(vorbiscomment, block))
1442                 return false;
1443         printf("OK\n");
1444
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");
1450                 return false;
1451         }
1452         if(!mutils__compare_block(vorbiscomment, block))
1453                 return false;
1454         printf("OK\n");
1455
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");
1461                 return false;
1462         }
1463         if(!mutils__compare_block(vorbiscomment, block))
1464                 return false;
1465         printf("OK\n");
1466
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");
1472                 return false;
1473         }
1474         if(!mutils__compare_block(vorbiscomment, block))
1475                 return false;
1476         printf("OK\n");
1477
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");
1483                 return false;
1484         }
1485         if(!mutils__compare_block(vorbiscomment, block))
1486                 return false;
1487         printf("OK\n");
1488
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");
1494                 return false;
1495         }
1496         if(!mutils__compare_block(vorbiscomment, block))
1497                 return false;
1498         printf("OK\n");
1499
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");
1505                 return false;
1506         }
1507         if(!mutils__compare_block(vorbiscomment, block))
1508                 return false;
1509         if(block->data.vorbis_comment.num_comments != 6) {
1510                 printf("FAILED, expected 6 comments, got %u\n", block->data.vorbis_comment.num_comments);
1511                 return false;
1512         }
1513         printf("OK\n");
1514
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");
1520                 return false;
1521         }
1522         if(!mutils__compare_block(vorbiscomment, block))
1523                 return false;
1524         if(block->data.vorbis_comment.num_comments != 4) {
1525                 printf("FAILED, expected 4 comments, got %u\n", block->data.vorbis_comment.num_comments);
1526                 return false;
1527         }
1528         printf("OK\n");
1529
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");
1534                 return false;
1535         }
1536         if(!mutils__compare_block(vorbiscomment, block))
1537                 return false;
1538         printf("OK\n");
1539
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");
1544                 return false;
1545         }
1546         if(!mutils__compare_block(vorbiscomment, block))
1547                 return false;
1548         printf("OK\n");
1549
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");
1554                 return false;
1555         }
1556         if(!mutils__compare_block(vorbiscomment, block))
1557                 return false;
1558         printf("OK\n");
1559
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))
1565                 return false;
1566         printf("OK\n");
1567
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))
1573                 return false;
1574         printf("OK\n");
1575
1576         printf("testing FLAC__metadata_object_delete()... ");
1577         FLAC__metadata_object_delete(vorbiscomment);
1578         FLAC__metadata_object_delete(block);
1579         printf("OK\n");
1580
1581
1582         printf("testing CUESHEET\n");
1583
1584         {
1585                 FLAC__StreamMetadata_CueSheet_Track *track_, *trackcopy_;
1586
1587                 printf("testing FLAC__metadata_object_cuesheet_track_new()... ");
1588                 track_ = FLAC__metadata_object_cuesheet_track_new();
1589                 if(0 == track_) {
1590                         printf("FAILED, returned NULL\n");
1591                         return false;
1592                 }
1593                 printf("OK\n");
1594
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");
1599                         return false;
1600                 }
1601                 if(!compare_track_(trackcopy_, track_))
1602                         return false;
1603                 printf("OK\n");
1604
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_);
1608                 printf("OK\n");
1609         }
1610
1611
1612         printf("testing FLAC__metadata_object_new()... ");
1613         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET);
1614         if(0 == block) {
1615                 printf("FAILED, returned NULL\n");
1616                 return false;
1617         }
1618         expected_length = (
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
1624         ) / 8;
1625         if(block->length != expected_length) {
1626                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
1627                 return false;
1628         }
1629         printf("OK\n");
1630
1631         printf("testing FLAC__metadata_object_clone()... ");
1632         cuesheet = FLAC__metadata_object_clone(block);
1633         if(0 == cuesheet) {
1634                 printf("FAILED, returned NULL\n");
1635                 return false;
1636         }
1637         if(!mutils__compare_block(cuesheet, block))
1638                 return false;
1639         printf("OK\n");
1640
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");
1645                 return false;
1646         }
1647         if(!mutils__compare_block(cuesheet, block))
1648                 return false;
1649         printf("OK\n");
1650
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");
1655                 return false;
1656         }
1657         if(!mutils__compare_block(cuesheet, block))
1658                 return false;
1659         printf("OK\n");
1660
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");
1665                 return false;
1666         }
1667         if(!mutils__compare_block(cuesheet, block))
1668                 return false;
1669         printf("OK\n");
1670
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");
1675                 return false;
1676         }
1677         if(!mutils__compare_block(cuesheet, block))
1678                 return false;
1679         printf("OK\n");
1680
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");
1685                 return false;
1686         }
1687         if(!mutils__compare_block(cuesheet, block))
1688                 return false;
1689         printf("OK\n");
1690
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");
1695                 return false;
1696         }
1697         if(!mutils__compare_block(cuesheet, block))
1698                 return false;
1699         printf("OK\n");
1700
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");
1705                 return false;
1706         }
1707         if(!mutils__compare_block(cuesheet, block))
1708                 return false;
1709         printf("OK\n");
1710
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");
1715                 return false;
1716         }
1717         if(!mutils__compare_block(cuesheet, block))
1718                 return false;
1719         printf("OK\n");
1720
1721         printf("testing FLAC__metadata_object_clone()... ");
1722         blockcopy = FLAC__metadata_object_clone(block);
1723         if(0 == blockcopy) {
1724                 printf("FAILED, returned NULL\n");
1725                 return false;
1726         }
1727         if(!mutils__compare_block(block, blockcopy))
1728                 return false;
1729         printf("OK\n");
1730
1731         printf("testing FLAC__metadata_object_delete()... ");
1732         FLAC__metadata_object_delete(blockcopy);
1733         printf("OK\n");
1734
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");
1739                 return false;
1740         }
1741         if(!mutils__compare_block(cuesheet, block))
1742                 return false;
1743         printf("OK\n");
1744
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");
1749                 return false;
1750         }
1751         if(!mutils__compare_block(cuesheet, block))
1752                 return false;
1753         printf("OK\n");
1754
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");
1759                 return false;
1760         }
1761         if(!mutils__compare_block(cuesheet, block))
1762                 return false;
1763         printf("OK\n");
1764
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");
1769                 return false;
1770         }
1771         if(!mutils__compare_block(cuesheet, block))
1772                 return false;
1773         printf("OK\n");
1774
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))
1779                 return false;
1780         printf("OK\n");
1781
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");
1786                 return false;
1787         }
1788         if(!mutils__compare_block(cuesheet, block))
1789                 return false;
1790         printf("OK\n");
1791
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");
1796                 return false;
1797         }
1798         if(!mutils__compare_block(cuesheet, block))
1799                 return false;
1800         printf("OK\n");
1801
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");
1806                 return false;
1807         }
1808         if(!mutils__compare_block(cuesheet, block))
1809                 return false;
1810         printf("OK\n");
1811
1812         index.offset = 0;
1813         index.number = 1;
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");
1818                 return false;
1819         }
1820         if(!mutils__compare_block(cuesheet, block))
1821                 return false;
1822         printf("OK\n");
1823
1824         index.offset = 10;
1825         index.number = 2;
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");
1830                 return false;
1831         }
1832         if(!mutils__compare_block(cuesheet, block))
1833                 return false;
1834         printf("OK\n");
1835
1836         index.offset = 20;
1837         index.number = 3;
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");
1842                 return false;
1843         }
1844         if(!mutils__compare_block(cuesheet, block))
1845                 return false;
1846         printf("OK\n");
1847
1848         index.offset = 30;
1849         index.number = 4;
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");
1854                 return false;
1855         }
1856         if(!mutils__compare_block(cuesheet, block))
1857                 return false;
1858         printf("OK\n");
1859
1860         index.offset = 0;
1861         index.number = 0;
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");
1866                 return false;
1867         }
1868         if(!mutils__compare_block(cuesheet, block))
1869                 return false;
1870         printf("OK\n");
1871
1872         printf("testing FLAC__metadata_object_clone()... ");
1873         blockcopy = FLAC__metadata_object_clone(block);
1874         if(0 == blockcopy) {
1875                 printf("FAILED, returned NULL\n");
1876                 return false;
1877         }
1878         if(!mutils__compare_block(block, blockcopy))
1879                 return false;
1880         printf("OK\n");
1881
1882         printf("testing FLAC__metadata_object_delete()... ");
1883         FLAC__metadata_object_delete(blockcopy);
1884         printf("OK\n");
1885
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");
1890                 return false;
1891         }
1892         if(!mutils__compare_block(cuesheet, block))
1893                 return false;
1894         printf("OK\n");
1895
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");
1900                 return false;
1901         }
1902         if(!mutils__compare_block(cuesheet, block))
1903                 return false;
1904         printf("OK\n");
1905
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");
1910                 return false;
1911         }
1912         if(!mutils__compare_block(cuesheet, block))
1913                 return false;
1914         printf("OK\n");
1915
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");
1920                 return false;
1921         }
1922         if(!mutils__compare_block(cuesheet, block))
1923                 return false;
1924         printf("OK\n");
1925
1926         printf("testing FLAC__metadata_object_delete()... ");
1927         FLAC__metadata_object_delete(cuesheet);
1928         FLAC__metadata_object_delete(block);
1929         printf("OK\n");
1930
1931
1932         printf("testing FLAC__metadata_object_new()... ");
1933         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET);
1934         if(0 == block) {
1935                 printf("FAILED, returned NULL\n");
1936                 return false;
1937         }
1938         printf("OK\n");
1939
1940         printf("testing FLAC__metadata_object_clone()... ");
1941         cuesheet = FLAC__metadata_object_clone(block);
1942         if(0 == cuesheet) {
1943                 printf("FAILED, returned NULL\n");
1944                 return false;
1945         }
1946         if(!mutils__compare_block(cuesheet, block))
1947                 return false;
1948         printf("OK\n");
1949
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");
1955                 return false;
1956         }
1957         if(!mutils__compare_block(cuesheet, block))
1958                 return false;
1959         printf("OK\n");
1960
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");
1966                 return false;
1967         }
1968         if(!mutils__compare_block(cuesheet, block))
1969                 return false;
1970         printf("OK\n");
1971
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");
1977                 return false;
1978         }
1979         if(!mutils__compare_block(cuesheet, block))
1980                 return false;
1981         printf("OK\n");
1982
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");
1988                 return false;
1989         }
1990         if(!mutils__compare_block(cuesheet, block))
1991                 return false;
1992         printf("OK\n");
1993
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");
1998                 return false;
1999         }
2000         if(!mutils__compare_block(cuesheet, block))
2001                 return false;
2002         printf("OK\n");
2003
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");
2008                 return false;
2009         }
2010         if(!mutils__compare_block(cuesheet, block))
2011                 return false;
2012         printf("OK\n");
2013
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");
2018                 return false;
2019         }
2020         if(!mutils__compare_block(cuesheet, block))
2021                 return false;
2022         printf("OK\n");
2023
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))
2029                 return false;
2030         printf("OK\n");
2031
2032         printf("testing FLAC__metadata_object_cuesheet_is_legal()...");
2033         {
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");
2037                         return false;
2038                 }
2039                 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2040         }
2041
2042         printf("testing FLAC__metadata_object_delete()... ");
2043         FLAC__metadata_object_delete(cuesheet);
2044         FLAC__metadata_object_delete(block);
2045         printf("OK\n");
2046
2047
2048         printf("testing PICTURE\n");
2049
2050         printf("testing FLAC__metadata_object_new()... ");
2051         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PICTURE);
2052         if(0 == block) {
2053                 printf("FAILED, returned NULL\n");
2054                 return false;
2055         }
2056         expected_length = (
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
2065         ) / 8;
2066         if(block->length != expected_length) {
2067                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
2068                 return false;
2069         }
2070         printf("OK\n");
2071
2072         printf("testing FLAC__metadata_object_clone()... ");
2073         picture = FLAC__metadata_object_clone(block);
2074         if(0 == picture) {
2075                 printf("FAILED, returned NULL\n");
2076                 return false;
2077         }
2078         if(!mutils__compare_block(picture, block))
2079                 return false;
2080         printf("OK\n");
2081
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");
2086                 return false;
2087         }
2088         if(!mutils__compare_block(picture, block))
2089                 return false;
2090         printf("OK\n");
2091
2092         printf("testing FLAC__metadata_object_picture_is_legal()...");
2093         {
2094                 const char *violation;
2095                 if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
2096                         printf("FAILED, returned true when expecting false\n");
2097                         return false;
2098                 }
2099                 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2100         }
2101
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");
2106                 return false;
2107         }
2108         if(!mutils__compare_block(picture, block))
2109                 return false;
2110         printf("OK\n");
2111
2112         printf("testing FLAC__metadata_object_picture_is_legal()...");
2113         {
2114                 const char *violation;
2115                 if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
2116                         printf("FAILED, returned false, violation=\"%s\"\n", violation);
2117                         return false;
2118                 }
2119                 printf("OK\n");
2120         }
2121
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");
2126                 return false;
2127         }
2128         if(!mutils__compare_block(picture, block))
2129                 return false;
2130         printf("OK\n");
2131
2132         printf("testing FLAC__metadata_object_picture_is_legal()...");
2133         {
2134                 const char *violation;
2135                 if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
2136                         printf("FAILED, returned true when expecting false\n");
2137                         return false;
2138                 }
2139                 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2140         }
2141
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");
2146                 return false;
2147         }
2148         if(!mutils__compare_block(picture, block))
2149                 return false;
2150         printf("OK\n");
2151
2152         printf("testing FLAC__metadata_object_picture_is_legal()...");
2153         {
2154                 const char *violation;
2155                 if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
2156                         printf("FAILED, returned false, violation=\"%s\"\n", violation);
2157                         return false;
2158                 }
2159                 printf("OK\n");
2160         }
2161
2162
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");
2167                 return false;
2168         }
2169         if(!mutils__compare_block(picture, block))
2170                 return false;
2171         printf("OK\n");
2172
2173         printf("testing FLAC__metadata_object_clone()... ");
2174         blockcopy = FLAC__metadata_object_clone(block);
2175         if(0 == blockcopy) {
2176                 printf("FAILED, returned NULL\n");
2177                 return false;
2178         }
2179         if(!mutils__compare_block(block, blockcopy))
2180                 return false;
2181         printf("OK\n");
2182
2183         printf("testing FLAC__metadata_object_delete()... ");
2184         FLAC__metadata_object_delete(blockcopy);
2185         printf("OK\n");
2186
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");
2191                 return false;
2192         }
2193         if(!mutils__compare_block(picture, block))
2194                 return false;
2195         printf("OK\n");
2196
2197         printf("testing FLAC__metadata_object_picture_is_legal()...");
2198         {
2199                 const char *violation;
2200                 if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
2201                         printf("FAILED, returned true when expecting false\n");
2202                         return false;
2203                 }
2204                 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2205         }
2206
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");
2211                 return false;
2212         }
2213         if(!mutils__compare_block(picture, block))
2214                 return false;
2215         printf("OK\n");
2216
2217         printf("testing FLAC__metadata_object_picture_is_legal()...");
2218         {
2219                 const char *violation;
2220                 if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
2221                         printf("FAILED, returned false, violation=\"%s\"\n", violation);
2222                         return false;
2223                 }
2224                 printf("OK\n");
2225         }
2226
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");
2231                 return false;
2232         }
2233         if(!mutils__compare_block(picture, block))
2234                 return false;
2235         printf("OK\n");
2236
2237         printf("testing FLAC__metadata_object_picture_is_legal()...");
2238         {
2239                 const char *violation;
2240                 if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
2241                         printf("FAILED, returned true when expecting false\n");
2242                         return false;
2243                 }
2244                 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2245         }
2246
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");
2251                 return false;
2252         }
2253         if(!mutils__compare_block(picture, block))
2254                 return false;
2255         printf("OK\n");
2256
2257         printf("testing FLAC__metadata_object_picture_is_legal()...");
2258         {
2259                 const char *violation;
2260                 if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
2261                         printf("FAILED, returned false, violation=\"%s\"\n", violation);
2262                         return false;
2263                 }
2264                 printf("OK\n");
2265         }
2266
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");
2271                 return false;
2272         }
2273         if(!mutils__compare_block(picture, block))
2274                 return false;
2275         printf("OK\n");
2276
2277         printf("testing FLAC__metadata_object_clone()... ");
2278         blockcopy = FLAC__metadata_object_clone(block);
2279         if(0 == blockcopy) {
2280                 printf("FAILED, returned NULL\n");
2281                 return false;
2282         }
2283         if(!mutils__compare_block(block, blockcopy))
2284                 return false;
2285         printf("OK\n");
2286
2287         printf("testing FLAC__metadata_object_delete()... ");
2288         FLAC__metadata_object_delete(blockcopy);
2289         printf("OK\n");
2290
2291         printf("testing FLAC__metadata_object_delete()... ");
2292         FLAC__metadata_object_delete(picture);
2293         FLAC__metadata_object_delete(block);
2294         printf("OK\n");
2295
2296
2297         return true;
2298 }