s3:include: remove typedef user_struct
[Samba/gebeck_regimport.git] / lib / tdb2 / test / api-14-exists.c
blob916e9b46f60973338df142ddc52a9cd568268cdc
1 #include "config.h"
2 #include "tdb2.h"
3 #include "tap-interface.h"
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include "logging.h"
9 static bool test_records(struct tdb_context *tdb)
11 int i;
12 struct tdb_data key = { (unsigned char *)&i, sizeof(i) };
13 struct tdb_data data = { (unsigned char *)&i, sizeof(i) };
15 for (i = 0; i < 1000; i++) {
16 if (tdb_exists(tdb, key))
17 return false;
18 if (tdb_store(tdb, key, data, TDB_REPLACE) != 0)
19 return false;
20 if (!tdb_exists(tdb, key))
21 return false;
24 for (i = 0; i < 1000; i++) {
25 if (!tdb_exists(tdb, key))
26 return false;
27 if (tdb_delete(tdb, key) != 0)
28 return false;
29 if (tdb_exists(tdb, key))
30 return false;
32 return true;
35 int main(int argc, char *argv[])
37 unsigned int i;
38 struct tdb_context *tdb;
39 int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
40 TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
41 TDB_NOMMAP|TDB_CONVERT,
42 TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
43 TDB_NOMMAP|TDB_VERSION1,
44 TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
45 TDB_CONVERT|TDB_VERSION1,
46 TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
48 plan_tests(sizeof(flags) / sizeof(flags[0]) * 2 + 1);
49 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
50 tdb = tdb_open("run-14-exists.tdb", flags[i],
51 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
52 if (ok1(tdb))
53 ok1(test_records(tdb));
54 tdb_close(tdb);
57 ok1(tap_log_messages == 0);
58 return exit_status();