1 /* Make sure write operations fail during ntdb_parse(). */
4 #include "../private.h"
5 #include "tap-interface.h"
7 #include "helpapi-external-agent.h"
9 static struct ntdb_context *ntdb;
11 /* We could get either of these. */
12 static bool xfail(enum NTDB_ERROR ecode)
14 return ecode == NTDB_ERR_RDONLY || ecode == NTDB_ERR_LOCK;
17 static enum NTDB_ERROR parse(NTDB_DATA key, NTDB_DATA data,
20 NTDB_DATA add = ntdb_mkdata("another", strlen("another"));
22 if (!ntdb_deq(data, *expected)) {
23 return NTDB_ERR_EINVAL;
26 /* These should all fail.*/
27 if (!xfail(ntdb_store(ntdb, add, add, NTDB_INSERT))) {
28 return NTDB_ERR_EINVAL;
32 if (!xfail(ntdb_append(ntdb, key, add))) {
33 return NTDB_ERR_EINVAL;
37 if (!xfail(ntdb_delete(ntdb, key))) {
38 return NTDB_ERR_EINVAL;
42 if (!xfail(ntdb_transaction_start(ntdb))) {
43 return NTDB_ERR_EINVAL;
47 if (!xfail(ntdb_chainlock(ntdb, key))) {
48 return NTDB_ERR_EINVAL;
52 if (!xfail(ntdb_lockall(ntdb))) {
53 return NTDB_ERR_EINVAL;
57 if (!xfail(ntdb_wipe_all(ntdb))) {
58 return NTDB_ERR_EINVAL;
62 if (!xfail(ntdb_repack(ntdb))) {
63 return NTDB_ERR_EINVAL;
67 /* Access the record one more time. */
68 if (!ntdb_deq(data, *expected)) {
69 return NTDB_ERR_EINVAL;
75 int main(int argc, char *argv[])
78 int flags[] = { NTDB_DEFAULT, NTDB_NOMMAP, NTDB_CONVERT };
79 NTDB_DATA key = ntdb_mkdata("hello", 5), data = ntdb_mkdata("world", 5);
81 plan_tests(sizeof(flags) / sizeof(flags[0]) * 2 + 1);
82 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
83 ntdb = ntdb_open("api-95-read-only-during-parse.ntdb",
84 flags[i]|MAYBE_NOSYNC,
85 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
86 ok1(ntdb_store(ntdb, key, data, NTDB_INSERT) == NTDB_SUCCESS);
87 ok1(ntdb_parse_record(ntdb, key, parse, &data) == NTDB_SUCCESS);
91 ok1(tap_log_messages == 0);