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