s3:smbd: allocate out_context_blobs with talloc
[Samba.git] / lib / ntdb / test / api-12-store.c
blob532a8ee5c8223a33d4d31dae27c993ec8275f261
1 #include "config.h"
2 #include "ntdb.h"
3 #include "private.h"
4 #include "tap-interface.h"
5 #include <ccan/hash/hash.h>
7 #include "logging.h"
9 /* We use the same seed which we saw a failure on. */
10 static uint32_t fixedhash(const void *key, size_t len, uint32_t seed, void *p)
12 return hash64_stable((const unsigned char *)key, len,
13 *(uint64_t *)p);
16 int main(int argc, char *argv[])
18 unsigned int i, j;
19 struct ntdb_context *ntdb;
20 uint64_t seed = 16014841315512641303ULL;
21 union ntdb_attribute fixed_hattr
22 = { .hash = { .base = { NTDB_ATTRIBUTE_HASH },
23 .fn = fixedhash,
24 .data = &seed } };
25 int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
26 NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
27 NTDB_NOMMAP|NTDB_CONVERT };
28 NTDB_DATA key = { (unsigned char *)&j, sizeof(j) };
29 NTDB_DATA data = { (unsigned char *)&j, sizeof(j) };
31 fixed_hattr.base.next = &tap_log_attr;
33 plan_tests(sizeof(flags) / sizeof(flags[0]) * (1 + 500 * 3) + 1);
34 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
35 ntdb = ntdb_open("run-12-store.ntdb", flags[i]|MAYBE_NOSYNC,
36 O_RDWR|O_CREAT|O_TRUNC, 0600, &fixed_hattr);
37 ok1(ntdb);
38 if (!ntdb)
39 continue;
41 /* We seemed to lose some keys.
42 * Insert and check they're in there! */
43 for (j = 0; j < 500; j++) {
44 NTDB_DATA d = { NULL, 0 }; /* Bogus GCC warning */
45 ok1(ntdb_store(ntdb, key, data, NTDB_REPLACE) == 0);
46 ok1(ntdb_fetch(ntdb, key, &d) == NTDB_SUCCESS);
47 ok1(ntdb_deq(d, data));
48 free(d.dptr);
50 ntdb_close(ntdb);
53 ok1(tap_log_messages == 0);
54 return exit_status();