s3:registry: do not use regdb functions during db upgrade
[Samba/gebeck_regimport.git] / lib / tdb2 / test / api-14-exists.c
blob698006faf4ac946b7b813283d64cbc7fd57d5945
1 #include <ccan/tdb2/tdb2.h>
2 #include <ccan/tap/tap.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include "logging.h"
8 static bool test_records(struct tdb_context *tdb)
10 int i;
11 struct tdb_data key = { (unsigned char *)&i, sizeof(i) };
12 struct tdb_data data = { (unsigned char *)&i, sizeof(i) };
14 for (i = 0; i < 1000; i++) {
15 if (tdb_exists(tdb, key))
16 return false;
17 if (tdb_store(tdb, key, data, TDB_REPLACE) != 0)
18 return false;
19 if (!tdb_exists(tdb, key))
20 return false;
23 for (i = 0; i < 1000; i++) {
24 if (!tdb_exists(tdb, key))
25 return false;
26 if (tdb_delete(tdb, key) != 0)
27 return false;
28 if (tdb_exists(tdb, key))
29 return false;
31 return true;
34 int main(int argc, char *argv[])
36 unsigned int i;
37 struct tdb_context *tdb;
38 int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
39 TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
40 TDB_NOMMAP|TDB_CONVERT,
41 TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
42 TDB_NOMMAP|TDB_VERSION1,
43 TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
44 TDB_CONVERT|TDB_VERSION1,
45 TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
47 plan_tests(sizeof(flags) / sizeof(flags[0]) * 2 + 1);
48 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
49 tdb = tdb_open("run-14-exists.tdb", flags[i],
50 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
51 if (ok1(tdb))
52 ok1(test_records(tdb));
53 tdb_close(tdb);
56 ok1(tap_log_messages == 0);
57 return exit_status();