test_store_mdb.c 1.4 KB

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