tdb2: tdb_append implemented, beef up tests.
[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, TDB_NOMMAP,
17                         TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, 
18                         TDB_NOMMAP|TDB_CONVERT };
19         struct tdb_data key = { (unsigned char *)"key", 3 };
20         struct tdb_data data;
21
22         data.dptr = malloc(MAX_SIZE);
23         memset(data.dptr, 0x24, MAX_SIZE);
24
25         plan_tests(sizeof(flags) / sizeof(flags[0])
26                    * (3 + (1 + (MAX_SIZE/SIZE_STEP)) * 2) + 1);
27         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
28                 tdb = tdb_open("run-record-expand.tdb", flags[i],
29                                O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
30                 ok1(tdb);
31                 if (!tdb)
32                         continue;
33
34                 data.dsize = 0;
35                 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
36                 ok1(tdb_check(tdb, NULL, NULL) == 0);
37                 for (data.dsize = 0;
38                      data.dsize < MAX_SIZE;
39                      data.dsize += SIZE_STEP) {
40                         memset(data.dptr, data.dsize, data.dsize);
41                         ok1(tdb_store(tdb, key, data, TDB_MODIFY) == 0);
42                         ok1(tdb_check(tdb, NULL, NULL) == 0);
43                 }
44                 tdb_close(tdb);
45         }
46         ok1(tap_log_messages == 0);
47         return exit_status();
48 }