]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/test/run-record-expand.c
tdb2: test: try (almost) all tests with TDB_VERSION1 flag.
[ccan] / ccan / tdb2 / test / run-record-expand.c
1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
3 #include "logging.h"
4
5 #define MAX_SIZE 10000
6 #define SIZE_STEP 131
7
8 int main(int argc, char *argv[])
9 {
10         unsigned int i;
11         struct tdb_context *tdb;
12         int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
13                         TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, 
14                         TDB_NOMMAP|TDB_CONVERT,
15                         TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
16                         TDB_NOMMAP|TDB_VERSION1,
17                         TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
18                         TDB_CONVERT|TDB_VERSION1,
19                         TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
20         struct tdb_data key = tdb_mkdata("key", 3);
21         struct tdb_data data;
22
23         data.dptr = malloc(MAX_SIZE);
24         memset(data.dptr, 0x24, MAX_SIZE);
25
26         plan_tests(sizeof(flags) / sizeof(flags[0])
27                    * (3 + (1 + (MAX_SIZE/SIZE_STEP)) * 2) + 1);
28         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
29                 tdb = tdb_open("run-record-expand.tdb", flags[i],
30                                O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
31                 ok1(tdb);
32                 if (!tdb)
33                         continue;
34
35                 data.dsize = 0;
36                 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
37                 ok1(tdb_check(tdb, NULL, NULL) == 0);
38                 for (data.dsize = 0;
39                      data.dsize < MAX_SIZE;
40                      data.dsize += SIZE_STEP) {
41                         memset(data.dptr, data.dsize, data.dsize);
42                         ok1(tdb_store(tdb, key, data, TDB_MODIFY) == 0);
43                         ok1(tdb_check(tdb, NULL, NULL) == 0);
44                 }
45                 tdb_close(tdb);
46         }
47         ok1(tap_log_messages == 0);
48         free(data.dptr);
49
50         return exit_status();
51 }