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