tdb: always open internal databases with incompatible hash.
[Samba/wip.git] / lib / ntdb / test / api-add-remove-flags.c
blobc16ceeb2f6a3b8b18d360272182a68ac7b59c921
1 #include "private.h" // for ntdb_context
2 #include "ntdb.h"
3 #include "tap-interface.h"
4 #include "logging.h"
6 int main(int argc, char *argv[])
8 unsigned int i;
9 struct ntdb_context *ntdb;
10 int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
11 NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
12 NTDB_NOMMAP|NTDB_CONVERT };
14 plan_tests(87);
15 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
16 ntdb = ntdb_open("run-add-remove-flags.ntdb",
17 flags[i]|MAYBE_NOSYNC,
18 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
19 ok1(ntdb);
20 if (!ntdb)
21 continue;
23 ok1(ntdb_get_flags(ntdb) == ntdb->flags);
24 tap_log_messages = 0;
25 ntdb_add_flag(ntdb, NTDB_NOLOCK);
26 if (flags[i] & NTDB_INTERNAL)
27 ok1(tap_log_messages == 1);
28 else {
29 ok1(tap_log_messages == 0);
30 ok1(ntdb_get_flags(ntdb) & NTDB_NOLOCK);
33 tap_log_messages = 0;
34 ntdb_add_flag(ntdb, NTDB_NOMMAP);
35 if (flags[i] & NTDB_INTERNAL)
36 ok1(tap_log_messages == 1);
37 else {
38 ok1(tap_log_messages == 0);
39 ok1(ntdb_get_flags(ntdb) & NTDB_NOMMAP);
40 ok1(ntdb->file->map_ptr == NULL);
43 tap_log_messages = 0;
44 ntdb_add_flag(ntdb, NTDB_NOSYNC);
45 if (flags[i] & NTDB_INTERNAL)
46 ok1(tap_log_messages == 1);
47 else {
48 ok1(tap_log_messages == 0);
49 ok1(ntdb_get_flags(ntdb) & NTDB_NOSYNC);
52 ok1(ntdb_get_flags(ntdb) == ntdb->flags);
54 tap_log_messages = 0;
55 ntdb_remove_flag(ntdb, NTDB_NOLOCK);
56 if (flags[i] & NTDB_INTERNAL)
57 ok1(tap_log_messages == 1);
58 else {
59 ok1(tap_log_messages == 0);
60 ok1(!(ntdb_get_flags(ntdb) & NTDB_NOLOCK));
63 tap_log_messages = 0;
64 ntdb_remove_flag(ntdb, NTDB_NOMMAP);
65 if (flags[i] & NTDB_INTERNAL)
66 ok1(tap_log_messages == 1);
67 else {
68 ok1(tap_log_messages == 0);
69 ok1(!(ntdb_get_flags(ntdb) & NTDB_NOMMAP));
70 ok1(ntdb->file->map_ptr != NULL);
73 tap_log_messages = 0;
74 ntdb_remove_flag(ntdb, NTDB_NOSYNC);
75 if (flags[i] & NTDB_INTERNAL)
76 ok1(tap_log_messages == 1);
77 else {
78 ok1(tap_log_messages == 0);
79 ok1(!(ntdb_get_flags(ntdb) & NTDB_NOSYNC));
82 ntdb_close(ntdb);
85 ok1(tap_log_messages == 0);
86 return exit_status();