s3:registry: do not use regdb functions during db upgrade
[Samba/gebeck_regimport.git] / lib / tdb2 / test / api-12-store.c
blobccec53e029ef8d93dcb995436de539bda10a9e28
1 #include <ccan/tdb2/tdb2.h>
2 #include <ccan/tap/tap.h>
3 #include <ccan/hash/hash.h>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
8 #include "logging.h"
10 /* We use the same seed which we saw a failure on. */
11 static uint64_t fixedhash(const void *key, size_t len, uint64_t seed, void *p)
13 return hash64_stable((const unsigned char *)key, len,
14 *(uint64_t *)p);
17 int main(int argc, char *argv[])
19 unsigned int i, j;
20 struct tdb_context *tdb;
21 uint64_t seed = 16014841315512641303ULL;
22 union tdb_attribute fixed_hattr
23 = { .hash = { .base = { TDB_ATTRIBUTE_HASH },
24 .fn = fixedhash,
25 .data = &seed } };
26 int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
27 TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
28 TDB_NOMMAP|TDB_CONVERT };
29 struct tdb_data key = { (unsigned char *)&j, sizeof(j) };
30 struct tdb_data data = { (unsigned char *)&j, sizeof(j) };
32 fixed_hattr.base.next = &tap_log_attr;
34 plan_tests(sizeof(flags) / sizeof(flags[0]) * (1 + 500 * 3) + 1);
35 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
36 tdb = tdb_open("run-12-store.tdb", flags[i],
37 O_RDWR|O_CREAT|O_TRUNC, 0600, &fixed_hattr);
38 ok1(tdb);
39 if (!tdb)
40 continue;
42 /* We seemed to lose some keys.
43 * Insert and check they're in there! */
44 for (j = 0; j < 500; j++) {
45 struct tdb_data d = { NULL, 0 }; /* Bogus GCC warning */
46 ok1(tdb_store(tdb, key, data, TDB_REPLACE) == 0);
47 ok1(tdb_fetch(tdb, key, &d) == TDB_SUCCESS);
48 ok1(tdb_deq(d, data));
49 free(d.dptr);
51 tdb_close(tdb);
54 ok1(tap_log_messages == 0);
55 return exit_status();