Remove old run-tests, clean up #includes to all be <ccan/...
[ccan] / ccan / tdb / test / run-check.c
1 #define _XOPEN_SOURCE 500
2 #include "tdb/tdb.h"
3 #include "tdb/io.c"
4 #include "tdb/tdb.c"
5 #include "tdb/lock.c"
6 #include "tdb/freelist.c"
7 #include "tdb/traverse.c"
8 #include "tdb/transaction.c"
9 #include "tdb/error.c"
10 #include "tdb/open.c"
11 #include "tdb/check.c"
12 #include "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("/tmp/test5.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("/tmp/test5.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 }