1 #include <ccan/tdb2/private.h> // for tdb_context
2 #include <ccan/tdb2/tdb2.h>
3 #include <ccan/tap/tap.h>
9 int main(int argc
, char *argv
[])
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
};
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
);
30 ok1(tdb_get_flags(tdb
) == tdb
->flags
);
32 tdb_add_flag(tdb
, TDB_NOLOCK
);
33 if (flags
[i
] & TDB_INTERNAL
)
34 ok1(tap_log_messages
== 1);
36 ok1(tap_log_messages
== 0);
37 ok1(tdb_get_flags(tdb
) & TDB_NOLOCK
);
41 tdb_add_flag(tdb
, TDB_NOMMAP
);
42 if (flags
[i
] & TDB_INTERNAL
)
43 ok1(tap_log_messages
== 1);
45 ok1(tap_log_messages
== 0);
46 ok1(tdb_get_flags(tdb
) & TDB_NOMMAP
);
47 ok1(tdb
->file
->map_ptr
== NULL
);
51 tdb_add_flag(tdb
, TDB_NOSYNC
);
52 if (flags
[i
] & TDB_INTERNAL
)
53 ok1(tap_log_messages
== 1);
55 ok1(tap_log_messages
== 0);
56 ok1(tdb_get_flags(tdb
) & TDB_NOSYNC
);
59 ok1(tdb_get_flags(tdb
) == tdb
->flags
);
62 tdb_remove_flag(tdb
, TDB_NOLOCK
);
63 if (flags
[i
] & TDB_INTERNAL
)
64 ok1(tap_log_messages
== 1);
66 ok1(tap_log_messages
== 0);
67 ok1(!(tdb_get_flags(tdb
) & TDB_NOLOCK
));
71 tdb_remove_flag(tdb
, TDB_NOMMAP
);
72 if (flags
[i
] & TDB_INTERNAL
)
73 ok1(tap_log_messages
== 1);
75 ok1(tap_log_messages
== 0);
76 ok1(!(tdb_get_flags(tdb
) & TDB_NOMMAP
));
77 ok1(tdb
->file
->map_ptr
!= NULL
);
81 tdb_remove_flag(tdb
, TDB_NOSYNC
);
82 if (flags
[i
] & TDB_INTERNAL
)
83 ok1(tap_log_messages
== 1);
85 ok1(tap_log_messages
== 0);
86 ok1(!(tdb_get_flags(tdb
) & TDB_NOSYNC
));
92 ok1(tap_log_messages
== 0);