tdb2: allow multiple chain locks.
[ccan] / ccan / tdb2 / test / run-expand-in-transaction.c
1 #include <ccan/tdb2/tdb.c>
2 #include <ccan/tdb2/open.c>
3 #include <ccan/tdb2/free.c>
4 #include <ccan/tdb2/lock.c>
5 #include <ccan/tdb2/io.c>
6 #include <ccan/tdb2/hash.c>
7 #include <ccan/tdb2/check.c>
8 #include <ccan/tdb2/transaction.c>
9 #include <ccan/tap/tap.h>
10 #include "logging.h"
11
12 int main(int argc, char *argv[])
13 {
14         unsigned int i;
15         struct tdb_context *tdb;
16         int flags[] = { TDB_DEFAULT, TDB_NOMMAP,
17                         TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT,
18                         TDB_CONVERT|TDB_NOSYNC,
19                         TDB_NOMMAP|TDB_CONVERT|TDB_NOSYNC };
20         struct tdb_data key = tdb_mkdata("key", 3);
21         struct tdb_data data = tdb_mkdata("data", 4);
22
23         plan_tests(sizeof(flags) / sizeof(flags[0]) * 7 + 1);
24
25         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
26                 size_t size;
27                 tdb = tdb_open("run-expand-in-transaction.tdb", flags[i],
28                                O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
29                 ok1(tdb);
30                 if (!tdb)
31                         continue;
32
33                 size = tdb->file->map_size;
34                 ok1(tdb_transaction_start(tdb) == 0);
35                 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
36                 ok1(tdb->file->map_size > size);
37                 ok1(tdb_transaction_commit(tdb) == 0);
38                 ok1(tdb->file->map_size > size);
39                 ok1(tdb_check(tdb, NULL, NULL) == 0);
40                 tdb_close(tdb);
41         }
42
43         ok1(tap_log_messages == 0);
44         return exit_status();
45 }