api-simple-delete.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "config.h"
  2. #include "../ntdb.h"
  3. #include "../private.h"
  4. #include "tap-interface.h"
  5. #include "logging.h"
  6. #include "helpapi-external-agent.h"
  7. int main(int argc, char *argv[])
  8. {
  9. unsigned int i;
  10. struct ntdb_context *ntdb;
  11. int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
  12. NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
  13. NTDB_NOMMAP|NTDB_CONVERT };
  14. NTDB_DATA key = ntdb_mkdata("key", 3);
  15. NTDB_DATA data = ntdb_mkdata("data", 4);
  16. plan_tests(sizeof(flags) / sizeof(flags[0]) * 7 + 1);
  17. for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
  18. ntdb = ntdb_open("run-simple-delete.ntdb",
  19. flags[i]|MAYBE_NOSYNC,
  20. O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
  21. ok1(ntdb);
  22. if (ntdb) {
  23. /* Delete should fail. */
  24. ok1(ntdb_delete(ntdb, key) == NTDB_ERR_NOEXIST);
  25. ok1(ntdb_check(ntdb, NULL, NULL) == 0);
  26. /* Insert should succeed. */
  27. ok1(ntdb_store(ntdb, key, data, NTDB_INSERT) == 0);
  28. ok1(ntdb_check(ntdb, NULL, NULL) == 0);
  29. /* Delete should now work. */
  30. ok1(ntdb_delete(ntdb, key) == 0);
  31. ok1(ntdb_check(ntdb, NULL, NULL) == 0);
  32. ntdb_close(ntdb);
  33. }
  34. }
  35. ok1(tap_log_messages == 0);
  36. return exit_status();
  37. }