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>
17 static unsigned int jenkins_hash(TDB_DATA *key)
19 return hash_stable(key->dptr, key->dsize, 0);
22 static void log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...)
24 unsigned int *count = tdb_get_logging_private(tdb);
25 if (strstr(fmt, "hash"))
29 int main(int argc, char *argv[])
31 struct tdb_context *tdb;
32 unsigned int log_count;
33 struct tdb_logging_context log_ctx = { log_fn, &log_count };
37 /* Create with default hash. */
39 tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0,
40 O_CREAT|O_RDWR|O_TRUNC, 0600, &log_ctx, NULL);
45 /* Fail to open with different hash. */
46 tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDWR, 0,
47 &log_ctx, jenkins_hash);
51 /* Create with different hash. */
53 tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0,
54 O_CREAT|O_RDWR|O_TRUNC,
55 0600, &log_ctx, jenkins_hash);
60 /* Endian should be no problem. */
62 tdb = tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDWR, 0,
68 tdb = tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDWR, 0,
74 /* Fail to open with defailt hash. */
75 tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDWR, 0,
81 tdb = tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDONLY,
82 0, &log_ctx, jenkins_hash);
85 ok1(tdb_check(tdb, NULL, NULL) == 0);
89 tdb = tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDONLY,
90 0, &log_ctx, jenkins_hash);
93 ok1(tdb_check(tdb, NULL, NULL) == 0);