3 #include "tap-interface.h"
10 int main(int argc
, char *argv
[])
12 unsigned int i
, extra_messages
;
13 struct tdb_context
*tdb
, *tdb2
;
14 struct tdb_data key
= { (unsigned char *)&i
, sizeof(i
) };
15 struct tdb_data data
= { (unsigned char *)&i
, sizeof(i
) };
16 struct tdb_data d
= { NULL
, 0 }; /* Bogus GCC warning */
17 int flags
[] = { TDB_DEFAULT
, TDB_NOMMAP
,
18 TDB_CONVERT
, TDB_NOMMAP
|TDB_CONVERT
,
19 TDB_VERSION1
, TDB_NOMMAP
|TDB_VERSION1
,
20 TDB_CONVERT
|TDB_VERSION1
,
21 TDB_NOMMAP
|TDB_CONVERT
|TDB_VERSION1
};
23 plan_tests(sizeof(flags
) / sizeof(flags
[0]) * 28);
24 for (i
= 0; i
< sizeof(flags
) / sizeof(flags
[0]); i
++) {
25 tdb
= tdb_open("run-open-multiple-times.tdb", flags
[i
],
26 O_RDWR
|O_CREAT
|O_TRUNC
, 0600, &tap_log_attr
);
31 if (flags
[i
] & TDB_VERSION1
) {
36 tdb2
= tdb_open("run-open-multiple-times.tdb", flags
[i
],
37 O_RDWR
|O_CREAT
, 0600, &tap_log_attr
);
38 ok1(tdb_check(tdb
, NULL
, NULL
) == 0);
39 ok1(tdb_check(tdb2
, NULL
, NULL
) == 0);
41 /* Store in one, fetch in the other. */
42 ok1(tdb_store(tdb
, key
, data
, TDB_REPLACE
) == 0);
43 ok1(tdb_fetch(tdb2
, key
, &d
) == TDB_SUCCESS
);
44 ok1(tdb_deq(d
, data
));
47 /* Vice versa, with delete. */
48 ok1(tdb_delete(tdb2
, key
) == 0);
49 ok1(tdb_fetch(tdb
, key
, &d
) == TDB_ERR_NOEXIST
);
51 /* OK, now close first one, check second still good. */
52 ok1(tdb_close(tdb
) == 0);
54 ok1(tdb_store(tdb2
, key
, data
, TDB_REPLACE
) == 0);
55 ok1(tdb_fetch(tdb2
, key
, &d
) == TDB_SUCCESS
);
56 ok1(tdb_deq(d
, data
));
60 tdb
= tdb_open("run-open-multiple-times.tdb", flags
[i
],
61 O_RDWR
|O_CREAT
, 0600, &tap_log_attr
);
64 ok1(tdb_transaction_start(tdb2
) == 0);
66 /* Anything in the other one should fail. */
67 ok1(tdb_fetch(tdb
, key
, &d
) == TDB_ERR_LOCK
);
68 tap_log_messages
-= extra_messages
;
69 ok1(tap_log_messages
== 1);
70 ok1(tdb_store(tdb
, key
, data
, TDB_REPLACE
) == TDB_ERR_LOCK
);
71 tap_log_messages
-= extra_messages
;
72 ok1(tap_log_messages
== 2);
73 ok1(tdb_transaction_start(tdb
) == TDB_ERR_LOCK
);
74 ok1(tap_log_messages
== 3);
75 ok1(tdb_chainlock(tdb
, key
) == TDB_ERR_LOCK
);
76 tap_log_messages
-= extra_messages
;
77 ok1(tap_log_messages
== 4);
79 /* Transaciton should work as normal. */
80 ok1(tdb_store(tdb2
, key
, data
, TDB_REPLACE
) == TDB_SUCCESS
);
82 /* Now... try closing with locks held. */
83 ok1(tdb_close(tdb2
) == 0);
85 ok1(tdb_fetch(tdb
, key
, &d
) == TDB_SUCCESS
);
86 ok1(tdb_deq(d
, data
));
88 ok1(tdb_close(tdb
) == 0);
89 ok1(tap_log_messages
== 4);