]> git.ozlabs.org Git - ccan/blob - junkcode/rusty@rustcorp.com.au-ntdb/test/api-14-exists.c
base64: fix for unsigned chars (e.g. ARM).
[ccan] / junkcode / rusty@rustcorp.com.au-ntdb / test / api-14-exists.c
1 #include "config.h"
2 #include "../ntdb.h"
3 #include "../private.h"
4 #include "tap-interface.h"
5 #include "logging.h"
6 #include "helpapi-external-agent.h"
7
8 static bool test_records(struct ntdb_context *ntdb)
9 {
10         int i;
11         NTDB_DATA key = { (unsigned char *)&i, sizeof(i) };
12         NTDB_DATA data = { (unsigned char *)&i, sizeof(i) };
13
14         for (i = 0; i < 1000; i++) {
15                 if (ntdb_exists(ntdb, key))
16                         return false;
17                 if (ntdb_store(ntdb, key, data, NTDB_REPLACE) != 0)
18                         return false;
19                 if (!ntdb_exists(ntdb, key))
20                         return false;
21         }
22
23         for (i = 0; i < 1000; i++) {
24                 if (!ntdb_exists(ntdb, key))
25                         return false;
26                 if (ntdb_delete(ntdb, key) != 0)
27                         return false;
28                 if (ntdb_exists(ntdb, key))
29                         return false;
30         }
31         return true;
32 }
33
34 int main(int argc, char *argv[])
35 {
36         unsigned int i;
37         struct ntdb_context *ntdb;
38         int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
39                         NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
40                         NTDB_NOMMAP|NTDB_CONVERT };
41
42         plan_tests(sizeof(flags) / sizeof(flags[0]) * 2 + 1);
43         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
44                 ntdb = ntdb_open("run-14-exists.ntdb", flags[i]|MAYBE_NOSYNC,
45                                O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
46                 if (ok1(ntdb))
47                         ok1(test_records(ntdb));
48                 ntdb_close(ntdb);
49         }
50
51         ok1(tap_log_messages == 0);
52         return exit_status();
53 }