1 #include "ntdb-source.h"
2 #include "tap-interface.h"
7 static uint32_t badhash(const void *key
, size_t len
, uint32_t seed
, void *priv
)
12 static int trav(struct ntdb_context
*ntdb
, NTDB_DATA key
, NTDB_DATA dbuf
, void *p
)
15 return ntdb_delete(ntdb
, key
);
19 int main(int argc
, char *argv
[])
22 struct ntdb_context
*ntdb
;
23 NTDB_DATA key
= { (unsigned char *)&j
, sizeof(j
) };
24 NTDB_DATA dbuf
= { (unsigned char *)&j
, sizeof(j
) };
25 union ntdb_attribute hattr
= { .hash
= { .base
= { NTDB_ATTRIBUTE_HASH
},
27 int flags
[] = { NTDB_INTERNAL
, NTDB_DEFAULT
, NTDB_NOMMAP
,
28 NTDB_INTERNAL
|NTDB_CONVERT
, NTDB_CONVERT
,
29 NTDB_NOMMAP
|NTDB_CONVERT
,
32 hattr
.base
.next
= &tap_log_attr
;
34 plan_tests(sizeof(flags
) / sizeof(flags
[0]) * (7 * OVERLOAD
+ 11) + 1);
35 for (i
= 0; i
< sizeof(flags
) / sizeof(flags
[0]); i
++) {
36 NTDB_DATA d
= { NULL
, 0 }; /* Bogus GCC warning */
38 ntdb
= ntdb_open("run-25-hashoverload.ntdb",
39 flags
[i
]|MAYBE_NOSYNC
,
40 O_RDWR
|O_CREAT
|O_TRUNC
, 0600, &hattr
);
45 /* Overload a bucket. */
46 for (j
= 0; j
< OVERLOAD
; j
++) {
47 ok1(ntdb_store(ntdb
, key
, dbuf
, NTDB_INSERT
) == 0);
49 ok1(ntdb_check(ntdb
, NULL
, NULL
) == 0);
51 /* Check we can find them all. */
52 for (j
= 0; j
< OVERLOAD
; j
++) {
53 ok1(ntdb_fetch(ntdb
, key
, &d
) == NTDB_SUCCESS
);
54 ok1(d
.dsize
== sizeof(j
));
56 ok1(d
.dptr
&& memcmp(d
.dptr
, &j
, d
.dsize
) == 0);
60 /* Traverse through them. */
61 ok1(ntdb_traverse(ntdb
, trav
, NULL
) == OVERLOAD
);
63 /* Delete the first 99. */
64 for (j
= 0; j
< OVERLOAD
-1; j
++)
65 ok1(ntdb_delete(ntdb
, key
) == 0);
67 ok1(ntdb_check(ntdb
, NULL
, NULL
) == 0);
69 ok1(ntdb_fetch(ntdb
, key
, &d
) == NTDB_SUCCESS
);
70 ok1(d
.dsize
== sizeof(j
));
72 ok1(d
.dptr
&& memcmp(d
.dptr
, &j
, d
.dsize
) == 0);
75 /* Traverse through them. */
76 ok1(ntdb_traverse(ntdb
, trav
, NULL
) == 1);
79 for (j
= 0; j
< OVERLOAD
-1; j
++) {
80 ok1(ntdb_store(ntdb
, key
, dbuf
, NTDB_INSERT
) == 0);
82 ok1(ntdb_check(ntdb
, NULL
, NULL
) == 0);
84 /* Now try deleting as we go. */
85 ok1(ntdb_traverse(ntdb
, trav
, trav
) == OVERLOAD
);
86 ok1(ntdb_check(ntdb
, NULL
, NULL
) == 0);
87 ok1(ntdb_traverse(ntdb
, trav
, NULL
) == 0);
91 ok1(tap_log_messages
== 0);