c1bda8e4f408716d26d222c91a56960b85c25515
[ddiss/samba.git] / lib / ntdb / test / api-16-wipe_all.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 static bool add_records(struct ntdb_context *ntdb)
10 {
11         int i;
12         NTDB_DATA key = { (unsigned char *)&i, sizeof(i) };
13         NTDB_DATA data = { (unsigned char *)&i, sizeof(i) };
14
15         for (i = 0; i < 1000; i++) {
16                 if (ntdb_store(ntdb, key, data, NTDB_REPLACE) != 0)
17                         return false;
18         }
19         return true;
20 }
21
22
23 int main(int argc, char *argv[])
24 {
25         unsigned int i;
26         struct ntdb_context *ntdb;
27         int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
28                         NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
29                         NTDB_NOMMAP|NTDB_CONVERT };
30
31         plan_tests(sizeof(flags) / sizeof(flags[0]) * 4 + 1);
32         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
33                 ntdb = ntdb_open("run-16-wipe_all.ntdb", flags[i],
34                                O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
35                 if (ok1(ntdb)) {
36                         NTDB_DATA key;
37                         ok1(add_records(ntdb));
38                         ok1(ntdb_wipe_all(ntdb) == NTDB_SUCCESS);
39                         ok1(ntdb_firstkey(ntdb, &key) == NTDB_ERR_NOEXIST);
40                         ntdb_close(ntdb);
41                 }
42         }
43
44         ok1(tap_log_messages == 0);
45         return exit_status();
46 }