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/tdb/hash.c>
13 #include <ccan/tap/tap.h>
17 static void log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...)
19 unsigned int *count = tdb_get_logging_private(tdb);
20 if (strstr(fmt, "hash"))
24 int main(int argc, char *argv[])
26 struct tdb_context *tdb;
27 unsigned int log_count;
28 struct tdb_logging_context log_ctx = { log_fn, &log_count };
32 /* Create with default hash. */
34 tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0,
35 O_CREAT|O_RDWR|O_TRUNC, 0600, &log_ctx, NULL);
40 /* Fail to open with different hash. */
41 tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDWR, 0,
42 &log_ctx, tdb_jenkins_hash);
46 /* Create with different hash. */
48 tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0,
49 O_CREAT|O_RDWR|O_TRUNC,
50 0600, &log_ctx, tdb_jenkins_hash);
55 /* Endian should be no problem. */
57 tdb = tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDWR, 0,
63 tdb = tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDWR, 0,
69 /* Fail to open with default hash. */
70 tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDWR, 0,
76 tdb = tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDONLY,
77 0, &log_ctx, tdb_jenkins_hash);
80 ok1(tdb_check(tdb, NULL, NULL) == 0);
84 tdb = tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDONLY,
85 0, &log_ctx, tdb_jenkins_hash);
88 ok1(tdb_check(tdb, NULL, NULL) == 0);