]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/test/run-tdb1-hashsize.c
tdb2: test: fix run-57-die-during-transaction.c to be more efficient.
[ccan] / ccan / tdb2 / test / run-tdb1-hashsize.c
1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
3 #include <stdlib.h>
4 #include <err.h>
5 #include "logging.h"
6
7 int main(int argc, char *argv[])
8 {
9         struct tdb_context *tdb;
10         union tdb_attribute hsize, h2;
11
12         hsize.base.attr = TDB_ATTRIBUTE_TDB1_HASHSIZE;
13         hsize.base.next = &tap_log_attr;
14         hsize.tdb1_hashsize.hsize = 1024;
15
16         plan_tests(14);
17         tdb = tdb_open("run-tdb1-hashsize.tdb1", TDB_VERSION1,
18                        O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
19         ok1(tdb);
20         h2.base.attr = TDB_ATTRIBUTE_TDB1_HASHSIZE;
21         ok1(tdb_get_attribute(tdb, &h2) == TDB_SUCCESS);
22         ok1(h2.tdb1_hashsize.hsize == hsize.tdb1_hashsize.hsize);
23         tdb_close(tdb);
24
25         /* Can't specify TDB_ATTRIBUTE_TDB1_HASHSIZE without O_CREAT */
26         tdb = tdb_open("run-tdb1-hashsize.tdb1", TDB_VERSION1,
27                        O_RDWR, 0600, &hsize);
28         ok1(!tdb);
29         ok1(tap_log_messages == 1);
30
31         /* Can't specify TDB_ATTRIBUTE_TDB1_HASHSIZE for version2. */
32         tdb = tdb_open("run-tdb1-hashsize.tdb", TDB_DEFAULT,
33                         O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
34         ok1(!tdb);
35         ok1(tap_log_messages == 2);
36
37         /* We can get attribute even if we didn't set it though. */
38         tdb = tdb_open("run-tdb1-hashsize.tdb1", TDB_DEFAULT,
39                        O_RDWR, 0600, &tap_log_attr);
40
41         ok1(tdb);
42         memset(&h2, 0, sizeof(h2));
43         h2.base.attr = TDB_ATTRIBUTE_TDB1_HASHSIZE;
44         ok1(tdb_get_attribute(tdb, &h2) == TDB_SUCCESS);
45         ok1(h2.tdb1_hashsize.hsize == hsize.tdb1_hashsize.hsize);
46         tdb_close(tdb);
47
48         /* Check for default hash size. */
49         tdb = tdb_open("run-tdb1-hashsize.tdb1", TDB_VERSION1,
50                        O_CREAT|O_TRUNC|O_RDWR, 0600, &tap_log_attr);
51
52         ok1(tdb);
53         memset(&h2, 0, sizeof(h2));
54         h2.base.attr = TDB_ATTRIBUTE_TDB1_HASHSIZE;
55         ok1(tdb_get_attribute(tdb, &h2) == TDB_SUCCESS);
56         ok1(h2.tdb1_hashsize.hsize == TDB1_DEFAULT_HASH_SIZE);
57         tdb_close(tdb);
58         ok1(tap_log_messages == 2);
59
60         return exit_status();
61 }