3 #include "../private.h"
4 #include "tap-interface.h"
6 #include "helpapi-external-agent.h"
8 int main(int argc, char *argv[])
11 struct ntdb_context *ntdb;
12 NTDB_DATA key = ntdb_mkdata("key", 3);
13 NTDB_DATA data = ntdb_mkdata("data", 4);
14 int flags[] = { NTDB_DEFAULT, NTDB_NOMMAP,
15 NTDB_CONVERT, NTDB_NOMMAP|NTDB_CONVERT };
17 plan_tests(sizeof(flags) / sizeof(flags[0]) * 48);
19 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
21 ntdb = ntdb_open("run-92-get-set-readonly.ntdb",
22 flags[i]|MAYBE_NOSYNC,
23 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
25 ok1(!(ntdb_get_flags(ntdb) & NTDB_RDONLY));
27 ok1(ntdb_store(ntdb, key, data, NTDB_INSERT) == NTDB_SUCCESS);
29 ntdb_add_flag(ntdb, NTDB_RDONLY);
30 ok1(ntdb_get_flags(ntdb) & NTDB_RDONLY);
32 /* Can't store, append, delete. */
33 ok1(ntdb_store(ntdb, key, data, NTDB_MODIFY) == NTDB_ERR_RDONLY);
34 ok1(tap_log_messages == 1);
35 ok1(ntdb_append(ntdb, key, data) == NTDB_ERR_RDONLY);
36 ok1(tap_log_messages == 2);
37 ok1(ntdb_delete(ntdb, key) == NTDB_ERR_RDONLY);
38 ok1(tap_log_messages == 3);
40 /* Can't start a transaction, or any write lock. */
41 ok1(ntdb_transaction_start(ntdb) == NTDB_ERR_RDONLY);
42 ok1(tap_log_messages == 4);
43 ok1(ntdb_chainlock(ntdb, key) == NTDB_ERR_RDONLY);
44 ok1(tap_log_messages == 5);
45 ok1(ntdb_lockall(ntdb) == NTDB_ERR_RDONLY);
46 ok1(tap_log_messages == 6);
47 ok1(ntdb_wipe_all(ntdb) == NTDB_ERR_RDONLY);
48 ok1(tap_log_messages == 7);
51 ntdb_remove_flag(ntdb, NTDB_RDONLY);
52 ok1(!(ntdb_get_flags(ntdb) & NTDB_RDONLY));
54 ok1(ntdb_store(ntdb, key, data, NTDB_MODIFY) == NTDB_SUCCESS);
55 ok1(ntdb_append(ntdb, key, data) == NTDB_SUCCESS);
56 ok1(ntdb_delete(ntdb, key) == NTDB_SUCCESS);
58 ok1(ntdb_transaction_start(ntdb) == NTDB_SUCCESS);
59 ok1(ntdb_store(ntdb, key, data, NTDB_INSERT) == NTDB_SUCCESS);
60 ok1(ntdb_transaction_commit(ntdb) == NTDB_SUCCESS);
62 ok1(ntdb_chainlock(ntdb, key) == NTDB_SUCCESS);
63 ntdb_chainunlock(ntdb, key);
64 ok1(ntdb_lockall(ntdb) == NTDB_SUCCESS);
66 ok1(ntdb_wipe_all(ntdb) == NTDB_SUCCESS);
67 ok1(tap_log_messages == 7);
72 ntdb = ntdb_open("run-92-get-set-readonly.ntdb",
73 flags[i]|MAYBE_NOSYNC,
74 O_RDONLY, 0600, &tap_log_attr);
76 ok1(ntdb_get_flags(ntdb) & NTDB_RDONLY);
78 /* Can't store, append, delete. */
79 ok1(ntdb_store(ntdb, key, data, NTDB_INSERT) == NTDB_ERR_RDONLY);
80 ok1(tap_log_messages == 8);
81 ok1(ntdb_append(ntdb, key, data) == NTDB_ERR_RDONLY);
82 ok1(tap_log_messages == 9);
83 ok1(ntdb_delete(ntdb, key) == NTDB_ERR_RDONLY);
84 ok1(tap_log_messages == 10);
86 /* Can't start a transaction, or any write lock. */
87 ok1(ntdb_transaction_start(ntdb) == NTDB_ERR_RDONLY);
88 ok1(tap_log_messages == 11);
89 ok1(ntdb_chainlock(ntdb, key) == NTDB_ERR_RDONLY);
90 ok1(tap_log_messages == 12);
91 ok1(ntdb_lockall(ntdb) == NTDB_ERR_RDONLY);
92 ok1(tap_log_messages == 13);
93 ok1(ntdb_wipe_all(ntdb) == NTDB_ERR_RDONLY);
94 ok1(tap_log_messages == 14);
96 /* Can't remove NTDB_RDONLY since we opened with O_RDONLY */
97 ntdb_remove_flag(ntdb, NTDB_RDONLY);
98 ok1(tap_log_messages == 15);
99 ok1(ntdb_get_flags(ntdb) & NTDB_RDONLY);
102 ok1(tap_log_messages == 15);
103 tap_log_messages = 0;
105 return exit_status();