tdb2: tdb_name and tdb_fd functions.
[ccan] / ccan / tdb2 / test / run-80-tdb_fd.c
1 #include <ccan/tdb2/tdb.c>
2 #include <ccan/tdb2/open.c>
3 #include <ccan/tdb2/free.c>
4 #include <ccan/tdb2/lock.c>
5 #include <ccan/tdb2/io.c>
6 #include <ccan/tdb2/hash.c>
7 #include <ccan/tdb2/transaction.c>
8 #include <ccan/tdb2/check.c>
9 #include <ccan/tap/tap.h>
10 #include "logging.h"
11
12 int main(int argc, char *argv[])
13 {
14         unsigned int i;
15         struct tdb_context *tdb;
16         int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
17                         TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, 
18                         TDB_NOMMAP|TDB_CONVERT };
19
20         plan_tests(sizeof(flags) / sizeof(flags[0]) * 3);
21         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
22                 tdb = tdb_open("run-new_database.tdb", flags[i],
23                                O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
24                 if (!ok1(tdb))
25                         continue;
26
27                 if (flags[i] & TDB_INTERNAL)
28                         ok1(tdb_fd(tdb) == -1);
29                 else
30                         ok1(tdb_fd(tdb) > 2);
31                 tdb_close(tdb);
32                 ok1(tap_log_messages == 0);
33         }
34         return exit_status();
35 }