#include "test.h" #include "namespace.h" static int test_dres_create() { char *ttl1 = " , ; " " . " " . ", *ttl2 = " . " " ; " " , . "; LSUP_Graph *data[3] = {NULL}; FILE *input; char *err; size_t ct; input = fmemopen (ttl1, strlen (ttl1), "r"); ttl_codec.decode_graph(input, data, &ct, &err); LSUP_graph_set_uri (data[0], LSUP_iriref_new ("#usr1", NULL)); fclose(input); input = fmemopen (ttl2, strlen (ttl2), "r"); ttl_codec.decode_graph(input, data + 1, &ct, &err); LSUP_graph_set_uri (data[1], LSUP_iriref_new ("#usr2", NULL)); fclose(input); free(err); // Create resource. LSR_Dres *rsrc; EXPECT_PASS (LSR_dres_new_multi (data, &rsrc)); // Free input handles before using the resource to ensure that these // pointers are not being referenced by the resource. LSUP_graph_free (data[0]); LSUP_graph_free (data[1]); LSUP_Graph *md_gr = LSR_dres_metadata (rsrc); ASSERT (md_gr != NULL, "Error retrieving metadata graph!"); ASSERT ( LSUP_term_equals ( LSUP_graph_uri (md_gr), LSUP_graph_uri (rsrc->admin_data)), "Metadata function URI is incorrect!"); ASSERT (sizeof(md_gr) > 0, "No metadata found for resource!"); LSUP_Term *rsrc_urn = LSR_dres_urn (rsrc), *main_urn = LSR_id_to_urn (rsrc->id, "__main"), *admin_urn = LSR_id_to_urn (rsrc->id, "__admin"), *usr1_urn = LSR_id_to_urn (rsrc->id, "usr1"), *usr2_urn = LSR_id_to_urn (rsrc->id, "usr2"); // TODO tests: // * Existence of admin graph // * Existence of main graph // * Existence of user graphs // * Linkage of main, admin, and user graphs // * Size of user graphs // * Spot-test triples in user graphs ASSERT ( LSUP_term_equals (main_urn, LSUP_graph_uri (rsrc->main_data)), "Main graph URI is incorrect!"); ASSERT ( LSUP_term_equals (admin_urn, LSUP_graph_uri (md_gr)), "Admin graph URI is incorrect!"); LSUP_Term *t1 = LSUP_iriref_new ("foaf:topic", LSUP_default_nsm); LSUP_Triple *test_spo = LSUP_triple_new (main_urn, t1, rsrc_urn); /* ASSERT ( LSUP_graph_contains (rsrc->main_data, test_spo), "Main data missing topic triple!"); */ // TODO LSUP_term_free (usr2_urn); LSUP_term_free (usr1_urn); LSUP_term_free (admin_urn); LSUP_term_free (main_urn); LSUP_term_free (rsrc_urn); LSUP_graph_free (md_gr); // Store for next test before freeing. EXPECT_PASS (LSR_dres_store (rsrc)); LSR_dres_free (rsrc); return 0; } static int test_dres_get () { return 0; } int dres_tests() { RUN (test_dres_create); RUN (test_dres_get); return 0; }