1 /* Make sure write operations fail during ntdb_parse(). */
5 #include "tap-interface.h"
8 static struct ntdb_context *ntdb;
10 /* We could get either of these. */
11 static bool xfail(enum NTDB_ERROR ecode)
13 return ecode == NTDB_ERR_RDONLY || ecode == NTDB_ERR_LOCK;
16 static enum NTDB_ERROR parse(NTDB_DATA key, NTDB_DATA data,
19 NTDB_DATA add = ntdb_mkdata("another", strlen("another"));
21 if (!ntdb_deq(data, *expected)) {
22 return NTDB_ERR_EINVAL;
25 /* These should all fail.*/
26 if (!xfail(ntdb_store(ntdb, add, add, NTDB_INSERT))) {
27 return NTDB_ERR_EINVAL;
31 if (!xfail(ntdb_append(ntdb, key, add))) {
32 return NTDB_ERR_EINVAL;
36 if (!xfail(ntdb_delete(ntdb, key))) {
37 return NTDB_ERR_EINVAL;
41 if (!xfail(ntdb_transaction_start(ntdb))) {
42 return NTDB_ERR_EINVAL;
46 if (!xfail(ntdb_chainlock(ntdb, key))) {
47 return NTDB_ERR_EINVAL;
51 if (!xfail(ntdb_lockall(ntdb))) {
52 return NTDB_ERR_EINVAL;
56 if (!xfail(ntdb_wipe_all(ntdb))) {
57 return NTDB_ERR_EINVAL;
61 if (!xfail(ntdb_repack(ntdb))) {
62 return NTDB_ERR_EINVAL;
66 /* Access the record one more time. */
67 if (!ntdb_deq(data, *expected)) {
68 return NTDB_ERR_EINVAL;
74 int main(int argc, char *argv[])
77 int flags[] = { NTDB_DEFAULT, NTDB_NOMMAP, NTDB_CONVERT };
78 NTDB_DATA key = ntdb_mkdata("hello", 5), data = ntdb_mkdata("world", 5);
80 plan_tests(sizeof(flags) / sizeof(flags[0]) * 2 + 1);
81 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
82 ntdb = ntdb_open("api-95-read-only-during-parse.ntdb",
83 flags[i]|MAYBE_NOSYNC,
84 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
85 ok1(ntdb_store(ntdb, key, data, NTDB_INSERT) == NTDB_SUCCESS);
86 ok1(ntdb_parse_record(ntdb, key, parse, &data) == NTDB_SUCCESS);
90 ok1(tap_log_messages == 0);