strsplit: remove nump argument
[ccan] / ccan / tdb / test / run-check.c
1 #define _XOPEN_SOURCE 500
2 #include <ccan/tdb/tdb.h>
3 #include <ccan/tdb/io.c>
4 #include <ccan/tdb/tdb.c>
5 #include <ccan/tdb/lock.c>
6 #include <ccan/tdb/freelist.c>
7 #include <ccan/tdb/traverse.c>
8 #include <ccan/tdb/transaction.c>
9 #include <ccan/tdb/error.c>
10 #include <ccan/tdb/open.c>
11 #include <ccan/tdb/check.c>
12 #include <ccan/tdb/hash.c>
13 #include <ccan/tap/tap.h>
14 #include <stdlib.h>
15 #include <err.h>
16 #include "logging.h"
17
18 int main(int argc, char *argv[])
19 {
20         struct tdb_context *tdb;
21         TDB_DATA key, data;
22
23         plan_tests(13);
24         tdb = tdb_open_ex("run-check.tdb", 1, TDB_CLEAR_IF_FIRST,
25                           O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
26
27         ok1(tdb);
28         ok1(tdb_check(tdb, NULL, NULL) == 0);
29         
30         key.dsize = strlen("hi");
31         key.dptr = (void *)"hi";
32         data.dsize = strlen("world");
33         data.dptr = (void *)"world";
34
35         ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
36         ok1(tdb_check(tdb, NULL, NULL) == 0);
37         tdb_close(tdb);
38
39         tdb = tdb_open_ex("run-check.tdb", 1024, 0, O_RDWR, 0,
40                           &taplogctx, NULL);
41         ok1(tdb);
42         ok1(tdb_check(tdb, NULL, NULL) == 0);
43         tdb_close(tdb);
44
45         tdb = tdb_open_ex("test/tdb.corrupt", 1024, 0, O_RDWR, 0,
46                           &taplogctx, NULL);
47         ok1(tdb);
48         ok1(tdb_check(tdb, NULL, NULL) == -1);
49         ok1(tdb_error(tdb) == TDB_ERR_CORRUPT);
50         tdb_close(tdb);
51
52         /* Big and little endian should work! */
53         tdb = tdb_open_ex("test/old-nohash-le.tdb", 1024, 0, O_RDWR, 0,
54                           &taplogctx, NULL);
55         ok1(tdb);
56         ok1(tdb_check(tdb, NULL, NULL) == 0);
57         tdb_close(tdb);
58
59         tdb = tdb_open_ex("test/old-nohash-be.tdb", 1024, 0, O_RDWR, 0,
60                           &taplogctx, NULL);
61         ok1(tdb);
62         ok1(tdb_check(tdb, NULL, NULL) == 0);
63         tdb_close(tdb);
64
65         return exit_status();
66 }