1 /* We should be able to tdb1_check a O_RDONLY tdb, and we were previously allowed
2 * to tdb1_check() inside a transaction (though that's paranoia!). */
3 #include "tdb2-source.h"
4 #include <ccan/tap/tap.h>
7 #include "tdb1-logging.h"
9 int main(int argc, char *argv[])
11 struct tdb1_context *tdb;
15 tdb = tdb1_open_ex("run-readonly-check.tdb", 1024,
17 O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
20 key.dsize = strlen("hi");
21 key.dptr = (void *)"hi";
22 data.dsize = strlen("world");
23 data.dptr = (void *)"world";
25 ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
26 ok1(tdb1_check(tdb, NULL, NULL) == 0);
28 /* We are also allowed to do a check inside a transaction. */
29 ok1(tdb1_transaction_start(tdb) == 0);
30 ok1(tdb1_check(tdb, NULL, NULL) == 0);
31 ok1(tdb1_close(tdb) == 0);
33 tdb = tdb1_open_ex("run-readonly-check.tdb", 1024,
34 TDB_DEFAULT, O_RDONLY, 0, &taplogctx, NULL);
37 ok1(tdb1_store(tdb, key, data, TDB_MODIFY) == -1);
38 ok1(tdb_error(tdb) == TDB_ERR_RDONLY);
39 ok1(tdb1_check(tdb, NULL, NULL) == 0);
40 ok1(tdb1_close(tdb) == 0);