1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
5 static bool test_records(struct tdb_context *tdb)
8 struct tdb_data key = { (unsigned char *)&i, sizeof(i) };
9 struct tdb_data data = { (unsigned char *)&i, sizeof(i) };
11 for (i = 0; i < 1000; i++) {
12 if (tdb_exists(tdb, key))
14 if (tdb_store(tdb, key, data, TDB_REPLACE) != 0)
16 if (!tdb_exists(tdb, key))
20 for (i = 0; i < 1000; i++) {
21 if (!tdb_exists(tdb, key))
23 if (tdb_delete(tdb, key) != 0)
25 if (tdb_exists(tdb, key))
31 int main(int argc, char *argv[])
34 struct tdb_context *tdb;
35 int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
36 TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
37 TDB_NOMMAP|TDB_CONVERT };
39 plan_tests(sizeof(flags) / sizeof(flags[0]) * 2 + 1);
40 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
41 tdb = tdb_open("run-14-exists.tdb", flags[i],
42 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
44 ok1(test_records(tdb));
48 ok1(tap_log_messages == 0);