1 #define _XOPEN_SOURCE 500
2 #include "../common/tdb_private.h"
3 #include "../common/io.c"
4 #include "../common/tdb.c"
5 #include "../common/lock.c"
6 #include "../common/freelist.c"
7 #include "../common/traverse.c"
8 #include "../common/transaction.c"
9 #include "../common/error.c"
10 #include "../common/open.c"
11 #include "../common/check.c"
12 #include "../common/hash.c"
13 #include "tap-interface.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;
29 struct tdb_logging_context log_ctx = { log_fn, &log_count };
33 /* Create with default hash. */
35 tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0,
36 O_CREAT|O_RDWR|O_TRUNC, 0600, &log_ctx, NULL);
39 d.dptr = (void *)"Hello";
41 ok1(tdb_store(tdb, d, d, TDB_INSERT) == 0);
44 /* Fail to open with different hash. */
45 tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDWR, 0,
46 &log_ctx, tdb_jenkins_hash);
50 /* Create with different hash. */
52 tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0,
53 O_CREAT|O_RDWR|O_TRUNC,
54 0600, &log_ctx, tdb_jenkins_hash);
59 /* Endian should be no problem. */
61 tdb = tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDWR, 0,
62 &log_ctx, tdb_old_hash);
67 tdb = tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDWR, 0,
68 &log_ctx, tdb_old_hash);
73 /* Fail to open with old default hash. */
74 tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDWR, 0,
75 &log_ctx, tdb_old_hash);
80 tdb = tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDONLY,
81 0, &log_ctx, tdb_jenkins_hash);
84 ok1(tdb_check(tdb, NULL, NULL) == 0);
88 tdb = tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDONLY,
89 0, &log_ctx, tdb_jenkins_hash);
92 ok1(tdb_check(tdb, NULL, NULL) == 0);
95 /* It should open with jenkins hash if we don't specify. */
97 tdb = tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDWR, 0,
101 ok1(tdb_check(tdb, NULL, NULL) == 0);
105 tdb = tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDWR, 0,
109 ok1(tdb_check(tdb, NULL, NULL) == 0);
113 tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDONLY,
117 ok1(tdb_check(tdb, NULL, NULL) == 0);
121 return exit_status();