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