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