minor syntax
[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                 printf("FAILED, track offset mismatch, expected %llu, got %llu\n", to->offset, from->offset);
50                 return false;
51         }
52         if(from->number != to->number) {
53                 printf("FAILED, track number mismatch, expected %u, got %u\n", (unsigned)to->number, (unsigned)from->number);
54                 return false;
55         }
56         if(0 != strcmp(from->isrc, to->isrc)) {
57                 printf("FAILED, track number mismatch, expected %s, got %s\n", to->isrc, from->isrc);
58                 return false;
59         }
60         if(from->type != to->type) {
61                 printf("FAILED, track type mismatch, expected %u, got %u\n", (unsigned)to->type, (unsigned)from->type);
62                 return false;
63         }
64         if(from->pre_emphasis != to->pre_emphasis) {
65                 printf("FAILED, track pre_emphasis mismatch, expected %u, got %u\n", (unsigned)to->pre_emphasis, (unsigned)from->pre_emphasis);
66                 return false;
67         }
68         if(from->num_indices != to->num_indices) {
69                 printf("FAILED, track num_indices mismatch, expected %u, got %u\n", (unsigned)to->num_indices, (unsigned)from->num_indices);
70                 return false;
71         }
72         if(0 == to->indices || 0 == from->indices) {
73                 if(to->indices != from->indices) {
74                         printf("FAILED, track indices mismatch\n");
75                         return false;
76                 }
77         }
78         else {
79                 for(i = 0; i < to->num_indices; i++) {
80                         if(from->indices[i].offset != to->indices[i].offset) {
81                                 printf("FAILED, track indices[%u].offset mismatch, expected %llu, got %llu\n", i, to->indices[i].offset, from->indices[i].offset);
82                                 return false;
83                         }
84                         if(from->indices[i].number != to->indices[i].number) {
85                                 printf("FAILED, track indices[%u].number mismatch, expected %u, got %u\n", i, (unsigned)to->indices[i].number, (unsigned)from->indices[i].number);
86                                 return false;
87                         }
88                 }
89         }
90
91         return true;
92 }
93
94 static FLAC__bool compare_seekpoint_array_(const FLAC__StreamMetadata_SeekPoint *from, const FLAC__StreamMetadata_SeekPoint *to, unsigned n)
95 {
96         unsigned i;
97
98         FLAC__ASSERT(0 != from);
99         FLAC__ASSERT(0 != to);
100
101         for(i = 0; i < n; i++) {
102                 if(from[i].sample_number != to[i].sample_number) {
103                         printf("FAILED, point[%u].sample_number mismatch, expected %llu, got %llu\n", i, to[i].sample_number, from[i].sample_number);
104                         return false;
105                 }
106                 if(from[i].stream_offset != to[i].stream_offset) {
107                         printf("FAILED, point[%u].stream_offset mismatch, expected %llu, got %llu\n", i, to[i].stream_offset, from[i].stream_offset);
108                         return false;
109                 }
110                 if(from[i].frame_samples != to[i].frame_samples) {
111                         printf("FAILED, point[%u].frame_samples mismatch, expected %u, got %u\n", i, to[i].frame_samples, from[i].frame_samples);
112                         return false;
113                 }
114         }
115
116         return true;
117 }
118
119 static FLAC__bool check_seektable_(const FLAC__StreamMetadata *block, unsigned num_points, const FLAC__StreamMetadata_SeekPoint *array)
120 {
121         const unsigned expected_length = num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
122
123         if(block->length != expected_length) {
124                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
125                 return false;
126         }
127         if(block->data.seek_table.num_points != num_points) {
128                 printf("FAILED, expected %u point, got %u\n", num_points, block->data.seek_table.num_points);
129                 return false;
130         }
131         if(0 == array) {
132                 if(0 != block->data.seek_table.points) {
133                         printf("FAILED, 'points' pointer is not null\n");
134                         return false;
135                 }
136         }
137         else {
138                 if(!compare_seekpoint_array_(block->data.seek_table.points, array, num_points))
139                         return false;
140         }
141         printf("OK\n");
142
143         return true;
144 }
145
146 static void entry_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, const char *field)
147 {
148         entry->length = strlen(field);
149         entry->entry = (FLAC__byte*)malloc(entry->length+1);
150         FLAC__ASSERT(0 != entry->entry);
151         memcpy(entry->entry, field, entry->length);
152         entry->entry[entry->length] = '\0';
153 }
154
155 static void entry_clone_(FLAC__StreamMetadata_VorbisComment_Entry *entry)
156 {
157         FLAC__byte *x = (FLAC__byte*)malloc(entry->length+1);
158         FLAC__ASSERT(0 != x);
159         memcpy(x, entry->entry, entry->length);
160         x[entry->length] = '\0';
161         entry->entry = x;
162 }
163
164 static void vc_calc_len_(FLAC__StreamMetadata *block)
165 {
166         const FLAC__StreamMetadata_VorbisComment *vc = &block->data.vorbis_comment;
167         unsigned i;
168
169         block->length = FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
170         block->length += vc->vendor_string.length;
171         block->length += FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8;
172         for(i = 0; i < vc->num_comments; i++) {
173                 block->length += FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
174                 block->length += vc->comments[i].length;
175         }
176 }
177
178 static void vc_resize_(FLAC__StreamMetadata *block, unsigned num)
179 {
180         FLAC__StreamMetadata_VorbisComment *vc = &block->data.vorbis_comment;
181
182         if(vc->num_comments != 0) {
183                 FLAC__ASSERT(0 != vc->comments);
184                 if(num < vc->num_comments) {
185                         unsigned i;
186                         for(i = num; i < vc->num_comments; i++) {
187                                 if(0 != vc->comments[i].entry)
188                                         free(vc->comments[i].entry);
189                         }
190                 }
191         }
192         if(num == 0) {
193                 if(0 != vc->comments) {
194                         free(vc->comments);
195                         vc->comments = 0;
196                 }
197         }
198         else {
199                 vc->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)realloc(vc->comments, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*num);
200                 FLAC__ASSERT(0 != vc->comments);
201                 if(num > vc->num_comments)
202                         memset(vc->comments+vc->num_comments, 0, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(num-vc->num_comments));
203         }
204
205         vc->num_comments = num;
206         vc_calc_len_(block);
207 }
208
209 static int vc_find_from_(FLAC__StreamMetadata *block, const char *name, unsigned start)
210 {
211         const unsigned n = strlen(name);
212         unsigned i;
213         for(i = start; i < block->data.vorbis_comment.num_comments; i++) {
214                 const FLAC__StreamMetadata_VorbisComment_Entry *entry = &block->data.vorbis_comment.comments[i];
215                 if(entry->length > n && 0 == strncmp((const char *)entry->entry, name, n) && entry->entry[n] == '=')
216                         return (int)i;
217         }
218         return -1;
219 }
220
221 static void vc_set_vs_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, const char *field)
222 {
223         if(0 != block->data.vorbis_comment.vendor_string.entry)
224                 free(block->data.vorbis_comment.vendor_string.entry);
225         entry_new_(entry, field);
226         block->data.vorbis_comment.vendor_string = *entry;
227         vc_calc_len_(block);
228 }
229
230 static void vc_set_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, unsigned pos, const char *field)
231 {
232         if(0 != block->data.vorbis_comment.comments[pos].entry)
233                 free(block->data.vorbis_comment.comments[pos].entry);
234         entry_new_(entry, field);
235         block->data.vorbis_comment.comments[pos] = *entry;
236         vc_calc_len_(block);
237 }
238
239 static void vc_insert_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, unsigned pos, const char *field)
240 {
241         vc_resize_(block, block->data.vorbis_comment.num_comments+1);
242         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));
243         memset(&block->data.vorbis_comment.comments[pos], 0, sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
244         vc_set_new_(entry, block, pos, field);
245         vc_calc_len_(block);
246 }
247
248 static void vc_delete_(FLAC__StreamMetadata *block, unsigned pos)
249 {
250         if(0 != block->data.vorbis_comment.comments[pos].entry)
251                 free(block->data.vorbis_comment.comments[pos].entry);
252         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));
253         block->data.vorbis_comment.comments[block->data.vorbis_comment.num_comments-1].entry = 0;
254         block->data.vorbis_comment.comments[block->data.vorbis_comment.num_comments-1].length = 0;
255         vc_resize_(block, block->data.vorbis_comment.num_comments-1);
256         vc_calc_len_(block);
257 }
258
259 static void vc_replace_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, const char *field, FLAC__bool all)
260 {
261         int index;
262         char field_name[256];
263         const char *eq = strchr(field, '=');
264         FLAC__ASSERT(eq>field && (unsigned)(eq-field) < sizeof(field_name));
265         memcpy(field_name, field, eq-field);
266         field_name[eq-field]='\0';
267
268         index = vc_find_from_(block, field_name, 0);
269         if(index < 0)
270                 vc_insert_new_(entry, block, block->data.vorbis_comment.num_comments, field);
271         else {
272                 vc_set_new_(entry, block, (unsigned)index, field);
273                 if(all) {
274                         for(index = index+1; index >= 0 && (unsigned)index < block->data.vorbis_comment.num_comments; )
275                                 if((index = vc_find_from_(block, field_name, (unsigned)index)) >= 0)
276                                         vc_delete_(block, (unsigned)index);
277                 }
278         }
279
280         vc_calc_len_(block);
281 }
282
283 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)
284 {
285         track->offset = offset;
286         track->number = number;
287         memcpy(track->isrc, isrc, sizeof(track->isrc));
288         track->type = data;
289         track->pre_emphasis = pre_em;
290         track->num_indices = 0;
291         track->indices = 0;
292 }
293
294 static void track_clone_(FLAC__StreamMetadata_CueSheet_Track *track)
295 {
296         if(track->num_indices > 0) {
297                 size_t bytes = sizeof(FLAC__StreamMetadata_CueSheet_Index) * track->num_indices;
298                 FLAC__StreamMetadata_CueSheet_Index *x = (FLAC__StreamMetadata_CueSheet_Index*)malloc(bytes);
299                 FLAC__ASSERT(0 != x);
300                 memcpy(x, track->indices, bytes);
301                 track->indices = x;
302         }
303 }
304
305 static void cs_calc_len_(FLAC__StreamMetadata *block)
306 {
307         const FLAC__StreamMetadata_CueSheet *cs = &block->data.cue_sheet;
308         unsigned i;
309
310         block->length = (
311                 FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
312                 FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
313                 FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN +
314                 FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
315                 FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
316         ) / 8;
317         block->length += cs->num_tracks * (
318                 FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN +
319                 FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN +
320                 FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN +
321                 FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN +
322                 FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN +
323                 FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN +
324                 FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN
325         ) / 8;
326         for(i = 0; i < cs->num_tracks; i++) {
327                 block->length += cs->tracks[i].num_indices * (
328                         FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN +
329                         FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN +
330                         FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN
331                 ) / 8;
332         }
333 }
334
335 static void tr_resize_(FLAC__StreamMetadata *block, unsigned track_num, unsigned num)
336 {
337         FLAC__StreamMetadata_CueSheet_Track *tr;
338
339         FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
340
341         tr = &block->data.cue_sheet.tracks[track_num];
342
343         if(tr->num_indices != 0) {
344                 FLAC__ASSERT(0 != tr->indices);
345         }
346         if(num == 0) {
347                 if(0 != tr->indices) {
348                         free(tr->indices);
349                         tr->indices = 0;
350                 }
351         }
352         else {
353                 tr->indices = (FLAC__StreamMetadata_CueSheet_Index*)realloc(tr->indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)*num);
354                 FLAC__ASSERT(0 != tr->indices);
355                 if(num > tr->num_indices)
356                         memset(tr->indices+tr->num_indices, 0, sizeof(FLAC__StreamMetadata_CueSheet_Index)*(num-tr->num_indices));
357         }
358
359         tr->num_indices = num;
360         cs_calc_len_(block);
361 }
362
363 static void tr_set_new_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos, FLAC__StreamMetadata_CueSheet_Index index)
364 {
365         FLAC__StreamMetadata_CueSheet_Track *tr;
366
367         FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
368
369         tr = &block->data.cue_sheet.tracks[track_num];
370
371         FLAC__ASSERT(pos < tr->num_indices);
372
373         tr->indices[pos] = index;
374
375         cs_calc_len_(block);
376 }
377
378 static void tr_insert_new_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos, FLAC__StreamMetadata_CueSheet_Index index)
379 {
380         FLAC__StreamMetadata_CueSheet_Track *tr;
381
382         FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
383
384         tr = &block->data.cue_sheet.tracks[track_num];
385
386         FLAC__ASSERT(pos <= tr->num_indices);
387
388         tr_resize_(block, track_num, tr->num_indices+1);
389         memmove(&tr->indices[pos+1], &tr->indices[pos], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(tr->num_indices-1-pos));
390         tr_set_new_(block, track_num, pos, index);
391         cs_calc_len_(block);
392 }
393
394 static void tr_delete_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos)
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         memmove(&tr->indices[pos], &tr->indices[pos+1], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(tr->num_indices-pos-1));
405         tr_resize_(block, track_num, tr->num_indices-1);
406         cs_calc_len_(block);
407 }
408
409 static void cs_resize_(FLAC__StreamMetadata *block, unsigned num)
410 {
411         FLAC__StreamMetadata_CueSheet *cs = &block->data.cue_sheet;
412
413         if(cs->num_tracks != 0) {
414                 FLAC__ASSERT(0 != cs->tracks);
415                 if(num < cs->num_tracks) {
416                         unsigned i;
417                         for(i = num; i < cs->num_tracks; i++) {
418                                 if(0 != cs->tracks[i].indices)
419                                         free(cs->tracks[i].indices);
420                         }
421                 }
422         }
423         if(num == 0) {
424                 if(0 != cs->tracks) {
425                         free(cs->tracks);
426                         cs->tracks = 0;
427                 }
428         }
429         else {
430                 cs->tracks = (FLAC__StreamMetadata_CueSheet_Track*)realloc(cs->tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)*num);
431                 FLAC__ASSERT(0 != cs->tracks);
432                 if(num > cs->num_tracks)
433                         memset(cs->tracks+cs->num_tracks, 0, sizeof(FLAC__StreamMetadata_CueSheet_Track)*(num-cs->num_tracks));
434         }
435
436         cs->num_tracks = num;
437         cs_calc_len_(block);
438 }
439
440 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)
441 {
442         track_new_(track, offset, number, isrc, data, pre_em);
443         block->data.cue_sheet.tracks[pos] = *track;
444         cs_calc_len_(block);
445 }
446
447 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)
448 {
449         cs_resize_(block, block->data.cue_sheet.num_tracks+1);
450         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));
451         cs_set_new_(track, block, pos, offset, number, isrc, data, pre_em);
452         cs_calc_len_(block);
453 }
454
455 static void cs_delete_(FLAC__StreamMetadata *block, unsigned pos)
456 {
457         if(0 != block->data.cue_sheet.tracks[pos].indices)
458                 free(block->data.cue_sheet.tracks[pos].indices);
459         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));
460         block->data.cue_sheet.tracks[block->data.cue_sheet.num_tracks-1].indices = 0;
461         block->data.cue_sheet.tracks[block->data.cue_sheet.num_tracks-1].num_indices = 0;
462         cs_resize_(block, block->data.cue_sheet.num_tracks-1);
463         cs_calc_len_(block);
464 }
465
466 static void pi_set_mime_type(FLAC__StreamMetadata *block, const char *s)
467 {
468         if(block->data.picture.mime_type) {
469                 block->length -= strlen(block->data.picture.mime_type);
470                 free(block->data.picture.mime_type);
471         }
472         block->data.picture.mime_type = strdup(s);
473         FLAC__ASSERT(block->data.picture.mime_type);
474         block->length += strlen(block->data.picture.mime_type);
475 }
476
477 static void pi_set_description(FLAC__StreamMetadata *block, const FLAC__byte *s)
478 {
479         if(block->data.picture.description) {
480                 block->length -= strlen((const char *)block->data.picture.description);
481                 free(block->data.picture.description);
482         }
483         block->data.picture.description = (FLAC__byte*)strdup((const char *)s);
484         FLAC__ASSERT(block->data.picture.description);
485         block->length += strlen((const char *)block->data.picture.description);
486 }
487
488 static void pi_set_data(FLAC__StreamMetadata *block, const FLAC__byte *data, FLAC__uint32 len)
489 {
490         if(block->data.picture.data) {
491                 block->length -= block->data.picture.data_length;
492                 free(block->data.picture.data);
493         }
494         block->data.picture.data = (FLAC__byte*)strdup((const char *)data);
495         FLAC__ASSERT(block->data.picture.data);
496         block->data.picture.data_length = len;
497         block->length += len;
498 }
499
500 FLAC__bool test_metadata_object()
501 {
502         FLAC__StreamMetadata *block, *blockcopy, *vorbiscomment, *cuesheet, *picture;
503         FLAC__StreamMetadata_SeekPoint seekpoint_array[14];
504         FLAC__StreamMetadata_VorbisComment_Entry entry;
505         FLAC__StreamMetadata_CueSheet_Index index;
506         FLAC__StreamMetadata_CueSheet_Track track;
507         unsigned i, expected_length, seekpoints;
508         int j;
509         static FLAC__byte dummydata[4] = { 'a', 'b', 'c', 'd' };
510
511         printf("\n+++ libFLAC unit test: metadata objects\n\n");
512
513
514         printf("testing STREAMINFO\n");
515
516         printf("testing FLAC__metadata_object_new()... ");
517         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_STREAMINFO);
518         if(0 == block) {
519                 printf("FAILED, returned NULL\n");
520                 return false;
521         }
522         expected_length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
523         if(block->length != expected_length) {
524                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
525                 return false;
526         }
527         printf("OK\n");
528
529         printf("testing FLAC__metadata_object_clone()... ");
530         blockcopy = FLAC__metadata_object_clone(block);
531         if(0 == blockcopy) {
532                 printf("FAILED, returned NULL\n");
533                 return false;
534         }
535         if(!mutils__compare_block(block, blockcopy))
536                 return false;
537         printf("OK\n");
538
539         printf("testing FLAC__metadata_object_delete()... ");
540         FLAC__metadata_object_delete(blockcopy);
541         FLAC__metadata_object_delete(block);
542         printf("OK\n");
543
544
545         printf("testing PADDING\n");
546
547         printf("testing FLAC__metadata_object_new()... ");
548         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING);
549         if(0 == block) {
550                 printf("FAILED, returned NULL\n");
551                 return false;
552         }
553         expected_length = 0;
554         if(block->length != expected_length) {
555                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
556                 return false;
557         }
558         printf("OK\n");
559
560         printf("testing FLAC__metadata_object_clone()... ");
561         blockcopy = FLAC__metadata_object_clone(block);
562         if(0 == blockcopy) {
563                 printf("FAILED, returned NULL\n");
564                 return false;
565         }
566         if(!mutils__compare_block(block, blockcopy))
567                 return false;
568         printf("OK\n");
569
570         printf("testing FLAC__metadata_object_delete()... ");
571         FLAC__metadata_object_delete(blockcopy);
572         FLAC__metadata_object_delete(block);
573         printf("OK\n");
574
575
576         printf("testing APPLICATION\n");
577
578         printf("testing FLAC__metadata_object_new()... ");
579         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION);
580         if(0 == block) {
581                 printf("FAILED, returned NULL\n");
582                 return false;
583         }
584         expected_length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
585         if(block->length != expected_length) {
586                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
587                 return false;
588         }
589         printf("OK\n");
590
591         printf("testing FLAC__metadata_object_clone()... ");
592         blockcopy = FLAC__metadata_object_clone(block);
593         if(0 == blockcopy) {
594                 printf("FAILED, returned NULL\n");
595                 return false;
596         }
597         if(!mutils__compare_block(block, blockcopy))
598                 return false;
599         printf("OK\n");
600
601         printf("testing FLAC__metadata_object_delete()... ");
602         FLAC__metadata_object_delete(blockcopy);
603         printf("OK\n");
604
605         printf("testing FLAC__metadata_object_application_set_data(copy)... ");
606         if(!FLAC__metadata_object_application_set_data(block, dummydata, sizeof(dummydata), true/*copy*/)) {
607                 printf("FAILED, returned false\n");
608                 return false;
609         }
610         expected_length = (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) + sizeof(dummydata);
611         if(block->length != expected_length) {
612                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
613                 return false;
614         }
615         if(0 != memcmp(block->data.application.data, dummydata, sizeof(dummydata))) {
616                 printf("FAILED, data mismatch\n");
617                 return false;
618         }
619         printf("OK\n");
620
621         printf("testing FLAC__metadata_object_clone()... ");
622         blockcopy = FLAC__metadata_object_clone(block);
623         if(0 == blockcopy) {
624                 printf("FAILED, returned NULL\n");
625                 return false;
626         }
627         if(!mutils__compare_block(block, blockcopy))
628                 return false;
629         printf("OK\n");
630
631         printf("testing FLAC__metadata_object_delete()... ");
632         FLAC__metadata_object_delete(blockcopy);
633         printf("OK\n");
634
635         printf("testing FLAC__metadata_object_application_set_data(own)... ");
636         if(!FLAC__metadata_object_application_set_data(block, make_dummydata_(dummydata, sizeof(dummydata)), sizeof(dummydata), false/*own*/)) {
637                 printf("FAILED, returned false\n");
638                 return false;
639         }
640         expected_length = (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) + sizeof(dummydata);
641         if(block->length != expected_length) {
642                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
643                 return false;
644         }
645         if(0 != memcmp(block->data.application.data, dummydata, sizeof(dummydata))) {
646                 printf("FAILED, data mismatch\n");
647                 return false;
648         }
649         printf("OK\n");
650
651         printf("testing FLAC__metadata_object_clone()... ");
652         blockcopy = FLAC__metadata_object_clone(block);
653         if(0 == blockcopy) {
654                 printf("FAILED, returned NULL\n");
655                 return false;
656         }
657         if(!mutils__compare_block(block, blockcopy))
658                 return false;
659         printf("OK\n");
660
661         printf("testing FLAC__metadata_object_delete()... ");
662         FLAC__metadata_object_delete(blockcopy);
663         FLAC__metadata_object_delete(block);
664         printf("OK\n");
665
666
667         printf("testing SEEKTABLE\n");
668
669         for(i = 0; i < sizeof(seekpoint_array) / sizeof(FLAC__StreamMetadata_SeekPoint); i++) {
670                 seekpoint_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
671                 seekpoint_array[i].stream_offset = 0;
672                 seekpoint_array[i].frame_samples = 0;
673         }
674
675         seekpoints = 0;
676         printf("testing FLAC__metadata_object_new()... ");
677         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE);
678         if(0 == block) {
679                 printf("FAILED, returned NULL\n");
680                 return false;
681         }
682         if(!check_seektable_(block, seekpoints, 0))
683                 return false;
684
685         printf("testing FLAC__metadata_object_clone()... ");
686         blockcopy = FLAC__metadata_object_clone(block);
687         if(0 == blockcopy) {
688                 printf("FAILED, returned NULL\n");
689                 return false;
690         }
691         if(!mutils__compare_block(block, blockcopy))
692                 return false;
693         printf("OK\n");
694
695         printf("testing FLAC__metadata_object_delete()... ");
696         FLAC__metadata_object_delete(blockcopy);
697         printf("OK\n");
698
699         seekpoints = 2;
700         printf("testing FLAC__metadata_object_seektable_resize_points(grow to %u)...", seekpoints);
701         if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
702                 printf("FAILED, returned false\n");
703                 return false;
704         }
705         if(!check_seektable_(block, seekpoints, seekpoint_array))
706                 return false;
707
708         seekpoints = 1;
709         printf("testing FLAC__metadata_object_seektable_resize_points(shrink to %u)...", seekpoints);
710         if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
711                 printf("FAILED, returned false\n");
712                 return false;
713         }
714         if(!check_seektable_(block, seekpoints, seekpoint_array))
715                 return false;
716
717         printf("testing FLAC__metadata_object_seektable_is_legal()...");
718         if(!FLAC__metadata_object_seektable_is_legal(block)) {
719                 printf("FAILED, returned false\n");
720                 return false;
721         }
722         printf("OK\n");
723
724         seekpoints = 0;
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, 0))
731                 return false;
732
733         seekpoints++;
734         printf("testing FLAC__metadata_object_seektable_insert_point() on empty array...");
735         if(!FLAC__metadata_object_seektable_insert_point(block, 0, seekpoint_array[0])) {
736                 printf("FAILED, returned false\n");
737                 return false;
738         }
739         if(!check_seektable_(block, seekpoints, seekpoint_array))
740                 return false;
741
742         seekpoint_array[0].sample_number = 1;
743         seekpoints++;
744         printf("testing FLAC__metadata_object_seektable_insert_point() on beginning of non-empty array...");
745         if(!FLAC__metadata_object_seektable_insert_point(block, 0, seekpoint_array[0])) {
746                 printf("FAILED, returned false\n");
747                 return false;
748         }
749         if(!check_seektable_(block, seekpoints, seekpoint_array))
750                 return false;
751
752         seekpoint_array[1].sample_number = 2;
753         seekpoints++;
754         printf("testing FLAC__metadata_object_seektable_insert_point() on middle of non-empty array...");
755         if(!FLAC__metadata_object_seektable_insert_point(block, 1, seekpoint_array[1])) {
756                 printf("FAILED, returned false\n");
757                 return false;
758         }
759         if(!check_seektable_(block, seekpoints, seekpoint_array))
760                 return false;
761
762         seekpoint_array[3].sample_number = 3;
763         seekpoints++;
764         printf("testing FLAC__metadata_object_seektable_insert_point() on end of non-empty array...");
765         if(!FLAC__metadata_object_seektable_insert_point(block, 3, seekpoint_array[3])) {
766                 printf("FAILED, returned false\n");
767                 return false;
768         }
769         if(!check_seektable_(block, seekpoints, seekpoint_array))
770                 return false;
771
772         printf("testing FLAC__metadata_object_clone()... ");
773         blockcopy = FLAC__metadata_object_clone(block);
774         if(0 == blockcopy) {
775                 printf("FAILED, returned NULL\n");
776                 return false;
777         }
778         if(!mutils__compare_block(block, blockcopy))
779                 return false;
780         printf("OK\n");
781
782         printf("testing FLAC__metadata_object_delete()... ");
783         FLAC__metadata_object_delete(blockcopy);
784         printf("OK\n");
785
786         seekpoint_array[2].sample_number = seekpoint_array[3].sample_number;
787         seekpoints--;
788         printf("testing FLAC__metadata_object_seektable_delete_point() on middle of array...");
789         if(!FLAC__metadata_object_seektable_delete_point(block, 2)) {
790                 printf("FAILED, returned false\n");
791                 return false;
792         }
793         if(!check_seektable_(block, seekpoints, seekpoint_array))
794                 return false;
795
796         seekpoints--;
797         printf("testing FLAC__metadata_object_seektable_delete_point() on end of array...");
798         if(!FLAC__metadata_object_seektable_delete_point(block, 2)) {
799                 printf("FAILED, returned false\n");
800                 return false;
801         }
802         if(!check_seektable_(block, seekpoints, seekpoint_array))
803                 return false;
804
805         seekpoints--;
806         printf("testing FLAC__metadata_object_seektable_delete_point() on beginning of array...");
807         if(!FLAC__metadata_object_seektable_delete_point(block, 0)) {
808                 printf("FAILED, returned false\n");
809                 return false;
810         }
811         if(!check_seektable_(block, seekpoints, seekpoint_array+1))
812                 return false;
813
814         printf("testing FLAC__metadata_object_seektable_set_point()...");
815         FLAC__metadata_object_seektable_set_point(block, 0, seekpoint_array[0]);
816         if(!check_seektable_(block, seekpoints, seekpoint_array))
817                 return false;
818
819         printf("testing FLAC__metadata_object_delete()... ");
820         FLAC__metadata_object_delete(block);
821         printf("OK\n");
822
823         /* seektable template functions */
824
825         for(i = 0; i < sizeof(seekpoint_array) / sizeof(FLAC__StreamMetadata_SeekPoint); i++) {
826                 seekpoint_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
827                 seekpoint_array[i].stream_offset = 0;
828                 seekpoint_array[i].frame_samples = 0;
829         }
830
831         seekpoints = 0;
832         printf("testing FLAC__metadata_object_new()... ");
833         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE);
834         if(0 == block) {
835                 printf("FAILED, returned NULL\n");
836                 return false;
837         }
838         if(!check_seektable_(block, seekpoints, 0))
839                 return false;
840
841         seekpoints += 2;
842         printf("testing FLAC__metadata_object_seekpoint_template_append_placeholders()... ");
843         if(!FLAC__metadata_object_seektable_template_append_placeholders(block, 2)) {
844                 printf("FAILED, returned false\n");
845                 return false;
846         }
847         if(!check_seektable_(block, seekpoints, seekpoint_array))
848                 return false;
849
850         seekpoint_array[seekpoints++].sample_number = 7;
851         printf("testing FLAC__metadata_object_seekpoint_template_append_point()... ");
852         if(!FLAC__metadata_object_seektable_template_append_point(block, 7)) {
853                 printf("FAILED, returned false\n");
854                 return false;
855         }
856         if(!check_seektable_(block, seekpoints, seekpoint_array))
857                 return false;
858
859         {
860                 FLAC__uint64 nums[2] = { 3, 7 };
861                 seekpoint_array[seekpoints++].sample_number = nums[0];
862                 seekpoint_array[seekpoints++].sample_number = nums[1];
863                 printf("testing FLAC__metadata_object_seekpoint_template_append_points()... ");
864                 if(!FLAC__metadata_object_seektable_template_append_points(block, nums, sizeof(nums)/sizeof(FLAC__uint64))) {
865                         printf("FAILED, returned false\n");
866                         return false;
867                 }
868                 if(!check_seektable_(block, seekpoints, seekpoint_array))
869                         return false;
870         }
871
872         seekpoint_array[seekpoints++].sample_number = 0;
873         seekpoint_array[seekpoints++].sample_number = 10;
874         seekpoint_array[seekpoints++].sample_number = 20;
875         printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points()... ");
876         if(!FLAC__metadata_object_seektable_template_append_spaced_points(block, 3, 30)) {
877                 printf("FAILED, returned false\n");
878                 return false;
879         }
880         if(!check_seektable_(block, seekpoints, seekpoint_array))
881                 return false;
882
883         seekpoints--;
884         seekpoint_array[0].sample_number = 0;
885         seekpoint_array[1].sample_number = 3;
886         seekpoint_array[2].sample_number = 7;
887         seekpoint_array[3].sample_number = 10;
888         seekpoint_array[4].sample_number = 20;
889         seekpoint_array[5].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
890         seekpoint_array[6].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
891         printf("testing FLAC__metadata_object_seekpoint_template_sort(compact=true)... ");
892         if(!FLAC__metadata_object_seektable_template_sort(block, /*compact=*/true)) {
893                 printf("FAILED, returned false\n");
894                 return false;
895         }
896         if(!FLAC__metadata_object_seektable_is_legal(block)) {
897                 printf("FAILED, seek table is illegal\n");
898                 return false;
899         }
900         if(!check_seektable_(block, seekpoints, seekpoint_array))
901                 return false;
902
903         printf("testing FLAC__metadata_object_seekpoint_template_sort(compact=false)... ");
904         if(!FLAC__metadata_object_seektable_template_sort(block, /*compact=*/false)) {
905                 printf("FAILED, returned false\n");
906                 return false;
907         }
908         if(!FLAC__metadata_object_seektable_is_legal(block)) {
909                 printf("FAILED, seek table is illegal\n");
910                 return false;
911         }
912         if(!check_seektable_(block, seekpoints, seekpoint_array))
913                 return false;
914
915         seekpoint_array[seekpoints++].sample_number = 0;
916         seekpoint_array[seekpoints++].sample_number = 10;
917         seekpoint_array[seekpoints++].sample_number = 20;
918         printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points_by_samples()... ");
919         if(!FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(block, 10, 30)) {
920                 printf("FAILED, returned false\n");
921                 return false;
922         }
923         if(!check_seektable_(block, seekpoints, seekpoint_array))
924                 return false;
925
926         seekpoint_array[seekpoints++].sample_number = 0;
927         seekpoint_array[seekpoints++].sample_number = 11;
928         seekpoint_array[seekpoints++].sample_number = 22;
929         printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points_by_samples()... ");
930         if(!FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(block, 11, 30)) {
931                 printf("FAILED, returned false\n");
932                 return false;
933         }
934         if(!check_seektable_(block, seekpoints, seekpoint_array))
935                 return false;
936
937         printf("testing FLAC__metadata_object_delete()... ");
938         FLAC__metadata_object_delete(block);
939         printf("OK\n");
940
941
942         printf("testing VORBIS_COMMENT\n");
943
944         {
945                 FLAC__StreamMetadata_VorbisComment_Entry entry_;
946                 char *field_name, *field_value;
947
948                 printf("testing FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair()... ");
949                 if(!FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(&entry_, "name", "value")) {
950                         printf("FAILED, returned false\n");
951                         return false;
952                 }
953                 if(strcmp((const char *)entry_.entry, "name=value")) {
954                         printf("FAILED, field mismatch\n");
955                         return false;
956                 }
957                 printf("OK\n");
958
959                 printf("testing FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair()... ");
960                 if(!FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair(entry_, &field_name, &field_value)) {
961                         printf("FAILED, returned false\n");
962                         return false;
963                 }
964                 if(strcmp(field_name, "name")) {
965                         printf("FAILED, field name mismatch\n");
966                         return false;
967                 }
968                 if(strcmp(field_value, "value")) {
969                         printf("FAILED, field value mismatch\n");
970                         return false;
971                 }
972                 printf("OK\n");
973
974                 printf("testing FLAC__metadata_object_vorbiscomment_entry_matches()... ");
975                 if(!FLAC__metadata_object_vorbiscomment_entry_matches(entry_, field_name, strlen(field_name))) {
976                         printf("FAILED, expected true, returned false\n");
977                         return false;
978                 }
979                 printf("OK\n");
980
981                 printf("testing FLAC__metadata_object_vorbiscomment_entry_matches()... ");
982                 if(FLAC__metadata_object_vorbiscomment_entry_matches(entry_, "blah", strlen("blah"))) {
983                         printf("FAILED, expected false, returned true\n");
984                         return false;
985                 }
986                 printf("OK\n");
987
988                 free(entry_.entry);
989                 free(field_name);
990                 free(field_value);
991         }
992
993         printf("testing FLAC__metadata_object_new()... ");
994         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
995         if(0 == block) {
996                 printf("FAILED, returned NULL\n");
997                 return false;
998         }
999         expected_length = (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + strlen(FLAC__VENDOR_STRING) + FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN/8);
1000         if(block->length != expected_length) {
1001                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
1002                 return false;
1003         }
1004         printf("OK\n");
1005
1006         printf("testing FLAC__metadata_object_clone()... ");
1007         vorbiscomment = FLAC__metadata_object_clone(block);
1008         if(0 == vorbiscomment) {
1009                 printf("FAILED, returned NULL\n");
1010                 return false;
1011         }
1012         if(!mutils__compare_block(vorbiscomment, block))
1013                 return false;
1014         printf("OK\n");
1015
1016         vc_resize_(vorbiscomment, 2);
1017         printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(grow to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
1018         if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
1019                 printf("FAILED, returned false\n");
1020                 return false;
1021         }
1022         if(!mutils__compare_block(vorbiscomment, block))
1023                 return false;
1024         printf("OK\n");
1025
1026         vc_resize_(vorbiscomment, 1);
1027         printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
1028         if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
1029                 printf("FAILED, returned false\n");
1030                 return false;
1031         }
1032         if(!mutils__compare_block(vorbiscomment, block))
1033                 return false;
1034         printf("OK\n");
1035
1036         vc_resize_(vorbiscomment, 0);
1037         printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
1038         if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
1039                 printf("FAILED, returned false\n");
1040                 return false;
1041         }
1042         if(!mutils__compare_block(vorbiscomment, block))
1043                 return false;
1044         printf("OK\n");
1045
1046         printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on empty array...");
1047         vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
1048         if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
1049                 printf("FAILED, returned false\n");
1050                 return false;
1051         }
1052         if(!mutils__compare_block(vorbiscomment, block))
1053                 return false;
1054         printf("OK\n");
1055
1056         printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on non-empty array...");
1057         vc_insert_new_(&entry, vorbiscomment, 1, "name2=field2");
1058         if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
1059                 printf("FAILED, returned false\n");
1060                 return false;
1061         }
1062         if(!mutils__compare_block(vorbiscomment, block))
1063                 return false;
1064         printf("OK\n");
1065
1066         vc_resize_(vorbiscomment, 0);
1067         printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
1068         if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
1069                 printf("FAILED, returned false\n");
1070                 return false;
1071         }
1072         if(!mutils__compare_block(vorbiscomment, block))
1073                 return false;
1074         printf("OK\n");
1075
1076         printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on empty array...");
1077         vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
1078         if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/true)) {
1079                 printf("FAILED, returned false\n");
1080                 return false;
1081         }
1082         if(!mutils__compare_block(vorbiscomment, block))
1083                 return false;
1084         printf("OK\n");
1085
1086         printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on beginning of non-empty array...");
1087         vc_insert_new_(&entry, vorbiscomment, 0, "name2=field2");
1088         if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/true)) {
1089                 printf("FAILED, returned false\n");
1090                 return false;
1091         }
1092         if(!mutils__compare_block(vorbiscomment, block))
1093                 return false;
1094         printf("OK\n");
1095
1096         printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on middle of non-empty array...");
1097         vc_insert_new_(&entry, vorbiscomment, 1, "name3=field3");
1098         if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 1, entry, /*copy=*/true)) {
1099                 printf("FAILED, returned false\n");
1100                 return false;
1101         }
1102         if(!mutils__compare_block(vorbiscomment, block))
1103                 return false;
1104         printf("OK\n");
1105
1106         printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array...");
1107         vc_insert_new_(&entry, vorbiscomment, 3, "name4=field4");
1108         if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 3, entry, /*copy=*/true)) {
1109                 printf("FAILED, returned false\n");
1110                 return false;
1111         }
1112         if(!mutils__compare_block(vorbiscomment, block))
1113                 return false;
1114         printf("OK\n");
1115
1116         printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array...");
1117         vc_insert_new_(&entry, vorbiscomment, 4, "name3=field3dup1");
1118         if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 4, entry, /*copy=*/true)) {
1119                 printf("FAILED, returned false\n");
1120                 return false;
1121         }
1122         if(!mutils__compare_block(vorbiscomment, block))
1123                 return false;
1124         printf("OK\n");
1125
1126         printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array...");
1127         vc_insert_new_(&entry, vorbiscomment, 5, "name3=field3dup1");
1128         if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 5, entry, /*copy=*/true)) {
1129                 printf("FAILED, returned false\n");
1130                 return false;
1131         }
1132         if(!mutils__compare_block(vorbiscomment, block))
1133                 return false;
1134         printf("OK\n");
1135
1136         printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()...");
1137         if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0, "name3")) != 1) {
1138                 printf("FAILED, expected 1, got %d\n", j);
1139                 return false;
1140         }
1141         printf("OK\n");
1142
1143         printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()...");
1144         if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, j+1, "name3")) != 4) {
1145                 printf("FAILED, expected 4, got %d\n", j);
1146                 return false;
1147         }
1148         printf("OK\n");
1149
1150         printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()...");
1151         if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, j+1, "name3")) != 5) {
1152                 printf("FAILED, expected 5, got %d\n", j);
1153                 return false;
1154         }
1155         printf("OK\n");
1156
1157         printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()...");
1158         if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0, "name2")) != 0) {
1159                 printf("FAILED, expected 0, got %d\n", j);
1160                 return false;
1161         }
1162         printf("OK\n");
1163
1164         printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()...");
1165         if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, j+1, "name2")) != -1) {
1166                 printf("FAILED, expected -1, got %d\n", j);
1167                 return false;
1168         }
1169         printf("OK\n");
1170
1171         printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()...");
1172         if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0, "blah")) != -1) {
1173                 printf("FAILED, expected -1, got %d\n", j);
1174                 return false;
1175         }
1176         printf("OK\n");
1177
1178         printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(first, copy)...");
1179         vc_replace_new_(&entry, vorbiscomment, "name3=field3new1", /*all=*/false);
1180         if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/false, /*copy=*/true)) {
1181                 printf("FAILED, returned false\n");
1182                 return false;
1183         }
1184         if(!mutils__compare_block(vorbiscomment, block))
1185                 return false;
1186         if(block->data.vorbis_comment.num_comments != 6) {
1187                 printf("FAILED, expected 6 comments, got %u\n", block->data.vorbis_comment.num_comments);
1188                 return false;
1189         }
1190         printf("OK\n");
1191
1192         printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(all, copy)...");
1193         vc_replace_new_(&entry, vorbiscomment, "name3=field3new2", /*all=*/true);
1194         if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/true, /*copy=*/true)) {
1195                 printf("FAILED, returned false\n");
1196                 return false;
1197         }
1198         if(!mutils__compare_block(vorbiscomment, block))
1199                 return false;
1200         if(block->data.vorbis_comment.num_comments != 4) {
1201                 printf("FAILED, expected 4 comments, got %u\n", block->data.vorbis_comment.num_comments);
1202                 return false;
1203         }
1204         printf("OK\n");
1205
1206         printf("testing FLAC__metadata_object_clone()... ");
1207         blockcopy = FLAC__metadata_object_clone(block);
1208         if(0 == blockcopy) {
1209                 printf("FAILED, returned NULL\n");
1210                 return false;
1211         }
1212         if(!mutils__compare_block(block, blockcopy))
1213                 return false;
1214         printf("OK\n");
1215
1216         printf("testing FLAC__metadata_object_delete()... ");
1217         FLAC__metadata_object_delete(blockcopy);
1218         printf("OK\n");
1219
1220         printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on middle of array...");
1221         vc_delete_(vorbiscomment, 2);
1222         if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
1223                 printf("FAILED, returned false\n");
1224                 return false;
1225         }
1226         if(!mutils__compare_block(vorbiscomment, block))
1227                 return false;
1228         printf("OK\n");
1229
1230         printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on end of array...");
1231         vc_delete_(vorbiscomment, 2);
1232         if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
1233                 printf("FAILED, returned false\n");
1234                 return false;
1235         }
1236         if(!mutils__compare_block(vorbiscomment, block))
1237                 return false;
1238         printf("OK\n");
1239
1240         printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on beginning of array...");
1241         vc_delete_(vorbiscomment, 0);
1242         if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 0)) {
1243                 printf("FAILED, returned false\n");
1244                 return false;
1245         }
1246         if(!mutils__compare_block(vorbiscomment, block))
1247                 return false;
1248         printf("OK\n");
1249
1250         printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on non-empty array...");
1251         vc_insert_new_(&entry, vorbiscomment, 1, "rem0=val0");
1252         if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
1253                 printf("FAILED, returned false\n");
1254                 return false;
1255         }
1256         if(!mutils__compare_block(vorbiscomment, block))
1257                 return false;
1258         printf("OK\n");
1259
1260         printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on non-empty array...");
1261         vc_insert_new_(&entry, vorbiscomment, 2, "rem0=val1");
1262         if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
1263                 printf("FAILED, returned false\n");
1264                 return false;
1265         }
1266         if(!mutils__compare_block(vorbiscomment, block))
1267                 return false;
1268         printf("OK\n");
1269
1270         printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on non-empty array...");
1271         vc_insert_new_(&entry, vorbiscomment, 3, "rem0=val2");
1272         if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
1273                 printf("FAILED, returned false\n");
1274                 return false;
1275         }
1276         if(!mutils__compare_block(vorbiscomment, block))
1277                 return false;
1278         printf("OK\n");
1279
1280         printf("testing FLAC__metadata_object_vorbiscomment_remove_entry_matching(\"blah\")...");
1281         if((j = FLAC__metadata_object_vorbiscomment_remove_entry_matching(block, "blah")) != 0) {
1282                 printf("FAILED, expected 0, got %d\n", j);
1283                 return false;
1284         }
1285         if(block->data.vorbis_comment.num_comments != 4) {
1286                 printf("FAILED, expected 4 comments, got %u\n", block->data.vorbis_comment.num_comments);
1287                 return false;
1288         }
1289         if(!mutils__compare_block(vorbiscomment, block))
1290                 return false;
1291         printf("OK\n");
1292
1293         printf("testing FLAC__metadata_object_vorbiscomment_remove_entry_matching(\"rem0\")...");
1294         vc_delete_(vorbiscomment, 1);
1295         if((j = FLAC__metadata_object_vorbiscomment_remove_entry_matching(block, "rem0")) != 1) {
1296                 printf("FAILED, expected 1, got %d\n", j);
1297                 return false;
1298         }
1299         if(block->data.vorbis_comment.num_comments != 3) {
1300                 printf("FAILED, expected 3 comments, got %u\n", block->data.vorbis_comment.num_comments);
1301                 return false;
1302         }
1303         if(!mutils__compare_block(vorbiscomment, block))
1304                 return false;
1305         printf("OK\n");
1306
1307         printf("testing FLAC__metadata_object_vorbiscomment_remove_entries_matching(\"blah\")...");
1308         if((j = FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, "blah")) != 0) {
1309                 printf("FAILED, expected 0, got %d\n", j);
1310                 return false;
1311         }
1312         if(block->data.vorbis_comment.num_comments != 3) {
1313                 printf("FAILED, expected 3 comments, got %u\n", block->data.vorbis_comment.num_comments);
1314                 return false;
1315         }
1316         if(!mutils__compare_block(vorbiscomment, block))
1317                 return false;
1318         printf("OK\n");
1319
1320         printf("testing FLAC__metadata_object_vorbiscomment_remove_entries_matching(\"rem0\")...");
1321         vc_delete_(vorbiscomment, 1);
1322         vc_delete_(vorbiscomment, 1);
1323         if((j = FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, "rem0")) != 2) {
1324                 printf("FAILED, expected 2, got %d\n", j);
1325                 return false;
1326         }
1327         if(block->data.vorbis_comment.num_comments != 1) {
1328                 printf("FAILED, expected 1 comments, got %u\n", block->data.vorbis_comment.num_comments);
1329                 return false;
1330         }
1331         if(!mutils__compare_block(vorbiscomment, block))
1332                 return false;
1333         printf("OK\n");
1334
1335         printf("testing FLAC__metadata_object_vorbiscomment_set_comment(copy)...");
1336         vc_set_new_(&entry, vorbiscomment, 0, "name5=field5");
1337         FLAC__metadata_object_vorbiscomment_set_comment(block, 0, entry, /*copy=*/true);
1338         if(!mutils__compare_block(vorbiscomment, block))
1339                 return false;
1340         printf("OK\n");
1341
1342         printf("testing FLAC__metadata_object_vorbiscomment_set_vendor_string(copy)...");
1343         vc_set_vs_new_(&entry, vorbiscomment, "name6=field6");
1344         FLAC__metadata_object_vorbiscomment_set_vendor_string(block, entry, /*copy=*/true);
1345         if(!mutils__compare_block(vorbiscomment, block))
1346                 return false;
1347         printf("OK\n");
1348
1349         printf("testing FLAC__metadata_object_delete()... ");
1350         FLAC__metadata_object_delete(vorbiscomment);
1351         FLAC__metadata_object_delete(block);
1352         printf("OK\n");
1353
1354
1355         printf("testing FLAC__metadata_object_new()... ");
1356         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
1357         if(0 == block) {
1358                 printf("FAILED, returned NULL\n");
1359                 return false;
1360         }
1361         printf("OK\n");
1362
1363         printf("testing FLAC__metadata_object_clone()... ");
1364         vorbiscomment = FLAC__metadata_object_clone(block);
1365         if(0 == vorbiscomment) {
1366                 printf("FAILED, returned NULL\n");
1367                 return false;
1368         }
1369         if(!mutils__compare_block(vorbiscomment, block))
1370                 return false;
1371         printf("OK\n");
1372
1373         printf("testing FLAC__metadata_object_vorbiscomment_append_comment(own) on empty array...");
1374         vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
1375         entry_clone_(&entry);
1376         if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/false)) {
1377                 printf("FAILED, returned false\n");
1378                 return false;
1379         }
1380         if(!mutils__compare_block(vorbiscomment, block))
1381                 return false;
1382         printf("OK\n");
1383
1384         printf("testing FLAC__metadata_object_vorbiscomment_append_comment(own) on non-empty array...");
1385         vc_insert_new_(&entry, vorbiscomment, 1, "name2=field2");
1386         entry_clone_(&entry);
1387         if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/false)) {
1388                 printf("FAILED, returned false\n");
1389                 return false;
1390         }
1391         if(!mutils__compare_block(vorbiscomment, block))
1392                 return false;
1393         printf("OK\n");
1394
1395         printf("testing FLAC__metadata_object_delete()... ");
1396         FLAC__metadata_object_delete(vorbiscomment);
1397         FLAC__metadata_object_delete(block);
1398         printf("OK\n");
1399
1400         printf("testing FLAC__metadata_object_new()... ");
1401         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
1402         if(0 == block) {
1403                 printf("FAILED, returned NULL\n");
1404                 return false;
1405         }
1406         printf("OK\n");
1407
1408         printf("testing FLAC__metadata_object_clone()... ");
1409         vorbiscomment = FLAC__metadata_object_clone(block);
1410         if(0 == vorbiscomment) {
1411                 printf("FAILED, returned NULL\n");
1412                 return false;
1413         }
1414         if(!mutils__compare_block(vorbiscomment, block))
1415                 return false;
1416         printf("OK\n");
1417
1418         printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on empty array...");
1419         vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
1420         entry_clone_(&entry);
1421         if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/false)) {
1422                 printf("FAILED, returned false\n");
1423                 return false;
1424         }
1425         if(!mutils__compare_block(vorbiscomment, block))
1426                 return false;
1427         printf("OK\n");
1428
1429         printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on beginning of non-empty array...");
1430         vc_insert_new_(&entry, vorbiscomment, 0, "name2=field2");
1431         entry_clone_(&entry);
1432         if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/false)) {
1433                 printf("FAILED, returned false\n");
1434                 return false;
1435         }
1436         if(!mutils__compare_block(vorbiscomment, block))
1437                 return false;
1438         printf("OK\n");
1439
1440         printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on middle of non-empty array...");
1441         vc_insert_new_(&entry, vorbiscomment, 1, "name3=field3");
1442         entry_clone_(&entry);
1443         if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 1, entry, /*copy=*/false)) {
1444                 printf("FAILED, returned false\n");
1445                 return false;
1446         }
1447         if(!mutils__compare_block(vorbiscomment, block))
1448                 return false;
1449         printf("OK\n");
1450
1451         printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on end of non-empty array...");
1452         vc_insert_new_(&entry, vorbiscomment, 3, "name4=field4");
1453         entry_clone_(&entry);
1454         if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 3, entry, /*copy=*/false)) {
1455                 printf("FAILED, returned false\n");
1456                 return false;
1457         }
1458         if(!mutils__compare_block(vorbiscomment, block))
1459                 return false;
1460         printf("OK\n");
1461
1462         printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on end of non-empty array...");
1463         vc_insert_new_(&entry, vorbiscomment, 4, "name3=field3dup1");
1464         entry_clone_(&entry);
1465         if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 4, entry, /*copy=*/false)) {
1466                 printf("FAILED, returned false\n");
1467                 return false;
1468         }
1469         if(!mutils__compare_block(vorbiscomment, block))
1470                 return false;
1471         printf("OK\n");
1472
1473         printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on end of non-empty array...");
1474         vc_insert_new_(&entry, vorbiscomment, 5, "name3=field3dup1");
1475         entry_clone_(&entry);
1476         if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 5, entry, /*copy=*/false)) {
1477                 printf("FAILED, returned false\n");
1478                 return false;
1479         }
1480         if(!mutils__compare_block(vorbiscomment, block))
1481                 return false;
1482         printf("OK\n");
1483
1484         printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(first, own)...");
1485         vc_replace_new_(&entry, vorbiscomment, "name3=field3new1", /*all=*/false);
1486         entry_clone_(&entry);
1487         if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/false, /*copy=*/false)) {
1488                 printf("FAILED, returned false\n");
1489                 return false;
1490         }
1491         if(!mutils__compare_block(vorbiscomment, block))
1492                 return false;
1493         if(block->data.vorbis_comment.num_comments != 6) {
1494                 printf("FAILED, expected 6 comments, got %u\n", block->data.vorbis_comment.num_comments);
1495                 return false;
1496         }
1497         printf("OK\n");
1498
1499         printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(all, own)...");
1500         vc_replace_new_(&entry, vorbiscomment, "name3=field3new2", /*all=*/true);
1501         entry_clone_(&entry);
1502         if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/true, /*copy=*/false)) {
1503                 printf("FAILED, returned false\n");
1504                 return false;
1505         }
1506         if(!mutils__compare_block(vorbiscomment, block))
1507                 return false;
1508         if(block->data.vorbis_comment.num_comments != 4) {
1509                 printf("FAILED, expected 4 comments, got %u\n", block->data.vorbis_comment.num_comments);
1510                 return false;
1511         }
1512         printf("OK\n");
1513
1514         printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on middle of array...");
1515         vc_delete_(vorbiscomment, 2);
1516         if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
1517                 printf("FAILED, returned false\n");
1518                 return false;
1519         }
1520         if(!mutils__compare_block(vorbiscomment, block))
1521                 return false;
1522         printf("OK\n");
1523
1524         printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on end of array...");
1525         vc_delete_(vorbiscomment, 2);
1526         if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
1527                 printf("FAILED, returned false\n");
1528                 return false;
1529         }
1530         if(!mutils__compare_block(vorbiscomment, block))
1531                 return false;
1532         printf("OK\n");
1533
1534         printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on beginning of array...");
1535         vc_delete_(vorbiscomment, 0);
1536         if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 0)) {
1537                 printf("FAILED, returned false\n");
1538                 return false;
1539         }
1540         if(!mutils__compare_block(vorbiscomment, block))
1541                 return false;
1542         printf("OK\n");
1543
1544         printf("testing FLAC__metadata_object_vorbiscomment_set_comment(own)...");
1545         vc_set_new_(&entry, vorbiscomment, 0, "name5=field5");
1546         entry_clone_(&entry);
1547         FLAC__metadata_object_vorbiscomment_set_comment(block, 0, entry, /*copy=*/false);
1548         if(!mutils__compare_block(vorbiscomment, block))
1549                 return false;
1550         printf("OK\n");
1551
1552         printf("testing FLAC__metadata_object_vorbiscomment_set_vendor_string(own)...");
1553         vc_set_vs_new_(&entry, vorbiscomment, "name6=field6");
1554         entry_clone_(&entry);
1555         FLAC__metadata_object_vorbiscomment_set_vendor_string(block, entry, /*copy=*/false);
1556         if(!mutils__compare_block(vorbiscomment, block))
1557                 return false;
1558         printf("OK\n");
1559
1560         printf("testing FLAC__metadata_object_delete()... ");
1561         FLAC__metadata_object_delete(vorbiscomment);
1562         FLAC__metadata_object_delete(block);
1563         printf("OK\n");
1564
1565
1566         printf("testing CUESHEET\n");
1567
1568         {
1569                 FLAC__StreamMetadata_CueSheet_Track *track_, *trackcopy_;
1570
1571                 printf("testing FLAC__metadata_object_cuesheet_track_new()... ");
1572                 track_ = FLAC__metadata_object_cuesheet_track_new();
1573                 if(0 == track_) {
1574                         printf("FAILED, returned NULL\n");
1575                         return false;
1576                 }
1577                 printf("OK\n");
1578
1579                 printf("testing FLAC__metadata_object_cuesheet_track_clone()... ");
1580                 trackcopy_ = FLAC__metadata_object_cuesheet_track_clone(track_);
1581                 if(0 == trackcopy_) {
1582                         printf("FAILED, returned NULL\n");
1583                         return false;
1584                 }
1585                 if(!compare_track_(trackcopy_, track_))
1586                         return false;
1587                 printf("OK\n");
1588
1589                 printf("testing FLAC__metadata_object_cuesheet_track_delete()... ");
1590                 FLAC__metadata_object_cuesheet_track_delete(trackcopy_);
1591                 FLAC__metadata_object_cuesheet_track_delete(track_);
1592                 printf("OK\n");
1593         }
1594
1595
1596         printf("testing FLAC__metadata_object_new()... ");
1597         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET);
1598         if(0 == block) {
1599                 printf("FAILED, returned NULL\n");
1600                 return false;
1601         }
1602         expected_length = (
1603                 FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
1604                 FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
1605                 FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN +
1606                 FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
1607                 FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
1608         ) / 8;
1609         if(block->length != expected_length) {
1610                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
1611                 return false;
1612         }
1613         printf("OK\n");
1614
1615         printf("testing FLAC__metadata_object_clone()... ");
1616         cuesheet = FLAC__metadata_object_clone(block);
1617         if(0 == cuesheet) {
1618                 printf("FAILED, returned NULL\n");
1619                 return false;
1620         }
1621         if(!mutils__compare_block(cuesheet, block))
1622                 return false;
1623         printf("OK\n");
1624
1625         cs_resize_(cuesheet, 2);
1626         printf("testing FLAC__metadata_object_cuesheet_resize_tracks(grow to %u)...", cuesheet->data.cue_sheet.num_tracks);
1627         if(!FLAC__metadata_object_cuesheet_resize_tracks(block, cuesheet->data.cue_sheet.num_tracks)) {
1628                 printf("FAILED, returned false\n");
1629                 return false;
1630         }
1631         if(!mutils__compare_block(cuesheet, block))
1632                 return false;
1633         printf("OK\n");
1634
1635         cs_resize_(cuesheet, 1);
1636         printf("testing FLAC__metadata_object_cuesheet_resize_tracks(shrink to %u)...", cuesheet->data.cue_sheet.num_tracks);
1637         if(!FLAC__metadata_object_cuesheet_resize_tracks(block, cuesheet->data.cue_sheet.num_tracks)) {
1638                 printf("FAILED, returned false\n");
1639                 return false;
1640         }
1641         if(!mutils__compare_block(cuesheet, block))
1642                 return false;
1643         printf("OK\n");
1644
1645         cs_resize_(cuesheet, 0);
1646         printf("testing FLAC__metadata_object_cuesheet_resize_tracks(shrink to %u)...", cuesheet->data.cue_sheet.num_tracks);
1647         if(!FLAC__metadata_object_cuesheet_resize_tracks(block, cuesheet->data.cue_sheet.num_tracks)) {
1648                 printf("FAILED, returned false\n");
1649                 return false;
1650         }
1651         if(!mutils__compare_block(cuesheet, block))
1652                 return false;
1653         printf("OK\n");
1654
1655         printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on empty array...");
1656         cs_insert_new_(&track, cuesheet, 0, 0, 1, "ABCDE1234567", false, false);
1657         if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/true)) {
1658                 printf("FAILED, returned false\n");
1659                 return false;
1660         }
1661         if(!mutils__compare_block(cuesheet, block))
1662                 return false;
1663         printf("OK\n");
1664
1665         printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on beginning of non-empty array...");
1666         cs_insert_new_(&track, cuesheet, 0, 10, 2, "BBCDE1234567", false, false);
1667         if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/true)) {
1668                 printf("FAILED, returned false\n");
1669                 return false;
1670         }
1671         if(!mutils__compare_block(cuesheet, block))
1672                 return false;
1673         printf("OK\n");
1674
1675         printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on middle of non-empty array...");
1676         cs_insert_new_(&track, cuesheet, 1, 20, 3, "CBCDE1234567", false, false);
1677         if(!FLAC__metadata_object_cuesheet_insert_track(block, 1, &track, /*copy=*/true)) {
1678                 printf("FAILED, returned false\n");
1679                 return false;
1680         }
1681         if(!mutils__compare_block(cuesheet, block))
1682                 return false;
1683         printf("OK\n");
1684
1685         printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on end of non-empty array...");
1686         cs_insert_new_(&track, cuesheet, 3, 30, 4, "DBCDE1234567", false, false);
1687         if(!FLAC__metadata_object_cuesheet_insert_track(block, 3, &track, /*copy=*/true)) {
1688                 printf("FAILED, returned false\n");
1689                 return false;
1690         }
1691         if(!mutils__compare_block(cuesheet, block))
1692                 return false;
1693         printf("OK\n");
1694
1695         printf("testing FLAC__metadata_object_cuesheet_insert_blank_track() on end of non-empty array...");
1696         cs_insert_new_(&track, cuesheet, 4, 0, 0, "\0\0\0\0\0\0\0\0\0\0\0\0", false, false);
1697         if(!FLAC__metadata_object_cuesheet_insert_blank_track(block, 4)) {
1698                 printf("FAILED, returned false\n");
1699                 return false;
1700         }
1701         if(!mutils__compare_block(cuesheet, block))
1702                 return false;
1703         printf("OK\n");
1704
1705         printf("testing FLAC__metadata_object_clone()... ");
1706         blockcopy = FLAC__metadata_object_clone(block);
1707         if(0 == blockcopy) {
1708                 printf("FAILED, returned NULL\n");
1709                 return false;
1710         }
1711         if(!mutils__compare_block(block, blockcopy))
1712                 return false;
1713         printf("OK\n");
1714
1715         printf("testing FLAC__metadata_object_delete()... ");
1716         FLAC__metadata_object_delete(blockcopy);
1717         printf("OK\n");
1718
1719         printf("testing FLAC__metadata_object_cuesheet_delete_track() on end of array...");
1720         cs_delete_(cuesheet, 4);
1721         if(!FLAC__metadata_object_cuesheet_delete_track(block, 4)) {
1722                 printf("FAILED, returned false\n");
1723                 return false;
1724         }
1725         if(!mutils__compare_block(cuesheet, block))
1726                 return false;
1727         printf("OK\n");
1728
1729         printf("testing FLAC__metadata_object_cuesheet_delete_track() on middle of array...");
1730         cs_delete_(cuesheet, 2);
1731         if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1732                 printf("FAILED, returned false\n");
1733                 return false;
1734         }
1735         if(!mutils__compare_block(cuesheet, block))
1736                 return false;
1737         printf("OK\n");
1738
1739         printf("testing FLAC__metadata_object_cuesheet_delete_track() on end of array...");
1740         cs_delete_(cuesheet, 2);
1741         if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1742                 printf("FAILED, returned false\n");
1743                 return false;
1744         }
1745         if(!mutils__compare_block(cuesheet, block))
1746                 return false;
1747         printf("OK\n");
1748
1749         printf("testing FLAC__metadata_object_cuesheet_delete_track() on beginning of array...");
1750         cs_delete_(cuesheet, 0);
1751         if(!FLAC__metadata_object_cuesheet_delete_track(block, 0)) {
1752                 printf("FAILED, returned false\n");
1753                 return false;
1754         }
1755         if(!mutils__compare_block(cuesheet, block))
1756                 return false;
1757         printf("OK\n");
1758
1759         printf("testing FLAC__metadata_object_cuesheet_set_track(copy)...");
1760         cs_set_new_(&track, cuesheet, 0, 40, 5, "EBCDE1234567", false, false);
1761         FLAC__metadata_object_cuesheet_set_track(block, 0, &track, /*copy=*/true);
1762         if(!mutils__compare_block(cuesheet, block))
1763                 return false;
1764         printf("OK\n");
1765
1766         tr_resize_(cuesheet, 0, 2);
1767         printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(grow to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices);
1768         if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) {
1769                 printf("FAILED, returned false\n");
1770                 return false;
1771         }
1772         if(!mutils__compare_block(cuesheet, block))
1773                 return false;
1774         printf("OK\n");
1775
1776         tr_resize_(cuesheet, 0, 1);
1777         printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(shrink to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices);
1778         if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) {
1779                 printf("FAILED, returned false\n");
1780                 return false;
1781         }
1782         if(!mutils__compare_block(cuesheet, block))
1783                 return false;
1784         printf("OK\n");
1785
1786         tr_resize_(cuesheet, 0, 0);
1787         printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(shrink to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices);
1788         if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) {
1789                 printf("FAILED, returned false\n");
1790                 return false;
1791         }
1792         if(!mutils__compare_block(cuesheet, block))
1793                 return false;
1794         printf("OK\n");
1795
1796         index.offset = 0;
1797         index.number = 1;
1798         printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on empty array...");
1799         tr_insert_new_(cuesheet, 0, 0, index);
1800         if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 0, index)) {
1801                 printf("FAILED, returned false\n");
1802                 return false;
1803         }
1804         if(!mutils__compare_block(cuesheet, block))
1805                 return false;
1806         printf("OK\n");
1807
1808         index.offset = 10;
1809         index.number = 2;
1810         printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on beginning of non-empty array...");
1811         tr_insert_new_(cuesheet, 0, 0, index);
1812         if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 0, index)) {
1813                 printf("FAILED, returned false\n");
1814                 return false;
1815         }
1816         if(!mutils__compare_block(cuesheet, block))
1817                 return false;
1818         printf("OK\n");
1819
1820         index.offset = 20;
1821         index.number = 3;
1822         printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on middle of non-empty array...");
1823         tr_insert_new_(cuesheet, 0, 1, index);
1824         if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 1, index)) {
1825                 printf("FAILED, returned false\n");
1826                 return false;
1827         }
1828         if(!mutils__compare_block(cuesheet, block))
1829                 return false;
1830         printf("OK\n");
1831
1832         index.offset = 30;
1833         index.number = 4;
1834         printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on end of non-empty array...");
1835         tr_insert_new_(cuesheet, 0, 3, index);
1836         if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 3, index)) {
1837                 printf("FAILED, returned false\n");
1838                 return false;
1839         }
1840         if(!mutils__compare_block(cuesheet, block))
1841                 return false;
1842         printf("OK\n");
1843
1844         index.offset = 0;
1845         index.number = 0;
1846         printf("testing FLAC__metadata_object_cuesheet_track_insert_blank_index() on end of non-empty array...");
1847         tr_insert_new_(cuesheet, 0, 4, index);
1848         if(!FLAC__metadata_object_cuesheet_track_insert_blank_index(block, 0, 4)) {
1849                 printf("FAILED, returned false\n");
1850                 return false;
1851         }
1852         if(!mutils__compare_block(cuesheet, block))
1853                 return false;
1854         printf("OK\n");
1855
1856         printf("testing FLAC__metadata_object_clone()... ");
1857         blockcopy = FLAC__metadata_object_clone(block);
1858         if(0 == blockcopy) {
1859                 printf("FAILED, returned NULL\n");
1860                 return false;
1861         }
1862         if(!mutils__compare_block(block, blockcopy))
1863                 return false;
1864         printf("OK\n");
1865
1866         printf("testing FLAC__metadata_object_delete()... ");
1867         FLAC__metadata_object_delete(blockcopy);
1868         printf("OK\n");
1869
1870         printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on end of array...");
1871         tr_delete_(cuesheet, 0, 4);
1872         if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 4)) {
1873                 printf("FAILED, returned false\n");
1874                 return false;
1875         }
1876         if(!mutils__compare_block(cuesheet, block))
1877                 return false;
1878         printf("OK\n");
1879
1880         printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on middle of array...");
1881         tr_delete_(cuesheet, 0, 2);
1882         if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 2)) {
1883                 printf("FAILED, returned false\n");
1884                 return false;
1885         }
1886         if(!mutils__compare_block(cuesheet, block))
1887                 return false;
1888         printf("OK\n");
1889
1890         printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on end of array...");
1891         tr_delete_(cuesheet, 0, 2);
1892         if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 2)) {
1893                 printf("FAILED, returned false\n");
1894                 return false;
1895         }
1896         if(!mutils__compare_block(cuesheet, block))
1897                 return false;
1898         printf("OK\n");
1899
1900         printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on beginning of array...");
1901         tr_delete_(cuesheet, 0, 0);
1902         if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 0)) {
1903                 printf("FAILED, returned false\n");
1904                 return false;
1905         }
1906         if(!mutils__compare_block(cuesheet, block))
1907                 return false;
1908         printf("OK\n");
1909
1910         printf("testing FLAC__metadata_object_delete()... ");
1911         FLAC__metadata_object_delete(cuesheet);
1912         FLAC__metadata_object_delete(block);
1913         printf("OK\n");
1914
1915
1916         printf("testing FLAC__metadata_object_new()... ");
1917         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET);
1918         if(0 == block) {
1919                 printf("FAILED, returned NULL\n");
1920                 return false;
1921         }
1922         printf("OK\n");
1923
1924         printf("testing FLAC__metadata_object_clone()... ");
1925         cuesheet = FLAC__metadata_object_clone(block);
1926         if(0 == cuesheet) {
1927                 printf("FAILED, returned NULL\n");
1928                 return false;
1929         }
1930         if(!mutils__compare_block(cuesheet, block))
1931                 return false;
1932         printf("OK\n");
1933
1934         printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on empty array...");
1935         cs_insert_new_(&track, cuesheet, 0, 60, 7, "GBCDE1234567", false, false);
1936         track_clone_(&track);
1937         if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/false)) {
1938                 printf("FAILED, returned false\n");
1939                 return false;
1940         }
1941         if(!mutils__compare_block(cuesheet, block))
1942                 return false;
1943         printf("OK\n");
1944
1945         printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on beginning of non-empty array...");
1946         cs_insert_new_(&track, cuesheet, 0, 70, 8, "HBCDE1234567", false, false);
1947         track_clone_(&track);
1948         if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/false)) {
1949                 printf("FAILED, returned false\n");
1950                 return false;
1951         }
1952         if(!mutils__compare_block(cuesheet, block))
1953                 return false;
1954         printf("OK\n");
1955
1956         printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on middle of non-empty array...");
1957         cs_insert_new_(&track, cuesheet, 1, 80, 9, "IBCDE1234567", false, false);
1958         track_clone_(&track);
1959         if(!FLAC__metadata_object_cuesheet_insert_track(block, 1, &track, /*copy=*/false)) {
1960                 printf("FAILED, returned false\n");
1961                 return false;
1962         }
1963         if(!mutils__compare_block(cuesheet, block))
1964                 return false;
1965         printf("OK\n");
1966
1967         printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on end of non-empty array...");
1968         cs_insert_new_(&track, cuesheet, 3, 90, 10, "JBCDE1234567", false, false);
1969         track_clone_(&track);
1970         if(!FLAC__metadata_object_cuesheet_insert_track(block, 3, &track, /*copy=*/false)) {
1971                 printf("FAILED, returned false\n");
1972                 return false;
1973         }
1974         if(!mutils__compare_block(cuesheet, block))
1975                 return false;
1976         printf("OK\n");
1977
1978         printf("testing FLAC__metadata_object_cuesheet_delete_track() on middle of array...");
1979         cs_delete_(cuesheet, 2);
1980         if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1981                 printf("FAILED, returned false\n");
1982                 return false;
1983         }
1984         if(!mutils__compare_block(cuesheet, block))
1985                 return false;
1986         printf("OK\n");
1987
1988         printf("testing FLAC__metadata_object_cuesheet_delete_track() on end of array...");
1989         cs_delete_(cuesheet, 2);
1990         if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1991                 printf("FAILED, returned false\n");
1992                 return false;
1993         }
1994         if(!mutils__compare_block(cuesheet, block))
1995                 return false;
1996         printf("OK\n");
1997
1998         printf("testing FLAC__metadata_object_cuesheet_delete_track() on beginning of array...");
1999         cs_delete_(cuesheet, 0);
2000         if(!FLAC__metadata_object_cuesheet_delete_track(block, 0)) {
2001                 printf("FAILED, returned false\n");
2002                 return false;
2003         }
2004         if(!mutils__compare_block(cuesheet, block))
2005                 return false;
2006         printf("OK\n");
2007
2008         printf("testing FLAC__metadata_object_cuesheet_set_track(own)...");
2009         cs_set_new_(&track, cuesheet, 0, 100, 11, "KBCDE1234567", false, false);
2010         track_clone_(&track);
2011         FLAC__metadata_object_cuesheet_set_track(block, 0, &track, /*copy=*/false);
2012         if(!mutils__compare_block(cuesheet, block))
2013                 return false;
2014         printf("OK\n");
2015
2016         printf("testing FLAC__metadata_object_cuesheet_is_legal()...");
2017         {
2018                 const char *violation;
2019                 if(FLAC__metadata_object_cuesheet_is_legal(block, /*check_cd_da_subset=*/true, &violation)) {
2020                         printf("FAILED, returned true when expecting false\n");
2021                         return false;
2022                 }
2023                 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2024         }
2025
2026         printf("testing FLAC__metadata_object_delete()... ");
2027         FLAC__metadata_object_delete(cuesheet);
2028         FLAC__metadata_object_delete(block);
2029         printf("OK\n");
2030
2031
2032         printf("testing PICTURE\n");
2033
2034         printf("testing FLAC__metadata_object_new()... ");
2035         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PICTURE);
2036         if(0 == block) {
2037                 printf("FAILED, returned NULL\n");
2038                 return false;
2039         }
2040         expected_length = (
2041                 FLAC__STREAM_METADATA_PICTURE_TYPE_LEN +
2042                 FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN +
2043                 FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN +
2044                 FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN +
2045                 FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN +
2046                 FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN +
2047                 FLAC__STREAM_METADATA_PICTURE_COLORS_LEN +
2048                 FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN
2049         ) / 8;
2050         if(block->length != expected_length) {
2051                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
2052                 return false;
2053         }
2054         printf("OK\n");
2055
2056         printf("testing FLAC__metadata_object_clone()... ");
2057         picture = FLAC__metadata_object_clone(block);
2058         if(0 == picture) {
2059                 printf("FAILED, returned NULL\n");
2060                 return false;
2061         }
2062         if(!mutils__compare_block(picture, block))
2063                 return false;
2064         printf("OK\n");
2065
2066         pi_set_mime_type(picture, "image/png\t");
2067         printf("testing FLAC__metadata_object_picture_set_mime_type(copy)...");
2068         if(!FLAC__metadata_object_picture_set_mime_type(block, "image/png\t", /*copy=*/true)) {
2069                 printf("FAILED, returned false\n");
2070                 return false;
2071         }
2072         if(!mutils__compare_block(picture, block))
2073                 return false;
2074         printf("OK\n");
2075
2076         printf("testing FLAC__metadata_object_picture_is_legal()...");
2077         {
2078                 const char *violation;
2079                 if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
2080                         printf("FAILED, returned true when expecting false\n");
2081                         return false;
2082                 }
2083                 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2084         }
2085
2086         pi_set_mime_type(picture, "image/png");
2087         printf("testing FLAC__metadata_object_picture_set_mime_type(copy)...");
2088         if(!FLAC__metadata_object_picture_set_mime_type(block, "image/png", /*copy=*/true)) {
2089                 printf("FAILED, returned false\n");
2090                 return false;
2091         }
2092         if(!mutils__compare_block(picture, block))
2093                 return false;
2094         printf("OK\n");
2095
2096         printf("testing FLAC__metadata_object_picture_is_legal()...");
2097         {
2098                 const char *violation;
2099                 if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
2100                         printf("FAILED, returned false, violation=\"%s\"\n", violation);
2101                         return false;
2102                 }
2103                 printf("OK\n");
2104         }
2105
2106         pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION\xff");
2107         printf("testing FLAC__metadata_object_picture_set_description(copy)...");
2108         if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)"DESCRIPTION\xff", /*copy=*/true)) {
2109                 printf("FAILED, returned false\n");
2110                 return false;
2111         }
2112         if(!mutils__compare_block(picture, block))
2113                 return false;
2114         printf("OK\n");
2115
2116         printf("testing FLAC__metadata_object_picture_is_legal()...");
2117         {
2118                 const char *violation;
2119                 if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
2120                         printf("FAILED, returned true when expecting false\n");
2121                         return false;
2122                 }
2123                 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2124         }
2125
2126         pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION");
2127         printf("testing FLAC__metadata_object_picture_set_description(copy)...");
2128         if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)"DESCRIPTION", /*copy=*/true)) {
2129                 printf("FAILED, returned false\n");
2130                 return false;
2131         }
2132         if(!mutils__compare_block(picture, block))
2133                 return false;
2134         printf("OK\n");
2135
2136         printf("testing FLAC__metadata_object_picture_is_legal()...");
2137         {
2138                 const char *violation;
2139                 if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
2140                         printf("FAILED, returned false, violation=\"%s\"\n", violation);
2141                         return false;
2142                 }
2143                 printf("OK\n");
2144         }
2145
2146
2147         pi_set_data(picture, (const FLAC__byte*)"PNGDATA", strlen("PNGDATA"));
2148         printf("testing FLAC__metadata_object_picture_set_data(copy)...");
2149         if(!FLAC__metadata_object_picture_set_data(block, (FLAC__byte*)"PNGDATA", strlen("PNGDATA"), /*copy=*/true)) {
2150                 printf("FAILED, returned false\n");
2151                 return false;
2152         }
2153         if(!mutils__compare_block(picture, block))
2154                 return false;
2155         printf("OK\n");
2156
2157         printf("testing FLAC__metadata_object_clone()... ");
2158         blockcopy = FLAC__metadata_object_clone(block);
2159         if(0 == blockcopy) {
2160                 printf("FAILED, returned NULL\n");
2161                 return false;
2162         }
2163         if(!mutils__compare_block(block, blockcopy))
2164                 return false;
2165         printf("OK\n");
2166
2167         printf("testing FLAC__metadata_object_delete()... ");
2168         FLAC__metadata_object_delete(blockcopy);
2169         printf("OK\n");
2170
2171         pi_set_mime_type(picture, "image/png\t");
2172         printf("testing FLAC__metadata_object_picture_set_mime_type(own)...");
2173         if(!FLAC__metadata_object_picture_set_mime_type(block, strdup("image/png\t"), /*copy=*/false)) {
2174                 printf("FAILED, returned false\n");
2175                 return false;
2176         }
2177         if(!mutils__compare_block(picture, block))
2178                 return false;
2179         printf("OK\n");
2180
2181         printf("testing FLAC__metadata_object_picture_is_legal()...");
2182         {
2183                 const char *violation;
2184                 if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
2185                         printf("FAILED, returned true when expecting false\n");
2186                         return false;
2187                 }
2188                 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2189         }
2190
2191         pi_set_mime_type(picture, "image/png");
2192         printf("testing FLAC__metadata_object_picture_set_mime_type(own)...");
2193         if(!FLAC__metadata_object_picture_set_mime_type(block, strdup("image/png"), /*copy=*/false)) {
2194                 printf("FAILED, returned false\n");
2195                 return false;
2196         }
2197         if(!mutils__compare_block(picture, block))
2198                 return false;
2199         printf("OK\n");
2200
2201         printf("testing FLAC__metadata_object_picture_is_legal()...");
2202         {
2203                 const char *violation;
2204                 if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
2205                         printf("FAILED, returned false, violation=\"%s\"\n", violation);
2206                         return false;
2207                 }
2208                 printf("OK\n");
2209         }
2210
2211         pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION\xff");
2212         printf("testing FLAC__metadata_object_picture_set_description(own)...");
2213         if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)strdup("DESCRIPTION\xff"), /*copy=*/false)) {
2214                 printf("FAILED, returned false\n");
2215                 return false;
2216         }
2217         if(!mutils__compare_block(picture, block))
2218                 return false;
2219         printf("OK\n");
2220
2221         printf("testing FLAC__metadata_object_picture_is_legal()...");
2222         {
2223                 const char *violation;
2224                 if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
2225                         printf("FAILED, returned true when expecting false\n");
2226                         return false;
2227                 }
2228                 printf("returned false as expected, violation=\"%s\" OK\n", violation);
2229         }
2230
2231         pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION");
2232         printf("testing FLAC__metadata_object_picture_set_description(own)...");
2233         if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)strdup("DESCRIPTION"), /*copy=*/false)) {
2234                 printf("FAILED, returned false\n");
2235                 return false;
2236         }
2237         if(!mutils__compare_block(picture, block))
2238                 return false;
2239         printf("OK\n");
2240
2241         printf("testing FLAC__metadata_object_picture_is_legal()...");
2242         {
2243                 const char *violation;
2244                 if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
2245                         printf("FAILED, returned false, violation=\"%s\"\n", violation);
2246                         return false;
2247                 }
2248                 printf("OK\n");
2249         }
2250
2251         pi_set_data(picture, (const FLAC__byte*)"PNGDATA", strlen("PNGDATA"));
2252         printf("testing FLAC__metadata_object_picture_set_data(own)...");
2253         if(!FLAC__metadata_object_picture_set_data(block, (FLAC__byte*)strdup("PNGDATA"), strlen("PNGDATA"), /*copy=*/false)) {
2254                 printf("FAILED, returned false\n");
2255                 return false;
2256         }
2257         if(!mutils__compare_block(picture, block))
2258                 return false;
2259         printf("OK\n");
2260
2261         printf("testing FLAC__metadata_object_clone()... ");
2262         blockcopy = FLAC__metadata_object_clone(block);
2263         if(0 == blockcopy) {
2264                 printf("FAILED, returned NULL\n");
2265                 return false;
2266         }
2267         if(!mutils__compare_block(block, blockcopy))
2268                 return false;
2269         printf("OK\n");
2270
2271         printf("testing FLAC__metadata_object_delete()... ");
2272         FLAC__metadata_object_delete(blockcopy);
2273         printf("OK\n");
2274
2275         printf("testing FLAC__metadata_object_delete()... ");
2276         FLAC__metadata_object_delete(picture);
2277         FLAC__metadata_object_delete(block);
2278         printf("OK\n");
2279
2280
2281         return true;
2282 }