summaryrefslogtreecommitdiff
path: root/lib/ntdb/test/api-add-remove-flags.c
blob: c5a3f421fc99c627d12bdd9c79808510d64493c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "private.h" // for ntdb_context
#include "ntdb.h"
#include "tap-interface.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "logging.h"

int main(int argc, char *argv[])
{
	unsigned int i;
	struct ntdb_context *ntdb;
	int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
			NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
			NTDB_NOMMAP|NTDB_CONVERT };

	plan_tests(87);
	for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
		ntdb = ntdb_open("run-add-remove-flags.ntdb",
				 flags[i]|MAYBE_NOSYNC,
				 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
		ok1(ntdb);
		if (!ntdb)
			continue;

		ok1(ntdb_get_flags(ntdb) == ntdb->flags);
		tap_log_messages = 0;
		ntdb_add_flag(ntdb, NTDB_NOLOCK);
		if (flags[i] & NTDB_INTERNAL)
			ok1(tap_log_messages == 1);
		else {
			ok1(tap_log_messages == 0);
			ok1(ntdb_get_flags(ntdb) & NTDB_NOLOCK);
		}

		tap_log_messages = 0;
		ntdb_add_flag(ntdb, NTDB_NOMMAP);
		if (flags[i] & NTDB_INTERNAL)
			ok1(tap_log_messages == 1);
		else {
			ok1(tap_log_messages == 0);
			ok1(ntdb_get_flags(ntdb) & NTDB_NOMMAP);
			ok1(ntdb->file->map_ptr == NULL);
		}

		tap_log_messages = 0;
		ntdb_add_flag(ntdb, NTDB_NOSYNC);
		if (flags[i] & NTDB_INTERNAL)
			ok1(tap_log_messages == 1);
		else {
			ok1(tap_log_messages == 0);
			ok1(ntdb_get_flags(ntdb) & NTDB_NOSYNC);
		}

		ok1(ntdb_get_flags(ntdb) == ntdb->flags);

		tap_log_messages = 0;
		ntdb_remove_flag(ntdb, NTDB_NOLOCK);
		if (flags[i] & NTDB_INTERNAL)
			ok1(tap_log_messages == 1);
		else {
			ok1(tap_log_messages == 0);
			ok1(!(ntdb_get_flags(ntdb) & NTDB_NOLOCK));
		}

		tap_log_messages = 0;
		ntdb_remove_flag(ntdb, NTDB_NOMMAP);
		if (flags[i] & NTDB_INTERNAL)
			ok1(tap_log_messages == 1);
		else {
			ok1(tap_log_messages == 0);
			ok1(!(ntdb_get_flags(ntdb) & NTDB_NOMMAP));
			ok1(ntdb->file->map_ptr != NULL);
		}

		tap_log_messages = 0;
		ntdb_remove_flag(ntdb, NTDB_NOSYNC);
		if (flags[i] & NTDB_INTERNAL)
			ok1(tap_log_messages == 1);
		else {
			ok1(tap_log_messages == 0);
			ok1(!(ntdb_get_flags(ntdb) & NTDB_NOSYNC));
		}

		ntdb_close(ntdb);
	}

	ok1(tap_log_messages == 0);
	return exit_status();
}