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