|
@@ -50,7 +50,7 @@ _graph_add (LSUP_StoreType type)
|
|
|
LSUP_Graph *gr;
|
|
|
LSUP_Store *store;
|
|
|
|
|
|
- if (type = LSUP_STORE_HTABLE) store = NULL;
|
|
|
+ if (type == LSUP_STORE_HTABLE) store = NULL;
|
|
|
else store = LSUP_store_new (type, NULL, 0);
|
|
|
|
|
|
gr = LSUP_graph_new (store, NULL, NULL);
|
|
@@ -123,6 +123,8 @@ _graph_get (LSUP_StoreType type)
|
|
|
}
|
|
|
LSUP_graph_add_done (it2);
|
|
|
|
|
|
+ free_triples (trp);
|
|
|
+
|
|
|
EXPECT_INT_EQ (LSUP_graph_size (gr1), 5);
|
|
|
EXPECT_INT_EQ (LSUP_graph_size (gr2), 3);
|
|
|
|
|
@@ -143,13 +145,118 @@ _graph_get (LSUP_StoreType type)
|
|
|
LSUP_graph_free (gr2);
|
|
|
LSUP_graph_free (gr3);
|
|
|
LSUP_graph_free (gr4);
|
|
|
- free_triples (trp);
|
|
|
if (type != LSUP_STORE_HTABLE) LSUP_store_free (store);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
+static int
|
|
|
+_graph_link_map (LSUP_StoreType type)
|
|
|
+{
|
|
|
+ const LSUP_StoreInt *sif = LSUP_store_int (type);
|
|
|
+
|
|
|
+ if (sif->setup_fn) sif->setup_fn (NULL, true);
|
|
|
+
|
|
|
+ LSUP_Triple **trp = create_triples();
|
|
|
+
|
|
|
+ LSUP_Store *store = LSUP_store_new (type, NULL, 0);
|
|
|
+ LSUP_Graph *gr = LSUP_graph_new (store, NULL, NULL);
|
|
|
+
|
|
|
+ size_t ct;
|
|
|
+ LSUP_graph_add (gr, trp, &ct);
|
|
|
+
|
|
|
+ LSUP_LinkMap *lmap;
|
|
|
+ LSUP_LinkMapIterator *lmit ;
|
|
|
+ //LSUP_Term *k = NULL;
|
|
|
+ LSUP_TermSet *ts = NULL; // Term set being iterated in link map loop.
|
|
|
+ LSUP_Term *k_res[9] = {NULL}; // Collected keys.
|
|
|
+ LSUP_Term *ts_res[9] = {NULL}; // Collected terms in term set in loop.
|
|
|
+ size_t i = 0, j = 0;
|
|
|
+
|
|
|
+ LSUP_Term *po[6][4] = {
|
|
|
+ {trp[0]->p, trp[0]->o, NULL},
|
|
|
+ {trp[3]->p, trp[3]->o, NULL},
|
|
|
+ {trp[4]->p, trp[4]->o, trp[7]->o, NULL},
|
|
|
+ {trp[5]->p, trp[5]->o, NULL},
|
|
|
+ {NULL}
|
|
|
+ };
|
|
|
+
|
|
|
+ // terms connected to subject, urn:s:0
|
|
|
+ lmap = LSUP_graph_connections (gr, trp[0]->s, LSUP_LINK_OUTBOUND);
|
|
|
+ lmit = LSUP_link_map_iter_new (lmap);
|
|
|
+ while (LSUP_link_map_next (lmit, k_res + i, &ts) == LSUP_OK) {
|
|
|
+ while (LSUP_term_set_next (ts, &j, ts_res + j) == LSUP_OK);
|
|
|
+ /*
|
|
|
+ // TODO test exact terms. This requires a cross-check.
|
|
|
+ ASSERT (
|
|
|
+ LSUP_term_equals (k_res[i], po[i][0]),
|
|
|
+ "Wrong term in link map!");
|
|
|
+ for (size_t k = 1; po[i][k]; k++)
|
|
|
+ ASSERT (
|
|
|
+ LSUP_term_equals (ts_res[k - 1], po[i][k]),
|
|
|
+ "Wrong term in term set!");
|
|
|
+ */
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ EXPECT_INT_EQ (i, 4);
|
|
|
+
|
|
|
+ i = 0; j = 0;
|
|
|
+ memset (k_res, 0, sizeof (k_res));
|
|
|
+ memset (ts_res, 0, sizeof (ts_res));
|
|
|
+ LSUP_Term *so[3][3] = {
|
|
|
+ {trp[1]->s, trp[1]->o, NULL},
|
|
|
+ {trp[3]->s, trp[3]->o, NULL},
|
|
|
+ };
|
|
|
+ // terms connected to predicate, urn:p:1
|
|
|
+ lmap = LSUP_graph_connections (gr, trp[1]->p, LSUP_LINK_EDGE);
|
|
|
+ lmit = LSUP_link_map_iter_new (lmap);
|
|
|
+ while (LSUP_link_map_next (lmit, k_res + i, &ts) == LSUP_OK) {
|
|
|
+ while (LSUP_term_set_next (ts, &j, ts_res + j) == LSUP_OK);
|
|
|
+ /*
|
|
|
+ ASSERT (
|
|
|
+ LSUP_term_equals (k_res[i], so[i][0]),
|
|
|
+ "Wrong term in link map!");
|
|
|
+ for (size_t k = 1; so[i][k]; k++)
|
|
|
+ ASSERT (
|
|
|
+ LSUP_term_equals (ts_res[k - 1], so[i][k]),
|
|
|
+ "Wrong term in term set!");
|
|
|
+ */
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ EXPECT_INT_EQ (i, 2);
|
|
|
+
|
|
|
+ i = 0; j = 0;
|
|
|
+ memset (k_res, 0, sizeof (k_res));
|
|
|
+ memset (ts_res, 0, sizeof (ts_res));
|
|
|
+ LSUP_Term *sp[1][3] = {
|
|
|
+ {trp[6]->s, trp[6]->p, NULL},
|
|
|
+ };
|
|
|
+ // terms connected to object, "String 1"@es-ES
|
|
|
+ lmap = LSUP_graph_connections (gr, trp[6]->o, LSUP_LINK_INBOUND);
|
|
|
+ lmit = LSUP_link_map_iter_new (lmap);
|
|
|
+ while (LSUP_link_map_next (lmit, k_res + i, &ts) == LSUP_OK) {
|
|
|
+ while (LSUP_term_set_next (ts, &j, ts_res + j) == LSUP_OK);
|
|
|
+ /*
|
|
|
+ ASSERT (
|
|
|
+ LSUP_term_equals (k_res[i], sp[i][0]),
|
|
|
+ "Wrong term in link map!");
|
|
|
+ for (size_t k = 1; sp[i][k]; k++)
|
|
|
+ ASSERT (
|
|
|
+ LSUP_term_equals (ts_res[k - 1], sp[i][k]),
|
|
|
+ "Wrong term in term set!");
|
|
|
+ */
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ EXPECT_INT_EQ (i, 1);
|
|
|
+
|
|
|
+ free_triples (trp);
|
|
|
+ LSUP_graph_free (gr);
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
static int
|
|
|
_graph_bool_ops (LSUP_StoreType type)
|
|
|
{
|
|
@@ -578,6 +685,16 @@ BACKEND_TBL
|
|
|
}
|
|
|
|
|
|
|
|
|
+static int test_graph_link_map() {
|
|
|
+#define ENTRY(a, b) \
|
|
|
+ if (_graph_link_map (LSUP_STORE_##a) != 0) return -1;
|
|
|
+BACKEND_TBL
|
|
|
+#undef ENTRY
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
static int test_graph_bool_ops() {
|
|
|
#define ENTRY(a, b) \
|
|
|
if (_graph_bool_ops (LSUP_STORE_##a) != 0) return -1;
|
|
@@ -684,6 +801,7 @@ int graph_tests()
|
|
|
RUN (test_graph_new);
|
|
|
RUN (test_graph_add);
|
|
|
RUN (test_graph_get);
|
|
|
+ RUN (test_graph_link_map);
|
|
|
RUN (test_graph_bool_ops);
|
|
|
RUN (test_graph_lookup);
|
|
|
RUN (test_graph_remove);
|