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