1 #include "private.h" // struct ntdb_context
3 #include "tap-interface.h"
10 int main(int argc
, char *argv
[])
13 struct ntdb_context
*ntdb
;
14 unsigned char *buffer
;
15 int flags
[] = { NTDB_DEFAULT
, NTDB_NOMMAP
,
16 NTDB_CONVERT
, NTDB_NOMMAP
|NTDB_CONVERT
};
17 NTDB_DATA key
= ntdb_mkdata("key", 3);
20 buffer
= malloc(1000);
21 for (i
= 0; i
< 1000; i
++)
24 plan_tests(sizeof(flags
) / sizeof(flags
[0]) * 20 + 1);
26 for (i
= 0; i
< sizeof(flags
) / sizeof(flags
[0]); i
++) {
27 ntdb
= ntdb_open("run-55-transaction.ntdb",
28 flags
[i
]|MAYBE_NOSYNC
,
29 O_RDWR
|O_CREAT
|O_TRUNC
, 0600, &tap_log_attr
);
34 ok1(ntdb_transaction_start(ntdb
) == 0);
37 ok1(ntdb_store(ntdb
, key
, data
, NTDB_INSERT
) == 0);
38 ok1(ntdb_fetch(ntdb
, key
, &data
) == NTDB_SUCCESS
);
39 ok1(data
.dsize
== 1000);
40 ok1(memcmp(data
.dptr
, buffer
, data
.dsize
) == 0);
43 /* Cancelling a transaction means no store */
44 ntdb_transaction_cancel(ntdb
);
45 ok1(ntdb
->file
->allrecord_lock
.count
== 0
46 && ntdb
->file
->num_lockrecs
== 0);
47 ok1(ntdb_check(ntdb
, NULL
, NULL
) == 0);
48 ok1(ntdb_fetch(ntdb
, key
, &data
) == NTDB_ERR_NOEXIST
);
50 /* Commit the transaction. */
51 ok1(ntdb_transaction_start(ntdb
) == 0);
54 ok1(ntdb_store(ntdb
, key
, data
, NTDB_INSERT
) == 0);
55 ok1(ntdb_fetch(ntdb
, key
, &data
) == NTDB_SUCCESS
);
56 ok1(data
.dsize
== 1000);
57 ok1(memcmp(data
.dptr
, buffer
, data
.dsize
) == 0);
59 ok1(ntdb_transaction_commit(ntdb
) == 0);
60 ok1(ntdb
->file
->allrecord_lock
.count
== 0
61 && ntdb
->file
->num_lockrecs
== 0);
62 ok1(ntdb_check(ntdb
, NULL
, NULL
) == 0);
63 ok1(ntdb_fetch(ntdb
, key
, &data
) == NTDB_SUCCESS
);
64 ok1(data
.dsize
== 1000);
65 ok1(memcmp(data
.dptr
, buffer
, data
.dsize
) == 0);
71 ok1(tap_log_messages
== 0);