test_graph.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. EXPECT_PASS (LSUP_graph_resize (gr, 10));
  13. EXPECT_INT_EQ (LSUP_graph_capacity (gr), 10);
  14. ASSERT (strcmp (LSUP_graph_uri (gr)->data, "urn:gr:1") == 0, "Graph URI mismatch!");
  15. EXPECT_INT_EQ (LSUP_graph_size (gr), 0);
  16. LSUP_graph_free (gr);
  17. return 0;
  18. }
  19. static int
  20. test_graph_mdb_new ()
  21. {
  22. LSUP_Graph *gr;
  23. gr = LSUP_graph_new (LSUP_STORE_MDB);
  24. ASSERT (gr != NULL, "Error creating graph!");
  25. EXPECT_PASS (LSUP_graph_set_uri (gr, "urn:gr:1"));
  26. EXPECT_STR_EQ (LSUP_graph_uri (gr)->data, "urn:gr:1");
  27. ASSERT (strcmp (LSUP_graph_uri (gr)->data, "urn:gr:1") == 0, "Graph URI mismatch!");
  28. EXPECT_INT_EQ (LSUP_graph_size (gr), 0);
  29. LSUP_graph_free (gr);
  30. return 0;
  31. }
  32. static int
  33. test_graph_mdb_add()
  34. {
  35. LSUP_Triple *trp = create_triples();
  36. LSUP_Graph *gr = LSUP_graph_new (LSUP_STORE_MDB);
  37. size_t ct;
  38. LSUP_graph_add_trp (gr, trp, NUM_TRP, &ct);
  39. for (int i = 0; i < sizeof (trp); i++) {
  40. printf ("checking triple #%d... ", i);
  41. ASSERT (LSUP_graph_contains (gr, trp + i), "Triple not in graph!");
  42. printf ("OK.\n");
  43. }
  44. free_triples (trp); // gr copied data.
  45. EXPECT_INT_EQ (LSUP_graph_size (gr), 8);
  46. LSUP_graph_free (gr);
  47. return 0;
  48. }
  49. int graph_tests()
  50. {
  51. RUN (test_graph_mdb_new);
  52. RUN (test_graph_mdb_add);
  53. return 0;
  54. }