tdb2: test: try (almost) all tests with TDB_VERSION1 flag.
[ccan] / ccan / tdb2 / test / run-simple-delete.c
1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
3 #include "logging.h"
4
5 int main(int argc, char *argv[])
6 {
7         unsigned int i;
8         struct tdb_context *tdb;
9         int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
10                         TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, 
11                         TDB_NOMMAP|TDB_CONVERT,
12                         TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
13                         TDB_NOMMAP|TDB_VERSION1,
14                         TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
15                         TDB_CONVERT|TDB_VERSION1,
16                         TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
17         struct tdb_data key = tdb_mkdata("key", 3);
18         struct tdb_data data = tdb_mkdata("data", 4);
19
20         plan_tests(sizeof(flags) / sizeof(flags[0]) * 7 + 1);
21         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
22                 tdb = tdb_open("run-simple-delete.tdb", flags[i],
23                                O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
24                 ok1(tdb);
25                 if (tdb) {
26                         /* Delete should fail. */
27                         ok1(tdb_delete(tdb, key) == TDB_ERR_NOEXIST);
28                         ok1(tdb_check(tdb, NULL, NULL) == 0);
29                         /* Insert should succeed. */
30                         ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
31                         ok1(tdb_check(tdb, NULL, NULL) == 0);
32                         /* Delete should now work. */
33                         ok1(tdb_delete(tdb, key) == 0);
34                         ok1(tdb_check(tdb, NULL, NULL) == 0);
35                         tdb_close(tdb);
36                 }
37         }
38         ok1(tap_log_messages == 0);
39         return exit_status();
40 }