test_graph.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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_mem_add()
  18. {
  19. LSUP_Triple *trp = create_triples();
  20. LSUP_Graph *gr = LSUP_graph_new (LSUP_STORE_MEM);
  21. ASSERT (gr != NULL, "Error creating graph!");
  22. size_t ct;
  23. LSUP_graph_add_trp (gr, trp, &ct);
  24. EXPECT_INT_EQ (ct, 8);
  25. EXPECT_INT_EQ (LSUP_graph_size (gr), 8);
  26. for (int i = 0; i < sizeof (trp); i++) {
  27. printf ("checking triple #%d... ", i);
  28. ASSERT (LSUP_graph_contains (gr, trp + i), "Triple not in graph!");
  29. printf ("OK.\n");
  30. }
  31. free_triples (trp); // gr copied data.
  32. LSUP_graph_free (gr);
  33. return 0;
  34. }
  35. static int
  36. test_graph_mdb_new ()
  37. {
  38. LSUP_Graph *gr;
  39. gr = LSUP_graph_new (LSUP_STORE_MDB);
  40. ASSERT (gr != NULL, "Error creating graph!");
  41. EXPECT_PASS (LSUP_graph_set_uri (gr, "urn:gr:1"));
  42. EXPECT_STR_EQ (LSUP_graph_uri (gr)->data, "urn:gr:1");
  43. ASSERT (
  44. strcmp (LSUP_graph_uri (gr)->data, "urn:gr:1") == 0,
  45. "Graph URI mismatch!");
  46. EXPECT_INT_EQ (LSUP_graph_size (gr), 0);
  47. LSUP_graph_free (gr);
  48. return 0;
  49. }
  50. static int
  51. test_graph_mdb_add()
  52. {
  53. LSUP_Triple *trp = create_triples();
  54. LSUP_Graph *gr = LSUP_graph_new (LSUP_STORE_MDB);
  55. ASSERT (gr != NULL, "Error creating graph!");
  56. size_t ct;
  57. LSUP_graph_add_trp (gr, trp, &ct);
  58. EXPECT_INT_EQ (ct, 8);
  59. EXPECT_INT_EQ (LSUP_graph_size (gr), 8);
  60. for (int i = 0; i < sizeof (trp); i++) {
  61. printf ("checking triple #%d... ", i);
  62. ASSERT (LSUP_graph_contains (gr, trp + i), "Triple not in graph!");
  63. printf ("OK.\n");
  64. }
  65. free_triples (trp); // gr copied data.
  66. LSUP_graph_free (gr);
  67. return 0;
  68. }
  69. int graph_tests()
  70. {
  71. RUN (test_graph_mem_new);
  72. RUN (test_graph_mem_add);
  73. RUN (test_graph_mdb_new);
  74. RUN (test_graph_mdb_add);
  75. return 0;
  76. }