tdb2: use ccan/err instead of err.h
[ddiss/samba.git] / lib / tdb2 / test / run-tdb1-readonly-check.c
1 /* We should be able to tdb_check a O_RDONLY tdb, and we were previously allowed
2  * to tdb_check() inside a transaction (though that's paranoia!). */
3 #include "tdb2-source.h"
4 #include "tap-interface.h"
5 #include <stdlib.h>
6 #include "logging.h"
7
8 int main(int argc, char *argv[])
9 {
10         struct tdb_context *tdb;
11         TDB_DATA key, data;
12         union tdb_attribute hsize;
13
14         hsize.base.attr = TDB_ATTRIBUTE_TDB1_HASHSIZE;
15         hsize.base.next = &tap_log_attr;
16         hsize.tdb1_hashsize.hsize = 1024;
17
18         plan_tests(10);
19         tdb = tdb_open("run-readonly-check.tdb1",
20                        TDB_VERSION1,
21                        O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
22
23         ok1(tdb);
24         key = tdb_mkdata("hi", strlen("hi"));
25         data = tdb_mkdata("world", strlen("world"));
26
27         ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS);
28         ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
29
30         /* We are also allowed to do a check inside a transaction. */
31         ok1(tdb_transaction_start(tdb) == TDB_SUCCESS);
32         ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
33         ok1(tdb_close(tdb) == 0);
34
35         tdb = tdb_open("run-readonly-check.tdb1",
36                        TDB_DEFAULT, O_RDONLY, 0, &tap_log_attr);
37
38         ok1(tdb);
39         ok1(tdb_store(tdb, key, data, TDB_MODIFY) == TDB_ERR_RDONLY);
40         ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
41         ok1(tdb_close(tdb) == 0);
42
43         return exit_status();
44 }