|
@@ -11,7 +11,7 @@ _graph_new (LSUP_StoreType type)
|
|
|
if (sif->setup_fn) sif->setup_fn (NULL, true);
|
|
|
|
|
|
LSUP_Graph *gr;
|
|
|
- LSUP_Store *store;
|
|
|
+ LSUP_Store *store = NULL;
|
|
|
if (type == LSUP_STORE_HTABLE) {
|
|
|
gr = LSUP_graph_new (NULL, NULL, NULL);
|
|
|
} else {
|
|
@@ -33,7 +33,7 @@ _graph_new (LSUP_StoreType type)
|
|
|
EXPECT_INT_EQ (LSUP_graph_size (gr), 0);
|
|
|
|
|
|
LSUP_graph_free (gr);
|
|
|
- if (type != LSUP_STORE_HTABLE) LSUP_store_free (store);
|
|
|
+ LSUP_store_free (store);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -71,7 +71,8 @@ _graph_ns_uri (LSUP_StoreType type)
|
|
|
LSUP_term_free (comp);
|
|
|
|
|
|
LSUP_graph_free (gr);
|
|
|
- if (store) LSUP_store_free (store);
|
|
|
+ LSUP_nsmap_free (nsm);
|
|
|
+ LSUP_store_free (store);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -87,7 +88,6 @@ _graph_add (LSUP_StoreType type)
|
|
|
|
|
|
LSUP_Graph *gr;
|
|
|
LSUP_Store *store;
|
|
|
-
|
|
|
if (type == LSUP_STORE_HTABLE) store = NULL;
|
|
|
else store = LSUP_store_new (type, NULL, 0);
|
|
|
|
|
@@ -123,7 +123,7 @@ _graph_add (LSUP_StoreType type)
|
|
|
|
|
|
LSUP_graph_free (gr);
|
|
|
LSUP_graph_free (gr2);
|
|
|
- if (type != LSUP_STORE_HTABLE) LSUP_store_free (store);
|
|
|
+ LSUP_store_free (store);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -140,7 +140,9 @@ _graph_get (LSUP_StoreType type)
|
|
|
|
|
|
LSUP_Triple **trp = create_triples();
|
|
|
|
|
|
- LSUP_Store *store = LSUP_store_new (type, NULL, 0);
|
|
|
+ LSUP_Store *store;
|
|
|
+ if (type == LSUP_STORE_HTABLE) store = NULL;
|
|
|
+ else store = LSUP_store_new (type, NULL, 0);
|
|
|
LSUP_Graph
|
|
|
*gr1 = LSUP_graph_new (store, NULL, NULL),
|
|
|
*gr2 = LSUP_graph_new (store, NULL, NULL);
|
|
@@ -184,7 +186,7 @@ _graph_get (LSUP_StoreType type)
|
|
|
LSUP_graph_free (gr2);
|
|
|
LSUP_graph_free (gr3);
|
|
|
LSUP_graph_free (gr4);
|
|
|
- if (type != LSUP_STORE_HTABLE) LSUP_store_free (store);
|
|
|
+ LSUP_store_free (store);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -199,7 +201,9 @@ _graph_link_map (LSUP_StoreType type)
|
|
|
|
|
|
LSUP_Triple **trp = create_triples();
|
|
|
|
|
|
- LSUP_Store *store = LSUP_store_new (type, NULL, 0);
|
|
|
+ LSUP_Store *store;
|
|
|
+ if (type == LSUP_STORE_HTABLE) store = NULL;
|
|
|
+ else store = LSUP_store_new (type, NULL, 0);
|
|
|
LSUP_Graph *gr = LSUP_graph_new (store, NULL, NULL);
|
|
|
|
|
|
size_t ct;
|
|
@@ -297,7 +301,7 @@ _graph_link_map (LSUP_StoreType type)
|
|
|
|
|
|
free_triples (trp);
|
|
|
LSUP_graph_free (gr);
|
|
|
- if (type != LSUP_STORE_HTABLE) LSUP_store_free (store);
|
|
|
+ LSUP_store_free (store);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -314,7 +318,9 @@ _graph_bool_ops (LSUP_StoreType type)
|
|
|
|
|
|
LSUP_Triple **trp = create_triples();
|
|
|
|
|
|
- LSUP_Store *store = LSUP_store_new (type, NULL, 0);
|
|
|
+ LSUP_Store *store;
|
|
|
+ if (type == LSUP_STORE_HTABLE) store = NULL;
|
|
|
+ else store = LSUP_store_new (type, NULL, 0);
|
|
|
LSUP_Graph
|
|
|
*gr1 = LSUP_graph_new (store, NULL, NULL),
|
|
|
*gr2 = LSUP_graph_new (store, NULL, NULL),
|
|
@@ -402,7 +408,7 @@ _graph_bool_ops (LSUP_StoreType type)
|
|
|
LSUP_graph_free (gr1);
|
|
|
LSUP_graph_free (gr2);
|
|
|
free_triples (trp);
|
|
|
- if (type != LSUP_STORE_HTABLE) LSUP_store_free (store);
|
|
|
+ LSUP_store_free (store);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -463,7 +469,7 @@ _graph_lookup (LSUP_StoreType type)
|
|
|
if (sif->setup_fn) sif->setup_fn (NULL, true);
|
|
|
|
|
|
LSUP_Graph *gr;
|
|
|
- LSUP_Store *store;
|
|
|
+ LSUP_Store *store = NULL;
|
|
|
if (type == LSUP_STORE_HTABLE) {
|
|
|
gr = LSUP_graph_new (NULL, NULL, NULL);
|
|
|
} else {
|
|
@@ -519,7 +525,7 @@ _graph_lookup (LSUP_StoreType type)
|
|
|
|
|
|
free_triples (trp);
|
|
|
LSUP_graph_free (gr);
|
|
|
- if (type != LSUP_STORE_HTABLE) LSUP_store_free (store);
|
|
|
+ LSUP_store_free (store);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -534,7 +540,7 @@ _graph_remove (LSUP_StoreType type)
|
|
|
LSUP_Triple **trp = create_triples();
|
|
|
|
|
|
LSUP_Graph *gr;
|
|
|
- LSUP_Store *store;
|
|
|
+ LSUP_Store *store = NULL;
|
|
|
if (type == LSUP_STORE_HTABLE) {
|
|
|
gr = LSUP_graph_new (NULL, NULL, NULL);
|
|
|
} else {
|
|
@@ -565,7 +571,7 @@ _graph_remove (LSUP_StoreType type)
|
|
|
free_triples (trp); // gr copied data.
|
|
|
|
|
|
LSUP_graph_free (gr);
|
|
|
- if (type != LSUP_STORE_HTABLE) LSUP_store_free (store);
|
|
|
+ LSUP_store_free (store);
|
|
|
|
|
|
// TODO Test complete removal of triples from index when they are not
|
|
|
// in another context.
|
|
@@ -611,7 +617,7 @@ _graph_txn (LSUP_StoreType type)
|
|
|
EXPECT_INT_EQ (LSUP_graph_size (gr), 8);
|
|
|
|
|
|
LSUP_graph_free (gr);
|
|
|
- if (type != LSUP_STORE_HTABLE) LSUP_store_free (store);
|
|
|
+ LSUP_store_free (store);
|
|
|
|
|
|
free_triples (trp); // gr copied data.
|
|
|
|
|
@@ -672,7 +678,7 @@ _graph_relative (LSUP_StoreType type)
|
|
|
LSUP_term_free (rel_o);
|
|
|
free (rel_spo);
|
|
|
LSUP_graph_free (gr);
|
|
|
- if (type != LSUP_STORE_HTABLE) LSUP_store_free (store);
|
|
|
+ LSUP_store_free (store);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -688,18 +694,36 @@ _graph_list (LSUP_StoreType type)
|
|
|
|
|
|
LSUP_Store *store = LSUP_store_new (type, NULL, 0);
|
|
|
|
|
|
- LSUP_Graph
|
|
|
- *gr1 = LSUP_graph_new (store, "urn:gr:1", NULL),
|
|
|
- *gr2 = LSUP_graph_new (store, "urn:gr:2", NULL),
|
|
|
- *gr3 = LSUP_graph_new (store, "urn:gr:3", NULL);
|
|
|
+ LSUP_Graph *gg[3] = {
|
|
|
+ LSUP_graph_new (store, "urn:gr:1", NULL),
|
|
|
+ LSUP_graph_new (store, "urn:gr:2", NULL),
|
|
|
+ LSUP_graph_new (store, "urn:gr:3", NULL),
|
|
|
+ };
|
|
|
|
|
|
LSUP_Triple **trp = create_triples();
|
|
|
- LSUP_graph_add (gr1, trp, NULL);
|
|
|
+ LSUP_graph_add (gg[0], trp, NULL); // Add some triples to the 1st graph.
|
|
|
+ LSUP_graph_add (gg[1], trp + 4, NULL); // Same with the 2nd graph.
|
|
|
+ free_triples (trp);
|
|
|
|
|
|
LSUP_TermSet *ts = LSUP_graph_list (store);
|
|
|
- //TODO
|
|
|
+ ASSERT (ts != NULL, "Error creating context list!");
|
|
|
|
|
|
- free_triples (trp);
|
|
|
+ EXPECT_INT_EQ (hashmap_count (ts), 2);
|
|
|
+
|
|
|
+ // Check if first 2 graphs (with triples) are in the context set.
|
|
|
+ LSUP_Hash key;
|
|
|
+ key = LSUP_term_hash (LSUP_graph_uri (gg[0]));
|
|
|
+ ASSERT (LSUP_term_set_get (ts, key) != NULL, "Context #1 not found!");
|
|
|
+ key = LSUP_term_hash (LSUP_graph_uri (gg[1]));
|
|
|
+ ASSERT (LSUP_term_set_get (ts, key) != NULL, "Context #2 not found!");
|
|
|
+ key = LSUP_term_hash (LSUP_graph_uri (gg[2]));
|
|
|
+ ASSERT (
|
|
|
+ LSUP_term_set_get (ts, key) == NULL,
|
|
|
+ "Empty context shoud not be here!");
|
|
|
+
|
|
|
+ for (size_t i = 0; i < 3; i++) LSUP_graph_free (gg[i]);
|
|
|
+ LSUP_term_set_free (ts);
|
|
|
+ LSUP_store_free (store);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -836,6 +860,20 @@ BACKEND_TBL
|
|
|
}
|
|
|
|
|
|
|
|
|
+static int test_graph_list()
|
|
|
+{
|
|
|
+ /*
|
|
|
+ * Test relative URIs in graphs.
|
|
|
+ */
|
|
|
+#define ENTRY(a, b) \
|
|
|
+ if (_graph_list (LSUP_STORE_##a) != 0) return -1;
|
|
|
+BACKEND_TBL
|
|
|
+#undef ENTRY
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
static int test_graph_copy()
|
|
|
{
|
|
|
LSUP_Triple **trp = create_triples();
|
|
@@ -892,6 +930,7 @@ int graph_tests()
|
|
|
RUN (test_graph_copy);
|
|
|
RUN (test_graph_txn);
|
|
|
RUN (test_graph_relative);
|
|
|
+ RUN (test_graph_list);
|
|
|
|
|
|
return 0;
|
|
|
}
|