1 /* test_libFLAC - Unit tester for libFLAC
2 * Copyright (C) 2002 Josh Coalson
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.
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.
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.
19 #include "FLAC/assert.h"
20 #include "FLAC/metadata.h"
21 #include "metadata_utils.h"
23 #include <stdlib.h> /* for malloc() */
24 #include <string.h> /* for memcmp() */
26 static FLAC__byte *make_dummydata_(FLAC__byte *dummydata, unsigned len)
30 if(0 == (ret = (FLAC__byte*)malloc(len))) {
31 printf("FAILED, malloc error\n");
35 memcpy(ret, dummydata, len);
40 static FLAC__bool compare_seekpoint_array_(const FLAC__StreamMetadata_SeekPoint *from, const FLAC__StreamMetadata_SeekPoint *to, unsigned n)
44 FLAC__ASSERT(0 != from);
45 FLAC__ASSERT(0 != to);
47 for(i = 0; i < n; i++) {
48 if(from[i].sample_number != to[i].sample_number) {
49 printf("FAILED, point[%u].sample_number mismatch, expected %llu, got %llu\n", i, to[i].sample_number, from[i].sample_number);
52 if(from[i].stream_offset != to[i].stream_offset) {
53 printf("FAILED, point[%u].stream_offset mismatch, expected %llu, got %llu\n", i, to[i].stream_offset, from[i].stream_offset);
56 if(from[i].frame_samples != to[i].frame_samples) {
57 printf("FAILED, point[%u].frame_samples mismatch, expected %u, got %u\n", i, to[i].frame_samples, from[i].frame_samples);
65 static FLAC__bool check_seektable_(const FLAC__StreamMetadata *block, unsigned num_points, const FLAC__StreamMetadata_SeekPoint *array)
67 const unsigned expected_length = num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
69 if(block->length != expected_length) {
70 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
73 if(block->data.seek_table.num_points != num_points) {
74 printf("FAILED, expected %u point, got %u\n", num_points, block->data.seek_table.num_points);
78 if(0 != block->data.seek_table.points) {
79 printf("FAILED, 'points' pointer is not null\n");
84 if(!compare_seekpoint_array_(block->data.seek_table.points, array, num_points))
92 static void entry_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, const char *field)
94 entry->length = strlen(field);
95 entry->entry = (FLAC__byte*)malloc(entry->length);
96 FLAC__ASSERT(0 != entry->entry);
97 memcpy(entry->entry, field, entry->length);
100 static void entry_clone_(FLAC__StreamMetadata_VorbisComment_Entry *entry)
102 FLAC__byte *x = (FLAC__byte*)malloc(entry->length);
103 FLAC__ASSERT(0 != x);
104 memcpy(x, entry->entry, entry->length);
108 static void vc_calc_len_(FLAC__StreamMetadata *block)
110 const FLAC__StreamMetadata_VorbisComment *vc = &block->data.vorbis_comment;
113 block->length = FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
114 block->length += vc->vendor_string.length;
115 block->length += FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8;
116 for(i = 0; i < vc->num_comments; i++) {
117 block->length += FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
118 block->length += vc->comments[i].length;
122 static void vc_resize_(FLAC__StreamMetadata *block, unsigned num)
124 FLAC__StreamMetadata_VorbisComment *vc = &block->data.vorbis_comment;
126 if(vc->num_comments != 0) {
127 FLAC__ASSERT(0 != vc->comments);
128 if(num < vc->num_comments) {
130 for(i = num; i < vc->num_comments; i++) {
131 if(0 != vc->comments[i].entry)
132 free(vc->comments[i].entry);
137 if(0 != vc->comments) {
143 vc->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)realloc(vc->comments, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*num);
144 FLAC__ASSERT(0 != vc->comments);
145 if(num > vc->num_comments)
146 memset(vc->comments+vc->num_comments, 0, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(num-vc->num_comments));
149 vc->num_comments = num;
153 static void vc_set_vs_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, const char *field)
155 entry_new_(entry, field);
156 block->data.vorbis_comment.vendor_string = *entry;
160 static void vc_set_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, unsigned pos, const char *field)
162 entry_new_(entry, field);
163 block->data.vorbis_comment.comments[pos] = *entry;
167 static void vc_insert_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, unsigned pos, const char *field)
169 vc_resize_(block, block->data.vorbis_comment.num_comments+1);
170 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));
171 vc_set_new_(entry, block, pos, field);
175 static void vc_delete_(FLAC__StreamMetadata *block, unsigned pos)
177 if(0 != block->data.vorbis_comment.comments[pos].entry)
178 free(block->data.vorbis_comment.comments[pos].entry);
179 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));
180 block->data.vorbis_comment.comments[block->data.vorbis_comment.num_comments-1].entry = 0;
181 block->data.vorbis_comment.comments[block->data.vorbis_comment.num_comments-1].length = 0;
182 vc_resize_(block, block->data.vorbis_comment.num_comments-1);
186 FLAC__bool test_metadata_object()
188 FLAC__StreamMetadata *block, *blockcopy, *vorbiscomment;
189 FLAC__StreamMetadata_SeekPoint seekpoint_array[8];
190 FLAC__StreamMetadata_VorbisComment_Entry entry;
191 unsigned i, expected_length, seekpoints;
192 static FLAC__byte dummydata[4] = { 'a', 'b', 'c', 'd' };
194 printf("\n+++ libFLAC unit test: metadata objects\n\n");
197 printf("testing STREAMINFO\n");
199 printf("testing FLAC__metadata_object_new()... ");
200 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_STREAMINFO);
202 printf("FAILED, returned NULL\n");
205 expected_length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
206 if(block->length != expected_length) {
207 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
212 printf("testing FLAC__metadata_object_clone()... ");
213 blockcopy = FLAC__metadata_object_clone(block);
215 printf("FAILED, returned NULL\n");
218 if(!compare_block_(block, blockcopy))
222 printf("testing FLAC__metadata_object_delete()... ");
223 FLAC__metadata_object_delete(blockcopy);
224 FLAC__metadata_object_delete(block);
228 printf("testing PADDING\n");
230 printf("testing FLAC__metadata_object_new()... ");
231 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING);
233 printf("FAILED, returned NULL\n");
237 if(block->length != expected_length) {
238 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
243 printf("testing FLAC__metadata_object_clone()... ");
244 blockcopy = FLAC__metadata_object_clone(block);
246 printf("FAILED, returned NULL\n");
249 if(!compare_block_(block, blockcopy))
253 printf("testing FLAC__metadata_object_delete()... ");
254 FLAC__metadata_object_delete(blockcopy);
255 FLAC__metadata_object_delete(block);
259 printf("testing APPLICATION\n");
261 printf("testing FLAC__metadata_object_new()... ");
262 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION);
264 printf("FAILED, returned NULL\n");
267 expected_length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
268 if(block->length != expected_length) {
269 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
274 printf("testing FLAC__metadata_object_clone()... ");
275 blockcopy = FLAC__metadata_object_clone(block);
277 printf("FAILED, returned NULL\n");
280 if(!compare_block_(block, blockcopy))
284 printf("testing FLAC__metadata_object_delete()... ");
285 FLAC__metadata_object_delete(blockcopy);
288 printf("testing FLAC__metadata_object_application_set_data(copy)... ");
289 if(!FLAC__metadata_object_application_set_data(block, dummydata, sizeof(dummydata), true/*copy*/)) {
290 printf("FAILED, returned false\n");
293 expected_length = (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) + sizeof(dummydata);
294 if(block->length != expected_length) {
295 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
298 if(0 != memcmp(block->data.application.data, dummydata, sizeof(dummydata))) {
299 printf("FAILED, data mismatch\n");
304 printf("testing FLAC__metadata_object_clone()... ");
305 blockcopy = FLAC__metadata_object_clone(block);
307 printf("FAILED, returned NULL\n");
310 if(!compare_block_(block, blockcopy))
314 printf("testing FLAC__metadata_object_delete()... ");
315 FLAC__metadata_object_delete(blockcopy);
318 printf("testing FLAC__metadata_object_application_set_data(own)... ");
319 if(!FLAC__metadata_object_application_set_data(block, make_dummydata_(dummydata, sizeof(dummydata)), sizeof(dummydata), false/*own*/)) {
320 printf("FAILED, returned false\n");
323 expected_length = (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) + sizeof(dummydata);
324 if(block->length != expected_length) {
325 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
328 if(0 != memcmp(block->data.application.data, dummydata, sizeof(dummydata))) {
329 printf("FAILED, data mismatch\n");
334 printf("testing FLAC__metadata_object_clone()... ");
335 blockcopy = FLAC__metadata_object_clone(block);
337 printf("FAILED, returned NULL\n");
340 if(!compare_block_(block, blockcopy))
344 printf("testing FLAC__metadata_object_delete()... ");
345 FLAC__metadata_object_delete(blockcopy);
346 FLAC__metadata_object_delete(block);
350 printf("testing SEEKTABLE\n");
352 for(i = 0; i < sizeof(seekpoint_array) / sizeof(FLAC__StreamMetadata_SeekPoint); i++) {
353 seekpoint_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
354 seekpoint_array[i].stream_offset = 0;
355 seekpoint_array[i].frame_samples = 0;
359 printf("testing FLAC__metadata_object_new()... ");
360 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE);
362 printf("FAILED, returned NULL\n");
365 if(!check_seektable_(block, seekpoints, 0))
368 printf("testing FLAC__metadata_object_clone()... ");
369 blockcopy = FLAC__metadata_object_clone(block);
371 printf("FAILED, returned NULL\n");
374 if(!compare_block_(block, blockcopy))
378 printf("testing FLAC__metadata_object_delete()... ");
379 FLAC__metadata_object_delete(blockcopy);
383 printf("testing FLAC__metadata_object_seektable_resize_points(grow to %u)...", seekpoints);
384 if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
385 printf("FAILED, returned false\n");
388 if(!check_seektable_(block, seekpoints, seekpoint_array))
392 printf("testing FLAC__metadata_object_seektable_resize_points(shrink to %u)...", seekpoints);
393 if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
394 printf("FAILED, returned false\n");
397 if(!check_seektable_(block, seekpoints, seekpoint_array))
400 printf("testing FLAC__metadata_object_seektable_is_legal()...");
401 if(!FLAC__metadata_object_seektable_is_legal(block)) {
402 printf("FAILED, returned false\n");
408 printf("testing FLAC__metadata_object_seektable_resize_points(shrink to %u)...", seekpoints);
409 if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
410 printf("FAILED, returned false\n");
413 if(!check_seektable_(block, seekpoints, 0))
417 printf("testing FLAC__metadata_object_seektable_insert_point() on empty array...");
418 if(!FLAC__metadata_object_seektable_insert_point(block, 0, seekpoint_array[0])) {
419 printf("FAILED, returned false\n");
422 if(!check_seektable_(block, seekpoints, seekpoint_array))
425 seekpoint_array[0].sample_number = 1;
427 printf("testing FLAC__metadata_object_seektable_insert_point() on beginning of non-empty array...");
428 if(!FLAC__metadata_object_seektable_insert_point(block, 0, seekpoint_array[0])) {
429 printf("FAILED, returned false\n");
432 if(!check_seektable_(block, seekpoints, seekpoint_array))
435 seekpoint_array[1].sample_number = 2;
437 printf("testing FLAC__metadata_object_seektable_insert_point() on middle of non-empty array...");
438 if(!FLAC__metadata_object_seektable_insert_point(block, 1, seekpoint_array[1])) {
439 printf("FAILED, returned false\n");
442 if(!check_seektable_(block, seekpoints, seekpoint_array))
445 seekpoint_array[3].sample_number = 3;
447 printf("testing FLAC__metadata_object_seektable_insert_point() on end of non-empty array...");
448 if(!FLAC__metadata_object_seektable_insert_point(block, 3, seekpoint_array[3])) {
449 printf("FAILED, returned false\n");
452 if(!check_seektable_(block, seekpoints, seekpoint_array))
455 printf("testing FLAC__metadata_object_clone()... ");
456 blockcopy = FLAC__metadata_object_clone(block);
458 printf("FAILED, returned NULL\n");
461 if(!compare_block_(block, blockcopy))
465 printf("testing FLAC__metadata_object_delete()... ");
466 FLAC__metadata_object_delete(blockcopy);
469 seekpoint_array[2].sample_number = seekpoint_array[3].sample_number;
471 printf("testing FLAC__metadata_object_seektable_delete_point() on middle of array...");
472 if(!FLAC__metadata_object_seektable_delete_point(block, 2)) {
473 printf("FAILED, returned false\n");
476 if(!check_seektable_(block, seekpoints, seekpoint_array))
480 printf("testing FLAC__metadata_object_seektable_delete_point() on end of array...");
481 if(!FLAC__metadata_object_seektable_delete_point(block, 2)) {
482 printf("FAILED, returned false\n");
485 if(!check_seektable_(block, seekpoints, seekpoint_array))
489 printf("testing FLAC__metadata_object_seektable_delete_point() on beginning of array...");
490 if(!FLAC__metadata_object_seektable_delete_point(block, 0)) {
491 printf("FAILED, returned false\n");
494 if(!check_seektable_(block, seekpoints, seekpoint_array+1))
497 printf("testing FLAC__metadata_object_seektable_set_point()...");
498 FLAC__metadata_object_seektable_set_point(block, 0, seekpoint_array[0]);
499 if(!check_seektable_(block, seekpoints, seekpoint_array))
502 printf("testing FLAC__metadata_object_delete()... ");
503 FLAC__metadata_object_delete(block);
506 /* seektable template functions */
508 for(i = 0; i < sizeof(seekpoint_array) / sizeof(FLAC__StreamMetadata_SeekPoint); i++) {
509 seekpoint_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
510 seekpoint_array[i].stream_offset = 0;
511 seekpoint_array[i].frame_samples = 0;
515 printf("testing FLAC__metadata_object_new()... ");
516 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE);
518 printf("FAILED, returned NULL\n");
521 if(!check_seektable_(block, seekpoints, 0))
525 printf("testing FLAC__metadata_object_seekpoint_template_append_placeholders()... ");
526 if(!FLAC__metadata_object_seektable_template_append_placeholders(block, 2)) {
527 printf("FAILED, returned false\n");
530 if(!check_seektable_(block, seekpoints, seekpoint_array))
533 seekpoint_array[seekpoints++].sample_number = 7;
534 printf("testing FLAC__metadata_object_seekpoint_template_append_point()... ");
535 if(!FLAC__metadata_object_seektable_template_append_point(block, 7)) {
536 printf("FAILED, returned false\n");
539 if(!check_seektable_(block, seekpoints, seekpoint_array))
543 FLAC__uint64 nums[2] = { 3, 7 };
544 seekpoint_array[seekpoints++].sample_number = nums[0];
545 seekpoint_array[seekpoints++].sample_number = nums[1];
546 printf("testing FLAC__metadata_object_seekpoint_template_append_points()... ");
547 if(!FLAC__metadata_object_seektable_template_append_points(block, nums, sizeof(nums)/sizeof(FLAC__uint64))) {
548 printf("FAILED, returned false\n");
551 if(!check_seektable_(block, seekpoints, seekpoint_array))
555 seekpoint_array[seekpoints++].sample_number = 0;
556 seekpoint_array[seekpoints++].sample_number = 10;
557 seekpoint_array[seekpoints++].sample_number = 20;
558 printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points()... ");
559 if(!FLAC__metadata_object_seektable_template_append_spaced_points(block, 3, 30)) {
560 printf("FAILED, returned false\n");
563 if(!check_seektable_(block, seekpoints, seekpoint_array))
567 seekpoint_array[0].sample_number = 0;
568 seekpoint_array[1].sample_number = 3;
569 seekpoint_array[2].sample_number = 7;
570 seekpoint_array[3].sample_number = 10;
571 seekpoint_array[4].sample_number = 20;
572 seekpoint_array[5].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
573 seekpoint_array[6].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
574 printf("testing FLAC__metadata_object_seekpoint_template_sort(compact=true)... ");
575 if(!FLAC__metadata_object_seektable_template_sort(block, /*compact=*/true)) {
576 printf("FAILED, returned false\n");
579 if(!FLAC__metadata_object_seektable_is_legal(block)) {
580 printf("FAILED, seek table is illegal\n");
583 if(!check_seektable_(block, seekpoints, seekpoint_array))
586 printf("testing FLAC__metadata_object_seekpoint_template_sort(compact=false)... ");
587 if(!FLAC__metadata_object_seektable_template_sort(block, /*compact=*/false)) {
588 printf("FAILED, returned false\n");
591 if(!FLAC__metadata_object_seektable_is_legal(block)) {
592 printf("FAILED, seek table is illegal\n");
595 if(!check_seektable_(block, seekpoints, seekpoint_array))
598 printf("testing FLAC__metadata_object_delete()... ");
599 FLAC__metadata_object_delete(block);
603 printf("testing VORBIS_COMMENT\n");
605 printf("testing FLAC__metadata_object_new()... ");
606 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
608 printf("FAILED, returned NULL\n");
611 expected_length = (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN + FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN) / 8;
612 if(block->length != expected_length) {
613 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
618 printf("testing FLAC__metadata_object_clone()... ");
619 vorbiscomment = FLAC__metadata_object_clone(block);
620 if(0 == vorbiscomment) {
621 printf("FAILED, returned NULL\n");
624 if(!compare_block_(vorbiscomment, block))
628 vc_resize_(vorbiscomment, 2);
629 printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(grow to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
630 if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
631 printf("FAILED, returned false\n");
634 if(!compare_block_(vorbiscomment, block))
638 vc_resize_(vorbiscomment, 1);
639 printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
640 if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
641 printf("FAILED, returned false\n");
644 if(!compare_block_(vorbiscomment, block))
648 vc_resize_(vorbiscomment, 0);
649 printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
650 if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
651 printf("FAILED, returned false\n");
654 if(!compare_block_(vorbiscomment, block))
658 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on empty array...");
659 vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
660 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/true)) {
661 printf("FAILED, returned false\n");
664 if(!compare_block_(vorbiscomment, block))
668 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on beginning of non-empty array...");
669 vc_insert_new_(&entry, vorbiscomment, 0, "name2=field2");
670 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/true)) {
671 printf("FAILED, returned false\n");
674 if(!compare_block_(vorbiscomment, block))
678 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on middle of non-empty array...");
679 vc_insert_new_(&entry, vorbiscomment, 1, "name3=field3");
680 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 1, entry, /*copy=*/true)) {
681 printf("FAILED, returned false\n");
684 if(!compare_block_(vorbiscomment, block))
688 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array...");
689 vc_insert_new_(&entry, vorbiscomment, 3, "name4=field4");
690 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 3, entry, /*copy=*/true)) {
691 printf("FAILED, returned false\n");
694 if(!compare_block_(vorbiscomment, block))
698 printf("testing FLAC__metadata_object_clone()... ");
699 blockcopy = FLAC__metadata_object_clone(block);
701 printf("FAILED, returned NULL\n");
704 if(!compare_block_(block, blockcopy))
708 printf("testing FLAC__metadata_object_delete()... ");
709 FLAC__metadata_object_delete(blockcopy);
712 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on middle of array...");
713 vc_delete_(vorbiscomment, 2);
714 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
715 printf("FAILED, returned false\n");
718 if(!compare_block_(vorbiscomment, block))
722 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on end of array...");
723 vc_delete_(vorbiscomment, 2);
724 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
725 printf("FAILED, returned false\n");
728 if(!compare_block_(vorbiscomment, block))
732 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on beginning of array...");
733 vc_delete_(vorbiscomment, 0);
734 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 0)) {
735 printf("FAILED, returned false\n");
738 if(!compare_block_(vorbiscomment, block))
742 printf("testing FLAC__metadata_object_vorbiscomment_set_comment(copy)...");
743 vc_set_new_(&entry, vorbiscomment, 0, "name5=field5");
744 FLAC__metadata_object_vorbiscomment_set_comment(block, 0, entry, /*copy=*/true);
745 if(!compare_block_(vorbiscomment, block))
749 printf("testing FLAC__metadata_object_vorbiscomment_set_vendor_string(copy)...");
750 vc_set_vs_new_(&entry, vorbiscomment, "name6=field6");
751 FLAC__metadata_object_vorbiscomment_set_vendor_string(block, entry, /*copy=*/true);
752 if(!compare_block_(vorbiscomment, block))
756 printf("testing FLAC__metadata_object_delete()... ");
757 FLAC__metadata_object_delete(vorbiscomment);
758 FLAC__metadata_object_delete(block);
762 printf("testing FLAC__metadata_object_new()... ");
763 block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
765 printf("FAILED, returned NULL\n");
770 printf("testing FLAC__metadata_object_clone()... ");
771 vorbiscomment = FLAC__metadata_object_clone(block);
772 if(0 == vorbiscomment) {
773 printf("FAILED, returned NULL\n");
776 if(!compare_block_(vorbiscomment, block))
780 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on empty array...");
781 vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
782 entry_clone_(&entry);
783 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/false)) {
784 printf("FAILED, returned false\n");
787 if(!compare_block_(vorbiscomment, block))
791 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on beginning of non-empty array...");
792 vc_insert_new_(&entry, vorbiscomment, 0, "name2=field2");
793 entry_clone_(&entry);
794 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/false)) {
795 printf("FAILED, returned false\n");
798 if(!compare_block_(vorbiscomment, block))
802 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on middle of non-empty array...");
803 vc_insert_new_(&entry, vorbiscomment, 1, "name3=field3");
804 entry_clone_(&entry);
805 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 1, entry, /*copy=*/false)) {
806 printf("FAILED, returned false\n");
809 if(!compare_block_(vorbiscomment, block))
813 printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on end of non-empty array...");
814 vc_insert_new_(&entry, vorbiscomment, 3, "name4=field4");
815 entry_clone_(&entry);
816 if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 3, entry, /*copy=*/false)) {
817 printf("FAILED, returned false\n");
820 if(!compare_block_(vorbiscomment, block))
824 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on middle of array...");
825 vc_delete_(vorbiscomment, 2);
826 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
827 printf("FAILED, returned false\n");
830 if(!compare_block_(vorbiscomment, block))
834 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on end of array...");
835 vc_delete_(vorbiscomment, 2);
836 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
837 printf("FAILED, returned false\n");
840 if(!compare_block_(vorbiscomment, block))
844 printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on beginning of array...");
845 vc_delete_(vorbiscomment, 0);
846 if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 0)) {
847 printf("FAILED, returned false\n");
850 if(!compare_block_(vorbiscomment, block))
854 printf("testing FLAC__metadata_object_vorbiscomment_set_comment(own)...");
855 vc_set_new_(&entry, vorbiscomment, 0, "name5=field5");
856 entry_clone_(&entry);
857 FLAC__metadata_object_vorbiscomment_set_comment(block, 0, entry, /*copy=*/false);
858 if(!compare_block_(vorbiscomment, block))
862 printf("testing FLAC__metadata_object_vorbiscomment_set_vendor_string(own)...");
863 vc_set_vs_new_(&entry, vorbiscomment, "name6=field6");
864 entry_clone_(&entry);
865 FLAC__metadata_object_vorbiscomment_set_vendor_string(block, entry, /*copy=*/false);
866 if(!compare_block_(vorbiscomment, block))
870 printf("testing FLAC__metadata_object_delete()... ");
871 FLAC__metadata_object_delete(vorbiscomment);
872 FLAC__metadata_object_delete(block);