s3:registry: do not use regdb functions during db upgrade
[Samba/gebeck_regimport.git] / lib / tdb2 / test / run-tdb1-hashsize.c
blob8a78196c8258fa59e9fec6bc84488f6632d2d50b
1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
3 #include <stdlib.h>
4 #include <err.h>
5 #include "logging.h"
7 int main(int argc, char *argv[])
9 struct tdb_context *tdb;
10 union tdb_attribute hsize, h2;
12 hsize.base.attr = TDB_ATTRIBUTE_TDB1_HASHSIZE;
13 hsize.base.next = &tap_log_attr;
14 hsize.tdb1_hashsize.hsize = 1024;
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);
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);
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);
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);
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);
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);
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);
60 return exit_status();