1 #define _XOPEN_SOURCE 500
6 #include "tdb/freelist.c"
7 #include "tdb/traverse.c"
8 #include "tdb/transaction.c"
15 int main(int argc, char *argv[])
17 struct tdb_context *tdb;
21 key.dsize = strlen("hi");
22 key.dptr = (void *)"hi";
24 tdb = tdb_open("/tmp/test4.tdb", 1024, TDB_CLEAR_IF_FIRST,
25 O_CREAT|O_TRUNC|O_RDWR, 0600);
28 /* No nesting by default. */
29 ok1(tdb_transaction_start(tdb) == 0);
30 data.dptr = (void *)"world";
31 data.dsize = strlen("world");
32 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
33 data = tdb_fetch(tdb, key);
34 ok1(data.dsize == strlen("world"));
35 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
37 ok1(tdb_transaction_start(tdb) != 0);
38 ok1(tdb_error(tdb) == TDB_ERR_NESTING);
40 data = tdb_fetch(tdb, key);
41 ok1(data.dsize == strlen("world"));
42 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
44 ok1(tdb_transaction_commit(tdb) == 0);
45 data = tdb_fetch(tdb, key);
46 ok1(data.dsize == strlen("world"));
47 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
51 tdb = tdb_open("/tmp/test4.tdb", 1024, TDB_ALLOW_NESTING, O_RDWR, 0);
54 ok1(tdb_transaction_start(tdb) == 0);
55 ok1(tdb_transaction_start(tdb) == 0);
56 ok1(tdb_delete(tdb, key) == 0);
57 ok1(tdb_transaction_commit(tdb) == 0);
58 ok1(!tdb_exists(tdb, key));
59 ok1(tdb_transaction_cancel(tdb) == 0);
60 /* Surprise! Kills inner "committed" transaction. */
61 ok1(tdb_exists(tdb, key));
63 ok1(tdb_transaction_start(tdb) == 0);
64 ok1(tdb_transaction_start(tdb) == 0);
65 ok1(tdb_delete(tdb, key) == 0);
66 ok1(tdb_transaction_commit(tdb) == 0);
67 ok1(!tdb_exists(tdb, key));
68 ok1(tdb_transaction_commit(tdb) == 0);
69 ok1(!tdb_exists(tdb, key));