Sfoglia il codice sorgente

Merge branch 'master' into ctx_list

scossu 3 giorni fa
parent
commit
83d4178b53
6 ha cambiato i file con 84 aggiunte e 11 eliminazioni
  1. 12 1
      include/lsup/store.h
  2. 2 2
      include/lsup/store_interface.h
  3. 7 7
      src/graph.c
  4. 2 1
      src/namespace.c
  5. 12 0
      src/store.c
  6. 49 0
      test/test_graph.c

+ 12 - 1
include/lsup/store.h

@@ -70,7 +70,18 @@ typedef struct store_t {
 
 /** @brief Return store interface for a specific type.
  */
-const LSUP_StoreInt *LSUP_store_int (LSUP_StoreType type);
+const LSUP_StoreInt *
+LSUP_store_int (LSUP_StoreType type);
+
+
+/** @brief Return the store type label.
+ *
+ * @param type Store type enum.
+ *
+ * @return Store type label as `STORE_<type>`.
+ */
+const char *
+LSUP_store_type_label (LSUP_StoreType type);
 
 
 /** @brief Create a new store.

+ 2 - 2
include/lsup/store_interface.h

@@ -376,7 +376,7 @@ typedef LSUP_rc (*store_remove_fn_t)(
  * ns3: <urn:ns:a#>
  * ns2: <urn:ns:c#>
  *
- * @param[in] store MDB store to update.
+ * @param[in] store Store back end to update.
  *
  * @param[out] nsm Namespace map handle to store.
  *
@@ -531,7 +531,7 @@ typedef struct store_if_t {
                                         ///< Only available (and mandatory)
                                         ///< in stores with the
                                         ///< #LSUP_STORE_IDX feature.
-    store_nsm_get_fn_t  nsm_get_fn;     ///< Get a namespace from the map.
+    store_nsm_get_fn_t  nsm_get_fn;     ///< Get the store's namespace map.
                                         ///<
                                         ///< Only available (and mandatory)
                                         ///< in stores with the

+ 7 - 7
src/graph.c

@@ -45,19 +45,19 @@ LSUP_Graph *
 LSUP_graph_new (LSUP_Store *store, const char *uri_str, LSUP_NSMap *nsm)
 {
     // Create a HTable graph by default.
-    if (!store) store = LSUP_store_new (LSUP_STORE_HTABLE, NULL, 0);
-
     LSUP_Graph *gr;
     MALLOC_GUARD (gr, NULL);
 
-    gr->uri =
-        uri_str? LSUP_iriref_new (uri_str, nsm) :
-        LSUP_iriref_new (NULL, NULL);
-    gr->store = store;
+    gr->store = (store) ? store : LSUP_store_new (LSUP_STORE_HTABLE, NULL, 0);
 
-    if (gr->store->sif->features & LSUP_STORE_PERM) gr->nsm = NULL;
+    if (gr->store->sif->nsm_get_fn)
+        gr->nsm = gr->store->sif->nsm_get_fn (gr->store->data);
     else gr->nsm = nsm ? nsm : LSUP_default_nsm;
 
+    gr->uri =
+        uri_str? LSUP_iriref_new (uri_str, gr->nsm) :
+        LSUP_iriref_new (NULL, NULL);
+
     LOG_DEBUG("Graph created.");
     return gr;
 }

+ 2 - 1
src/namespace.c

@@ -45,6 +45,7 @@ static bool nsmap_dump_ns_iter_fn (const void *item, void *udata)
 {
     const NSEntry *entry = item;
     struct dump_iter_t *cur = udata;
+    //LOG_TRACE ("Dumping NS to string: %s %s", entry->pfx, entry->ns);
 
     cur->data[cur->i][0] = (const char *)entry->pfx;
     cur->data[cur->i++][1] = (const char *)entry->ns;
@@ -87,7 +88,7 @@ LSUP_nsmap_add (NSMap *map, const char *pfx, const char *nsstr)
         entry_s.ns = ns;
         hashmap_set (map, &entry_s);
         if (hashmap_oom (map)) return LSUP_MEM_ERR;
-        LOG_DEBUG("Added prefix '%s' to NS map.", entry_s.pfx);
+        LOG_DEBUG("Added prefix '%s' to NS map @%p.", entry_s.pfx, map);
     } else {
         LOG_DEBUG(
                 "Replacing NS '%s' with '%s' for prefix '%s'.",

+ 12 - 0
src/store.c

@@ -12,6 +12,18 @@ LSUP_store_int (LSUP_StoreType type) {
 #undef ENTRY
 
 
+const char *
+LSUP_store_type_label (LSUP_StoreType type)
+{
+#define ENTRY(a, b) case LSUP_STORE_##a: return "STORE_" #a;
+    switch (type) {
+        BACKEND_TBL
+        default: return "";
+    }
+#undef ENTRY
+}
+
+
 LSUP_Store *
 LSUP_store_new (
         const LSUP_StoreType store_type, const char *store_id, size_t size)

+ 49 - 0
test/test_graph.c

@@ -39,6 +39,44 @@ _graph_new (LSUP_StoreType type)
 }
 
 
+/// Test creating a graph with a namespaced URI.
+static int
+_graph_ns_uri (LSUP_StoreType type)
+{
+    const LSUP_StoreInt *sif = LSUP_store_int (type);
+    if (sif->setup_fn) sif->setup_fn (NULL, true);
+
+    LSUP_NSMap *nsm = LSUP_nsmap_new();
+    LSUP_nsmap_add (nsm, "ns1", "urn:ns1#");
+    LSUP_nsmap_add (nsm, "ns2", "urn:ns2#");
+    LSUP_nsmap_add (nsm, "ns3", "urn:ns3#");
+
+    LSUP_Graph *gr;
+    LSUP_Store *store = NULL;
+    if (sif->features & LSUP_STORE_PERM) {
+        store = LSUP_store_new (type, NULL, 0);
+        store->sif->nsm_put_fn (store->data, nsm, NULL);
+    }
+    gr = LSUP_graph_new (store, "ns1:gr1", nsm);
+    ASSERT (gr != NULL, "Error creating graph!");
+
+    ASSERT (
+            LSUP_graph_uri (gr)->type == LSUP_TERM_NS_IRIREF,
+            "Namespace prefixing failed!");
+
+    LSUP_Term *comp = LSUP_iriref_new ("urn:ns1#gr1", NULL);
+    ASSERT (
+            LSUP_term_equals (LSUP_graph_uri (gr), comp),
+            "Namespaced graph URI is incorrect!" );
+    LSUP_term_free (comp);
+
+    LSUP_graph_free (gr);
+    if (store) LSUP_store_free (store);
+
+    return 0;
+}
+
+
 static int
 _graph_add (LSUP_StoreType type)
 {
@@ -700,6 +738,16 @@ BACKEND_TBL
 }
 
 
+static int test_graph_ns_uri() {
+#define ENTRY(a, b) \
+    if (_graph_ns_uri (LSUP_STORE_##a) != 0) return -1;
+BACKEND_TBL
+#undef ENTRY
+
+    return 0;
+}
+
+
 static int test_graph_add() {
 #define ENTRY(a, b) \
     if (_graph_add (LSUP_STORE_##a) != 0) return -1;
@@ -834,6 +882,7 @@ int graph_tests()
 {
     RUN (test_environment);
     RUN (test_graph_new);
+    RUN (test_graph_ns_uri);
     RUN (test_graph_add);
     RUN (test_graph_get);
     RUN (test_graph_link_map);