1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
6 static void log_fn(struct tdb1_context *tdb, enum tdb_log_level level,
7 enum TDB_ERROR ecode, const char *message, void *priv)
9 unsigned int *count = priv;
10 if (strstr(message, "hash"))
14 int main(int argc, char *argv[])
16 struct tdb1_context *tdb;
17 unsigned int log_count;
19 struct tdb1_logging_context log_ctx = { log_fn, &log_count };
23 /* Create with default hash. */
25 tdb = tdb1_open_ex("run-wronghash-fail.tdb", 0, 0,
26 O_CREAT|O_RDWR|O_TRUNC, 0600, &log_ctx, NULL);
29 d.dptr = (void *)"Hello";
31 ok1(tdb1_store(tdb, d, d, TDB1_INSERT) == 0);
34 /* Fail to open with different hash. */
35 tdb = tdb1_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDWR, 0,
36 &log_ctx, tdb1_jenkins_hash);
40 /* Create with different hash. */
42 tdb = tdb1_open_ex("run-wronghash-fail.tdb", 0, 0,
43 O_CREAT|O_RDWR|O_TRUNC,
44 0600, &log_ctx, tdb1_jenkins_hash);
49 /* Endian should be no problem. */
51 tdb = tdb1_open_ex("test/jenkins-le-hash.tdb1", 0, 0, O_RDWR, 0,
52 &log_ctx, tdb1_old_hash);
57 tdb = tdb1_open_ex("test/jenkins-be-hash.tdb1", 0, 0, O_RDWR, 0,
58 &log_ctx, tdb1_old_hash);
63 /* Fail to open with old default hash. */
64 tdb = tdb1_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDWR, 0,
65 &log_ctx, tdb1_old_hash);
70 tdb = tdb1_open_ex("test/jenkins-le-hash.tdb1", 0, 0, O_RDONLY,
71 0, &log_ctx, tdb1_jenkins_hash);
74 ok1(tdb1_check(tdb, NULL, NULL) == 0);
78 tdb = tdb1_open_ex("test/jenkins-be-hash.tdb1", 0, 0, O_RDONLY,
79 0, &log_ctx, tdb1_jenkins_hash);
82 ok1(tdb1_check(tdb, NULL, NULL) == 0);
85 /* It should open with jenkins hash if we don't specify. */
87 tdb = tdb1_open_ex("test/jenkins-le-hash.tdb1", 0, 0, O_RDWR, 0,
91 ok1(tdb1_check(tdb, NULL, NULL) == 0);
95 tdb = tdb1_open_ex("test/jenkins-be-hash.tdb1", 0, 0, O_RDWR, 0,
99 ok1(tdb1_check(tdb, NULL, NULL) == 0);
103 tdb = tdb1_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDONLY,
107 ok1(tdb1_check(tdb, NULL, NULL) == 0);
111 return exit_status();