📄 metadata_object.c
字号:
seekpoints--; printf("testing FLAC__metadata_object_seektable_delete_point() on end of array..."); if(!FLAC__metadata_object_seektable_delete_point(block, 2)) { printf("FAILED, returned false\n"); return false; } if(!check_seektable_(block, seekpoints, seekpoint_array)) return false; seekpoints--; printf("testing FLAC__metadata_object_seektable_delete_point() on beginning of array..."); if(!FLAC__metadata_object_seektable_delete_point(block, 0)) { printf("FAILED, returned false\n"); return false; } if(!check_seektable_(block, seekpoints, seekpoint_array+1)) return false; printf("testing FLAC__metadata_object_seektable_set_point()..."); FLAC__metadata_object_seektable_set_point(block, 0, seekpoint_array[0]); if(!check_seektable_(block, seekpoints, seekpoint_array)) return false; printf("testing FLAC__metadata_object_delete()... "); FLAC__metadata_object_delete(block); printf("OK\n"); /* seektable template functions */ for(i = 0; i < sizeof(seekpoint_array) / sizeof(FLAC__StreamMetadata_SeekPoint); i++) { seekpoint_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER; seekpoint_array[i].stream_offset = 0; seekpoint_array[i].frame_samples = 0; } seekpoints = 0; printf("testing FLAC__metadata_object_new()... "); block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE); if(0 == block) { printf("FAILED, returned NULL\n"); return false; } if(!check_seektable_(block, seekpoints, 0)) return false; seekpoints += 2; printf("testing FLAC__metadata_object_seekpoint_template_append_placeholders()... "); if(!FLAC__metadata_object_seektable_template_append_placeholders(block, 2)) { printf("FAILED, returned false\n"); return false; } if(!check_seektable_(block, seekpoints, seekpoint_array)) return false; seekpoint_array[seekpoints++].sample_number = 7; printf("testing FLAC__metadata_object_seekpoint_template_append_point()... "); if(!FLAC__metadata_object_seektable_template_append_point(block, 7)) { printf("FAILED, returned false\n"); return false; } if(!check_seektable_(block, seekpoints, seekpoint_array)) return false; { FLAC__uint64 nums[2] = { 3, 7 }; seekpoint_array[seekpoints++].sample_number = nums[0]; seekpoint_array[seekpoints++].sample_number = nums[1]; printf("testing FLAC__metadata_object_seekpoint_template_append_points()... "); if(!FLAC__metadata_object_seektable_template_append_points(block, nums, sizeof(nums)/sizeof(FLAC__uint64))) { printf("FAILED, returned false\n"); return false; } if(!check_seektable_(block, seekpoints, seekpoint_array)) return false; } seekpoint_array[seekpoints++].sample_number = 0; seekpoint_array[seekpoints++].sample_number = 10; seekpoint_array[seekpoints++].sample_number = 20; printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points()... "); if(!FLAC__metadata_object_seektable_template_append_spaced_points(block, 3, 30)) { printf("FAILED, returned false\n"); return false; } if(!check_seektable_(block, seekpoints, seekpoint_array)) return false; seekpoints--; seekpoint_array[0].sample_number = 0; seekpoint_array[1].sample_number = 3; seekpoint_array[2].sample_number = 7; seekpoint_array[3].sample_number = 10; seekpoint_array[4].sample_number = 20; seekpoint_array[5].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER; seekpoint_array[6].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER; printf("testing FLAC__metadata_object_seekpoint_template_sort(compact=true)... "); if(!FLAC__metadata_object_seektable_template_sort(block, /*compact=*/true)) { printf("FAILED, returned false\n"); return false; } if(!FLAC__metadata_object_seektable_is_legal(block)) { printf("FAILED, seek table is illegal\n"); return false; } if(!check_seektable_(block, seekpoints, seekpoint_array)) return false; printf("testing FLAC__metadata_object_seekpoint_template_sort(compact=false)... "); if(!FLAC__metadata_object_seektable_template_sort(block, /*compact=*/false)) { printf("FAILED, returned false\n"); return false; } if(!FLAC__metadata_object_seektable_is_legal(block)) { printf("FAILED, seek table is illegal\n"); return false; } if(!check_seektable_(block, seekpoints, seekpoint_array)) return false; printf("testing FLAC__metadata_object_delete()... "); FLAC__metadata_object_delete(block); printf("OK\n"); printf("testing VORBIS_COMMENT\n"); { FLAC__StreamMetadata_VorbisComment_Entry entry_; char *field_name, *field_value; printf("testing FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair()... "); if(!FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(&entry_, "name", "value")) { printf("FAILED, returned false\n"); return false; } if(strcmp(entry_.entry, "name=value")) { printf("FAILED, field mismatch\n"); return false; } printf("OK\n"); printf("testing FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair()... "); if(!FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair(entry_, &field_name, &field_value)) { printf("FAILED, returned false\n"); return false; } if(strcmp(field_name, "name")) { printf("FAILED, field name mismatch\n"); return false; } if(strcmp(field_value, "value")) { printf("FAILED, field value mismatch\n"); return false; } printf("OK\n"); printf("testing FLAC__metadata_object_vorbiscomment_entry_matches()... "); if(!FLAC__metadata_object_vorbiscomment_entry_matches(entry_, field_name, strlen(field_name))) { printf("FAILED, expected true, returned false\n"); return false; } printf("OK\n"); printf("testing FLAC__metadata_object_vorbiscomment_entry_matches()... "); if(FLAC__metadata_object_vorbiscomment_entry_matches(entry_, "blah", strlen("blah"))) { printf("FAILED, expected false, returned true\n"); return false; } printf("OK\n"); free(entry_.entry); free(field_name); free(field_value); } printf("testing FLAC__metadata_object_new()... "); block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT); if(0 == block) { printf("FAILED, returned NULL\n"); return false; } expected_length = (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + strlen(FLAC__VENDOR_STRING) + FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN/8); if(block->length != expected_length) { printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length); return false; } printf("OK\n"); printf("testing FLAC__metadata_object_clone()... "); vorbiscomment = FLAC__metadata_object_clone(block); if(0 == vorbiscomment) { printf("FAILED, returned NULL\n"); return false; } if(!mutils__compare_block(vorbiscomment, block)) return false; printf("OK\n"); vc_resize_(vorbiscomment, 2); printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(grow to %u)...", vorbiscomment->data.vorbis_comment.num_comments); if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) { printf("FAILED, returned false\n"); return false; } if(!mutils__compare_block(vorbiscomment, block)) return false; printf("OK\n"); vc_resize_(vorbiscomment, 1); printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments); if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) { printf("FAILED, returned false\n"); return false; } if(!mutils__compare_block(vorbiscomment, block)) return false; printf("OK\n"); vc_resize_(vorbiscomment, 0); printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments); if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) { printf("FAILED, returned false\n"); return false; } if(!mutils__compare_block(vorbiscomment, block)) return false; printf("OK\n"); printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on empty array..."); vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1"); if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) { printf("FAILED, returned false\n"); return false; } if(!mutils__compare_block(vorbiscomment, block)) return false; printf("OK\n"); printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on non-empty array..."); vc_insert_new_(&entry, vorbiscomment, 1, "name2=field2"); if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) { printf("FAILED, returned false\n"); return false; } if(!mutils__compare_block(vorbiscomment, block)) return false; printf("OK\n"); vc_resize_(vorbiscomment, 0); printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments); if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) { printf("FAILED, returned false\n"); return false; } if(!mutils__compare_block(vorbiscomment, block)) return false; printf("OK\n"); printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on empty array..."); vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1"); if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/true)) { printf("FAILED, returned false\n"); return false; } if(!mutils__compare_block(vorbiscomment, block)) return false; printf("OK\n"); printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on beginning of non-empty array..."); vc_insert_new_(&entry, vorbiscomment, 0, "name2=field2"); if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/true)) { printf("FAILED, returned false\n"); return false; } if(!mutils__compare_block(vorbiscomment, block)) return false; printf("OK\n"); printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on middle of non-empty array..."); vc_insert_new_(&entry, vorbiscomment, 1, "name3=field3"); if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 1, entry, /*copy=*/true)) { printf("FAILED, returned false\n"); return false; } if(!mutils__compare_block(vorbiscomment, block)) return false; printf("OK\n"); printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array..."); vc_insert_new_(&entry, vorbiscomment, 3, "name4=field4"); if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 3, entry, /*copy=*/true)) { printf("FAILED, returned false\n"); return false; } if(!mutils__compare_block(vorbiscomment, block)) return false; printf("OK\n"); printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array..."); vc_insert_new_(&entry, vorbiscomment, 4, "name3=field3dup1"); if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 4, entry, /*copy=*/true)) { printf("FAILED, returned false\n"); return false; } if(!mutils__compare_block(vorbiscomment, block)) return false; printf("OK\n"); printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array..."); vc_insert_new_(&entry, vorbiscomment, 5, "name3=field3dup1"); if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 5, entry, /*copy=*/true)) { printf("FAILED, returned false\n"); return false; } if(!mutils__compare_block(vorbiscomment, block)) return false; printf("OK\n"); printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()..."); if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0, "name3")) != 1) { printf("FAILED, expected 1, got %d\n", j); return false; } printf("OK\n"); printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()..."); if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, j+1, "name3")) != 4) { printf("FAILED, expected 4, got %d\n", j); return false; } printf("OK\n"); printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()..."); if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, j+1, "name3")) != 5) { printf("FAILED, expected 5, got %d\n", j); return false; } printf("OK\n"); printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()..."); if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0, "name2")) != 0) { printf("FAILED, expected 0, got %d\n", j); return false; } printf("OK\n"); printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()..."); if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, j+1, "name2")) != -1) { printf("FAILED, expected -1, got %d\n", j); return false; } printf("OK\n"); printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()..."); if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0, "blah")) != -1) { printf("FAILED, expected -1, got %d\n", j); return false; } printf("OK\n"); printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(first, copy)..."); vc_replace_new_(&entry, vorbiscomment, "name3=field3new1", /*all=*/false); if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/false, /*copy=*/true)) { printf("FAILED, returned false\n"); return false; } if(!mutils__compare_block(vorbiscomment, block)) return false; if(block->data.vorbis_comment.num_comments != 6) { printf("FAILED, expected 6 comments, got %u\n", block->data.vorbis_comment.num_comments); return false; } printf("OK\n"); printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(all, copy)..."); vc_replace_new_(&entry, vorbiscomment, "name3=field3new2", /*all=*/true); if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/true, /*copy=*/true)) { printf("FAILED, returned false\n"); return false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -