]> git.ozlabs.org Git - ccan/blob - ccan/tdb/test/run-oldhash.c
tdb: put example hashes into header, so we notice incorrect hash_fn.
[ccan] / ccan / tdb / test / run-oldhash.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/hash/hash.h>
13 #include <ccan/tap/tap.h>
14 #include <stdlib.h>
15 #include <err.h>
16 #include "logging.h"
17
18 static unsigned int jenkins_hash(TDB_DATA *key)
19 {
20         return hash_stable(key->dptr, key->dsize, 0);
21 }
22
23 int main(int argc, char *argv[])
24 {
25         struct tdb_context *tdb;
26
27         plan_tests(8);
28
29         /* Old format (with zeroes in the hash magic fields) should
30          * open with any hash (since we don't know what hash they used). */
31         tdb = tdb_open_ex("test/old-nohash-le.tdb", 0, 0, O_RDWR, 0,
32                           &taplogctx, NULL);
33         ok1(tdb);
34         ok1(tdb_check(tdb, NULL, NULL) == 0);
35         tdb_close(tdb);
36
37         tdb = tdb_open_ex("test/old-nohash-be.tdb", 0, 0, O_RDWR, 0,
38                           &taplogctx, NULL);
39         ok1(tdb);
40         ok1(tdb_check(tdb, NULL, NULL) == 0);
41         tdb_close(tdb);
42
43         tdb = tdb_open_ex("test/old-nohash-le.tdb", 0, 0, O_RDWR, 0,
44                           &taplogctx, jenkins_hash);
45         ok1(tdb);
46         ok1(tdb_check(tdb, NULL, NULL) == 0);
47         tdb_close(tdb);
48
49         tdb = tdb_open_ex("test/old-nohash-be.tdb", 0, 0, O_RDWR, 0,
50                           &taplogctx, jenkins_hash);
51         ok1(tdb);
52         ok1(tdb_check(tdb, NULL, NULL) == 0);
53         tdb_close(tdb);
54
55         return exit_status();
56 }