test_graph.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "test.h"
  2. #include "graph.h"
  3. #include "assets.h"
  4. /* TODO Not yet implemented. */
  5. static int __attribute__ ((unused))
  6. test_graph_mem_new ()
  7. {
  8. LSUP_Graph *gr;
  9. gr = LSUP_graph_new (LSUP_STORE_MEM);
  10. EXPECT_PASS (LSUP_graph_set_uri (gr, "urn:gr:1"));
  11. EXPECT_STR_EQ (LSUP_graph_uri (gr)->data, "urn:gr:1");
  12. ASSERT (strcmp (LSUP_graph_uri (gr)->data, "urn:gr:1") == 0, "Graph URI mismatch!");
  13. EXPECT_INT_EQ (LSUP_graph_size (gr), 0);
  14. LSUP_graph_free (gr);
  15. return 0;
  16. }
  17. static int
  18. test_graph_mdb_new ()
  19. {
  20. LSUP_Graph *gr;
  21. gr = LSUP_graph_new (LSUP_STORE_MDB);
  22. ASSERT (gr != NULL, "Error creating graph!");
  23. EXPECT_PASS (LSUP_graph_set_uri (gr, "urn:gr:1"));
  24. EXPECT_STR_EQ (LSUP_graph_uri (gr)->data, "urn:gr:1");
  25. ASSERT (strcmp (LSUP_graph_uri (gr)->data, "urn:gr:1") == 0, "Graph URI mismatch!");
  26. EXPECT_INT_EQ (LSUP_graph_size (gr), 0);
  27. LSUP_graph_free (gr);
  28. return 0;
  29. }
  30. static int
  31. test_graph_mdb_add()
  32. {
  33. LSUP_Triple *trp = create_triples();
  34. LSUP_Graph *gr = LSUP_graph_new (LSUP_STORE_MDB);
  35. size_t ct;
  36. LSUP_graph_add_trp (gr, trp, NUM_TRP, &ct);
  37. for (int i = 0; i < sizeof (trp); i++) {
  38. printf ("checking triple #%d... ", i);
  39. ASSERT (LSUP_graph_contains (gr, trp + i), "Triple not in graph!");
  40. printf ("OK.\n");
  41. }
  42. free_triples (trp); // gr copied data.
  43. EXPECT_INT_EQ (LSUP_graph_size (gr), 8);
  44. LSUP_graph_free (gr);
  45. return 0;
  46. }
  47. int graph_tests()
  48. {
  49. RUN (test_graph_mdb_new);
  50. RUN (test_graph_mdb_add);
  51. return 0;
  52. }