tdb2: move open routines into a separate file (open.c)
[ccan] / ccan / tdb2 / test / run-record-expand.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 #define MAX_SIZE 10000
13 #define SIZE_STEP 131
14
15 int main(int argc, char *argv[])
16 {
17         unsigned int i;
18         struct tdb_context *tdb;
19         int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
20                         TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, 
21                         TDB_NOMMAP|TDB_CONVERT };
22         struct tdb_data key = { (unsigned char *)"key", 3 };
23         struct tdb_data data;
24
25         data.dptr = malloc(MAX_SIZE);
26         memset(data.dptr, 0x24, MAX_SIZE);
27
28         plan_tests(sizeof(flags) / sizeof(flags[0])
29                    * (3 + (1 + (MAX_SIZE/SIZE_STEP)) * 2) + 1);
30         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
31                 tdb = tdb_open("run-record-expand.tdb", flags[i],
32                                O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
33                 ok1(tdb);
34                 if (!tdb)
35                         continue;
36
37                 data.dsize = 0;
38                 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
39                 ok1(tdb_check(tdb, NULL, NULL) == 0);
40                 for (data.dsize = 0;
41                      data.dsize < MAX_SIZE;
42                      data.dsize += SIZE_STEP) {
43                         memset(data.dptr, data.dsize, data.dsize);
44                         ok1(tdb_store(tdb, key, data, TDB_MODIFY) == 0);
45                         ok1(tdb_check(tdb, NULL, NULL) == 0);
46                 }
47                 tdb_close(tdb);
48         }
49         ok1(tap_log_messages == 0);
50         free(data.dptr);
51
52         return exit_status();
53 }