lib:crypto: Reformat source code
[samba.git] / lib / tdb / test / run-wronghash-fail.c
blobc44b0f5aaee3612e775dcc0d52c70c4934d3ccba
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"
14 #include <stdlib.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"))
20 (*count)++;
23 int main(int argc, char *argv[])
25 struct tdb_context *tdb;
26 unsigned int log_count;
27 TDB_DATA d;
28 struct tdb_logging_context log_ctx = { log_fn, &log_count };
30 plan_tests(28);
32 /* Create with default hash. */
33 log_count = 0;
34 tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0,
35 O_CREAT|O_RDWR|O_TRUNC, 0600, &log_ctx, NULL);
36 ok1(tdb);
37 ok1(log_count == 0);
38 d.dptr = discard_const_p(uint8_t, "Hello");
39 d.dsize = 5;
40 ok1(tdb_store(tdb, d, d, TDB_INSERT) == 0);
41 tdb_close(tdb);
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);
46 ok1(!tdb);
47 ok1(log_count == 1);
49 /* Create with different hash. */
50 log_count = 0;
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);
54 ok1(tdb);
55 ok1(log_count == 0);
56 tdb_close(tdb);
58 /* Endian should be no problem. */
59 log_count = 0;
60 tdb = tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDWR, 0,
61 &log_ctx, tdb_old_hash);
62 ok1(!tdb);
63 ok1(log_count == 1);
65 log_count = 0;
66 tdb = tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDWR, 0,
67 &log_ctx, tdb_old_hash);
68 ok1(!tdb);
69 ok1(log_count == 1);
71 log_count = 0;
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);
75 ok1(!tdb);
76 ok1(log_count == 1);
78 log_count = 0;
79 tdb = tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDONLY,
80 0, &log_ctx, tdb_jenkins_hash);
81 ok1(tdb);
82 ok1(log_count == 0);
83 ok1(tdb_check(tdb, NULL, NULL) == 0);
84 tdb_close(tdb);
86 log_count = 0;
87 tdb = tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDONLY,
88 0, &log_ctx, tdb_jenkins_hash);
89 ok1(tdb);
90 ok1(log_count == 0);
91 ok1(tdb_check(tdb, NULL, NULL) == 0);
92 tdb_close(tdb);
94 /* It should open with jenkins hash if we don't specify. */
95 log_count = 0;
96 tdb = tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDWR, 0,
97 &log_ctx, NULL);
98 ok1(tdb);
99 ok1(log_count == 0);
100 ok1(tdb_check(tdb, NULL, NULL) == 0);
101 tdb_close(tdb);
103 log_count = 0;
104 tdb = tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDWR, 0,
105 &log_ctx, NULL);
106 ok1(tdb);
107 ok1(log_count == 0);
108 ok1(tdb_check(tdb, NULL, NULL) == 0);
109 tdb_close(tdb);
111 log_count = 0;
112 tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDONLY,
113 0, &log_ctx, NULL);
114 ok1(tdb);
115 ok1(log_count == 0);
116 ok1(tdb_check(tdb, NULL, NULL) == 0);
117 tdb_close(tdb);
120 return exit_status();