1 /* Make sure write operations fail during ntdb_parse(). */
4 #include "tap-interface.h"
10 static struct ntdb_context
*ntdb
;
12 /* We could get either of these. */
13 static bool xfail(enum NTDB_ERROR ecode
)
15 return ecode
== NTDB_ERR_RDONLY
|| ecode
== NTDB_ERR_LOCK
;
18 static enum NTDB_ERROR
parse(NTDB_DATA key
, NTDB_DATA data
,
21 NTDB_DATA add
= ntdb_mkdata("another", strlen("another"));
23 if (!ntdb_deq(data
, *expected
)) {
24 return NTDB_ERR_EINVAL
;
27 /* These should all fail.*/
28 if (!xfail(ntdb_store(ntdb
, add
, add
, NTDB_INSERT
))) {
29 return NTDB_ERR_EINVAL
;
33 if (!xfail(ntdb_append(ntdb
, key
, add
))) {
34 return NTDB_ERR_EINVAL
;
38 if (!xfail(ntdb_delete(ntdb
, key
))) {
39 return NTDB_ERR_EINVAL
;
43 if (!xfail(ntdb_transaction_start(ntdb
))) {
44 return NTDB_ERR_EINVAL
;
48 if (!xfail(ntdb_chainlock(ntdb
, key
))) {
49 return NTDB_ERR_EINVAL
;
53 if (!xfail(ntdb_lockall(ntdb
))) {
54 return NTDB_ERR_EINVAL
;
58 if (!xfail(ntdb_wipe_all(ntdb
))) {
59 return NTDB_ERR_EINVAL
;
63 if (!xfail(ntdb_repack(ntdb
))) {
64 return NTDB_ERR_EINVAL
;
68 /* Access the record one more time. */
69 if (!ntdb_deq(data
, *expected
)) {
70 return NTDB_ERR_EINVAL
;
76 int main(int argc
, char *argv
[])
79 int flags
[] = { NTDB_DEFAULT
, NTDB_NOMMAP
, NTDB_CONVERT
};
80 NTDB_DATA key
= ntdb_mkdata("hello", 5), data
= ntdb_mkdata("world", 5);
82 plan_tests(sizeof(flags
) / sizeof(flags
[0]) * 2 + 1);
83 for (i
= 0; i
< sizeof(flags
) / sizeof(flags
[0]); i
++) {
84 ntdb
= ntdb_open("api-95-read-only-during-parse.ntdb",
85 flags
[i
]|MAYBE_NOSYNC
,
86 O_RDWR
|O_CREAT
|O_TRUNC
, 0600, &tap_log_attr
);
87 ok1(ntdb_store(ntdb
, key
, data
, NTDB_INSERT
) == NTDB_SUCCESS
);
88 ok1(ntdb_parse_record(ntdb
, key
, parse
, &data
) == NTDB_SUCCESS
);
92 ok1(tap_log_messages
== 0);