test_graph.c 1.5 KB

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