test_store_mdb.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "test.h"
  4. #include "store_mdb.h"
  5. #include "assets.h"
  6. static char *path = "/tmp/testdb";
  7. static void rmdb() {
  8. char data_path[32], lock_path[32];
  9. sprintf(data_path, "%s/data.mdb", path);
  10. sprintf(lock_path, "%s/lock.mdb", path);
  11. printf("Removing %s\n", data_path);
  12. remove(data_path);
  13. printf("Removing %s\n", lock_path);
  14. remove(lock_path);
  15. remove(path);
  16. }
  17. /** @brief Test triple store.
  18. */
  19. static int test_triple_store()
  20. {
  21. rmdb();
  22. EXPECT_PASS(LSUP_store_setup(&path));
  23. LSUP_MDBStore *store;
  24. store = LSUP_store_new(path, NULL); // triple store.
  25. ASSERT(store != NULL, "Error initializing store!");
  26. LSUP_Triple *trp = create_triples();
  27. LSUP_SerTerm sterms[NUM_TRP][3];
  28. LSUP_SerTriple ser_trp[NUM_TRP];
  29. for (int i = 0; i < NUM_TRP; i++) {
  30. ser_trp[i].s = sterms[i];
  31. ser_trp[i].p = sterms[i] + 1;
  32. ser_trp[i].o = sterms[i] + 2;
  33. for (int j = 0; j < 3; j++) {
  34. LSUP_term_serialize(
  35. LSUP_triple_term_by_pos(trp + i, j),
  36. LSUP_ser_triple_term_by_pos(ser_trp + i, j));
  37. }
  38. }
  39. EXPECT_PASS(LSUP_store_add(store, NULL, ser_trp, NUM_TRP));
  40. for (int i = 0; i < NUM_TRP; i++) {
  41. LSUP_buffer_done(ser_trp[i].s);
  42. LSUP_buffer_done(ser_trp[i].p);
  43. LSUP_buffer_done(ser_trp[i].o);
  44. }
  45. LSUP_store_free(store);
  46. free_triples(trp);
  47. return 0;
  48. }
  49. static int test_quad_store()
  50. {
  51. return 0;
  52. }
  53. int store_mdb_test()
  54. {
  55. RUN(test_triple_store);
  56. RUN(test_quad_store);
  57. return 0;
  58. }