s3:include: remove typedef user_struct
[Samba/gebeck_regimport.git] / lib / tdb2 / test / api-12-store.c
blob6a9dd95f5fb8b9bda916751de3cc950c845d14a0
1 #include "config.h"
2 #include "tdb2.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 uint64_t fixedhash(const void *key, size_t len, uint64_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 tdb_context *tdb;
22 uint64_t seed = 16014841315512641303ULL;
23 union tdb_attribute fixed_hattr
24 = { .hash = { .base = { TDB_ATTRIBUTE_HASH },
25 .fn = fixedhash,
26 .data = &seed } };
27 int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
28 TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
29 TDB_NOMMAP|TDB_CONVERT };
30 struct tdb_data key = { (unsigned char *)&j, sizeof(j) };
31 struct tdb_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 tdb = tdb_open("run-12-store.tdb", flags[i],
38 O_RDWR|O_CREAT|O_TRUNC, 0600, &fixed_hattr);
39 ok1(tdb);
40 if (!tdb)
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 struct tdb_data d = { NULL, 0 }; /* Bogus GCC warning */
47 ok1(tdb_store(tdb, key, data, TDB_REPLACE) == 0);
48 ok1(tdb_fetch(tdb, key, &d) == TDB_SUCCESS);
49 ok1(tdb_deq(d, data));
50 free(d.dptr);
52 tdb_close(tdb);
55 ok1(tap_log_messages == 0);
56 return exit_status();