tsocket_bsd: Attempt to increase the SO_SNDBUF if we get EMSGSIZE in sendto()
[Samba.git] / lib / ntdb / test / api-21-parse_record.c
blob975bbfaf1c97867cb0868becd6628c838e0b3dad
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"
9 static enum NTDB_ERROR parse(NTDB_DATA key, NTDB_DATA data, NTDB_DATA *expected)
11 if (!ntdb_deq(data, *expected))
12 return NTDB_ERR_EINVAL;
13 return NTDB_SUCCESS;
16 static enum NTDB_ERROR parse_err(NTDB_DATA key, NTDB_DATA data, void *unused)
18 return 100;
21 static bool test_records(struct ntdb_context *ntdb)
23 int i;
24 NTDB_DATA key = { (unsigned char *)&i, sizeof(i) };
25 NTDB_DATA data = { (unsigned char *)&i, sizeof(i) };
27 for (i = 0; i < 1000; i++) {
28 if (ntdb_store(ntdb, key, data, NTDB_REPLACE) != 0)
29 return false;
32 for (i = 0; i < 1000; i++) {
33 if (ntdb_parse_record(ntdb, key, parse, &data) != NTDB_SUCCESS)
34 return false;
37 if (ntdb_parse_record(ntdb, key, parse, &data) != NTDB_ERR_NOEXIST)
38 return false;
40 /* Test error return from parse function. */
41 i = 0;
42 if (ntdb_parse_record(ntdb, key, parse_err, NULL) != 100)
43 return false;
45 return true;
48 int main(int argc, char *argv[])
50 unsigned int i;
51 struct ntdb_context *ntdb;
52 int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
53 NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
54 NTDB_NOMMAP|NTDB_CONVERT };
56 plan_tests(sizeof(flags) / sizeof(flags[0]) * 2 + 1);
57 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
58 ntdb = ntdb_open("api-21-parse_record.ntdb",
59 flags[i]|MAYBE_NOSYNC,
60 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
61 if (ok1(ntdb))
62 ok1(test_records(ntdb));
63 ntdb_close(ntdb);
66 ok1(tap_log_messages == 0);
67 return exit_status();