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