selftest: smb2.durable-open.delete_on_close1 is not flapping any more
[Samba/gebeck_regimport.git] / lib / ntdb / test / run-features.c
bloba332572deb58764f7e230298eeda65434e6bcbf7
1 #include "ntdb-source.h"
2 #include "tap-interface.h"
3 #include "logging.h"
5 int main(int argc, char *argv[])
7 unsigned int i, j;
8 struct ntdb_context *ntdb;
9 int flags[] = { NTDB_DEFAULT, NTDB_NOMMAP,
10 NTDB_CONVERT, NTDB_NOMMAP|NTDB_CONVERT };
11 NTDB_DATA key = { (unsigned char *)&j, sizeof(j) };
12 NTDB_DATA data = { (unsigned char *)&j, sizeof(j) };
14 plan_tests(sizeof(flags) / sizeof(flags[0]) * 8 + 1);
15 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
16 uint64_t features;
17 ntdb = ntdb_open("run-features.ntdb", flags[i]|MAYBE_NOSYNC,
18 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
19 ok1(ntdb);
20 if (!ntdb)
21 continue;
23 /* Put some stuff in there. */
24 for (j = 0; j < 100; j++) {
25 if (ntdb_store(ntdb, key, data, NTDB_REPLACE) != 0)
26 fail("Storing in ntdb");
29 /* Mess with features fields in hdr. */
30 features = (~NTDB_FEATURE_MASK ^ 1);
31 ok1(ntdb_write_convert(ntdb, offsetof(struct ntdb_header,
32 features_used),
33 &features, sizeof(features)) == 0);
34 ok1(ntdb_write_convert(ntdb, offsetof(struct ntdb_header,
35 features_offered),
36 &features, sizeof(features)) == 0);
37 ntdb_close(ntdb);
39 ntdb = ntdb_open("run-features.ntdb", flags[i]|MAYBE_NOSYNC,
40 O_RDWR, 0, &tap_log_attr);
41 ok1(ntdb);
42 if (!ntdb)
43 continue;
45 /* Should not have changed features offered. */
46 ok1(ntdb_read_convert(ntdb, offsetof(struct ntdb_header,
47 features_offered),
48 &features, sizeof(features)) == 0);
49 ok1(features == (~NTDB_FEATURE_MASK ^ 1));
51 /* Should have cleared unknown bits in features_used. */
52 ok1(ntdb_read_convert(ntdb, offsetof(struct ntdb_header,
53 features_used),
54 &features, sizeof(features)) == 0);
55 ok1(features == (1 & NTDB_FEATURE_MASK));
57 ntdb_close(ntdb);
60 ok1(tap_log_messages == 0);
61 return exit_status();