1 #include <ccan/tdb2/tdb.c>
2 #include <ccan/tdb2/free.c>
3 #include <ccan/tdb2/lock.c>
4 #include <ccan/tdb2/io.c>
5 #include <ccan/tdb2/hash.c>
6 #include <ccan/tdb2/check.c>
7 #include <ccan/tdb2/transaction.c>
8 #include <ccan/tap/tap.h>
11 int main(int argc, char *argv[])
14 struct tdb_context *tdb;
15 unsigned char *buffer;
16 int flags[] = { TDB_DEFAULT, TDB_NOMMAP,
17 TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT };
18 struct tdb_data key = { (unsigned char *)"key", 3 };
21 buffer = malloc(1000);
22 for (i = 0; i < 1000; i++)
25 plan_tests(sizeof(flags) / sizeof(flags[0]) * 18 + 1);
27 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
28 tdb = tdb_open("run-55-transaction.tdb", flags[i],
29 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
34 ok1(tdb_transaction_start(tdb) == 0);
37 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
38 data = tdb_fetch(tdb, key);
39 ok1(data.dsize == 1000);
40 ok1(memcmp(data.dptr, buffer, data.dsize) == 0);
43 /* Cancelling a transaction means no store */
44 tdb_transaction_cancel(tdb);
45 ok1(tdb->allrecord_lock.count == 0 && tdb->num_lockrecs == 0);
46 ok1(tdb_check(tdb, NULL, NULL) == 0);
47 data = tdb_fetch(tdb, key);
49 ok1(data.dptr == NULL);
51 /* Commit the transaction. */
52 ok1(tdb_transaction_start(tdb) == 0);
55 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
56 data = tdb_fetch(tdb, key);
57 ok1(data.dsize == 1000);
58 ok1(memcmp(data.dptr, buffer, data.dsize) == 0);
60 ok1(tdb_transaction_commit(tdb) == 0);
61 ok1(tdb->allrecord_lock.count == 0 && tdb->num_lockrecs == 0);
62 ok1(tdb_check(tdb, NULL, NULL) == 0);
63 data = tdb_fetch(tdb, key);
64 ok1(data.dsize == 1000);
65 ok1(memcmp(data.dptr, buffer, data.dsize) == 0);
71 ok1(tap_log_messages == 0);