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 "tap-interface.h"
15 static void log_fn(struct tdb_context
*tdb
, enum tdb_debug_level level
, const char *fmt
, ...)
17 unsigned int *count
= tdb_get_logging_private(tdb
);
18 if (strstr(fmt
, "hash"))
22 int main(int argc
, char *argv
[])
24 struct tdb_context
*tdb
;
25 unsigned int log_count
;
27 struct tdb_logging_context log_ctx
= { log_fn
, &log_count
};
31 /* Create with default hash. */
33 tdb
= tdb_open_ex("run-wronghash-fail.tdb", 0, 0,
34 O_CREAT
|O_RDWR
|O_TRUNC
, 0600, &log_ctx
, NULL
);
37 d
.dptr
= (void *)"Hello";
39 ok1(tdb_store(tdb
, d
, d
, TDB_INSERT
) == 0);
42 /* Fail to open with different hash. */
43 tdb
= tdb_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDWR
, 0,
44 &log_ctx
, tdb_jenkins_hash
);
48 /* Create with different hash. */
50 tdb
= tdb_open_ex("run-wronghash-fail.tdb", 0, 0,
51 O_CREAT
|O_RDWR
|O_TRUNC
,
52 0600, &log_ctx
, tdb_jenkins_hash
);
57 /* Endian should be no problem. */
59 tdb
= tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDWR
, 0,
60 &log_ctx
, tdb_old_hash
);
65 tdb
= tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDWR
, 0,
66 &log_ctx
, tdb_old_hash
);
71 /* Fail to open with old default hash. */
72 tdb
= tdb_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDWR
, 0,
73 &log_ctx
, tdb_old_hash
);
78 tdb
= tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDONLY
,
79 0, &log_ctx
, tdb_jenkins_hash
);
82 ok1(tdb_check(tdb
, NULL
, NULL
) == 0);
86 tdb
= tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDONLY
,
87 0, &log_ctx
, tdb_jenkins_hash
);
90 ok1(tdb_check(tdb
, NULL
, NULL
) == 0);
93 /* It should open with jenkins hash if we don't specify. */
95 tdb
= tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDWR
, 0,
99 ok1(tdb_check(tdb
, NULL
, NULL
) == 0);
103 tdb
= tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDWR
, 0,
107 ok1(tdb_check(tdb
, NULL
, NULL
) == 0);
111 tdb
= tdb_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDONLY
,
115 ok1(tdb_check(tdb
, NULL
, NULL
) == 0);
119 return exit_status();