3 #include "tap-interface.h"
9 #include "../private.h"
11 int main(int argc
, char *argv
[])
14 struct ntdb_context
*ntdb
, *ntdb2
;
15 NTDB_DATA key
= { (unsigned char *)&i
, sizeof(i
) };
16 NTDB_DATA data
= { (unsigned char *)&i
, sizeof(i
) };
17 NTDB_DATA d
= { NULL
, 0 }; /* Bogus GCC warning */
18 int flags
[] = { NTDB_DEFAULT
, NTDB_NOMMAP
,
19 NTDB_CONVERT
, NTDB_NOMMAP
|NTDB_CONVERT
};
21 plan_tests(sizeof(flags
) / sizeof(flags
[0]) * 30);
22 for (i
= 0; i
< sizeof(flags
) / sizeof(flags
[0]); i
++) {
23 ntdb
= ntdb_open("run-open-multiple-times.ntdb",
24 flags
[i
]|MAYBE_NOSYNC
,
25 O_RDWR
|O_CREAT
|O_TRUNC
, 0600, &tap_log_attr
);
30 ntdb2
= ntdb_open("run-open-multiple-times.ntdb",
31 flags
[i
]|MAYBE_NOSYNC
,
32 O_RDWR
|O_CREAT
, 0600, &tap_log_attr
);
33 ok1(ntdb_check(ntdb
, NULL
, NULL
) == 0);
34 ok1(ntdb_check(ntdb2
, NULL
, NULL
) == 0);
35 ok1((flags
[i
] & NTDB_NOMMAP
) || ntdb2
->file
->map_ptr
);
37 /* Store in one, fetch in the other. */
38 ok1(ntdb_store(ntdb
, key
, data
, NTDB_REPLACE
) == 0);
39 ok1(ntdb_fetch(ntdb2
, key
, &d
) == NTDB_SUCCESS
);
40 ok1(ntdb_deq(d
, data
));
43 /* Vice versa, with delete. */
44 ok1(ntdb_delete(ntdb2
, key
) == 0);
45 ok1(ntdb_fetch(ntdb
, key
, &d
) == NTDB_ERR_NOEXIST
);
47 /* OK, now close first one, check second still good. */
48 ok1(ntdb_close(ntdb
) == 0);
50 ok1((flags
[i
] & NTDB_NOMMAP
) || ntdb2
->file
->map_ptr
);
51 ok1(ntdb_store(ntdb2
, key
, data
, NTDB_REPLACE
) == 0);
52 ok1(ntdb_fetch(ntdb2
, key
, &d
) == NTDB_SUCCESS
);
53 ok1(ntdb_deq(d
, data
));
57 ntdb
= ntdb_open("run-open-multiple-times.ntdb",
58 flags
[i
]|MAYBE_NOSYNC
,
59 O_RDWR
|O_CREAT
, 0600, &tap_log_attr
);
62 ok1(ntdb_transaction_start(ntdb2
) == 0);
64 /* Anything in the other one should fail. */
65 ok1(ntdb_fetch(ntdb
, key
, &d
) == NTDB_ERR_LOCK
);
66 ok1(tap_log_messages
== 1);
67 ok1(ntdb_store(ntdb
, key
, data
, NTDB_REPLACE
) == NTDB_ERR_LOCK
);
68 ok1(tap_log_messages
== 2);
69 ok1(ntdb_transaction_start(ntdb
) == NTDB_ERR_LOCK
);
70 ok1(tap_log_messages
== 3);
71 ok1(ntdb_chainlock(ntdb
, key
) == NTDB_ERR_LOCK
);
72 ok1(tap_log_messages
== 4);
74 /* Transaciton should work as normal. */
75 ok1(ntdb_store(ntdb2
, key
, data
, NTDB_REPLACE
) == NTDB_SUCCESS
);
77 /* Now... try closing with locks held. */
78 ok1(ntdb_close(ntdb2
) == 0);
80 ok1(ntdb_fetch(ntdb
, key
, &d
) == NTDB_SUCCESS
);
81 ok1(ntdb_deq(d
, data
));
83 ok1(ntdb_close(ntdb
) == 0);
84 ok1(tap_log_messages
== 4);