123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- #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", DEFAULT_DTYPE, NULL);
- LSUP_Term *tllit1 = LSUP_term_new(
- LSUP_TERM_LITERAL, "hello", NULL, "en-US");
- LSUP_Term *tllit2 = LSUP_term_new(
- LSUP_TERM_LITERAL, "hello",
- "http://www.w3.org/2001/XMLSchema#string", "en-GB");
- LSUP_Key uri_key = LSUP_term_hash (uri);
- LSUP_Key lit_key = LSUP_term_hash (lit);
- LSUP_Key tlit_key = LSUP_term_hash (tlit);
- LSUP_Key tllit1_key = LSUP_term_hash (tllit1);
- LSUP_Key tllit2_key = LSUP_term_hash (tllit2);
- ASSERT (uri_key != lit_key, "URI key conflict!");
- ASSERT (lit_key == tlit_key, "URI keys differ!");
- 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;
- }
|