3 #include "tap-interface.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
;
16 static enum NTDB_ERROR
parse_err(NTDB_DATA key
, NTDB_DATA data
, void *unused
)
21 static bool test_records(struct ntdb_context
*ntdb
)
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)
32 for (i
= 0; i
< 1000; i
++) {
33 if (ntdb_parse_record(ntdb
, key
, parse
, &data
) != NTDB_SUCCESS
)
37 if (ntdb_parse_record(ntdb
, key
, parse
, &data
) != NTDB_ERR_NOEXIST
)
40 /* Test error return from parse function. */
42 if (ntdb_parse_record(ntdb
, key
, parse_err
, NULL
) != 100)
48 int main(int argc
, char *argv
[])
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
);
62 ok1(test_records(ntdb
));
66 ok1(tap_log_messages
== 0);