lib/ntdb optimize includes in ntdb tests
[Samba.git] / lib / ntdb / test / api-21-parse_record.c
blob5af9abe00fea77dab0155998097e345020a20bc8
1 #include "config.h"
2 #include "ntdb.h"
3 #include "private.h"
4 #include "tap-interface.h"
5 #include "logging.h"
7 static enum NTDB_ERROR parse(NTDB_DATA key, NTDB_DATA data, NTDB_DATA *expected)
9 if (!ntdb_deq(data, *expected))
10 return NTDB_ERR_EINVAL;
11 return NTDB_SUCCESS;
14 static enum NTDB_ERROR parse_err(NTDB_DATA key, NTDB_DATA data, void *unused)
16 return 100;
19 static bool test_records(struct ntdb_context *ntdb)
21 int i;
22 NTDB_DATA key = { (unsigned char *)&i, sizeof(i) };
23 NTDB_DATA data = { (unsigned char *)&i, sizeof(i) };
25 for (i = 0; i < 1000; i++) {
26 if (ntdb_store(ntdb, key, data, NTDB_REPLACE) != 0)
27 return false;
30 for (i = 0; i < 1000; i++) {
31 if (ntdb_parse_record(ntdb, key, parse, &data) != NTDB_SUCCESS)
32 return false;
35 if (ntdb_parse_record(ntdb, key, parse, &data) != NTDB_ERR_NOEXIST)
36 return false;
38 /* Test error return from parse function. */
39 i = 0;
40 if (ntdb_parse_record(ntdb, key, parse_err, NULL) != 100)
41 return false;
43 return true;
46 int main(int argc, char *argv[])
48 unsigned int i;
49 struct ntdb_context *ntdb;
50 int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
51 NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
52 NTDB_NOMMAP|NTDB_CONVERT };
54 plan_tests(sizeof(flags) / sizeof(flags[0]) * 2 + 1);
55 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
56 ntdb = ntdb_open("api-21-parse_record.ntdb",
57 flags[i]|MAYBE_NOSYNC,
58 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
59 if (ok1(ntdb))
60 ok1(test_records(ntdb));
61 ntdb_close(ntdb);
64 ok1(tap_log_messages == 0);
65 return exit_status();