4 #include "tap-interface.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
;
14 static enum NTDB_ERROR
parse_err(NTDB_DATA key
, NTDB_DATA data
, void *unused
)
19 static bool test_records(struct ntdb_context
*ntdb
)
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)
30 for (i
= 0; i
< 1000; i
++) {
31 if (ntdb_parse_record(ntdb
, key
, parse
, &data
) != NTDB_SUCCESS
)
35 if (ntdb_parse_record(ntdb
, key
, parse
, &data
) != NTDB_ERR_NOEXIST
)
38 /* Test error return from parse function. */
40 if (ntdb_parse_record(ntdb
, key
, parse_err
, NULL
) != 100)
46 int main(int argc
, char *argv
[])
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
);
60 ok1(test_records(ntdb
));
64 ok1(tap_log_messages
== 0);