s3:smbd: add exit_server to the smbd_shim hooks
[Samba/gebeck_regimport.git] / lib / tdb / test / run-nested-transactions.c
blob8c84bcac836a4b2251f472e93241a9d5ec8f4448
1 #include "../common/tdb_private.h"
2 #include "../common/io.c"
3 #include "../common/tdb.c"
4 #include "../common/lock.c"
5 #include "../common/freelist.c"
6 #include "../common/traverse.c"
7 #include "../common/transaction.c"
8 #include "../common/error.c"
9 #include "../common/open.c"
10 #include "../common/check.c"
11 #include "../common/hash.c"
12 #include "tap-interface.h"
13 #include <stdlib.h>
14 #include <stdbool.h>
15 #include "logging.h"
17 int main(int argc, char *argv[])
19 struct tdb_context *tdb;
20 TDB_DATA key, data;
22 plan_tests(27);
23 key.dsize = strlen("hi");
24 key.dptr = (void *)"hi";
26 tdb = tdb_open_ex("run-nested-transactions.tdb",
27 1024, TDB_CLEAR_IF_FIRST|TDB_DISALLOW_NESTING,
28 O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
29 ok1(tdb);
31 /* Nesting disallowed. */
32 ok1(tdb_transaction_start(tdb) == 0);
33 data.dptr = (void *)"world";
34 data.dsize = strlen("world");
35 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
36 data = tdb_fetch(tdb, key);
37 ok1(data.dsize == strlen("world"));
38 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
39 free(data.dptr);
40 ok1(tdb_transaction_start(tdb) != 0);
41 ok1(tdb_error(tdb) == TDB_ERR_NESTING);
43 data = tdb_fetch(tdb, key);
44 ok1(data.dsize == strlen("world"));
45 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
46 free(data.dptr);
47 ok1(tdb_transaction_commit(tdb) == 0);
48 data = tdb_fetch(tdb, key);
49 ok1(data.dsize == strlen("world"));
50 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
51 free(data.dptr);
52 tdb_close(tdb);
54 /* Nesting allowed by default */
55 tdb = tdb_open_ex("run-nested-transactions.tdb",
56 1024, TDB_DEFAULT, O_RDWR, 0, &taplogctx, NULL);
57 ok1(tdb);
59 ok1(tdb_transaction_start(tdb) == 0);
60 ok1(tdb_transaction_start(tdb) == 0);
61 ok1(tdb_delete(tdb, key) == 0);
62 ok1(tdb_transaction_commit(tdb) == 0);
63 ok1(!tdb_exists(tdb, key));
64 ok1(tdb_transaction_cancel(tdb) == 0);
65 /* Surprise! Kills inner "committed" transaction. */
66 ok1(tdb_exists(tdb, key));
68 ok1(tdb_transaction_start(tdb) == 0);
69 ok1(tdb_transaction_start(tdb) == 0);
70 ok1(tdb_delete(tdb, key) == 0);
71 ok1(tdb_transaction_commit(tdb) == 0);
72 ok1(!tdb_exists(tdb, key));
73 ok1(tdb_transaction_commit(tdb) == 0);
74 ok1(!tdb_exists(tdb, key));
75 tdb_close(tdb);
77 return exit_status();