tdb2: test: fix run-57-die-during-transaction.c to be more efficient.
[ccan] / ccan / tdb2 / test / run-add-remove-flags.c
1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
3 #include "logging.h"
4
5 int main(int argc, char *argv[])
6 {
7         unsigned int i;
8         struct tdb_context *tdb;
9         int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
10                         TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, 
11                         TDB_NOMMAP|TDB_CONVERT,
12                         TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
13                         TDB_NOMMAP|TDB_VERSION1,
14                         TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
15                         TDB_CONVERT|TDB_VERSION1,
16                         TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
17
18         plan_tests(173);
19         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
20                 tdb = tdb_open("run-add-remove-flags.tdb", flags[i],
21                                O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
22                 ok1(tdb);
23                 if (!tdb)
24                         continue;
25
26                 ok1(tdb_get_flags(tdb) == tdb->flags);
27                 tap_log_messages = 0;
28                 tdb_add_flag(tdb, TDB_NOLOCK);
29                 if (flags[i] & TDB_INTERNAL)
30                         ok1(tap_log_messages == 1);
31                 else {
32                         ok1(tap_log_messages == 0);
33                         ok1(tdb_get_flags(tdb) & TDB_NOLOCK);
34                 }
35
36                 tap_log_messages = 0;
37                 tdb_add_flag(tdb, TDB_NOMMAP);
38                 if (flags[i] & TDB_INTERNAL)
39                         ok1(tap_log_messages == 1);
40                 else {
41                         ok1(tap_log_messages == 0);
42                         ok1(tdb_get_flags(tdb) & TDB_NOMMAP);
43                         ok1(tdb->file->map_ptr == NULL);
44                 }
45
46                 tap_log_messages = 0;
47                 tdb_add_flag(tdb, TDB_NOSYNC);
48                 if (flags[i] & TDB_INTERNAL)
49                         ok1(tap_log_messages == 1);
50                 else {
51                         ok1(tap_log_messages == 0);
52                         ok1(tdb_get_flags(tdb) & TDB_NOSYNC);
53                 }
54
55                 ok1(tdb_get_flags(tdb) == tdb->flags);
56
57                 tap_log_messages = 0;
58                 tdb_remove_flag(tdb, TDB_NOLOCK);
59                 if (flags[i] & TDB_INTERNAL)
60                         ok1(tap_log_messages == 1);
61                 else {
62                         ok1(tap_log_messages == 0);
63                         ok1(!(tdb_get_flags(tdb) & TDB_NOLOCK));
64                 }
65
66                 tap_log_messages = 0;
67                 tdb_remove_flag(tdb, TDB_NOMMAP);
68                 if (flags[i] & TDB_INTERNAL)
69                         ok1(tap_log_messages == 1);
70                 else {
71                         ok1(tap_log_messages == 0);
72                         ok1(!(tdb_get_flags(tdb) & TDB_NOMMAP));
73                         ok1(tdb->file->map_ptr != NULL);
74                 }
75
76                 tap_log_messages = 0;
77                 tdb_remove_flag(tdb, TDB_NOSYNC);
78                 if (flags[i] & TDB_INTERNAL)
79                         ok1(tap_log_messages == 1);
80                 else {
81                         ok1(tap_log_messages == 0);
82                         ok1(!(tdb_get_flags(tdb) & TDB_NOSYNC));
83                 }
84
85                 tdb_close(tdb);
86         }
87
88         ok1(tap_log_messages == 0);
89         return exit_status();
90 }