]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/test/api-16-wipe_all.c
tdb2: test: convert (non-invasive) run tests to api tests.
[ccan] / ccan / tdb2 / test / api-16-wipe_all.c
1 #include <ccan/tdb2/tdb2.h>
2 #include <ccan/tap/tap.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include "logging.h"
7
8 static bool add_records(struct tdb_context *tdb)
9 {
10         int i;
11         struct tdb_data key = { (unsigned char *)&i, sizeof(i) };
12         struct tdb_data data = { (unsigned char *)&i, sizeof(i) };
13
14         for (i = 0; i < 1000; i++) {
15                 if (tdb_store(tdb, key, data, TDB_REPLACE) != 0)
16                         return false;
17         }
18         return true;
19 }
20
21
22 int main(int argc, char *argv[])
23 {
24         unsigned int i;
25         struct tdb_context *tdb;
26         int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
27                         TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
28                         TDB_NOMMAP|TDB_CONVERT,
29                         TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
30                         TDB_NOMMAP|TDB_VERSION1,
31                         TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
32                         TDB_CONVERT|TDB_VERSION1,
33                         TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
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 }