Browse Source

First res creation test clean.

scossu 2 weeks ago
parent
commit
213e2539c9
3 changed files with 50 additions and 115 deletions
  1. 5 7
      include/desc.h
  2. 21 22
      src/desc.c
  3. 24 86
      test/test_desc.c

+ 5 - 7
include/desc.h

@@ -70,7 +70,7 @@ typedef struct desc_t {
  *  reference the resource itself, an IRIRef with an empty string as data may
  *  be used. The graph URI is maintained within the resource. As a convention,
  *  it is recommended to use a fragment URI with a short label, e.g.
- *  `#changeset37205`, `#~alice`, or `#ancillary`. Fragments beginning with two
+ *  `#changeset37205`, `#~alice`, or `#admin-md`. Fragments beginning with two
  *  underscores are reserved for internal use and are not allowed in the input.
  *
  * @param[out] rsrc Resource handle pointer. The handle should be freed with
@@ -123,8 +123,7 @@ LSR_desc_get (const uuid_t id, LSR_Desc **rsrc);
 /** @brief Update an existing resource.
  *
  * This operation works by first removing triples by graph and term matching,
- * if provided, then adding triples grouped by graphs. Both steps are
- * optional.
+ * if provided, then adding triples grouped by graphs. Both steps are optional.
  *
  * Updates to triples containing #LSR_managed_preds and #LSR_managed_types are
  * ignored.
@@ -132,8 +131,8 @@ LSR_desc_get (const uuid_t id, LSR_Desc **rsrc);
  * @param[in] rsrc Resource handle.
  *
  * @param[in] rm_data `{NULL}`-terminated array of term arrays. Each term array
- * contains, in the following order: graph URI, s, p, o. Any and all terms in
- * each array may be NULL, acting as wildcards. This function calls
+ * contains, in the following order: s, p, o, graph URI (c). Any and all terms
+ * in each array may be NULL, acting as wildcards. This function calls
  * #LSUP_graph_remove_txn() on each matching graph, or on all graphs if the
  * first term in an array is NULL.
  *
@@ -148,8 +147,7 @@ LSR_desc_get (const uuid_t id, LSR_Desc **rsrc);
  *
  * @return LSUP_OK on successful update; TODO
  */
-LSUP_rc
-LSR_desc_update ( LSR_Desc *rsrc, LSUP_Term *const rm_data[][4],
+LSUP_rc LSR_desc_update ( LSR_Desc *rsrc, LSUP_Term *const rm_data[][4],
         LSUP_Graph *const *add_data);
 
 

+ 21 - 22
src/desc.c

@@ -314,30 +314,22 @@ LSR_desc_update (
      */
 
     if (rm_data) {
-        size_t ct_loop;
-        for (size_t i = 0; rm_data[i] != NULL; i++) {
-            LSUP_Buffer
-                *ss = NULL,
-                *sp = NULL,
-                *so = NULL,
-                *sc = NULL;
-
-            if (rm_data[i][1])
-                ss = LSUP_term_serialize (rm_data[i][1]);
-            if (rm_data[i][2])
-                sp = LSUP_term_serialize (rm_data[i][2]);
-            if (rm_data[i][3])
-                so = LSUP_term_serialize (rm_data[i][3]);
-            if (rm_data[i][0])
-                sc = LSUP_term_serialize (rm_data[i][0]);
+        size_t ct_loop, i, j;
+        for (i = 0; rm_data[i] != NULL; i++) {
+            LSUP_Buffer *sspoc[4] = {NULL};
+
+            for (j = 0; j < 4; j++) {
+                if (rm_data[i][j])
+                    sspoc[j] = LSUP_term_serialize (rm_data[i][j]);
+            }
 
             LSR_store->sif->remove_fn (
-                    LSR_store->data, ss, sp, so, sc, NULL, &ct_loop);
+                    LSR_store->data,
+                    sspoc[0], sspoc[1], sspoc[2], sspoc[3],
+                    NULL, &ct_loop);
 
-            LSUP_buffer_free (ss);
-            LSUP_buffer_free (sp);
-            LSUP_buffer_free (so);
-            LSUP_buffer_free (sc);
+            for (j = 0; j < 4; j++)
+                LSUP_buffer_free (sspoc[j]);
 
             log_debug (
                     "Removed %lu triples for %s",
@@ -350,6 +342,13 @@ LSR_desc_update (
 
     /*
      * ADD user data.
+     *
+     * Extensively using URIs relative to each graph, following
+     * https://www.w3.org/TR/ldp-bp/#use-relative-uris
+     *
+     * Note: a URI such as `#doc1` in graph `urn:lsres:1234#__main` is
+     * considered relative to `urn:lsres:1234` (`#__main` is the fragment of a
+     * document).
      */
 
     // Count graphs to be inserted and allocate space.
@@ -368,7 +367,7 @@ LSR_desc_update (
     for (size_t i = 0; i < ct; i++) {
         LSUP_Term *gr_uri = LSUP_graph_uri (add_data[i]);
 
-        log_debug ("Adding graph #%lu with uri: %s", i, gr_uri->data);
+        log_debug ("Adding user data #%lu with uri: %s", i, gr_uri->data);
 
         LSUP_Term *rel_uri = LSUP_iriref_relative (rsrc_uri, gr_uri);
         if (strstr (rel_uri->data, "#__") == rel_uri->data) {

+ 24 - 86
test/test_desc.c

@@ -4,71 +4,6 @@
 static int
 test_desc_create()
 {
-    /*
-    LSUP_Term *terms1[] = {
-        LSUP_iriref_new ("urn:s:1", NULL),
-        LSUP_iriref_new ("urn:s:2", NULL),
-        LSUP_iriref_new ("urn:p:1", NULL),
-        LSUP_iriref_new ("urn:p:2", NULL),
-        LSUP_iriref_new ("urn:o:1", NULL),
-        LSUP_iriref_new ("urn:o:2", NULL),
-    };
-    LSUP_Term *terms2[] = {
-        LSUP_iriref_new ("urn:s:10", NULL),
-        LSUP_iriref_new ("urn:s:20", NULL),
-        LSUP_iriref_new ("urn:p:10", NULL),
-        LSUP_iriref_new ("urn:p:20", NULL),
-        LSUP_iriref_new ("urn:o:10", NULL),
-        LSUP_iriref_new ("urn:o:20", NULL),
-    };
-
-    LSUP_Triple *trp1[] = {
-        LSUP_triple_new (terms1[0], terms1[2], terms1[4]),
-        LSUP_triple_new (terms1[0], terms1[3], terms1[4]),
-        LSUP_triple_new (terms1[0], terms1[3], terms1[5]),
-        LSUP_triple_new (terms1[1], terms1[2], terms1[4]),
-        NULL
-    };
-    LSUP_Triple *trp2[] = {
-        LSUP_triple_new (terms2[0], terms2[2], terms2[4]),
-        LSUP_triple_new (terms2[0], terms2[3], terms2[4]),
-        LSUP_triple_new (terms2[0], terms2[3], terms2[5]),
-        LSUP_triple_new (terms2[1], terms2[2], terms2[4]),
-        NULL
-    };
-
-    LSUP_Term *usr1_uri = LSUP_iriref_new ("#usr1", NULL);
-    LSUP_Graph *gr1 = LSUP_graph_new (NULL, usr1_uri, NULL);
-    LSUP_term_free (usr1_uri);
-    ASSERT (gr1, "Error creating graph!");
-    EXPECT_PASS (LSUP_graph_add (gr1, trp1, NULL));
-
-    for (size_t i = 0; trp1[i]; i++)
-        free (trp1[i]);
-
-    LSUP_Term *usr2_uri = LSUP_iriref_new ("#usr2", NULL);
-    LSUP_Graph *gr2 = LSUP_graph_new (NULL, usr2_uri, NULL);
-    LSUP_term_free (usr2_uri);
-    ASSERT (gr2, "Error creating graph!");
-    EXPECT_PASS (LSUP_graph_add (gr2, trp2, NULL));
-
-    char *tmp = NULL;
-    void *it;
-    it = ttl_codec.encode_graph_init(gr1);
-    while (ttl_codec.encode_graph_iter (it, &tmp) != LSUP_END)
-        log_info ("gr1: %s\n", tmp);
-    ttl_codec.encode_graph_done (it);
-
-    it = ttl_codec.encode_graph_init(gr2);
-    while (ttl_codec.encode_graph_iter (it, &tmp) != LSUP_END)
-        log_info ("gr2: %s\n", tmp);
-    ttl_codec.encode_graph_done (it);
-
-    free (tmp);
-
-    for (size_t i = 0; trp2[i]; i++)
-        free (trp2[i]);
-    */
     char
         *ttl1 = "<urn:s:1> <urn:p:2> <urn:o:2> , <urn:o:1> ; "
         "<urn:p:1> <urn:o:1> . "
@@ -77,37 +12,40 @@ test_desc_create()
         "<urn:s:10> <urn:p:10> <urn:o:10> ; "
         "<urn:p:20> <urn:o:20> , <urn:o:10> . ";
 
-    LSUP_Term
-        *usr1_uri = LSUP_iriref_new ("#usr1", NULL),
-        *usr2_uri = LSUP_iriref_new ("#usr2", NULL);
+    LSUP_Graph *data[3] = {NULL};
 
-    LSUP_Graph
-        *gr1 = LSUP_graph_new(NULL, usr1_uri, NULL),
-        *gr2 = LSUP_graph_new(NULL, usr2_uri, NULL);
+    FILE *input;
+    char *err;
+    size_t ct;
 
-    LSUP_term_free (usr1_uri);
-    LSUP_term_free (usr2_uri);
+    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);
 
-    ttl_codec.
+    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);
 
-    LSUP_Graph *data[] = {gr1, gr2, NULL};
     LSR_Desc *rsrc;
     EXPECT_PASS (LSR_desc_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 (gr1);
-    LSUP_graph_free (gr2);
-
-    /*
-    for (int i = 0; i < 6; i++) {
-        LSUP_term_free (terms1[i]);
-        LSUP_term_free (terms2[i]);
-    }
-    */
-
-    // TODO more action
+    LSUP_graph_free (data[0]);
+    LSUP_graph_free (data[1]);
+
+    // TODO tests:
+    // * Existence of admin graph
+    // * Existence of main graph
+    // * Linkage of admin and main graphs
+    // * Existence of user graphs
+    // * Linkage of user graphs
+    // * Size of user graphs
+    // * Spot-test triples in user graphs
 
     // Store for next test before freeing.
     EXPECT_PASS (LSR_desc_store (rsrc));