run-11-simple-fetch.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <ccan/failtest/failtest_override.h>
  2. #include "ntdb-source.h"
  3. #include "tap-interface.h"
  4. #include <ccan/failtest/failtest.h>
  5. #include "logging.h"
  6. #include "failtest_helper.h"
  7. #include "helprun-external-agent.h"
  8. int main(int argc, char *argv[])
  9. {
  10. unsigned int i;
  11. struct ntdb_context *ntdb;
  12. int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
  13. NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
  14. NTDB_NOMMAP|NTDB_CONVERT };
  15. NTDB_DATA key = ntdb_mkdata("key", 3);
  16. NTDB_DATA data = ntdb_mkdata("data", 4);
  17. failtest_init(argc, argv);
  18. failtest_hook = block_repeat_failures;
  19. failtest_exit_check = exit_check_log;
  20. failtest_suppress = true;
  21. plan_tests(sizeof(flags) / sizeof(flags[0]) * 8 + 1);
  22. for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
  23. ntdb = ntdb_open("run-11-simple-fetch.ntdb",
  24. flags[i]|MAYBE_NOSYNC,
  25. O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
  26. ok1(ntdb);
  27. if (ntdb) {
  28. NTDB_DATA d = { NULL, 0 }; /* Bogus GCC warning */
  29. /* fetch should fail. */
  30. failtest_suppress = false;
  31. if (!ok1(ntdb_fetch(ntdb, key, &d) == NTDB_ERR_NOEXIST))
  32. goto fail;
  33. failtest_suppress = true;
  34. ok1(ntdb_check(ntdb, NULL, NULL) == 0);
  35. /* Insert should succeed. */
  36. ok1(ntdb_store(ntdb, key, data, NTDB_INSERT) == 0);
  37. ok1(ntdb_check(ntdb, NULL, NULL) == 0);
  38. /* Fetch should now work. */
  39. failtest_suppress = false;
  40. if (!ok1(ntdb_fetch(ntdb, key, &d) == NTDB_SUCCESS))
  41. goto fail;
  42. failtest_suppress = true;
  43. ok1(ntdb_deq(d, data));
  44. free(d.dptr);
  45. ok1(ntdb_check(ntdb, NULL, NULL) == 0);
  46. ntdb_close(ntdb);
  47. }
  48. }
  49. ok1(tap_log_messages == 0);
  50. failtest_exit(exit_status());
  51. fail:
  52. failtest_suppress = true;
  53. ntdb_close(ntdb);
  54. failtest_exit(exit_status());
  55. /*
  56. * We will never reach this but the compiler complains if we do not
  57. * return in this function.
  58. */
  59. return EFAULT;
  60. }