3a4a39f1f32fad5ba55ba689c0b1c9ffec4d9653
[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/tap/tap.h>
13 #include <stdlib.h>
14 #include <err.h>
15
16 int main(int argc, char *argv[])
17 {
18         struct tdb_context *tdb;
19         TDB_DATA key, data;
20
21         plan_tests(9);
22         tdb = tdb_open("run-check.tdb", 1, TDB_CLEAR_IF_FIRST,
23                        O_CREAT|O_TRUNC|O_RDWR, 0600);
24
25         ok1(tdb);
26         ok1(tdb_check(tdb, NULL, NULL) == 0);
27         
28         key.dsize = strlen("hi");
29         key.dptr = (void *)"hi";
30         data.dsize = strlen("world");
31         data.dptr = (void *)"world";
32
33         ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
34         ok1(tdb_check(tdb, NULL, NULL) == 0);
35         tdb_close(tdb);
36
37         tdb = tdb_open("run-check.tdb", 1024, 0, O_RDWR, 0);
38         ok1(tdb);
39         ok1(tdb_check(tdb, NULL, NULL) == 0);
40         tdb_close(tdb);
41
42         tdb = tdb_open("test/tdb.corrupt", 1024, 0, O_RDWR, 0);
43         ok1(tdb);
44         ok1(tdb_check(tdb, NULL, NULL) == -1);
45         ok1(tdb_error(tdb) == TDB_ERR_CORRUPT);
46         tdb_close(tdb);
47
48         return exit_status();
49 }