]> git.ozlabs.org Git - ccan/blob - ccan/ntdb/test/run-35-convert.c
ntdb: fix up tests.
[ccan] / ccan / ntdb / test / run-35-convert.c
1 #include "../private.h"
2 #include <ccan/failtest/failtest_override.h>
3 #include "ntdb-source.h"
4 #include "tap-interface.h"
5 #include <ccan/failtest/failtest.h>
6 #include "logging.h"
7 #include "failtest_helper.h"
8 #include "helprun-external-agent.h"
9
10 int main(int argc, char *argv[])
11 {
12         unsigned int i, messages = 0;
13         struct ntdb_context *ntdb;
14         int flags[] = { NTDB_DEFAULT, NTDB_NOMMAP,
15                         NTDB_CONVERT, NTDB_NOMMAP|NTDB_CONVERT };
16
17         failtest_init(argc, argv);
18         failtest_hook = block_repeat_failures;
19         failtest_exit_check = exit_check_log;
20         plan_tests(sizeof(flags) / sizeof(flags[0]) * 4);
21         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
22                 ntdb = ntdb_open("run-35-convert.ntdb", flags[i]|MAYBE_NOSYNC,
23                                  O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
24                 if (!ok1(ntdb))
25                         failtest_exit(exit_status());
26
27                 ntdb_close(ntdb);
28                 /* We can fail in log message formatting or open.  That's OK */
29                 if (failtest_has_failed()) {
30                         failtest_exit(exit_status());
31                 }
32                 /* If we say NTDB_CONVERT, it must be converted */
33                 ntdb = ntdb_open("run-35-convert.ntdb",
34                                  flags[i]|NTDB_CONVERT|MAYBE_NOSYNC,
35                                  O_RDWR, 0600, &tap_log_attr);
36                 if (flags[i] & NTDB_CONVERT) {
37                         if (!ntdb)
38                                 failtest_exit(exit_status());
39                         ok1(ntdb_get_flags(ntdb) & NTDB_CONVERT);
40                         ntdb_close(ntdb);
41                 } else {
42                         if (!ok1(!ntdb && errno == EIO))
43                                 failtest_exit(exit_status());
44                         ok1(tap_log_messages == ++messages);
45                         if (!ok1(log_last && strstr(log_last, "NTDB_CONVERT")))
46                                 failtest_exit(exit_status());
47                 }
48
49                 /* If don't say NTDB_CONVERT, it *may* be converted */
50                 ntdb = ntdb_open("run-35-convert.ntdb",
51                                  (flags[i] & ~NTDB_CONVERT)|MAYBE_NOSYNC,
52                                  O_RDWR, 0600, &tap_log_attr);
53                 if (!ntdb)
54                         failtest_exit(exit_status());
55                 ok1(ntdb_get_flags(ntdb) == (flags[i]|MAYBE_NOSYNC));
56                 ntdb_close(ntdb);
57         }
58         failtest_exit(exit_status());
59
60         /*
61          * We will never reach this but the compiler complains if we do not
62          * return in this function.
63          */
64         return EFAULT;
65 }