1 #include "../common/tdb_private.h"
2 #include "../common/io.c"
3 #include "../common/tdb.c"
4 #include "../common/lock.c"
5 #include "../common/freelist.c"
6 #include "../common/traverse.c"
7 #include "../common/transaction.c"
8 #include "../common/error.c"
9 #include "../common/open.c"
10 #include "../common/check.c"
11 #include "../common/hash.c"
12 #include "../common/mutex.c"
13 #include "tap-interface.h"
16 static void log_fn(struct tdb_context
*tdb
, enum tdb_debug_level level
, const char *fmt
, ...)
18 unsigned int *count
= tdb_get_logging_private(tdb
);
19 if (strstr(fmt
, "hash"))
23 int main(int argc
, char *argv
[])
25 struct tdb_context
*tdb
;
26 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
);
38 d
.dptr
= discard_const_p(uint8_t, "Hello");
40 ok1(tdb_store(tdb
, d
, d
, TDB_INSERT
) == 0);
43 /* Fail to open with different hash. */
44 tdb
= tdb_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDWR
, 0,
45 &log_ctx
, tdb_jenkins_hash
);
49 /* Create with different hash. */
51 tdb
= tdb_open_ex("run-wronghash-fail.tdb", 0, 0,
52 O_CREAT
|O_RDWR
|O_TRUNC
,
53 0600, &log_ctx
, tdb_jenkins_hash
);
58 /* Endian should be no problem. */
60 tdb
= tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDWR
, 0,
61 &log_ctx
, tdb_old_hash
);
66 tdb
= tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDWR
, 0,
67 &log_ctx
, tdb_old_hash
);
72 /* Fail to open with old default hash. */
73 tdb
= tdb_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDWR
, 0,
74 &log_ctx
, tdb_old_hash
);
79 tdb
= tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDONLY
,
80 0, &log_ctx
, tdb_jenkins_hash
);
83 ok1(tdb_check(tdb
, NULL
, NULL
) == 0);
87 tdb
= tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDONLY
,
88 0, &log_ctx
, tdb_jenkins_hash
);
91 ok1(tdb_check(tdb
, NULL
, NULL
) == 0);
94 /* It should open with jenkins hash if we don't specify. */
96 tdb
= tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDWR
, 0,
100 ok1(tdb_check(tdb
, NULL
, NULL
) == 0);
104 tdb
= tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDWR
, 0,
108 ok1(tdb_check(tdb
, NULL
, NULL
) == 0);
112 tdb
= tdb_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDONLY
,
116 ok1(tdb_check(tdb
, NULL
, NULL
) == 0);
120 return exit_status();