]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/test/run-16-wipe_all.c
tdb2: add TDB_ATTRIBUTE_TDB1_HASHSIZE
[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
27         plan_tests(sizeof(flags) / sizeof(flags[0]) * 4 + 1);
28         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
29                 tdb = tdb_open("run-16-wipe_all.tdb", flags[i],
30                                O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
31                 if (ok1(tdb)) {
32                         struct tdb_data key;
33                         ok1(add_records(tdb));
34                         ok1(tdb_wipe_all(tdb) == TDB_SUCCESS);
35                         ok1(tdb_firstkey(tdb, &key) == TDB_ERR_NOEXIST);
36                         tdb_close(tdb);
37                 }
38         }
39
40         ok1(tap_log_messages == 0);
41         return exit_status();
42 }