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