tdb2: make tests include a single mega-header to simplify future patches
[ccan] / ccan / tdb2 / test / run-simple-delete.c
1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
3 #include "logging.h"
4
5 int main(int argc, char *argv[])
6 {
7         unsigned int i;
8         struct tdb_context *tdb;
9         int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
10                         TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, 
11                         TDB_NOMMAP|TDB_CONVERT };
12         struct tdb_data key = tdb_mkdata("key", 3);
13         struct tdb_data data = tdb_mkdata("data", 4);
14
15         plan_tests(sizeof(flags) / sizeof(flags[0]) * 7 + 1);
16         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
17                 tdb = tdb_open("run-simple-delete.tdb", flags[i],
18                                O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
19                 ok1(tdb);
20                 if (tdb) {
21                         /* Delete should fail. */
22                         ok1(tdb_delete(tdb, key) == TDB_ERR_NOEXIST);
23                         ok1(tdb_check(tdb, NULL, NULL) == 0);
24                         /* Insert should succeed. */
25                         ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
26                         ok1(tdb_check(tdb, NULL, NULL) == 0);
27                         /* Delete should now work. */
28                         ok1(tdb_delete(tdb, key) == 0);
29                         ok1(tdb_check(tdb, NULL, NULL) == 0);
30                         tdb_close(tdb);
31                 }
32         }
33         ok1(tap_log_messages == 0);
34         return exit_status();
35 }