]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/test/api-80-tdb_fd.c
htable: fix bug where first entry has hash of 0 or 1.
[ccan] / ccan / tdb2 / test / api-80-tdb_fd.c
1 #include <ccan/tdb2/tdb2.h>
2 #include <ccan/tap/tap.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include "logging.h"
7
8 int main(int argc, char *argv[])
9 {
10         unsigned int i;
11         struct tdb_context *tdb;
12         int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
13                         TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
14                         TDB_NOMMAP|TDB_CONVERT,
15                         TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
16                         TDB_NOMMAP|TDB_VERSION1,
17                         TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
18                         TDB_CONVERT|TDB_VERSION1,
19                         TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
20
21         plan_tests(sizeof(flags) / sizeof(flags[0]) * 3);
22         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
23                 tdb = tdb_open("api-80-tdb_fd.tdb", flags[i],
24                                O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
25                 if (!ok1(tdb))
26                         continue;
27
28                 if (flags[i] & TDB_INTERNAL)
29                         ok1(tdb_fd(tdb) == -1);
30                 else
31                         ok1(tdb_fd(tdb) > 2);
32                 tdb_close(tdb);
33                 ok1(tap_log_messages == 0);
34         }
35         return exit_status();
36 }