tdb2: allow multiple chain locks.
[ccan] / ccan / tdb2 / test / run-16-wipe_all.c
1 #include <ccan/tdb2/tdb.c>
2 #include <ccan/tdb2/open.c>
3 #include <ccan/tdb2/free.c>
4 #include <ccan/tdb2/lock.c>
5 #include <ccan/tdb2/io.c>
6 #include <ccan/tdb2/hash.c>
7 #include <ccan/tdb2/check.c>
8 #include <ccan/tdb2/transaction.c>
9 #include <ccan/tdb2/traverse.c>
10 #include <ccan/tap/tap.h>
11 #include "logging.h"
12
13 static bool add_records(struct tdb_context *tdb)
14 {
15         int i;
16         struct tdb_data key = { (unsigned char *)&i, sizeof(i) };
17         struct tdb_data data = { (unsigned char *)&i, sizeof(i) };
18
19         for (i = 0; i < 1000; i++) {
20                 if (tdb_store(tdb, key, data, TDB_REPLACE) != 0)
21                         return false;
22         }
23         return true;
24 }
25
26
27 int main(int argc, char *argv[])
28 {
29         unsigned int i;
30         struct tdb_context *tdb;
31         int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
32                         TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
33                         TDB_NOMMAP|TDB_CONVERT };
34
35         plan_tests(sizeof(flags) / sizeof(flags[0]) * 4 + 1);
36         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
37                 tdb = tdb_open("run-16-wipe_all.tdb", flags[i],
38                                O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
39                 if (ok1(tdb)) {
40                         struct tdb_data key;
41                         ok1(add_records(tdb));
42                         ok1(tdb_wipe_all(tdb) == TDB_SUCCESS);
43                         ok1(tdb_firstkey(tdb, &key) == TDB_ERR_NOEXIST);
44                         tdb_close(tdb);
45                 }
46         }
47
48         ok1(tap_log_messages == 0);
49         return exit_status();
50 }