#include "test.h" static int test_term_new() { char *data = "hello"; char *datatype = "xsd:string"; char *lang = "en-US"; TRACE (STR, "Test term, heap-allocated."); LSUP_Term *term = LSUP_term_new (LSUP_TERM_LITERAL, data, datatype, lang); TRACE ("Term data: %s", term->data); EXPECT_STR_EQ (term->data, data); EXPECT_STR_EQ (term->datatype, datatype); EXPECT_STR_EQ (term->lang, lang); TRACE (STR, "Reset term.\n"); char *uri_data = "urn:id:2144564356"; LSUP_term_init (term, LSUP_TERM_URI, uri_data, NULL, NULL); EXPECT_STR_EQ (term->data, uri_data); LSUP_term_free (term); return 0; } static int test_term_serialize_deserialize() { LSUP_Term *uri = LSUP_uri_new ("http://hello.org"); LSUP_Term *lit = LSUP_term_new (LSUP_TERM_LITERAL, "hello", NULL, NULL); LSUP_Term *tlit = LSUP_term_new (LSUP_TERM_LITERAL, "hello", "xsd:string", NULL); LSUP_Term *tllit = LSUP_term_new (LSUP_TERM_LITERAL, "hello", "xsd:string", "en-US"); LSUP_Buffer *sterm = BUF_DUMMY; LSUP_Term *dsterm = TERM_DUMMY; LSUP_term_serialize (uri, sterm); TRACE ("%s", "Serialized URI: "); LSUP_buffer_print (sterm); TRACE ("%s", "\n"); LSUP_term_deserialize (sterm, dsterm); ASSERT (LSUP_term_equals (dsterm, uri), "URI serialization error!"); LSUP_term_free (uri); LSUP_term_serialize (lit, sterm); TRACE ("%s", "Serialized literal: "); LSUP_buffer_print (sterm); TRACE ("%s", "\n"); LSUP_term_deserialize (sterm, dsterm); ASSERT (LSUP_term_equals (dsterm, lit), "lit serialization error!"); LSUP_term_free (lit); LSUP_term_serialize (tlit, sterm); TRACE ("%s", "Serialized typed literal: "); LSUP_buffer_print (sterm); TRACE ("%s", "\n"); LSUP_term_deserialize (sterm, dsterm); ASSERT (LSUP_term_equals (dsterm, tlit), "tlit serialization error!"); LSUP_term_free (tlit); LSUP_term_serialize (tllit, sterm); TRACE ("%s", "Serialized typed and language-tagged URI: "); LSUP_buffer_print (sterm); TRACE ("%s", "\n"); LSUP_term_deserialize (sterm, dsterm); ASSERT (LSUP_term_equals (dsterm, tllit), "URI serialization error!"); LSUP_term_free (tllit); LSUP_term_free (dsterm); LSUP_buffer_free (sterm); return 0; } static int test_term_to_key() { LSUP_Term *uri = LSUP_uri_new ("http://hello.org"); LSUP_Term *lit = LSUP_term_new (LSUP_TERM_LITERAL, "hello", NULL, NULL); LSUP_Term *tlit = LSUP_term_new( LSUP_TERM_LITERAL, "hello", "xsd:string", NULL); LSUP_Term *tllit1 = LSUP_term_new( LSUP_TERM_LITERAL, "hello", "xsd:string", "en-US"); LSUP_Term *tllit2 = LSUP_term_new( LSUP_TERM_LITERAL, "hello", "xsd:string", "en-GB"); LSUP_Key uri_key = LSUP_term_to_key (uri); LSUP_Key lit_key = LSUP_term_to_key (lit); LSUP_Key tlit_key = LSUP_term_to_key (tlit); LSUP_Key tllit1_key = LSUP_term_to_key (tllit1); LSUP_Key tllit2_key = LSUP_term_to_key (tllit2); ASSERT (uri_key != lit_key, "URI key conflict!"); ASSERT (lit_key != tlit_key, "URI key conflict!"); ASSERT (lit_key != tllit1_key, "URI key conflict!"); ASSERT (tlit_key != tllit1_key, "URI key conflict!"); ASSERT (tllit1_key != tllit2_key, "URI key conflict!"); LSUP_term_free (uri); LSUP_term_free (lit); LSUP_term_free (tlit); LSUP_term_free (tllit1); LSUP_term_free (tllit2); return 0; } int term_tests() { RUN (test_term_new); RUN (test_term_serialize_deserialize); RUN (test_term_to_key); return 0; }