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