static int test_comments () { th_comment tc; int n; char * value; INFO ("+ Initializing th_comment"); th_comment_init (&tc); INFO ("+ Adding ARTIST1"); th_comment_add (&tc, "ARTIST=" ARTIST1); INFO ("+ Adding LICENSE by tag"); th_comment_add_tag (&tc, "LICENSE", LICENSE); INFO ("+ Adding ARTIST2 by tag"); th_comment_add_tag (&tc, "ARTIST", ARTIST2); INFO ("+ Querying value of LICENSE"); value = th_comment_query (&tc, "LICENSE", 0); printf("foo %s\n", value); if (strcmp (value, LICENSE)) FAIL ("Incorrect value for LICENSE"); INFO ("+ Querying count of ARTIST comments"); n = th_comment_query_count (&tc, "ARTIST"); if (n != 2) FAIL ("Incorrect count of ARTIST comments"); INFO ("+ Querying value of ARTIST index 0"); value = th_comment_query (&tc, "ARTIST", 0); if (strcmp (value, ARTIST1)) FAIL ("Incorrect value for ARTIST index 0"); INFO ("+ Querying value of ARTIST index 1"); value = th_comment_query (&tc, "ARTIST", 1); if (strcmp (value, ARTIST2)) FAIL ("Incorrect value for ARTIST index 1"); INFO ("+ Querying value of ARTIST index 2 (out of bounds)"); value = th_comment_query (&tc, "ARTIST", 2); if (value != NULL) FAIL ("Non-NULL value for ARTIST index 2 (out of bounds)"); INFO ("+ Querying value of UNDEF index 7 (tag not defined)"); value = th_comment_query (&tc, "UNDEF", 7); if (value != NULL) FAIL ("Non-NULL value for UNDEF index 7 (tag not defined)"); INFO ("+ Clearing th_comment"); th_comment_clear (&tc); return 0; }
void th_comment_add_tag(th_comment *_tc,char *_tag,char *_val){ char *comment; int tag_len; int val_len; tag_len=strlen(_tag); val_len=strlen(_val); /*+2 for '=' and '\0'.*/ comment=_ogg_malloc(tag_len+val_len+2); memcpy(comment,_tag,tag_len); comment[tag_len]='='; memcpy(comment+tag_len+1,_val,val_len+1); th_comment_add(_tc,comment); _ogg_free(comment); }
void theora_comment_add(theora_comment *_tc,char *_comment){ th_comment_add((th_comment *)_tc,_comment); }