1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
6 static void log_fn(struct tdb1_context *tdb, enum tdb1_debug_level level, const char *fmt, ...)
8 unsigned int *count = tdb1_get_logging_private(tdb);
9 if (strstr(fmt, "hash"))
13 int main(int argc, char *argv[])
15 struct tdb1_context *tdb;
16 unsigned int log_count;
18 struct tdb1_logging_context log_ctx = { log_fn, &log_count };
22 /* Create with default hash. */
24 tdb = tdb1_open_ex("run-wronghash-fail.tdb", 0, 0,
25 O_CREAT|O_RDWR|O_TRUNC, 0600, &log_ctx, NULL);
28 d.dptr = (void *)"Hello";
30 ok1(tdb1_store(tdb, d, d, TDB1_INSERT) == 0);
33 /* Fail to open with different hash. */
34 tdb = tdb1_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDWR, 0,
35 &log_ctx, tdb1_jenkins_hash);
39 /* Create with different hash. */
41 tdb = tdb1_open_ex("run-wronghash-fail.tdb", 0, 0,
42 O_CREAT|O_RDWR|O_TRUNC,
43 0600, &log_ctx, tdb1_jenkins_hash);
48 /* Endian should be no problem. */
50 tdb = tdb1_open_ex("test/jenkins-le-hash.tdb1", 0, 0, O_RDWR, 0,
51 &log_ctx, tdb1_old_hash);
56 tdb = tdb1_open_ex("test/jenkins-be-hash.tdb1", 0, 0, O_RDWR, 0,
57 &log_ctx, tdb1_old_hash);
62 /* Fail to open with old default hash. */
63 tdb = tdb1_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDWR, 0,
64 &log_ctx, tdb1_old_hash);
69 tdb = tdb1_open_ex("test/jenkins-le-hash.tdb1", 0, 0, O_RDONLY,
70 0, &log_ctx, tdb1_jenkins_hash);
73 ok1(tdb1_check(tdb, NULL, NULL) == 0);
77 tdb = tdb1_open_ex("test/jenkins-be-hash.tdb1", 0, 0, O_RDONLY,
78 0, &log_ctx, tdb1_jenkins_hash);
81 ok1(tdb1_check(tdb, NULL, NULL) == 0);
84 /* It should open with jenkins hash if we don't specify. */
86 tdb = tdb1_open_ex("test/jenkins-le-hash.tdb1", 0, 0, O_RDWR, 0,
90 ok1(tdb1_check(tdb, NULL, NULL) == 0);
94 tdb = tdb1_open_ex("test/jenkins-be-hash.tdb1", 0, 0, O_RDWR, 0,
98 ok1(tdb1_check(tdb, NULL, NULL) == 0);
102 tdb = tdb1_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDONLY,
106 ok1(tdb1_check(tdb, NULL, NULL) == 0);
110 return exit_status();