Revert "libwbclient4: Remove unused composite-based functions"
[Samba.git] / lib / ntdb / test / api-14-exists.c
blobc40d9016cfbd71067f2dbb2b3b88da9d47dfcc1c
1 #include "config.h"
2 #include "ntdb.h"
3 #include "private.h"
4 #include "tap-interface.h"
5 #include "logging.h"
7 static bool test_records(struct ntdb_context *ntdb)
9 int i;
10 NTDB_DATA key = { (unsigned char *)&i, sizeof(i) };
11 NTDB_DATA data = { (unsigned char *)&i, sizeof(i) };
13 for (i = 0; i < 1000; i++) {
14 if (ntdb_exists(ntdb, key))
15 return false;
16 if (ntdb_store(ntdb, key, data, NTDB_REPLACE) != 0)
17 return false;
18 if (!ntdb_exists(ntdb, key))
19 return false;
22 for (i = 0; i < 1000; i++) {
23 if (!ntdb_exists(ntdb, key))
24 return false;
25 if (ntdb_delete(ntdb, key) != 0)
26 return false;
27 if (ntdb_exists(ntdb, key))
28 return false;
30 return true;
33 int main(int argc, char *argv[])
35 unsigned int i;
36 struct ntdb_context *ntdb;
37 int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
38 NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
39 NTDB_NOMMAP|NTDB_CONVERT };
41 plan_tests(sizeof(flags) / sizeof(flags[0]) * 2 + 1);
42 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
43 ntdb = ntdb_open("run-14-exists.ntdb", flags[i]|MAYBE_NOSYNC,
44 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
45 if (ok1(ntdb))
46 ok1(test_records(ntdb));
47 ntdb_close(ntdb);
50 ok1(tap_log_messages == 0);
51 return exit_status();