s4:scripting/python: always treat the highwatermark as opaque (bug #9508)
[Samba/gebeck_regimport.git] / lib / tdb / test / run-wronghash-fail.c
blob74bbc30ba6fbf2b4ba6c791166d10b25d2df73f1
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"
13 #include <stdlib.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"))
19 (*count)++;
22 int main(int argc, char *argv[])
24 struct tdb_context *tdb;
25 unsigned int log_count;
26 TDB_DATA d;
27 struct tdb_logging_context log_ctx = { log_fn, &log_count };
29 plan_tests(28);
31 /* Create with default hash. */
32 log_count = 0;
33 tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0,
34 O_CREAT|O_RDWR|O_TRUNC, 0600, &log_ctx, NULL);
35 ok1(tdb);
36 ok1(log_count == 0);
37 d.dptr = (void *)"Hello";
38 d.dsize = 5;
39 ok1(tdb_store(tdb, d, d, TDB_INSERT) == 0);
40 tdb_close(tdb);
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);
45 ok1(!tdb);
46 ok1(log_count == 1);
48 /* Create with different hash. */
49 log_count = 0;
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);
53 ok1(tdb);
54 ok1(log_count == 0);
55 tdb_close(tdb);
57 /* Endian should be no problem. */
58 log_count = 0;
59 tdb = tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDWR, 0,
60 &log_ctx, tdb_old_hash);
61 ok1(!tdb);
62 ok1(log_count == 1);
64 log_count = 0;
65 tdb = tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDWR, 0,
66 &log_ctx, tdb_old_hash);
67 ok1(!tdb);
68 ok1(log_count == 1);
70 log_count = 0;
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);
74 ok1(!tdb);
75 ok1(log_count == 1);
77 log_count = 0;
78 tdb = tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDONLY,
79 0, &log_ctx, tdb_jenkins_hash);
80 ok1(tdb);
81 ok1(log_count == 0);
82 ok1(tdb_check(tdb, NULL, NULL) == 0);
83 tdb_close(tdb);
85 log_count = 0;
86 tdb = tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDONLY,
87 0, &log_ctx, tdb_jenkins_hash);
88 ok1(tdb);
89 ok1(log_count == 0);
90 ok1(tdb_check(tdb, NULL, NULL) == 0);
91 tdb_close(tdb);
93 /* It should open with jenkins hash if we don't specify. */
94 log_count = 0;
95 tdb = tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDWR, 0,
96 &log_ctx, NULL);
97 ok1(tdb);
98 ok1(log_count == 0);
99 ok1(tdb_check(tdb, NULL, NULL) == 0);
100 tdb_close(tdb);
102 log_count = 0;
103 tdb = tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDWR, 0,
104 &log_ctx, NULL);
105 ok1(tdb);
106 ok1(log_count == 0);
107 ok1(tdb_check(tdb, NULL, NULL) == 0);
108 tdb_close(tdb);
110 log_count = 0;
111 tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDONLY,
112 0, &log_ctx, NULL);
113 ok1(tdb);
114 ok1(log_count == 0);
115 ok1(tdb_check(tdb, NULL, NULL) == 0);
116 tdb_close(tdb);
119 return exit_status();