tdb2: change to using a hash tree.
[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/tap/tap.h>
8 #include "logging.h"
9
10 #define MAX_SIZE 10000
11 #define SIZE_STEP 131
12
13 int main(int argc, char *argv[])
14 {
15         unsigned int i;
16         struct tdb_context *tdb;
17         int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
18                         TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, 
19                         TDB_NOMMAP|TDB_CONVERT };
20         struct tdb_data key = { (unsigned char *)"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         return exit_status();
49 }