Line data Source code
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 :
17 1 : int main(int argc, char *argv[])
18 : {
19 : struct tdb_context *tdb;
20 : TDB_DATA key, data;
21 :
22 : plan_tests(13);
23 1 : tdb = tdb_open_ex("run-check.tdb", 1, TDB_CLEAR_IF_FIRST,
24 : O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
25 :
26 1 : ok1(tdb);
27 1 : ok1(tdb_check(tdb, NULL, NULL) == 0);
28 :
29 1 : key.dsize = strlen("hi");
30 1 : key.dptr = discard_const_p(uint8_t, "hi");
31 1 : data.dsize = strlen("world");
32 1 : data.dptr = discard_const_p(uint8_t, "world");
33 :
34 1 : ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
35 1 : ok1(tdb_check(tdb, NULL, NULL) == 0);
36 1 : tdb_close(tdb);
37 :
38 1 : tdb = tdb_open_ex("run-check.tdb", 1024, 0, O_RDWR, 0,
39 : &taplogctx, NULL);
40 1 : ok1(tdb);
41 1 : ok1(tdb_check(tdb, NULL, NULL) == 0);
42 1 : tdb_close(tdb);
43 :
44 1 : tdb = tdb_open_ex("test/tdb.corrupt", 1024, 0, O_RDWR, 0,
45 : &taplogctx, NULL);
46 1 : ok1(tdb);
47 1 : ok1(tdb_check(tdb, NULL, NULL) == -1);
48 1 : ok1(tdb_error(tdb) == TDB_ERR_CORRUPT);
49 1 : tdb_close(tdb);
50 :
51 : /* Big and little endian should work! */
52 1 : tdb = tdb_open_ex("test/old-nohash-le.tdb", 1024, 0, O_RDWR, 0,
53 : &taplogctx, NULL);
54 1 : ok1(tdb);
55 1 : ok1(tdb_check(tdb, NULL, NULL) == 0);
56 1 : tdb_close(tdb);
57 :
58 1 : tdb = tdb_open_ex("test/old-nohash-be.tdb", 1024, 0, O_RDWR, 0,
59 : &taplogctx, NULL);
60 1 : ok1(tdb);
61 1 : ok1(tdb_check(tdb, NULL, NULL) == 0);
62 1 : tdb_close(tdb);
63 :
64 1 : return exit_status();
65 : }
|