123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- #include "test.h"
- #include "graph.h"
- #include "assets/triples.h"
- static int
- test_graph_mem_new ()
- {
- LSUP_Graph *gr;
- gr = LSUP_graph_new (LSUP_STORE_MEM);
- EXPECT_PASS (LSUP_graph_set_uri (gr, "urn:gr:1"));
- EXPECT_STR_EQ (LSUP_graph_uri (gr)->data, "urn:gr:1");
- ASSERT (strcmp (LSUP_graph_uri (gr)->data, "urn:gr:1") == 0, "Graph URI mismatch!");
- EXPECT_INT_EQ (LSUP_graph_size (gr), 0);
- LSUP_graph_free (gr);
- return 0;
- }
- static int
- test_graph_mem_add()
- {
- LSUP_Triple *trp = create_triples();
- LSUP_Graph *gr = LSUP_graph_new (LSUP_STORE_MEM);
- ASSERT (gr != NULL, "Error creating graph!");
- size_t ct;
- LSUP_graph_add_trp (gr, trp, &ct);
- EXPECT_INT_EQ (ct, 8);
- EXPECT_INT_EQ (LSUP_graph_size (gr), 8);
- for (int i = 0; i < sizeof (trp); i++) {
- printf ("checking triple #%d... ", i);
- ASSERT (LSUP_graph_contains (gr, trp + i), "Triple not in graph!");
- printf ("OK.\n");
- }
- LSUP_Triple *missing_trp = LSUP_triple_new (trp[1].s, trp[6].p, trp[4].o);
- ASSERT (! LSUP_graph_contains (gr, missing_trp), "Triple in graph!");
- free (missing_trp);
- free_triples (trp); // gr copied data.
- LSUP_graph_free (gr);
- return 0;
- }
- static int
- test_graph_mdb_new ()
- {
- LSUP_Graph *gr;
- gr = LSUP_graph_new (LSUP_STORE_MDB);
- ASSERT (gr != NULL, "Error creating graph!");
- EXPECT_PASS (LSUP_graph_set_uri (gr, "urn:gr:1"));
- EXPECT_STR_EQ (LSUP_graph_uri (gr)->data, "urn:gr:1");
- ASSERT (
- strcmp (LSUP_graph_uri (gr)->data, "urn:gr:1") == 0,
- "Graph URI mismatch!");
- EXPECT_INT_EQ (LSUP_graph_size (gr), 0);
- LSUP_graph_free (gr);
- return 0;
- }
- static int
- test_graph_mdb_add()
- {
- LSUP_Triple *trp = create_triples();
- LSUP_Graph *gr = LSUP_graph_new (LSUP_STORE_MDB);
- ASSERT (gr != NULL, "Error creating graph!");
- size_t ct;
- LSUP_graph_add_trp (gr, trp, &ct);
- EXPECT_INT_EQ (ct, 8);
- EXPECT_INT_EQ (LSUP_graph_size (gr), 8);
- for (int i = 0; i < sizeof (trp); i++) {
- printf ("checking triple #%d... ", i);
- ASSERT (LSUP_graph_contains (gr, trp + i), "Triple not in graph!");
- printf ("OK.\n");
- }
- LSUP_Triple *missing_trp = LSUP_triple_new (trp[1].s, trp[6].p, trp[4].o);
- ASSERT (! LSUP_graph_contains (gr, missing_trp), "Triple in graph!");
- free (missing_trp);
- free_triples (trp); // gr copied data.
- LSUP_graph_free (gr);
- return 0;
- }
- int graph_tests()
- {
- RUN (test_graph_mem_new);
- RUN (test_graph_mem_add);
- RUN (test_graph_mdb_new);
- RUN (test_graph_mdb_add);
- return 0;
- }
|