]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/test/api-simple-delete.c
tdb2: make tests work in parallel.
[ccan] / ccan / tdb2 / test / api-simple-delete.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 int main(int argc, char *argv[])
9 {
10         unsigned int i;
11         struct tdb_context *tdb;
12         int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
13                         TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
14                         TDB_NOMMAP|TDB_CONVERT,
15                         TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
16                         TDB_NOMMAP|TDB_VERSION1,
17                         TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
18                         TDB_CONVERT|TDB_VERSION1,
19                         TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
20         struct tdb_data key = tdb_mkdata("key", 3);
21         struct tdb_data data = tdb_mkdata("data", 4);
22
23         plan_tests(sizeof(flags) / sizeof(flags[0]) * 7 + 1);
24         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
25                 tdb = tdb_open("run-simple-delete.tdb", flags[i],
26                                O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
27                 ok1(tdb);
28                 if (tdb) {
29                         /* Delete should fail. */
30                         ok1(tdb_delete(tdb, key) == TDB_ERR_NOEXIST);
31                         ok1(tdb_check(tdb, NULL, NULL) == 0);
32                         /* Insert should succeed. */
33                         ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
34                         ok1(tdb_check(tdb, NULL, NULL) == 0);
35                         /* Delete should now work. */
36                         ok1(tdb_delete(tdb, key) == 0);
37                         ok1(tdb_check(tdb, NULL, NULL) == 0);
38                         tdb_close(tdb);
39                 }
40         }
41         ok1(tap_log_messages == 0);
42         return exit_status();
43 }