Fix missing va_end()s
[ccan] / ccan / ntdb / test / api-add-remove-flags.c
1 #include "../private.h" // for ntdb_context
2 #include "../ntdb.h"
3 #include "tap-interface.h"
4 #include "logging.h"
5 #include "helpapi-external-agent.h"
6
7 int main(int argc, char *argv[])
8 {
9         unsigned int i;
10         struct ntdb_context *ntdb;
11         int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
12                         NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
13                         NTDB_NOMMAP|NTDB_CONVERT };
14
15         plan_tests(87);
16         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
17                 ntdb = ntdb_open("run-add-remove-flags.ntdb",
18                                  flags[i]|MAYBE_NOSYNC,
19                                  O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
20                 ok1(ntdb);
21                 if (!ntdb)
22                         continue;
23
24                 ok1(ntdb_get_flags(ntdb) == ntdb->flags);
25                 tap_log_messages = 0;
26                 ntdb_add_flag(ntdb, NTDB_NOLOCK);
27                 if (flags[i] & NTDB_INTERNAL)
28                         ok1(tap_log_messages == 1);
29                 else {
30                         ok1(tap_log_messages == 0);
31                         ok1(ntdb_get_flags(ntdb) & NTDB_NOLOCK);
32                 }
33
34                 tap_log_messages = 0;
35                 ntdb_add_flag(ntdb, NTDB_NOMMAP);
36                 if (flags[i] & NTDB_INTERNAL)
37                         ok1(tap_log_messages == 1);
38                 else {
39                         ok1(tap_log_messages == 0);
40                         ok1(ntdb_get_flags(ntdb) & NTDB_NOMMAP);
41                         ok1(ntdb->file->map_ptr == NULL);
42                 }
43
44                 tap_log_messages = 0;
45                 ntdb_add_flag(ntdb, NTDB_NOSYNC);
46                 if (flags[i] & NTDB_INTERNAL)
47                         ok1(tap_log_messages == 1);
48                 else {
49                         ok1(tap_log_messages == 0);
50                         ok1(ntdb_get_flags(ntdb) & NTDB_NOSYNC);
51                 }
52
53                 ok1(ntdb_get_flags(ntdb) == ntdb->flags);
54
55                 tap_log_messages = 0;
56                 ntdb_remove_flag(ntdb, NTDB_NOLOCK);
57                 if (flags[i] & NTDB_INTERNAL)
58                         ok1(tap_log_messages == 1);
59                 else {
60                         ok1(tap_log_messages == 0);
61                         ok1(!(ntdb_get_flags(ntdb) & NTDB_NOLOCK));
62                 }
63
64                 tap_log_messages = 0;
65                 ntdb_remove_flag(ntdb, NTDB_NOMMAP);
66                 if (flags[i] & NTDB_INTERNAL)
67                         ok1(tap_log_messages == 1);
68                 else {
69                         ok1(tap_log_messages == 0);
70                         ok1(!(ntdb_get_flags(ntdb) & NTDB_NOMMAP));
71                         ok1(ntdb->file->map_ptr != NULL);
72                 }
73
74                 tap_log_messages = 0;
75                 ntdb_remove_flag(ntdb, NTDB_NOSYNC);
76                 if (flags[i] & NTDB_INTERNAL)
77                         ok1(tap_log_messages == 1);
78                 else {
79                         ok1(tap_log_messages == 0);
80                         ok1(!(ntdb_get_flags(ntdb) & NTDB_NOSYNC));
81                 }
82
83                 ntdb_close(ntdb);
84         }
85
86         ok1(tap_log_messages == 0);
87         return exit_status();
88 }