#include "test.h" static int test_index_add() { LSUP_Term *uri = LSUP_term_new( LSUP_TERM_URI, "http://hello.org", NULL, NULL); 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"); // Make capacity lower intentionally, to test expansion. LSUP_Index *idx = LSUP_index_new(3); LSUP_Key key; LSUP_SerTerm *s_uri = malloc(sizeof(LSUP_SerTerm)); LSUP_term_serialize(uri, s_uri); LSUP_index_add(idx, s_uri); key = LSUP_term_to_key(uri); ASSERT( LSUP_buffer_eq(LSUP_index_lookup(idx, key), s_uri), "URI not found!"); LSUP_SerTerm *s_lit = malloc(sizeof(LSUP_SerTerm)); LSUP_term_serialize(lit, s_lit); LSUP_index_add(idx, s_lit); key = LSUP_term_to_key(lit); ASSERT( LSUP_buffer_eq(LSUP_index_lookup(idx, key), s_lit), "Literal not found!"); LSUP_SerTerm *s_tlit = malloc(sizeof(LSUP_SerTerm)); LSUP_term_serialize(tlit, s_tlit); LSUP_index_add(idx, s_tlit); key = LSUP_term_to_key(tlit); ASSERT( LSUP_buffer_eq(LSUP_index_lookup(idx, key), s_tlit), "Typed literal not found!"); LSUP_SerTerm *s_tllit1 = malloc(sizeof(LSUP_SerTerm)); LSUP_term_serialize(tllit1, s_tllit1); LSUP_index_add(idx, s_tllit1); key = LSUP_term_to_key(tllit1); ASSERT( LSUP_buffer_eq(LSUP_index_lookup(idx, key), s_tllit1), "US lang literal not found!"); LSUP_SerTerm *s_tllit2 = malloc(sizeof(LSUP_SerTerm)); LSUP_term_serialize(tllit2, s_tllit2); LSUP_index_add(idx, s_tllit2); key = LSUP_term_to_key(tllit2); ASSERT( LSUP_buffer_eq(LSUP_index_lookup(idx, key), s_tllit2), "GB lang literal not found!"); LSUP_term_free(uri); LSUP_term_free(lit); LSUP_term_free(tlit); LSUP_term_free(tllit1); LSUP_term_free(tllit2); LSUP_index_free(idx); LSUP_buffer_done(s_uri); free(s_uri); LSUP_buffer_done(s_lit); free(s_lit); LSUP_buffer_done(s_tlit); free(s_tlit); LSUP_buffer_done(s_tllit1); free(s_tllit1); LSUP_buffer_done(s_tllit2); free(s_tllit2); return 0; } int test_index_add_pair() { LSUP_Term *uri = LSUP_term_new( LSUP_TERM_URI, "http://hello.org", NULL, NULL); LSUP_Index *idx = LSUP_index_new(1); LSUP_SerTerm *s_uri = malloc(sizeof(LSUP_SerTerm)); LSUP_term_serialize(uri, s_uri); LSUP_index_add(idx, s_uri); LSUP_Key key; key = LSUP_term_to_key(uri); LSUP_index_add_pair(idx, key, s_uri); ASSERT( LSUP_buffer_eq(LSUP_index_lookup(idx, key), s_uri), "URI not found!"); LSUP_index_free(idx); LSUP_term_free(uri); LSUP_buffer_done(s_uri); free(s_uri); return 0; } int index_tests() { RUN(test_index_add); RUN(test_index_add_pair); return 0; }