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