run-10-simple-store.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include <ccan/failtest/failtest_override.h>
  2. #include "tdb2-source.h"
  3. #include <ccan/tap/tap.h>
  4. #include <ccan/failtest/failtest.h>
  5. #include "logging.h"
  6. #include "failtest_helper.h"
  7. static bool failtest_suppress = false;
  8. /* Don't need to test everything here, just want expand testing. */
  9. static enum failtest_result
  10. suppress_failure(struct failtest_call *history, unsigned num)
  11. {
  12. if (failtest_suppress)
  13. return FAIL_DONT_FAIL;
  14. return block_repeat_failures(history, num);
  15. }
  16. int main(int argc, char *argv[])
  17. {
  18. unsigned int i;
  19. struct tdb_context *tdb;
  20. int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
  21. TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
  22. TDB_NOMMAP|TDB_CONVERT,
  23. TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
  24. TDB_NOMMAP|TDB_VERSION1,
  25. TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
  26. TDB_CONVERT|TDB_VERSION1,
  27. TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
  28. struct tdb_data key = tdb_mkdata("key", 3);
  29. struct tdb_data data = tdb_mkdata("data", 4);
  30. failtest_init(argc, argv);
  31. failtest_hook = suppress_failure;
  32. failtest_exit_check = exit_check_log;
  33. failtest_suppress = true;
  34. plan_tests(sizeof(flags) / sizeof(flags[0]) * 7 + 1);
  35. for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
  36. tdb = tdb_open("run-10-simple-store.tdb", flags[i],
  37. O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
  38. if (!ok1(tdb))
  39. break;
  40. /* Modify should fail. */
  41. failtest_suppress = false;
  42. if (!ok1(tdb_store(tdb, key, data, TDB_MODIFY)
  43. == TDB_ERR_NOEXIST))
  44. goto fail;
  45. failtest_suppress = true;
  46. ok1(tdb_check(tdb, NULL, NULL) == 0);
  47. /* Insert should succeed. */
  48. failtest_suppress = false;
  49. if (!ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0))
  50. goto fail;
  51. failtest_suppress = true;
  52. ok1(tdb_check(tdb, NULL, NULL) == 0);
  53. /* Second insert should fail. */
  54. failtest_suppress = false;
  55. if (!ok1(tdb_store(tdb, key, data, TDB_INSERT)
  56. == TDB_ERR_EXISTS))
  57. goto fail;
  58. failtest_suppress = true;
  59. ok1(tdb_check(tdb, NULL, NULL) == 0);
  60. tdb_close(tdb);
  61. }
  62. ok1(tap_log_messages == 0);
  63. failtest_exit(exit_status());
  64. fail:
  65. failtest_suppress = true;
  66. tdb_close(tdb);
  67. failtest_exit(exit_status());
  68. }