]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/test/run-12-check.c
tdb2: simplify failtest helper.
[ccan] / ccan / tdb2 / test / run-12-check.c
1 #include <ccan/tdb2/private.h>
2 #include <ccan/failtest/failtest_override.h>
3 #include "tdb2-source.h"
4 #include <ccan/tap/tap.h>
5 #include <ccan/failtest/failtest.h>
6 #include "logging.h"
7 #include "failtest_helper.h"
8
9 int main(int argc, char *argv[])
10 {
11         unsigned int i;
12         struct tdb_context *tdb;
13         int flags[] = { TDB_INTERNAL,
14                         TDB_INTERNAL|TDB_CONVERT,
15                         TDB_CONVERT,
16                         TDB_INTERNAL|TDB_VERSION1,
17                         TDB_VERSION1,
18                         TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
19                         TDB_CONVERT|TDB_VERSION1 };
20         struct tdb_data key = tdb_mkdata("key", 3);
21         struct tdb_data data = tdb_mkdata("data", 4);
22
23         failtest_init(argc, argv);
24         failtest_hook = block_repeat_failures;
25         failtest_exit_check = exit_check_log;
26
27         failtest_suppress = true;
28         plan_tests(sizeof(flags) / sizeof(flags[0]) * 3 + 1);
29         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
30                 tdb = tdb_open("run-12-check.tdb", flags[i],
31                                O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
32                 ok1(tdb);
33                 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
34
35                 /* This is what we really want to test: tdb_check(). */
36                 failtest_suppress = false;
37                 if (!ok1(tdb_check(tdb, NULL, NULL) == 0))
38                         goto fail;
39                 failtest_suppress = true;
40
41                 tdb_close(tdb);
42         }
43         ok1(tap_log_messages == 0);
44         failtest_exit(exit_status());
45
46 fail:
47         failtest_suppress = true;
48         tdb_close(tdb);
49         failtest_exit(exit_status());
50 }