1 #include <ccan/tdb2/tdb2.h>
2 #include <ccan/tap/tap.h>
8 static bool test_records(struct tdb_context
*tdb
)
11 struct tdb_data key
= { (unsigned char *)&i
, sizeof(i
) };
12 struct tdb_data data
= { (unsigned char *)&i
, sizeof(i
) };
14 for (i
= 0; i
< 1000; i
++) {
15 if (tdb_exists(tdb
, key
))
17 if (tdb_store(tdb
, key
, data
, TDB_REPLACE
) != 0)
19 if (!tdb_exists(tdb
, key
))
23 for (i
= 0; i
< 1000; i
++) {
24 if (!tdb_exists(tdb
, key
))
26 if (tdb_delete(tdb
, key
) != 0)
28 if (tdb_exists(tdb
, key
))
34 int main(int argc
, char *argv
[])
37 struct tdb_context
*tdb
;
38 int flags
[] = { TDB_INTERNAL
, TDB_DEFAULT
, TDB_NOMMAP
,
39 TDB_INTERNAL
|TDB_CONVERT
, TDB_CONVERT
,
40 TDB_NOMMAP
|TDB_CONVERT
,
41 TDB_INTERNAL
|TDB_VERSION1
, TDB_VERSION1
,
42 TDB_NOMMAP
|TDB_VERSION1
,
43 TDB_INTERNAL
|TDB_CONVERT
|TDB_VERSION1
,
44 TDB_CONVERT
|TDB_VERSION1
,
45 TDB_NOMMAP
|TDB_CONVERT
|TDB_VERSION1
};
47 plan_tests(sizeof(flags
) / sizeof(flags
[0]) * 2 + 1);
48 for (i
= 0; i
< sizeof(flags
) / sizeof(flags
[0]); i
++) {
49 tdb
= tdb_open("run-14-exists.tdb", flags
[i
],
50 O_RDWR
|O_CREAT
|O_TRUNC
, 0600, &tap_log_attr
);
52 ok1(test_records(tdb
));
56 ok1(tap_log_messages
== 0);