add some more missing unit tests
[platform/upstream/flac.git] / src / test_libFLAC / metadata_object.c
1 /* test_libFLAC - Unit tester for libFLAC
2  * Copyright (C) 2002,2003  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 #include "FLAC/assert.h"
20 #include "FLAC/metadata.h"
21 #include "metadata_utils.h"
22 #include <stdio.h>
23 #include <stdlib.h> /* for malloc() */
24 #include <string.h> /* for memcmp() */
25
26 static FLAC__byte *make_dummydata_(FLAC__byte *dummydata, unsigned len)
27 {
28         FLAC__byte *ret;
29
30         if(0 == (ret = (FLAC__byte*)malloc(len))) {
31                 printf("FAILED, malloc error\n");
32                 exit(1);
33         }
34         else
35                 memcpy(ret, dummydata, len);
36
37         return ret;
38 }
39
40 static FLAC__bool compare_track_(const FLAC__StreamMetadata_CueSheet_Track *from, const FLAC__StreamMetadata_CueSheet_Track *to)
41 {
42         unsigned i;
43
44         if(from->offset != to->offset) {
45                 printf("FAILED, track offset mismatch, expected %llu, got %llu\n", to->offset, from->offset);
46                 return false;
47         }
48         if(from->number != to->number) {
49                 printf("FAILED, track number mismatch, expected %u, got %u\n", (unsigned)to->number, (unsigned)from->number);
50                 return false;
51         }
52         if(0 != strcmp(from->isrc, to->isrc)) {
53                 printf("FAILED, track number mismatch, expected %s, got %s\n", to->isrc, from->isrc);
54                 return false;
55         }
56         if(from->type != to->type) {
57                 printf("FAILED, track type mismatch, expected %u, got %u\n", (unsigned)to->type, (unsigned)from->type);
58                 return false;
59         }
60         if(from->pre_emphasis != to->pre_emphasis) {
61                 printf("FAILED, track pre_emphasis mismatch, expected %u, got %u\n", (unsigned)to->pre_emphasis, (unsigned)from->pre_emphasis);
62                 return false;
63         }
64         if(from->num_indices != to->num_indices) {
65                 printf("FAILED, track num_indices mismatch, expected %u, got %u\n", (unsigned)to->num_indices, (unsigned)from->num_indices);
66                 return false;
67         }
68         if(0 == to->indices || 0 == from->indices) {
69                 if(to->indices != from->indices) {
70                         printf("FAILED, track indices mismatch\n");
71                         return false;
72                 }
73         }
74         else {
75                 for(i = 0; i < to->num_indices; i++) {
76                         if(from->indices[i].offset != to->indices[i].offset) {
77                                 printf("FAILED, track indices[%u].offset mismatch, expected %llu, got %llu\n", i, to->indices[i].offset, from->indices[i].offset);
78                                 return false;
79                         }
80                         if(from->indices[i].number != to->indices[i].number) {
81                                 printf("FAILED, track indices[%u].number mismatch, expected %u, got %u\n", i, (unsigned)to->indices[i].number, (unsigned)from->indices[i].number);
82                                 return false;
83                         }
84                 }
85         }
86
87         return true;
88 }
89
90 static FLAC__bool compare_seekpoint_array_(const FLAC__StreamMetadata_SeekPoint *from, const FLAC__StreamMetadata_SeekPoint *to, unsigned n)
91 {
92         unsigned i;
93
94         FLAC__ASSERT(0 != from);
95         FLAC__ASSERT(0 != to);
96
97         for(i = 0; i < n; i++) {
98                 if(from[i].sample_number != to[i].sample_number) {
99                         printf("FAILED, point[%u].sample_number mismatch, expected %llu, got %llu\n", i, to[i].sample_number, from[i].sample_number);
100                         return false;
101                 }
102                 if(from[i].stream_offset != to[i].stream_offset) {
103                         printf("FAILED, point[%u].stream_offset mismatch, expected %llu, got %llu\n", i, to[i].stream_offset, from[i].stream_offset);
104                         return false;
105                 }
106                 if(from[i].frame_samples != to[i].frame_samples) {
107                         printf("FAILED, point[%u].frame_samples mismatch, expected %u, got %u\n", i, to[i].frame_samples, from[i].frame_samples);
108                         return false;
109                 }
110         }
111
112         return true;
113 }
114
115 static FLAC__bool check_seektable_(const FLAC__StreamMetadata *block, unsigned num_points, const FLAC__StreamMetadata_SeekPoint *array)
116 {
117         const unsigned expected_length = num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
118
119         if(block->length != expected_length) {
120                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
121                 return false;
122         }
123         if(block->data.seek_table.num_points != num_points) {
124                 printf("FAILED, expected %u point, got %u\n", num_points, block->data.seek_table.num_points);
125                 return false;
126         }
127         if(0 == array) {
128                 if(0 != block->data.seek_table.points) {
129                         printf("FAILED, 'points' pointer is not null\n");
130                         return false;
131                 }
132         }
133         else {
134                 if(!compare_seekpoint_array_(block->data.seek_table.points, array, num_points))
135                         return false;
136         }
137         printf("OK\n");
138
139         return true;
140 }
141
142 static void entry_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, const char *field)
143 {
144         entry->length = strlen(field);
145         entry->entry = (FLAC__byte*)malloc(entry->length);
146         FLAC__ASSERT(0 != entry->entry);
147         memcpy(entry->entry, field, entry->length);
148 }
149
150 static void entry_clone_(FLAC__StreamMetadata_VorbisComment_Entry *entry)
151 {
152         FLAC__byte *x = (FLAC__byte*)malloc(entry->length);
153         FLAC__ASSERT(0 != x);
154         memcpy(x, entry->entry, entry->length);
155         entry->entry = x;
156 }
157
158 static void vc_calc_len_(FLAC__StreamMetadata *block)
159 {
160         const FLAC__StreamMetadata_VorbisComment *vc = &block->data.vorbis_comment;
161         unsigned i;
162
163         block->length = FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
164         block->length += vc->vendor_string.length;
165         block->length += FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8;
166         for(i = 0; i < vc->num_comments; i++) {
167                 block->length += FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
168                 block->length += vc->comments[i].length;
169         }
170 }
171
172 static void vc_resize_(FLAC__StreamMetadata *block, unsigned num)
173 {
174         FLAC__StreamMetadata_VorbisComment *vc = &block->data.vorbis_comment;
175
176         if(vc->num_comments != 0) {
177                 FLAC__ASSERT(0 != vc->comments);
178                 if(num < vc->num_comments) {
179                         unsigned i;
180                         for(i = num; i < vc->num_comments; i++) {
181                                 if(0 != vc->comments[i].entry)
182                                         free(vc->comments[i].entry);
183                         }
184                 }
185         }
186         if(num == 0) {
187                 if(0 != vc->comments) {
188                         free(vc->comments);
189                         vc->comments = 0;
190                 }
191         }
192         else {
193                 vc->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)realloc(vc->comments, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*num);
194                 FLAC__ASSERT(0 != vc->comments);
195                 if(num > vc->num_comments)
196                         memset(vc->comments+vc->num_comments, 0, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(num-vc->num_comments));
197         }
198
199         vc->num_comments = num;
200         vc_calc_len_(block);
201 }
202
203 static void vc_set_vs_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, const char *field)
204 {
205         if(0 != block->data.vorbis_comment.vendor_string.entry)
206                 free(block->data.vorbis_comment.vendor_string.entry);
207         entry_new_(entry, field);
208         block->data.vorbis_comment.vendor_string = *entry;
209         vc_calc_len_(block);
210 }
211
212 static void vc_set_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, unsigned pos, const char *field)
213 {
214         if(0 != block->data.vorbis_comment.comments[pos].entry)
215                 free(block->data.vorbis_comment.comments[pos].entry);
216         entry_new_(entry, field);
217         block->data.vorbis_comment.comments[pos] = *entry;
218         vc_calc_len_(block);
219 }
220
221 static void vc_insert_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, unsigned pos, const char *field)
222 {
223         vc_resize_(block, block->data.vorbis_comment.num_comments+1);
224         memmove(&block->data.vorbis_comment.comments[pos+1], &block->data.vorbis_comment.comments[pos], sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(block->data.vorbis_comment.num_comments-1-pos));
225         memset(&block->data.vorbis_comment.comments[pos], 0, sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
226         vc_set_new_(entry, block, pos, field);
227         vc_calc_len_(block);
228 }
229
230 static void vc_delete_(FLAC__StreamMetadata *block, unsigned pos)
231 {
232         if(0 != block->data.vorbis_comment.comments[pos].entry)
233                 free(block->data.vorbis_comment.comments[pos].entry);
234         memmove(&block->data.vorbis_comment.comments[pos], &block->data.vorbis_comment.comments[pos+1], sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(block->data.vorbis_comment.num_comments-pos-1));
235         block->data.vorbis_comment.comments[block->data.vorbis_comment.num_comments-1].entry = 0;
236         block->data.vorbis_comment.comments[block->data.vorbis_comment.num_comments-1].length = 0;
237         vc_resize_(block, block->data.vorbis_comment.num_comments-1);
238         vc_calc_len_(block);
239 }
240
241 static void track_new_(FLAC__StreamMetadata_CueSheet_Track *track, FLAC__uint64 offset, FLAC__byte number, const char *isrc, FLAC__bool data, FLAC__bool pre_em)
242 {
243         track->offset = offset;
244         track->number = number;
245         memcpy(track->isrc, isrc, sizeof(track->isrc));
246         track->type = data;
247         track->pre_emphasis = pre_em;
248         track->num_indices = 0;
249         track->indices = 0;
250 }
251
252 static void track_clone_(FLAC__StreamMetadata_CueSheet_Track *track)
253 {
254         if(track->num_indices > 0) {
255                 size_t bytes = sizeof(FLAC__StreamMetadata_CueSheet_Index) * track->num_indices;
256                 FLAC__StreamMetadata_CueSheet_Index *x = (FLAC__StreamMetadata_CueSheet_Index*)malloc(bytes);
257                 FLAC__ASSERT(0 != x);
258                 memcpy(x, track->indices, bytes);
259                 track->indices = x;
260         }
261 }
262
263 static void cs_calc_len_(FLAC__StreamMetadata *block)
264 {
265         const FLAC__StreamMetadata_CueSheet *cs = &block->data.cue_sheet;
266         unsigned i;
267
268         block->length = (
269                 FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
270                 FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
271                 FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN +
272                 FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
273                 FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
274         ) / 8;
275         block->length += cs->num_tracks * (
276                 FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN +
277                 FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN +
278                 FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN +
279                 FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN +
280                 FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN +
281                 FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN +
282                 FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN
283         ) / 8;
284         for(i = 0; i < cs->num_tracks; i++) {
285                 block->length += cs->tracks[i].num_indices * (
286                         FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN +
287                         FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN +
288                         FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN
289                 ) / 8;
290         }
291 }
292
293 static void tr_resize_(FLAC__StreamMetadata *block, unsigned track_num, unsigned num)
294 {
295         FLAC__StreamMetadata_CueSheet_Track *tr;
296
297         FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
298
299         tr = &block->data.cue_sheet.tracks[track_num];
300
301         if(tr->num_indices != 0) {
302                 FLAC__ASSERT(0 != tr->indices);
303         }
304         if(num == 0) {
305                 if(0 != tr->indices) {
306                         free(tr->indices);
307                         tr->indices = 0;
308                 }
309         }
310         else {
311                 tr->indices = (FLAC__StreamMetadata_CueSheet_Index*)realloc(tr->indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)*num);
312                 FLAC__ASSERT(0 != tr->indices);
313                 if(num > tr->num_indices)
314                         memset(tr->indices+tr->num_indices, 0, sizeof(FLAC__StreamMetadata_CueSheet_Index)*(num-tr->num_indices));
315         }
316
317         tr->num_indices = num;
318         cs_calc_len_(block);
319 }
320
321 static void tr_set_new_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos, FLAC__StreamMetadata_CueSheet_Index index)
322 {
323         FLAC__StreamMetadata_CueSheet_Track *tr;
324
325         FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
326
327         tr = &block->data.cue_sheet.tracks[track_num];
328
329         FLAC__ASSERT(pos < tr->num_indices);
330
331         tr->indices[pos] = index;
332
333         cs_calc_len_(block);
334 }
335
336 static void tr_insert_new_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos, FLAC__StreamMetadata_CueSheet_Index index)
337 {
338         FLAC__StreamMetadata_CueSheet_Track *tr;
339
340         FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
341
342         tr = &block->data.cue_sheet.tracks[track_num];
343
344         FLAC__ASSERT(pos <= tr->num_indices);
345
346         tr_resize_(block, track_num, tr->num_indices+1);
347         memmove(&tr->indices[pos+1], &tr->indices[pos], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(tr->num_indices-1-pos));
348         tr_set_new_(block, track_num, pos, index);
349         cs_calc_len_(block);
350 }
351
352 static void tr_delete_(FLAC__StreamMetadata *block, unsigned track_num, unsigned pos)
353 {
354         FLAC__StreamMetadata_CueSheet_Track *tr;
355
356         FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks);
357
358         tr = &block->data.cue_sheet.tracks[track_num];
359
360         FLAC__ASSERT(pos <= tr->num_indices);
361
362         memmove(&tr->indices[pos], &tr->indices[pos+1], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(tr->num_indices-pos-1));
363         tr_resize_(block, track_num, tr->num_indices-1);
364         cs_calc_len_(block);
365 }
366
367 static void cs_resize_(FLAC__StreamMetadata *block, unsigned num)
368 {
369         FLAC__StreamMetadata_CueSheet *cs = &block->data.cue_sheet;
370
371         if(cs->num_tracks != 0) {
372                 FLAC__ASSERT(0 != cs->tracks);
373                 if(num < cs->num_tracks) {
374                         unsigned i;
375                         for(i = num; i < cs->num_tracks; i++) {
376                                 if(0 != cs->tracks[i].indices)
377                                         free(cs->tracks[i].indices);
378                         }
379                 }
380         }
381         if(num == 0) {
382                 if(0 != cs->tracks) {
383                         free(cs->tracks);
384                         cs->tracks = 0;
385                 }
386         }
387         else {
388                 cs->tracks = (FLAC__StreamMetadata_CueSheet_Track*)realloc(cs->tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)*num);
389                 FLAC__ASSERT(0 != cs->tracks);
390                 if(num > cs->num_tracks)
391                         memset(cs->tracks+cs->num_tracks, 0, sizeof(FLAC__StreamMetadata_CueSheet_Track)*(num-cs->num_tracks));
392         }
393
394         cs->num_tracks = num;
395         cs_calc_len_(block);
396 }
397
398 static void cs_set_new_(FLAC__StreamMetadata_CueSheet_Track *track, FLAC__StreamMetadata *block, unsigned pos, FLAC__uint64 offset, FLAC__byte number, const char *isrc, FLAC__bool data, FLAC__bool pre_em)
399 {
400         track_new_(track, offset, number, isrc, data, pre_em);
401         block->data.cue_sheet.tracks[pos] = *track;
402         cs_calc_len_(block);
403 }
404
405 static void cs_insert_new_(FLAC__StreamMetadata_CueSheet_Track *track, FLAC__StreamMetadata *block, unsigned pos, FLAC__uint64 offset, FLAC__byte number, const char *isrc, FLAC__bool data, FLAC__bool pre_em)
406 {
407         cs_resize_(block, block->data.cue_sheet.num_tracks+1);
408         memmove(&block->data.cue_sheet.tracks[pos+1], &block->data.cue_sheet.tracks[pos], sizeof(FLAC__StreamMetadata_CueSheet_Track)*(block->data.cue_sheet.num_tracks-1-pos));
409         cs_set_new_(track, block, pos, offset, number, isrc, data, pre_em);
410         cs_calc_len_(block);
411 }
412
413 static void cs_delete_(FLAC__StreamMetadata *block, unsigned pos)
414 {
415         if(0 != block->data.cue_sheet.tracks[pos].indices)
416                 free(block->data.cue_sheet.tracks[pos].indices);
417         memmove(&block->data.cue_sheet.tracks[pos], &block->data.cue_sheet.tracks[pos+1], sizeof(FLAC__StreamMetadata_CueSheet_Track)*(block->data.cue_sheet.num_tracks-pos-1));
418         block->data.cue_sheet.tracks[block->data.cue_sheet.num_tracks-1].indices = 0;
419         block->data.cue_sheet.tracks[block->data.cue_sheet.num_tracks-1].num_indices = 0;
420         cs_resize_(block, block->data.cue_sheet.num_tracks-1);
421         cs_calc_len_(block);
422 }
423
424
425 FLAC__bool test_metadata_object()
426 {
427         FLAC__StreamMetadata *block, *blockcopy, *vorbiscomment, *cuesheet;
428         FLAC__StreamMetadata_SeekPoint seekpoint_array[8];
429         FLAC__StreamMetadata_VorbisComment_Entry entry;
430         FLAC__StreamMetadata_CueSheet_Index index;
431         FLAC__StreamMetadata_CueSheet_Track track;
432         unsigned i, expected_length, seekpoints;
433         static FLAC__byte dummydata[4] = { 'a', 'b', 'c', 'd' };
434
435         printf("\n+++ libFLAC unit test: metadata objects\n\n");
436
437
438         printf("testing STREAMINFO\n");
439
440         printf("testing FLAC__metadata_object_new()... ");
441         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_STREAMINFO);
442         if(0 == block) {
443                 printf("FAILED, returned NULL\n");
444                 return false;
445         }
446         expected_length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
447         if(block->length != expected_length) {
448                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
449                 return false;
450         }
451         printf("OK\n");
452
453         printf("testing FLAC__metadata_object_clone()... ");
454         blockcopy = FLAC__metadata_object_clone(block);
455         if(0 == blockcopy) {
456                 printf("FAILED, returned NULL\n");
457                 return false;
458         }
459         if(!mutils__compare_block(block, blockcopy))
460                 return false;
461         printf("OK\n");
462
463         printf("testing FLAC__metadata_object_delete()... ");
464         FLAC__metadata_object_delete(blockcopy);
465         FLAC__metadata_object_delete(block);
466         printf("OK\n");
467
468
469         printf("testing PADDING\n");
470
471         printf("testing FLAC__metadata_object_new()... ");
472         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING);
473         if(0 == block) {
474                 printf("FAILED, returned NULL\n");
475                 return false;
476         }
477         expected_length = 0;
478         if(block->length != expected_length) {
479                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
480                 return false;
481         }
482         printf("OK\n");
483
484         printf("testing FLAC__metadata_object_clone()... ");
485         blockcopy = FLAC__metadata_object_clone(block);
486         if(0 == blockcopy) {
487                 printf("FAILED, returned NULL\n");
488                 return false;
489         }
490         if(!mutils__compare_block(block, blockcopy))
491                 return false;
492         printf("OK\n");
493
494         printf("testing FLAC__metadata_object_delete()... ");
495         FLAC__metadata_object_delete(blockcopy);
496         FLAC__metadata_object_delete(block);
497         printf("OK\n");
498
499
500         printf("testing APPLICATION\n");
501
502         printf("testing FLAC__metadata_object_new()... ");
503         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION);
504         if(0 == block) {
505                 printf("FAILED, returned NULL\n");
506                 return false;
507         }
508         expected_length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
509         if(block->length != expected_length) {
510                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
511                 return false;
512         }
513         printf("OK\n");
514
515         printf("testing FLAC__metadata_object_clone()... ");
516         blockcopy = FLAC__metadata_object_clone(block);
517         if(0 == blockcopy) {
518                 printf("FAILED, returned NULL\n");
519                 return false;
520         }
521         if(!mutils__compare_block(block, blockcopy))
522                 return false;
523         printf("OK\n");
524
525         printf("testing FLAC__metadata_object_delete()... ");
526         FLAC__metadata_object_delete(blockcopy);
527         printf("OK\n");
528
529         printf("testing FLAC__metadata_object_application_set_data(copy)... ");
530         if(!FLAC__metadata_object_application_set_data(block, dummydata, sizeof(dummydata), true/*copy*/)) {
531                 printf("FAILED, returned false\n");
532                 return false;
533         }
534         expected_length = (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) + sizeof(dummydata);
535         if(block->length != expected_length) {
536                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
537                 return false;
538         }
539         if(0 != memcmp(block->data.application.data, dummydata, sizeof(dummydata))) {
540                 printf("FAILED, data mismatch\n");
541                 return false;
542         }
543         printf("OK\n");
544
545         printf("testing FLAC__metadata_object_clone()... ");
546         blockcopy = FLAC__metadata_object_clone(block);
547         if(0 == blockcopy) {
548                 printf("FAILED, returned NULL\n");
549                 return false;
550         }
551         if(!mutils__compare_block(block, blockcopy))
552                 return false;
553         printf("OK\n");
554
555         printf("testing FLAC__metadata_object_delete()... ");
556         FLAC__metadata_object_delete(blockcopy);
557         printf("OK\n");
558
559         printf("testing FLAC__metadata_object_application_set_data(own)... ");
560         if(!FLAC__metadata_object_application_set_data(block, make_dummydata_(dummydata, sizeof(dummydata)), sizeof(dummydata), false/*own*/)) {
561                 printf("FAILED, returned false\n");
562                 return false;
563         }
564         expected_length = (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) + sizeof(dummydata);
565         if(block->length != expected_length) {
566                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
567                 return false;
568         }
569         if(0 != memcmp(block->data.application.data, dummydata, sizeof(dummydata))) {
570                 printf("FAILED, data mismatch\n");
571                 return false;
572         }
573         printf("OK\n");
574
575         printf("testing FLAC__metadata_object_clone()... ");
576         blockcopy = FLAC__metadata_object_clone(block);
577         if(0 == blockcopy) {
578                 printf("FAILED, returned NULL\n");
579                 return false;
580         }
581         if(!mutils__compare_block(block, blockcopy))
582                 return false;
583         printf("OK\n");
584
585         printf("testing FLAC__metadata_object_delete()... ");
586         FLAC__metadata_object_delete(blockcopy);
587         FLAC__metadata_object_delete(block);
588         printf("OK\n");
589
590
591         printf("testing SEEKTABLE\n");
592
593         for(i = 0; i < sizeof(seekpoint_array) / sizeof(FLAC__StreamMetadata_SeekPoint); i++) {
594                 seekpoint_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
595                 seekpoint_array[i].stream_offset = 0;
596                 seekpoint_array[i].frame_samples = 0;
597         }
598
599         seekpoints = 0;
600         printf("testing FLAC__metadata_object_new()... ");
601         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE);
602         if(0 == block) {
603                 printf("FAILED, returned NULL\n");
604                 return false;
605         }
606         if(!check_seektable_(block, seekpoints, 0))
607                 return false;
608
609         printf("testing FLAC__metadata_object_clone()... ");
610         blockcopy = FLAC__metadata_object_clone(block);
611         if(0 == blockcopy) {
612                 printf("FAILED, returned NULL\n");
613                 return false;
614         }
615         if(!mutils__compare_block(block, blockcopy))
616                 return false;
617         printf("OK\n");
618
619         printf("testing FLAC__metadata_object_delete()... ");
620         FLAC__metadata_object_delete(blockcopy);
621         printf("OK\n");
622
623         seekpoints = 2;
624         printf("testing FLAC__metadata_object_seektable_resize_points(grow to %u)...", seekpoints);
625         if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
626                 printf("FAILED, returned false\n");
627                 return false;
628         }
629         if(!check_seektable_(block, seekpoints, seekpoint_array))
630                 return false;
631
632         seekpoints = 1;
633         printf("testing FLAC__metadata_object_seektable_resize_points(shrink to %u)...", seekpoints);
634         if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
635                 printf("FAILED, returned false\n");
636                 return false;
637         }
638         if(!check_seektable_(block, seekpoints, seekpoint_array))
639                 return false;
640
641         printf("testing FLAC__metadata_object_seektable_is_legal()...");
642         if(!FLAC__metadata_object_seektable_is_legal(block)) {
643                 printf("FAILED, returned false\n");
644                 return false;
645         }
646         printf("OK\n");
647
648         seekpoints = 0;
649         printf("testing FLAC__metadata_object_seektable_resize_points(shrink to %u)...", seekpoints);
650         if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
651                 printf("FAILED, returned false\n");
652                 return false;
653         }
654         if(!check_seektable_(block, seekpoints, 0))
655                 return false;
656
657         seekpoints++;
658         printf("testing FLAC__metadata_object_seektable_insert_point() on empty array...");
659         if(!FLAC__metadata_object_seektable_insert_point(block, 0, seekpoint_array[0])) {
660                 printf("FAILED, returned false\n");
661                 return false;
662         }
663         if(!check_seektable_(block, seekpoints, seekpoint_array))
664                 return false;
665
666         seekpoint_array[0].sample_number = 1;
667         seekpoints++;
668         printf("testing FLAC__metadata_object_seektable_insert_point() on beginning of non-empty array...");
669         if(!FLAC__metadata_object_seektable_insert_point(block, 0, seekpoint_array[0])) {
670                 printf("FAILED, returned false\n");
671                 return false;
672         }
673         if(!check_seektable_(block, seekpoints, seekpoint_array))
674                 return false;
675
676         seekpoint_array[1].sample_number = 2;
677         seekpoints++;
678         printf("testing FLAC__metadata_object_seektable_insert_point() on middle of non-empty array...");
679         if(!FLAC__metadata_object_seektable_insert_point(block, 1, seekpoint_array[1])) {
680                 printf("FAILED, returned false\n");
681                 return false;
682         }
683         if(!check_seektable_(block, seekpoints, seekpoint_array))
684                 return false;
685
686         seekpoint_array[3].sample_number = 3;
687         seekpoints++;
688         printf("testing FLAC__metadata_object_seektable_insert_point() on end of non-empty array...");
689         if(!FLAC__metadata_object_seektable_insert_point(block, 3, seekpoint_array[3])) {
690                 printf("FAILED, returned false\n");
691                 return false;
692         }
693         if(!check_seektable_(block, seekpoints, seekpoint_array))
694                 return false;
695
696         printf("testing FLAC__metadata_object_clone()... ");
697         blockcopy = FLAC__metadata_object_clone(block);
698         if(0 == blockcopy) {
699                 printf("FAILED, returned NULL\n");
700                 return false;
701         }
702         if(!mutils__compare_block(block, blockcopy))
703                 return false;
704         printf("OK\n");
705
706         printf("testing FLAC__metadata_object_delete()... ");
707         FLAC__metadata_object_delete(blockcopy);
708         printf("OK\n");
709
710         seekpoint_array[2].sample_number = seekpoint_array[3].sample_number;
711         seekpoints--;
712         printf("testing FLAC__metadata_object_seektable_delete_point() on middle of array...");
713         if(!FLAC__metadata_object_seektable_delete_point(block, 2)) {
714                 printf("FAILED, returned false\n");
715                 return false;
716         }
717         if(!check_seektable_(block, seekpoints, seekpoint_array))
718                 return false;
719
720         seekpoints--;
721         printf("testing FLAC__metadata_object_seektable_delete_point() on end of array...");
722         if(!FLAC__metadata_object_seektable_delete_point(block, 2)) {
723                 printf("FAILED, returned false\n");
724                 return false;
725         }
726         if(!check_seektable_(block, seekpoints, seekpoint_array))
727                 return false;
728
729         seekpoints--;
730         printf("testing FLAC__metadata_object_seektable_delete_point() on beginning of array...");
731         if(!FLAC__metadata_object_seektable_delete_point(block, 0)) {
732                 printf("FAILED, returned false\n");
733                 return false;
734         }
735         if(!check_seektable_(block, seekpoints, seekpoint_array+1))
736                 return false;
737
738         printf("testing FLAC__metadata_object_seektable_set_point()...");
739         FLAC__metadata_object_seektable_set_point(block, 0, seekpoint_array[0]);
740         if(!check_seektable_(block, seekpoints, seekpoint_array))
741                 return false;
742
743         printf("testing FLAC__metadata_object_delete()... ");
744         FLAC__metadata_object_delete(block);
745         printf("OK\n");
746
747         /* seektable template functions */
748
749         for(i = 0; i < sizeof(seekpoint_array) / sizeof(FLAC__StreamMetadata_SeekPoint); i++) {
750                 seekpoint_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
751                 seekpoint_array[i].stream_offset = 0;
752                 seekpoint_array[i].frame_samples = 0;
753         }
754
755         seekpoints = 0;
756         printf("testing FLAC__metadata_object_new()... ");
757         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE);
758         if(0 == block) {
759                 printf("FAILED, returned NULL\n");
760                 return false;
761         }
762         if(!check_seektable_(block, seekpoints, 0))
763                 return false;
764
765         seekpoints += 2;
766         printf("testing FLAC__metadata_object_seekpoint_template_append_placeholders()... ");
767         if(!FLAC__metadata_object_seektable_template_append_placeholders(block, 2)) {
768                 printf("FAILED, returned false\n");
769                 return false;
770         }
771         if(!check_seektable_(block, seekpoints, seekpoint_array))
772                 return false;
773
774         seekpoint_array[seekpoints++].sample_number = 7;
775         printf("testing FLAC__metadata_object_seekpoint_template_append_point()... ");
776         if(!FLAC__metadata_object_seektable_template_append_point(block, 7)) {
777                 printf("FAILED, returned false\n");
778                 return false;
779         }
780         if(!check_seektable_(block, seekpoints, seekpoint_array))
781                 return false;
782
783         {
784                 FLAC__uint64 nums[2] = { 3, 7 };
785                 seekpoint_array[seekpoints++].sample_number = nums[0];
786                 seekpoint_array[seekpoints++].sample_number = nums[1];
787                 printf("testing FLAC__metadata_object_seekpoint_template_append_points()... ");
788                 if(!FLAC__metadata_object_seektable_template_append_points(block, nums, sizeof(nums)/sizeof(FLAC__uint64))) {
789                         printf("FAILED, returned false\n");
790                         return false;
791                 }
792                 if(!check_seektable_(block, seekpoints, seekpoint_array))
793                         return false;
794         }
795
796         seekpoint_array[seekpoints++].sample_number = 0;
797         seekpoint_array[seekpoints++].sample_number = 10;
798         seekpoint_array[seekpoints++].sample_number = 20;
799         printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points()... ");
800         if(!FLAC__metadata_object_seektable_template_append_spaced_points(block, 3, 30)) {
801                 printf("FAILED, returned false\n");
802                 return false;
803         }
804         if(!check_seektable_(block, seekpoints, seekpoint_array))
805                 return false;
806
807         seekpoints--;
808         seekpoint_array[0].sample_number = 0;
809         seekpoint_array[1].sample_number = 3;
810         seekpoint_array[2].sample_number = 7;
811         seekpoint_array[3].sample_number = 10;
812         seekpoint_array[4].sample_number = 20;
813         seekpoint_array[5].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
814         seekpoint_array[6].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
815         printf("testing FLAC__metadata_object_seekpoint_template_sort(compact=true)... ");
816         if(!FLAC__metadata_object_seektable_template_sort(block, /*compact=*/true)) {
817                 printf("FAILED, returned false\n");
818                 return false;
819         }
820         if(!FLAC__metadata_object_seektable_is_legal(block)) {
821                 printf("FAILED, seek table is illegal\n");
822                 return false;
823         }
824         if(!check_seektable_(block, seekpoints, seekpoint_array))
825                 return false;
826
827         printf("testing FLAC__metadata_object_seekpoint_template_sort(compact=false)... ");
828         if(!FLAC__metadata_object_seektable_template_sort(block, /*compact=*/false)) {
829                 printf("FAILED, returned false\n");
830                 return false;
831         }
832         if(!FLAC__metadata_object_seektable_is_legal(block)) {
833                 printf("FAILED, seek table is illegal\n");
834                 return false;
835         }
836         if(!check_seektable_(block, seekpoints, seekpoint_array))
837                 return false;
838
839         printf("testing FLAC__metadata_object_delete()... ");
840         FLAC__metadata_object_delete(block);
841         printf("OK\n");
842
843
844         printf("testing VORBIS_COMMENT\n");
845
846         printf("testing FLAC__metadata_object_new()... ");
847         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
848         if(0 == block) {
849                 printf("FAILED, returned NULL\n");
850                 return false;
851         }
852         expected_length = (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + strlen(FLAC__VENDOR_STRING) + FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN/8);
853         if(block->length != expected_length) {
854                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
855                 return false;
856         }
857         printf("OK\n");
858
859         printf("testing FLAC__metadata_object_clone()... ");
860         vorbiscomment = FLAC__metadata_object_clone(block);
861         if(0 == vorbiscomment) {
862                 printf("FAILED, returned NULL\n");
863                 return false;
864         }
865         if(!mutils__compare_block(vorbiscomment, block))
866                 return false;
867         printf("OK\n");
868
869         vc_resize_(vorbiscomment, 2);
870         printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(grow to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
871         if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
872                 printf("FAILED, returned false\n");
873                 return false;
874         }
875         if(!mutils__compare_block(vorbiscomment, block))
876                 return false;
877         printf("OK\n");
878
879         vc_resize_(vorbiscomment, 1);
880         printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
881         if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
882                 printf("FAILED, returned false\n");
883                 return false;
884         }
885         if(!mutils__compare_block(vorbiscomment, block))
886                 return false;
887         printf("OK\n");
888
889         vc_resize_(vorbiscomment, 0);
890         printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
891         if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
892                 printf("FAILED, returned false\n");
893                 return false;
894         }
895         if(!mutils__compare_block(vorbiscomment, block))
896                 return false;
897         printf("OK\n");
898
899         printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on empty array...");
900         vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
901         if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/true)) {
902                 printf("FAILED, returned false\n");
903                 return false;
904         }
905         if(!mutils__compare_block(vorbiscomment, block))
906                 return false;
907         printf("OK\n");
908
909         printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on beginning of non-empty array...");
910         vc_insert_new_(&entry, vorbiscomment, 0, "name2=field2");
911         if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/true)) {
912                 printf("FAILED, returned false\n");
913                 return false;
914         }
915         if(!mutils__compare_block(vorbiscomment, block))
916                 return false;
917         printf("OK\n");
918
919         printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on middle of non-empty array...");
920         vc_insert_new_(&entry, vorbiscomment, 1, "name3=field3");
921         if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 1, entry, /*copy=*/true)) {
922                 printf("FAILED, returned false\n");
923                 return false;
924         }
925         if(!mutils__compare_block(vorbiscomment, block))
926                 return false;
927         printf("OK\n");
928
929         printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array...");
930         vc_insert_new_(&entry, vorbiscomment, 3, "name4=field4");
931         if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 3, entry, /*copy=*/true)) {
932                 printf("FAILED, returned false\n");
933                 return false;
934         }
935         if(!mutils__compare_block(vorbiscomment, block))
936                 return false;
937         printf("OK\n");
938
939         printf("testing FLAC__metadata_object_clone()... ");
940         blockcopy = FLAC__metadata_object_clone(block);
941         if(0 == blockcopy) {
942                 printf("FAILED, returned NULL\n");
943                 return false;
944         }
945         if(!mutils__compare_block(block, blockcopy))
946                 return false;
947         printf("OK\n");
948
949         printf("testing FLAC__metadata_object_delete()... ");
950         FLAC__metadata_object_delete(blockcopy);
951         printf("OK\n");
952
953         printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on middle of array...");
954         vc_delete_(vorbiscomment, 2);
955         if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
956                 printf("FAILED, returned false\n");
957                 return false;
958         }
959         if(!mutils__compare_block(vorbiscomment, block))
960                 return false;
961         printf("OK\n");
962
963         printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on end of array...");
964         vc_delete_(vorbiscomment, 2);
965         if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
966                 printf("FAILED, returned false\n");
967                 return false;
968         }
969         if(!mutils__compare_block(vorbiscomment, block))
970                 return false;
971         printf("OK\n");
972
973         printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on beginning of array...");
974         vc_delete_(vorbiscomment, 0);
975         if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 0)) {
976                 printf("FAILED, returned false\n");
977                 return false;
978         }
979         if(!mutils__compare_block(vorbiscomment, block))
980                 return false;
981         printf("OK\n");
982
983         printf("testing FLAC__metadata_object_vorbiscomment_set_comment(copy)...");
984         vc_set_new_(&entry, vorbiscomment, 0, "name5=field5");
985         FLAC__metadata_object_vorbiscomment_set_comment(block, 0, entry, /*copy=*/true);
986         if(!mutils__compare_block(vorbiscomment, block))
987                 return false;
988         printf("OK\n");
989
990         printf("testing FLAC__metadata_object_vorbiscomment_set_vendor_string(copy)...");
991         vc_set_vs_new_(&entry, vorbiscomment, "name6=field6");
992         FLAC__metadata_object_vorbiscomment_set_vendor_string(block, entry, /*copy=*/true);
993         if(!mutils__compare_block(vorbiscomment, block))
994                 return false;
995         printf("OK\n");
996
997         printf("testing FLAC__metadata_object_delete()... ");
998         FLAC__metadata_object_delete(vorbiscomment);
999         FLAC__metadata_object_delete(block);
1000         printf("OK\n");
1001
1002
1003         printf("testing FLAC__metadata_object_new()... ");
1004         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
1005         if(0 == block) {
1006                 printf("FAILED, returned NULL\n");
1007                 return false;
1008         }
1009         printf("OK\n");
1010
1011         printf("testing FLAC__metadata_object_clone()... ");
1012         vorbiscomment = FLAC__metadata_object_clone(block);
1013         if(0 == vorbiscomment) {
1014                 printf("FAILED, returned NULL\n");
1015                 return false;
1016         }
1017         if(!mutils__compare_block(vorbiscomment, block))
1018                 return false;
1019         printf("OK\n");
1020
1021         printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on empty array...");
1022         vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
1023         entry_clone_(&entry);
1024         if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/false)) {
1025                 printf("FAILED, returned false\n");
1026                 return false;
1027         }
1028         if(!mutils__compare_block(vorbiscomment, block))
1029                 return false;
1030         printf("OK\n");
1031
1032         printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on beginning of non-empty array...");
1033         vc_insert_new_(&entry, vorbiscomment, 0, "name2=field2");
1034         entry_clone_(&entry);
1035         if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/false)) {
1036                 printf("FAILED, returned false\n");
1037                 return false;
1038         }
1039         if(!mutils__compare_block(vorbiscomment, block))
1040                 return false;
1041         printf("OK\n");
1042
1043         printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on middle of non-empty array...");
1044         vc_insert_new_(&entry, vorbiscomment, 1, "name3=field3");
1045         entry_clone_(&entry);
1046         if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 1, entry, /*copy=*/false)) {
1047                 printf("FAILED, returned false\n");
1048                 return false;
1049         }
1050         if(!mutils__compare_block(vorbiscomment, block))
1051                 return false;
1052         printf("OK\n");
1053
1054         printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on end of non-empty array...");
1055         vc_insert_new_(&entry, vorbiscomment, 3, "name4=field4");
1056         entry_clone_(&entry);
1057         if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 3, entry, /*copy=*/false)) {
1058                 printf("FAILED, returned false\n");
1059                 return false;
1060         }
1061         if(!mutils__compare_block(vorbiscomment, block))
1062                 return false;
1063         printf("OK\n");
1064
1065         printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on middle of array...");
1066         vc_delete_(vorbiscomment, 2);
1067         if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
1068                 printf("FAILED, returned false\n");
1069                 return false;
1070         }
1071         if(!mutils__compare_block(vorbiscomment, block))
1072                 return false;
1073         printf("OK\n");
1074
1075         printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on end of array...");
1076         vc_delete_(vorbiscomment, 2);
1077         if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
1078                 printf("FAILED, returned false\n");
1079                 return false;
1080         }
1081         if(!mutils__compare_block(vorbiscomment, block))
1082                 return false;
1083         printf("OK\n");
1084
1085         printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on beginning of array...");
1086         vc_delete_(vorbiscomment, 0);
1087         if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 0)) {
1088                 printf("FAILED, returned false\n");
1089                 return false;
1090         }
1091         if(!mutils__compare_block(vorbiscomment, block))
1092                 return false;
1093         printf("OK\n");
1094
1095         printf("testing FLAC__metadata_object_vorbiscomment_set_comment(own)...");
1096         vc_set_new_(&entry, vorbiscomment, 0, "name5=field5");
1097         entry_clone_(&entry);
1098         FLAC__metadata_object_vorbiscomment_set_comment(block, 0, entry, /*copy=*/false);
1099         if(!mutils__compare_block(vorbiscomment, block))
1100                 return false;
1101         printf("OK\n");
1102
1103         printf("testing FLAC__metadata_object_vorbiscomment_set_vendor_string(own)...");
1104         vc_set_vs_new_(&entry, vorbiscomment, "name6=field6");
1105         entry_clone_(&entry);
1106         FLAC__metadata_object_vorbiscomment_set_vendor_string(block, entry, /*copy=*/false);
1107         if(!mutils__compare_block(vorbiscomment, block))
1108                 return false;
1109         printf("OK\n");
1110
1111         printf("testing FLAC__metadata_object_delete()... ");
1112         FLAC__metadata_object_delete(vorbiscomment);
1113         FLAC__metadata_object_delete(block);
1114         printf("OK\n");
1115
1116
1117
1118         printf("testing CUESHEET\n");
1119
1120         {
1121                 FLAC__StreamMetadata_CueSheet_Track *track_, *trackcopy_;
1122
1123                 printf("testing FLAC__metadata_object_cuesheet_track_new()... ");
1124                 track_ = FLAC__metadata_object_cuesheet_track_new();
1125                 if(0 == track_) {
1126                         printf("FAILED, returned NULL\n");
1127                         return false;
1128                 }
1129                 printf("OK\n");
1130
1131                 printf("testing FLAC__metadata_object_cuesheet_track_clone()... ");
1132                 trackcopy_ = FLAC__metadata_object_cuesheet_track_clone(track_);
1133                 if(0 == trackcopy_) {
1134                         printf("FAILED, returned NULL\n");
1135                         return false;
1136                 }
1137                 if(!compare_track_(trackcopy_, track_))
1138                         return false;
1139                 printf("OK\n");
1140
1141                 printf("testing FLAC__metadata_object_cuesheet_track_delete()... ");
1142                 FLAC__metadata_object_cuesheet_track_delete(trackcopy_);
1143                 FLAC__metadata_object_cuesheet_track_delete(track_);
1144                 printf("OK\n");
1145         }
1146
1147
1148         printf("testing FLAC__metadata_object_new()... ");
1149         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET);
1150         if(0 == block) {
1151                 printf("FAILED, returned NULL\n");
1152                 return false;
1153         }
1154         expected_length = (
1155                 FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
1156                 FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
1157                 FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN +
1158                 FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
1159                 FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
1160         ) / 8;
1161         if(block->length != expected_length) {
1162                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
1163                 return false;
1164         }
1165         printf("OK\n");
1166
1167         printf("testing FLAC__metadata_object_clone()... ");
1168         cuesheet = FLAC__metadata_object_clone(block);
1169         if(0 == cuesheet) {
1170                 printf("FAILED, returned NULL\n");
1171                 return false;
1172         }
1173         if(!mutils__compare_block(cuesheet, block))
1174                 return false;
1175         printf("OK\n");
1176
1177         cs_resize_(cuesheet, 2);
1178         printf("testing FLAC__metadata_object_cuesheet_resize_tracks(grow to %u)...", cuesheet->data.cue_sheet.num_tracks);
1179         if(!FLAC__metadata_object_cuesheet_resize_tracks(block, cuesheet->data.cue_sheet.num_tracks)) {
1180                 printf("FAILED, returned false\n");
1181                 return false;
1182         }
1183         if(!mutils__compare_block(cuesheet, block))
1184                 return false;
1185         printf("OK\n");
1186
1187         cs_resize_(cuesheet, 1);
1188         printf("testing FLAC__metadata_object_cuesheet_resize_tracks(shrink to %u)...", cuesheet->data.cue_sheet.num_tracks);
1189         if(!FLAC__metadata_object_cuesheet_resize_tracks(block, cuesheet->data.cue_sheet.num_tracks)) {
1190                 printf("FAILED, returned false\n");
1191                 return false;
1192         }
1193         if(!mutils__compare_block(cuesheet, block))
1194                 return false;
1195         printf("OK\n");
1196
1197         cs_resize_(cuesheet, 0);
1198         printf("testing FLAC__metadata_object_cuesheet_resize_tracks(shrink to %u)...", cuesheet->data.cue_sheet.num_tracks);
1199         if(!FLAC__metadata_object_cuesheet_resize_tracks(block, cuesheet->data.cue_sheet.num_tracks)) {
1200                 printf("FAILED, returned false\n");
1201                 return false;
1202         }
1203         if(!mutils__compare_block(cuesheet, block))
1204                 return false;
1205         printf("OK\n");
1206
1207         printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on empty array...");
1208         cs_insert_new_(&track, cuesheet, 0, 0, 1, "ABCDE1234567", false, false);
1209         if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/true)) {
1210                 printf("FAILED, returned false\n");
1211                 return false;
1212         }
1213         if(!mutils__compare_block(cuesheet, block))
1214                 return false;
1215         printf("OK\n");
1216
1217         printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on beginning of non-empty array...");
1218         cs_insert_new_(&track, cuesheet, 0, 10, 2, "BBCDE1234567", false, false);
1219         if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/true)) {
1220                 printf("FAILED, returned false\n");
1221                 return false;
1222         }
1223         if(!mutils__compare_block(cuesheet, block))
1224                 return false;
1225         printf("OK\n");
1226
1227         printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on middle of non-empty array...");
1228         cs_insert_new_(&track, cuesheet, 1, 20, 3, "CBCDE1234567", false, false);
1229         if(!FLAC__metadata_object_cuesheet_insert_track(block, 1, &track, /*copy=*/true)) {
1230                 printf("FAILED, returned false\n");
1231                 return false;
1232         }
1233         if(!mutils__compare_block(cuesheet, block))
1234                 return false;
1235         printf("OK\n");
1236
1237         printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on end of non-empty array...");
1238         cs_insert_new_(&track, cuesheet, 3, 30, 4, "DBCDE1234567", false, false);
1239         if(!FLAC__metadata_object_cuesheet_insert_track(block, 3, &track, /*copy=*/true)) {
1240                 printf("FAILED, returned false\n");
1241                 return false;
1242         }
1243         if(!mutils__compare_block(cuesheet, block))
1244                 return false;
1245         printf("OK\n");
1246
1247         printf("testing FLAC__metadata_object_cuesheet_insert_blank_track() on end of non-empty array...");
1248         cs_insert_new_(&track, cuesheet, 4, 0, 0, "\0\0\0\0\0\0\0\0\0\0\0\0", false, false);
1249         if(!FLAC__metadata_object_cuesheet_insert_blank_track(block, 4)) {
1250                 printf("FAILED, returned false\n");
1251                 return false;
1252         }
1253         if(!mutils__compare_block(cuesheet, block))
1254                 return false;
1255         printf("OK\n");
1256
1257         printf("testing FLAC__metadata_object_clone()... ");
1258         blockcopy = FLAC__metadata_object_clone(block);
1259         if(0 == blockcopy) {
1260                 printf("FAILED, returned NULL\n");
1261                 return false;
1262         }
1263         if(!mutils__compare_block(block, blockcopy))
1264                 return false;
1265         printf("OK\n");
1266
1267         printf("testing FLAC__metadata_object_delete()... ");
1268         FLAC__metadata_object_delete(blockcopy);
1269         printf("OK\n");
1270
1271         printf("testing FLAC__metadata_object_cuesheet_delete_track() on end of array...");
1272         cs_delete_(cuesheet, 4);
1273         if(!FLAC__metadata_object_cuesheet_delete_track(block, 4)) {
1274                 printf("FAILED, returned false\n");
1275                 return false;
1276         }
1277         if(!mutils__compare_block(cuesheet, block))
1278                 return false;
1279         printf("OK\n");
1280
1281         printf("testing FLAC__metadata_object_cuesheet_delete_track() on middle of array...");
1282         cs_delete_(cuesheet, 2);
1283         if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1284                 printf("FAILED, returned false\n");
1285                 return false;
1286         }
1287         if(!mutils__compare_block(cuesheet, block))
1288                 return false;
1289         printf("OK\n");
1290
1291         printf("testing FLAC__metadata_object_cuesheet_delete_track() on end of array...");
1292         cs_delete_(cuesheet, 2);
1293         if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1294                 printf("FAILED, returned false\n");
1295                 return false;
1296         }
1297         if(!mutils__compare_block(cuesheet, block))
1298                 return false;
1299         printf("OK\n");
1300
1301         printf("testing FLAC__metadata_object_cuesheet_delete_track() on beginning of array...");
1302         cs_delete_(cuesheet, 0);
1303         if(!FLAC__metadata_object_cuesheet_delete_track(block, 0)) {
1304                 printf("FAILED, returned false\n");
1305                 return false;
1306         }
1307         if(!mutils__compare_block(cuesheet, block))
1308                 return false;
1309         printf("OK\n");
1310
1311         printf("testing FLAC__metadata_object_cuesheet_set_track(copy)...");
1312         cs_set_new_(&track, cuesheet, 0, 40, 5, "EBCDE1234567", false, false);
1313         FLAC__metadata_object_cuesheet_set_track(block, 0, &track, /*copy=*/true);
1314         if(!mutils__compare_block(cuesheet, block))
1315                 return false;
1316         printf("OK\n");
1317
1318         tr_resize_(cuesheet, 0, 2);
1319         printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(grow to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices);
1320         if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) {
1321                 printf("FAILED, returned false\n");
1322                 return false;
1323         }
1324         if(!mutils__compare_block(cuesheet, block))
1325                 return false;
1326         printf("OK\n");
1327
1328         tr_resize_(cuesheet, 0, 1);
1329         printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(shrink to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices);
1330         if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) {
1331                 printf("FAILED, returned false\n");
1332                 return false;
1333         }
1334         if(!mutils__compare_block(cuesheet, block))
1335                 return false;
1336         printf("OK\n");
1337
1338         tr_resize_(cuesheet, 0, 0);
1339         printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(shrink to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices);
1340         if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) {
1341                 printf("FAILED, returned false\n");
1342                 return false;
1343         }
1344         if(!mutils__compare_block(cuesheet, block))
1345                 return false;
1346         printf("OK\n");
1347
1348         index.offset = 0;
1349         index.number = 1;
1350         printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on empty array...");
1351         tr_insert_new_(cuesheet, 0, 0, index);
1352         if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 0, index)) {
1353                 printf("FAILED, returned false\n");
1354                 return false;
1355         }
1356         if(!mutils__compare_block(cuesheet, block))
1357                 return false;
1358         printf("OK\n");
1359
1360         index.offset = 10;
1361         index.number = 2;
1362         printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on beginning of non-empty array...");
1363         tr_insert_new_(cuesheet, 0, 0, index);
1364         if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 0, index)) {
1365                 printf("FAILED, returned false\n");
1366                 return false;
1367         }
1368         if(!mutils__compare_block(cuesheet, block))
1369                 return false;
1370         printf("OK\n");
1371
1372         index.offset = 20;
1373         index.number = 3;
1374         printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on middle of non-empty array...");
1375         tr_insert_new_(cuesheet, 0, 1, index);
1376         if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 1, index)) {
1377                 printf("FAILED, returned false\n");
1378                 return false;
1379         }
1380         if(!mutils__compare_block(cuesheet, block))
1381                 return false;
1382         printf("OK\n");
1383
1384         index.offset = 30;
1385         index.number = 4;
1386         printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on end of non-empty array...");
1387         tr_insert_new_(cuesheet, 0, 3, index);
1388         if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 3, index)) {
1389                 printf("FAILED, returned false\n");
1390                 return false;
1391         }
1392         if(!mutils__compare_block(cuesheet, block))
1393                 return false;
1394         printf("OK\n");
1395
1396         index.offset = 0;
1397         index.number = 0;
1398         printf("testing FLAC__metadata_object_cuesheet_track_insert_blank_index() on end of non-empty array...");
1399         tr_insert_new_(cuesheet, 0, 4, index);
1400         if(!FLAC__metadata_object_cuesheet_track_insert_blank_index(block, 0, 4)) {
1401                 printf("FAILED, returned false\n");
1402                 return false;
1403         }
1404         if(!mutils__compare_block(cuesheet, block))
1405                 return false;
1406         printf("OK\n");
1407
1408         printf("testing FLAC__metadata_object_clone()... ");
1409         blockcopy = FLAC__metadata_object_clone(block);
1410         if(0 == blockcopy) {
1411                 printf("FAILED, returned NULL\n");
1412                 return false;
1413         }
1414         if(!mutils__compare_block(block, blockcopy))
1415                 return false;
1416         printf("OK\n");
1417
1418         printf("testing FLAC__metadata_object_delete()... ");
1419         FLAC__metadata_object_delete(blockcopy);
1420         printf("OK\n");
1421
1422         printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on end of array...");
1423         tr_delete_(cuesheet, 0, 4);
1424         if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 4)) {
1425                 printf("FAILED, returned false\n");
1426                 return false;
1427         }
1428         if(!mutils__compare_block(cuesheet, block))
1429                 return false;
1430         printf("OK\n");
1431
1432         printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on middle of array...");
1433         tr_delete_(cuesheet, 0, 2);
1434         if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 2)) {
1435                 printf("FAILED, returned false\n");
1436                 return false;
1437         }
1438         if(!mutils__compare_block(cuesheet, block))
1439                 return false;
1440         printf("OK\n");
1441
1442         printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on end of array...");
1443         tr_delete_(cuesheet, 0, 2);
1444         if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 2)) {
1445                 printf("FAILED, returned false\n");
1446                 return false;
1447         }
1448         if(!mutils__compare_block(cuesheet, block))
1449                 return false;
1450         printf("OK\n");
1451
1452         printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on beginning of array...");
1453         tr_delete_(cuesheet, 0, 0);
1454         if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 0)) {
1455                 printf("FAILED, returned false\n");
1456                 return false;
1457         }
1458         if(!mutils__compare_block(cuesheet, block))
1459                 return false;
1460         printf("OK\n");
1461
1462         printf("testing FLAC__metadata_object_delete()... ");
1463         FLAC__metadata_object_delete(cuesheet);
1464         FLAC__metadata_object_delete(block);
1465         printf("OK\n");
1466
1467
1468         printf("testing FLAC__metadata_object_new()... ");
1469         block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET);
1470         if(0 == block) {
1471                 printf("FAILED, returned NULL\n");
1472                 return false;
1473         }
1474         printf("OK\n");
1475
1476         printf("testing FLAC__metadata_object_clone()... ");
1477         cuesheet = FLAC__metadata_object_clone(block);
1478         if(0 == cuesheet) {
1479                 printf("FAILED, returned NULL\n");
1480                 return false;
1481         }
1482         if(!mutils__compare_block(cuesheet, block))
1483                 return false;
1484         printf("OK\n");
1485
1486         printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on empty array...");
1487         cs_insert_new_(&track, cuesheet, 0, 60, 7, "GBCDE1234567", false, false);
1488         track_clone_(&track);
1489         if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/false)) {
1490                 printf("FAILED, returned false\n");
1491                 return false;
1492         }
1493         if(!mutils__compare_block(cuesheet, block))
1494                 return false;
1495         printf("OK\n");
1496
1497         printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on beginning of non-empty array...");
1498         cs_insert_new_(&track, cuesheet, 0, 70, 8, "HBCDE1234567", false, false);
1499         track_clone_(&track);
1500         if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/false)) {
1501                 printf("FAILED, returned false\n");
1502                 return false;
1503         }
1504         if(!mutils__compare_block(cuesheet, block))
1505                 return false;
1506         printf("OK\n");
1507
1508         printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on middle of non-empty array...");
1509         cs_insert_new_(&track, cuesheet, 1, 80, 9, "IBCDE1234567", false, false);
1510         track_clone_(&track);
1511         if(!FLAC__metadata_object_cuesheet_insert_track(block, 1, &track, /*copy=*/false)) {
1512                 printf("FAILED, returned false\n");
1513                 return false;
1514         }
1515         if(!mutils__compare_block(cuesheet, block))
1516                 return false;
1517         printf("OK\n");
1518
1519         printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on end of non-empty array...");
1520         cs_insert_new_(&track, cuesheet, 3, 90, 10, "JBCDE1234567", false, false);
1521         track_clone_(&track);
1522         if(!FLAC__metadata_object_cuesheet_insert_track(block, 3, &track, /*copy=*/false)) {
1523                 printf("FAILED, returned false\n");
1524                 return false;
1525         }
1526         if(!mutils__compare_block(cuesheet, block))
1527                 return false;
1528         printf("OK\n");
1529
1530         printf("testing FLAC__metadata_object_cuesheet_delete_track() on middle of array...");
1531         cs_delete_(cuesheet, 2);
1532         if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1533                 printf("FAILED, returned false\n");
1534                 return false;
1535         }
1536         if(!mutils__compare_block(cuesheet, block))
1537                 return false;
1538         printf("OK\n");
1539
1540         printf("testing FLAC__metadata_object_cuesheet_delete_track() on end of array...");
1541         cs_delete_(cuesheet, 2);
1542         if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) {
1543                 printf("FAILED, returned false\n");
1544                 return false;
1545         }
1546         if(!mutils__compare_block(cuesheet, block))
1547                 return false;
1548         printf("OK\n");
1549
1550         printf("testing FLAC__metadata_object_cuesheet_delete_track() on beginning of array...");
1551         cs_delete_(cuesheet, 0);
1552         if(!FLAC__metadata_object_cuesheet_delete_track(block, 0)) {
1553                 printf("FAILED, returned false\n");
1554                 return false;
1555         }
1556         if(!mutils__compare_block(cuesheet, block))
1557                 return false;
1558         printf("OK\n");
1559
1560         printf("testing FLAC__metadata_object_cuesheet_set_track(own)...");
1561         cs_set_new_(&track, cuesheet, 0, 100, 11, "KBCDE1234567", false, false);
1562         track_clone_(&track);
1563         FLAC__metadata_object_cuesheet_set_track(block, 0, &track, /*copy=*/false);
1564         if(!mutils__compare_block(cuesheet, block))
1565                 return false;
1566         printf("OK\n");
1567
1568         printf("testing FLAC__metadata_object_cuesheet_is_legal()...");
1569         {
1570                 const char *violation;
1571                 if(FLAC__metadata_object_cuesheet_is_legal(block, /*check_cd_da_subset=*/true, &violation)) {
1572                         printf("FAILED, returned true when expecting false\n");
1573                         return false;
1574                 }
1575                 printf("returned false as expected, violation=\"%s\" OK\n", violation);
1576         }
1577
1578         printf("testing FLAC__metadata_object_delete()... ");
1579         FLAC__metadata_object_delete(cuesheet);
1580         FLAC__metadata_object_delete(block);
1581         printf("OK\n");
1582
1583
1584         return true;
1585 }