3 #include "tap-interface.h"
9 int main(int argc
, char *argv
[])
12 struct ntdb_context
*ntdb
;
13 NTDB_DATA key
= ntdb_mkdata("key", 3);
14 NTDB_DATA data
= ntdb_mkdata("data", 4);
15 int flags
[] = { NTDB_DEFAULT
, NTDB_NOMMAP
,
16 NTDB_CONVERT
, NTDB_NOMMAP
|NTDB_CONVERT
};
18 plan_tests(sizeof(flags
) / sizeof(flags
[0]) * 48);
20 for (i
= 0; i
< sizeof(flags
) / sizeof(flags
[0]); i
++) {
22 ntdb
= ntdb_open("run-92-get-set-readonly.ntdb",
23 flags
[i
]|MAYBE_NOSYNC
,
24 O_RDWR
|O_CREAT
|O_TRUNC
, 0600, &tap_log_attr
);
26 ok1(!(ntdb_get_flags(ntdb
) & NTDB_RDONLY
));
28 ok1(ntdb_store(ntdb
, key
, data
, NTDB_INSERT
) == NTDB_SUCCESS
);
30 ntdb_add_flag(ntdb
, NTDB_RDONLY
);
31 ok1(ntdb_get_flags(ntdb
) & NTDB_RDONLY
);
33 /* Can't store, append, delete. */
34 ok1(ntdb_store(ntdb
, key
, data
, NTDB_MODIFY
) == NTDB_ERR_RDONLY
);
35 ok1(tap_log_messages
== 1);
36 ok1(ntdb_append(ntdb
, key
, data
) == NTDB_ERR_RDONLY
);
37 ok1(tap_log_messages
== 2);
38 ok1(ntdb_delete(ntdb
, key
) == NTDB_ERR_RDONLY
);
39 ok1(tap_log_messages
== 3);
41 /* Can't start a transaction, or any write lock. */
42 ok1(ntdb_transaction_start(ntdb
) == NTDB_ERR_RDONLY
);
43 ok1(tap_log_messages
== 4);
44 ok1(ntdb_chainlock(ntdb
, key
) == NTDB_ERR_RDONLY
);
45 ok1(tap_log_messages
== 5);
46 ok1(ntdb_lockall(ntdb
) == NTDB_ERR_RDONLY
);
47 ok1(tap_log_messages
== 6);
48 ok1(ntdb_wipe_all(ntdb
) == NTDB_ERR_RDONLY
);
49 ok1(tap_log_messages
== 7);
52 ntdb_remove_flag(ntdb
, NTDB_RDONLY
);
53 ok1(!(ntdb_get_flags(ntdb
) & NTDB_RDONLY
));
55 ok1(ntdb_store(ntdb
, key
, data
, NTDB_MODIFY
) == NTDB_SUCCESS
);
56 ok1(ntdb_append(ntdb
, key
, data
) == NTDB_SUCCESS
);
57 ok1(ntdb_delete(ntdb
, key
) == NTDB_SUCCESS
);
59 ok1(ntdb_transaction_start(ntdb
) == NTDB_SUCCESS
);
60 ok1(ntdb_store(ntdb
, key
, data
, NTDB_INSERT
) == NTDB_SUCCESS
);
61 ok1(ntdb_transaction_commit(ntdb
) == NTDB_SUCCESS
);
63 ok1(ntdb_chainlock(ntdb
, key
) == NTDB_SUCCESS
);
64 ntdb_chainunlock(ntdb
, key
);
65 ok1(ntdb_lockall(ntdb
) == NTDB_SUCCESS
);
67 ok1(ntdb_wipe_all(ntdb
) == NTDB_SUCCESS
);
68 ok1(tap_log_messages
== 7);
73 ntdb
= ntdb_open("run-92-get-set-readonly.ntdb",
74 flags
[i
]|MAYBE_NOSYNC
,
75 O_RDONLY
, 0600, &tap_log_attr
);
77 ok1(ntdb_get_flags(ntdb
) & NTDB_RDONLY
);
79 /* Can't store, append, delete. */
80 ok1(ntdb_store(ntdb
, key
, data
, NTDB_INSERT
) == NTDB_ERR_RDONLY
);
81 ok1(tap_log_messages
== 8);
82 ok1(ntdb_append(ntdb
, key
, data
) == NTDB_ERR_RDONLY
);
83 ok1(tap_log_messages
== 9);
84 ok1(ntdb_delete(ntdb
, key
) == NTDB_ERR_RDONLY
);
85 ok1(tap_log_messages
== 10);
87 /* Can't start a transaction, or any write lock. */
88 ok1(ntdb_transaction_start(ntdb
) == NTDB_ERR_RDONLY
);
89 ok1(tap_log_messages
== 11);
90 ok1(ntdb_chainlock(ntdb
, key
) == NTDB_ERR_RDONLY
);
91 ok1(tap_log_messages
== 12);
92 ok1(ntdb_lockall(ntdb
) == NTDB_ERR_RDONLY
);
93 ok1(tap_log_messages
== 13);
94 ok1(ntdb_wipe_all(ntdb
) == NTDB_ERR_RDONLY
);
95 ok1(tap_log_messages
== 14);
97 /* Can't remove NTDB_RDONLY since we opened with O_RDONLY */
98 ntdb_remove_flag(ntdb
, NTDB_RDONLY
);
99 ok1(tap_log_messages
== 15);
100 ok1(ntdb_get_flags(ntdb
) & NTDB_RDONLY
);
103 ok1(tap_log_messages
== 15);
104 tap_log_messages
= 0;
106 return exit_status();