ccan: Cast getpid() result to unsigned int for GNU/Solaris build
[Samba/gbeck.git] / lib / ntdb / test / api-60-noop-transaction.c
bloba429e679074e57526f7373c26ea519e099aacad2
1 #include "private.h" // struct ntdb_context
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 <stdlib.h>
8 #include "logging.h"
10 int main(int argc, char *argv[])
12 unsigned int i;
13 struct ntdb_context *ntdb;
14 int flags[] = { NTDB_DEFAULT, NTDB_NOMMAP,
15 NTDB_CONVERT, NTDB_NOMMAP|NTDB_CONVERT };
16 NTDB_DATA key = ntdb_mkdata("key", 3);
17 NTDB_DATA data = ntdb_mkdata("data", 4), d;
19 plan_tests(sizeof(flags) / sizeof(flags[0]) * 12 + 1);
21 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
22 ntdb = ntdb_open("api-60-transaction.ntdb",
23 flags[i]|MAYBE_NOSYNC,
24 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
25 ok1(ntdb);
26 if (!ntdb)
27 continue;
29 ok1(ntdb_store(ntdb, key, data, NTDB_INSERT) == 0);
31 ok1(ntdb_transaction_start(ntdb) == 0);
32 /* Do an identical replace. */
33 ok1(ntdb_store(ntdb, key, data, NTDB_REPLACE) == 0);
34 ok1(ntdb_transaction_commit(ntdb) == 0);
36 ok1(ntdb_check(ntdb, NULL, NULL) == 0);
37 ok1(ntdb_fetch(ntdb, key, &d) == NTDB_SUCCESS);
38 ok1(ntdb_deq(data, d));
39 free(d.dptr);
40 ntdb_close(ntdb);
42 /* Reopen, fetch. */
43 ntdb = ntdb_open("api-60-transaction.ntdb",
44 flags[i]|MAYBE_NOSYNC,
45 O_RDWR, 0600, &tap_log_attr);
46 ok1(ntdb);
47 if (!ntdb)
48 continue;
49 ok1(ntdb_check(ntdb, NULL, NULL) == 0);
50 ok1(ntdb_fetch(ntdb, key, &d) == NTDB_SUCCESS);
51 ok1(ntdb_deq(data, d));
52 free(d.dptr);
53 ntdb_close(ntdb);
56 ok1(tap_log_messages == 0);
57 return exit_status();