tdb2: make TDB1 code use tdb2's TDB_ERROR and tdb_logerr()
[Samba/gbeck.git] / lib / tdb2 / test / run-tdb1-readonly-check.c
blob6bfa0dc3f5ad4ac434c88c24c5c4b56532094a71
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>
5 #include <stdlib.h>
6 #include <err.h>
7 #include "tdb1-logging.h"
9 int main(int argc, char *argv[])
11 struct tdb1_context *tdb;
12 TDB1_DATA key, data;
14 plan_tests(11);
15 tdb = tdb1_open_ex("run-readonly-check.tdb", 1024,
16 TDB1_DEFAULT,
17 O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
19 ok1(tdb);
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, TDB1_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 TDB1_DEFAULT, O_RDONLY, 0, &taplogctx, NULL);
36 ok1(tdb);
37 ok1(tdb1_store(tdb, key, data, TDB1_MODIFY) == -1);
38 ok1(tdb_error(tdb) == TDB_ERR_RDONLY);
39 ok1(tdb1_check(tdb, NULL, NULL) == 0);
40 ok1(tdb1_close(tdb) == 0);
42 return exit_status();