lib/param: Merge parameter tables into a common file
[Samba/gebeck_regimport.git] / lib / ntdb / test / api-14-exists.c
blobabaaae0ee54d8ca1832ab8346040819fbdd4d0d0
1 #include "config.h"
2 #include "ntdb.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 ntdb_context *ntdb)
11 int i;
12 NTDB_DATA key = { (unsigned char *)&i, sizeof(i) };
13 NTDB_DATA data = { (unsigned char *)&i, sizeof(i) };
15 for (i = 0; i < 1000; i++) {
16 if (ntdb_exists(ntdb, key))
17 return false;
18 if (ntdb_store(ntdb, key, data, NTDB_REPLACE) != 0)
19 return false;
20 if (!ntdb_exists(ntdb, key))
21 return false;
24 for (i = 0; i < 1000; i++) {
25 if (!ntdb_exists(ntdb, key))
26 return false;
27 if (ntdb_delete(ntdb, key) != 0)
28 return false;
29 if (ntdb_exists(ntdb, key))
30 return false;
32 return true;
35 int main(int argc, char *argv[])
37 unsigned int i;
38 struct ntdb_context *ntdb;
39 int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
40 NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
41 NTDB_NOMMAP|NTDB_CONVERT };
43 plan_tests(sizeof(flags) / sizeof(flags[0]) * 2 + 1);
44 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
45 ntdb = ntdb_open("run-14-exists.ntdb", flags[i]|MAYBE_NOSYNC,
46 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
47 if (ok1(ntdb))
48 ok1(test_records(ntdb));
49 ntdb_close(ntdb);
52 ok1(tap_log_messages == 0);
53 return exit_status();