]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/test/run-tdb1-readonly-check.c
tdb2: make tdb1_open use attributes for logging, hash function.
[ccan] / ccan / tdb2 / test / run-tdb1-readonly-check.c
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 "logging.h"
8
9 int main(int argc, char *argv[])
10 {
11         struct tdb_context *tdb;
12         TDB_DATA key, data;
13
14         plan_tests(11);
15         tdb = tdb1_open("run-readonly-check.tdb", 1024,
16                         TDB_DEFAULT,
17                         O_CREAT|O_TRUNC|O_RDWR, 0600, &tap_log_attr);
18
19         ok1(tdb);
20         key.dsize = strlen("hi");
21         key.dptr = (void *)"hi";
22         data.dsize = strlen("world");
23         data.dptr = (void *)"world";
24
25         ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
26         ok1(tdb1_check(tdb, NULL, NULL) == 0);
27
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);
32
33         tdb = tdb1_open("run-readonly-check.tdb", 1024,
34                         TDB_DEFAULT, O_RDONLY, 0, &tap_log_attr);
35
36         ok1(tdb);
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);
41
42         return exit_status();
43 }