2b20e199ee29cc293b3a743788c0bcd3dbc73a7f
[ddiss/samba.git] / lib / ntdb / test / api-simple-delete.c
1 #include "config.h"
2 #include "ntdb.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 ntdb_context *ntdb;
13         int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
14                         NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
15                         NTDB_NOMMAP|NTDB_CONVERT };
16         NTDB_DATA key = ntdb_mkdata("key", 3);
17         NTDB_DATA data = ntdb_mkdata("data", 4);
18
19         plan_tests(sizeof(flags) / sizeof(flags[0]) * 7 + 1);
20         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
21                 ntdb = ntdb_open("run-simple-delete.ntdb", flags[i],
22                                O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
23                 ok1(ntdb);
24                 if (ntdb) {
25                         /* Delete should fail. */
26                         ok1(ntdb_delete(ntdb, key) == NTDB_ERR_NOEXIST);
27                         ok1(ntdb_check(ntdb, NULL, NULL) == 0);
28                         /* Insert should succeed. */
29                         ok1(ntdb_store(ntdb, key, data, NTDB_INSERT) == 0);
30                         ok1(ntdb_check(ntdb, NULL, NULL) == 0);
31                         /* Delete should now work. */
32                         ok1(ntdb_delete(ntdb, key) == 0);
33                         ok1(ntdb_check(ntdb, NULL, NULL) == 0);
34                         ntdb_close(ntdb);
35                 }
36         }
37         ok1(tap_log_messages == 0);
38         return exit_status();
39 }