]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/test/run-expand.c
ef2955cba9713593d0c13e87fe05a36430e544fe
[ccan] / ccan / tdb2 / test / run-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/tap/tap.h>
7 #include "logging.h"
8
9 int main(int argc, char *argv[])
10 {
11         unsigned int i;
12         struct tdb_context *tdb;
13         int flags[] = { TDB_INTERNAL, TDB_DEFAULT,
14                         TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT };
15
16         plan_tests(sizeof(flags) / sizeof(flags[0]) * 10 + 1);
17         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
18                 tdb = tdb_open("/tmp/run-new_database.tdb", flags[i],
19                                O_RDWR|O_CREAT|O_TRUNC, 0600, NULL);
20                 tdb->log = tap_log_fn;
21                 ok1(tdb);
22                 if (tdb) {
23                         /* First expand (expand file to fill zone). */
24                         ok1(tdb_expand(tdb, 1, 1, false) == 0);
25                         ok1(tdb->header.v.num_zones == 1);
26                         ok1(tdb_check(tdb, NULL, NULL) == 0);
27                         /* Little expand (extra zone). */
28                         ok1(tdb_expand(tdb, 1, 1, false) == 0);
29                         ok1(tdb->header.v.num_zones == 2);
30                         ok1(tdb_check(tdb, NULL, NULL) == 0);
31                         /* Big expand (enlarge zones) */
32                         ok1(tdb_expand(tdb, 1, 4096, false) == 0);
33                         ok1(tdb->header.v.num_zones == 2);
34                         ok1(tdb_check(tdb, NULL, NULL) == 0);
35                         tdb_close(tdb);
36                 }
37         }
38         ok1(tap_log_messages == 0);
39         return exit_status();
40 }