s3:smb2_write: pass fsp->fnum to init_strict_lock_struct()
[Samba/gebeck_regimport.git] / lib / tdb2 / test / run-tdb1-wronghash-fail.c
blob725b4d2d0022aa57a4dd73895fdf40ee864da087
1 #include "tdb2-source.h"
2 #include "tap-interface.h"
3 #include <stdlib.h>
5 static void log_fn(struct tdb_context *tdb, enum tdb_log_level level,
6 enum TDB_ERROR ecode, const char *message, void *priv)
8 unsigned int *count = priv;
9 if (strstr(message, "hash"))
10 (*count)++;
13 static uint64_t jenkins_hashfn(const void *key, size_t len, uint64_t seed,
14 void *unused)
16 return hashlittle(key, len);
19 /* the tdb1_old_hash function is "magic" as it automatically makes us test the
20 * tdb1_incompatible_hash as well, so use this wrapper. */
21 static uint64_t old_hash(const void *key, size_t len, uint64_t seed,
22 void *unused)
24 return tdb1_old_hash(key, len, seed, unused);
27 int main(int argc, char *argv[])
29 struct tdb_context *tdb;
30 unsigned int log_count;
31 TDB_DATA d;
32 union tdb_attribute log_attr, jhash_attr, ohash_attr,
33 incompat_hash_attr;
35 log_attr.base.attr = TDB_ATTRIBUTE_LOG;
36 log_attr.base.next = NULL;
37 log_attr.log.fn = log_fn;
38 log_attr.log.data = &log_count;
40 jhash_attr.base.attr = TDB_ATTRIBUTE_HASH;
41 jhash_attr.base.next = &log_attr;
42 jhash_attr.hash.fn = jenkins_hashfn;
44 ohash_attr.base.attr = TDB_ATTRIBUTE_HASH;
45 ohash_attr.base.next = &log_attr;
46 ohash_attr.hash.fn = old_hash;
48 incompat_hash_attr.base.attr = TDB_ATTRIBUTE_HASH;
49 incompat_hash_attr.base.next = &log_attr;
50 incompat_hash_attr.hash.fn = tdb1_incompatible_hash;
52 plan_tests(28);
54 /* Create with default hash. */
55 log_count = 0;
56 tdb = tdb_open("run-wronghash-fail.tdb1", TDB_VERSION1,
57 O_CREAT|O_RDWR|O_TRUNC, 0600, &log_attr);
58 ok1(tdb);
59 ok1(log_count == 0);
60 d = tdb_mkdata("Hello", strlen("Hello"));
61 ok1(tdb_store(tdb, d, d, TDB_INSERT) == TDB_SUCCESS);
62 tdb_close(tdb);
64 /* Fail to open with different hash. */
65 tdb = tdb_open("run-wronghash-fail.tdb1", TDB_VERSION1, O_RDWR, 0,
66 &jhash_attr);
67 ok1(!tdb);
68 ok1(log_count == 1);
70 /* Create with different hash. */
71 log_count = 0;
72 tdb = tdb_open("run-wronghash-fail.tdb1", TDB_VERSION1,
73 O_CREAT|O_RDWR|O_TRUNC, 0600, &jhash_attr);
74 ok1(tdb);
75 ok1(log_count == 0);
76 tdb_close(tdb);
78 /* Endian should be no problem. */
79 log_count = 0;
80 tdb = tdb_open("test/jenkins-le-hash.tdb1", TDB_VERSION1, O_RDWR, 0,
81 &ohash_attr);
82 ok1(!tdb);
83 ok1(log_count == 1);
85 log_count = 0;
86 tdb = tdb_open("test/jenkins-be-hash.tdb1", TDB_VERSION1, O_RDWR, 0,
87 &ohash_attr);
88 ok1(!tdb);
89 ok1(log_count == 1);
91 log_count = 0;
92 /* Fail to open with old default hash. */
93 tdb = tdb_open("run-wronghash-fail.tdb1", TDB_VERSION1, O_RDWR, 0,
94 &ohash_attr);
95 ok1(!tdb);
96 ok1(log_count == 1);
98 log_count = 0;
99 tdb = tdb_open("test/jenkins-le-hash.tdb1", TDB_VERSION1, O_RDONLY,
100 0, &incompat_hash_attr);
101 ok1(tdb);
102 ok1(log_count == 0);
103 ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
104 tdb_close(tdb);
106 log_count = 0;
107 tdb = tdb_open("test/jenkins-be-hash.tdb1", TDB_VERSION1, O_RDONLY,
108 0, &incompat_hash_attr);
109 ok1(tdb);
110 ok1(log_count == 0);
111 ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
112 tdb_close(tdb);
114 /* It should open with jenkins hash if we don't specify. */
115 log_count = 0;
116 tdb = tdb_open("test/jenkins-le-hash.tdb1", TDB_VERSION1, O_RDWR, 0,
117 &log_attr);
118 ok1(tdb);
119 ok1(log_count == 0);
120 ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
121 tdb_close(tdb);
123 log_count = 0;
124 tdb = tdb_open("test/jenkins-be-hash.tdb1", TDB_VERSION1, O_RDWR, 0,
125 &log_attr);
126 ok1(tdb);
127 ok1(log_count == 0);
128 ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
129 tdb_close(tdb);
131 log_count = 0;
132 tdb = tdb_open("run-wronghash-fail.tdb1", TDB_VERSION1, O_RDONLY,
133 0, &log_attr);
134 ok1(tdb);
135 ok1(log_count == 0);
136 ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
137 tdb_close(tdb);
140 return exit_status();