test_graph.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #include "test.h"
  2. #include "graph.h"
  3. #include "assets/triples.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. LSUP_Triple *missing_trp = LSUP_triple_new (trp[1].s, trp[6].p, trp[4].o);
  32. ASSERT (! LSUP_graph_contains (gr, missing_trp), "Triple in graph!");
  33. free (missing_trp);
  34. free_triples (trp); // gr copied data.
  35. LSUP_graph_free (gr);
  36. return 0;
  37. }
  38. static int
  39. test_graph_mdb_new ()
  40. {
  41. LSUP_Graph *gr;
  42. gr = LSUP_graph_new (LSUP_STORE_MDB);
  43. ASSERT (gr != NULL, "Error creating graph!");
  44. EXPECT_PASS (LSUP_graph_set_uri (gr, "urn:gr:1"));
  45. EXPECT_STR_EQ (LSUP_graph_uri (gr)->data, "urn:gr:1");
  46. ASSERT (
  47. strcmp (LSUP_graph_uri (gr)->data, "urn:gr:1") == 0,
  48. "Graph URI mismatch!");
  49. EXPECT_INT_EQ (LSUP_graph_size (gr), 0);
  50. LSUP_graph_free (gr);
  51. return 0;
  52. }
  53. static int
  54. test_graph_mdb_add()
  55. {
  56. LSUP_Triple *trp = create_triples();
  57. LSUP_Graph *gr = LSUP_graph_new (LSUP_STORE_MDB);
  58. ASSERT (gr != NULL, "Error creating graph!");
  59. size_t ct;
  60. LSUP_graph_add_trp (gr, trp, &ct);
  61. EXPECT_INT_EQ (ct, 8);
  62. EXPECT_INT_EQ (LSUP_graph_size (gr), 8);
  63. for (int i = 0; i < sizeof (trp); i++) {
  64. printf ("checking triple #%d... ", i);
  65. ASSERT (LSUP_graph_contains (gr, trp + i), "Triple not in graph!");
  66. printf ("OK.\n");
  67. }
  68. LSUP_Triple *missing_trp = LSUP_triple_new (trp[1].s, trp[6].p, trp[4].o);
  69. ASSERT (! LSUP_graph_contains (gr, missing_trp), "Triple in graph!");
  70. free (missing_trp);
  71. free_triples (trp); // gr copied data.
  72. LSUP_graph_free (gr);
  73. return 0;
  74. }
  75. int graph_tests()
  76. {
  77. RUN (test_graph_mem_new);
  78. RUN (test_graph_mem_add);
  79. RUN (test_graph_mdb_new);
  80. RUN (test_graph_mdb_add);
  81. return 0;
  82. }