tdb2: test: convert (non-invasive) run tests to api tests.
[Samba/gbeck.git] / lib / tdb2 / test / api-add-remove-flags.c
blob231b9f6cfeef348d110b7c432bd9031f7a8a1409
1 #include <ccan/tdb2/private.h> // for tdb_context
2 #include <ccan/tdb2/tdb2.h>
3 #include <ccan/tap/tap.h>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include "logging.h"
9 int main(int argc, char *argv[])
11 unsigned int i;
12 struct tdb_context *tdb;
13 int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
14 TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
15 TDB_NOMMAP|TDB_CONVERT,
16 TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
17 TDB_NOMMAP|TDB_VERSION1,
18 TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
19 TDB_CONVERT|TDB_VERSION1,
20 TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
22 plan_tests(173);
23 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
24 tdb = tdb_open("run-add-remove-flags.tdb", flags[i],
25 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
26 ok1(tdb);
27 if (!tdb)
28 continue;
30 ok1(tdb_get_flags(tdb) == tdb->flags);
31 tap_log_messages = 0;
32 tdb_add_flag(tdb, TDB_NOLOCK);
33 if (flags[i] & TDB_INTERNAL)
34 ok1(tap_log_messages == 1);
35 else {
36 ok1(tap_log_messages == 0);
37 ok1(tdb_get_flags(tdb) & TDB_NOLOCK);
40 tap_log_messages = 0;
41 tdb_add_flag(tdb, TDB_NOMMAP);
42 if (flags[i] & TDB_INTERNAL)
43 ok1(tap_log_messages == 1);
44 else {
45 ok1(tap_log_messages == 0);
46 ok1(tdb_get_flags(tdb) & TDB_NOMMAP);
47 ok1(tdb->file->map_ptr == NULL);
50 tap_log_messages = 0;
51 tdb_add_flag(tdb, TDB_NOSYNC);
52 if (flags[i] & TDB_INTERNAL)
53 ok1(tap_log_messages == 1);
54 else {
55 ok1(tap_log_messages == 0);
56 ok1(tdb_get_flags(tdb) & TDB_NOSYNC);
59 ok1(tdb_get_flags(tdb) == tdb->flags);
61 tap_log_messages = 0;
62 tdb_remove_flag(tdb, TDB_NOLOCK);
63 if (flags[i] & TDB_INTERNAL)
64 ok1(tap_log_messages == 1);
65 else {
66 ok1(tap_log_messages == 0);
67 ok1(!(tdb_get_flags(tdb) & TDB_NOLOCK));
70 tap_log_messages = 0;
71 tdb_remove_flag(tdb, TDB_NOMMAP);
72 if (flags[i] & TDB_INTERNAL)
73 ok1(tap_log_messages == 1);
74 else {
75 ok1(tap_log_messages == 0);
76 ok1(!(tdb_get_flags(tdb) & TDB_NOMMAP));
77 ok1(tdb->file->map_ptr != NULL);
80 tap_log_messages = 0;
81 tdb_remove_flag(tdb, TDB_NOSYNC);
82 if (flags[i] & TDB_INTERNAL)
83 ok1(tap_log_messages == 1);
84 else {
85 ok1(tap_log_messages == 0);
86 ok1(!(tdb_get_flags(tdb) & TDB_NOSYNC));
89 tdb_close(tdb);
92 ok1(tap_log_messages == 0);
93 return exit_status();