06e06ac9bb56d81cb4b4d1ad725f401117ae698c
[ccan] / ccan / tdb2 / test / run-02-expand.c
1 #include <ccan/tdb2/tdb.c>
2 #include <ccan/tdb2/free.c>
3 #include <ccan/tdb2/lock.c>
4 #include <ccan/tdb2/io.c>
5 #include <ccan/tdb2/check.c>
6 #include <ccan/tdb2/transaction.c>
7 #include <ccan/tdb2/hash.c>
8 #include <ccan/tap/tap.h>
9 #include "logging.h"
10
11 int main(int argc, char *argv[])
12 {
13         unsigned int i;
14         uint64_t val;
15         struct tdb_context *tdb;
16         int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
17                         TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
18                         TDB_NOMMAP|TDB_CONVERT };
19
20         plan_tests(sizeof(flags) / sizeof(flags[0]) * 7 + 1);
21
22         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
23                 tdb = tdb_open("run-expand.tdb", flags[i],
24                                O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
25                 ok1(tdb);
26                 if (!tdb)
27                         continue;
28
29                 val = tdb->map_size;
30                 ok1(tdb_expand(tdb, 1) == 0);
31                 ok1(tdb->map_size >= val + 1 * TDB_EXTENSION_FACTOR);
32                 ok1(tdb_check(tdb, NULL, NULL) == 0);
33
34                 val = tdb->map_size;
35                 ok1(tdb_expand(tdb, 1024) == 0);
36                 ok1(tdb->map_size >= val + 1024 * TDB_EXTENSION_FACTOR);
37                 ok1(tdb_check(tdb, NULL, NULL) == 0);
38                 tdb_close(tdb);
39         }
40
41         ok1(tap_log_messages == 0);
42         return exit_status();
43 }