]> git.ozlabs.org Git - ccan/blob - ccan/ntdb/test/api-simple-delete.c
ntdb: fix up tests.
[ccan] / ccan / ntdb / test / api-simple-delete.c
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
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
18         plan_tests(sizeof(flags) / sizeof(flags[0]) * 7 + 1);
19         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
20                 ntdb = ntdb_open("run-simple-delete.ntdb",
21                                  flags[i]|MAYBE_NOSYNC,
22                                  O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
23                 ok1(ntdb);
24                 if (ntdb) {
25                         /* Delete should fail. */
26                         ok1(ntdb_delete(ntdb, key) == NTDB_ERR_NOEXIST);
27                         ok1(ntdb_check(ntdb, NULL, NULL) == 0);
28                         /* Insert should succeed. */
29                         ok1(ntdb_store(ntdb, key, data, NTDB_INSERT) == 0);
30                         ok1(ntdb_check(ntdb, NULL, NULL) == 0);
31                         /* Delete should now work. */
32                         ok1(ntdb_delete(ntdb, key) == 0);
33                         ok1(ntdb_check(ntdb, NULL, NULL) == 0);
34                         ntdb_close(ntdb);
35                 }
36         }
37         ok1(tap_log_messages == 0);
38         return exit_status();
39 }