3 #include "../private.h"
4 #include "tap-interface.h"
6 #include "helpapi-external-agent.h"
8 #define NUM_RECORDS 1000
10 static bool store_records(struct ntdb_context *ntdb)
13 NTDB_DATA key = { (unsigned char *)&i, sizeof(i) };
14 NTDB_DATA data = { (unsigned char *)&i, sizeof(i) };
16 for (i = 0; i < NUM_RECORDS; i++)
17 if (ntdb_store(ntdb, key, data, NTDB_REPLACE) != 0)
22 static enum NTDB_ERROR check(NTDB_DATA key,
28 if (key.dsize != sizeof(val)) {
29 diag("Wrong key size: %zu\n", key.dsize);
30 return NTDB_ERR_CORRUPT;
33 if (key.dsize != data.dsize
34 || memcmp(key.dptr, data.dptr, sizeof(val)) != 0) {
35 diag("Key and data differ\n");
36 return NTDB_ERR_CORRUPT;
39 memcpy(&val, key.dptr, sizeof(val));
40 if (val >= NUM_RECORDS || val < 0) {
41 diag("check value %i\n", val);
42 return NTDB_ERR_CORRUPT;
46 diag("Value %i already seen\n", val);
47 return NTDB_ERR_CORRUPT;
54 int main(int argc, char *argv[])
57 struct ntdb_context *ntdb;
58 int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
59 NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
60 NTDB_NOMMAP|NTDB_CONVERT };
63 plan_tests(sizeof(flags) / sizeof(flags[0]) * 4 + 1);
64 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
65 bool array[NUM_RECORDS];
67 ntdb = ntdb_open("run-check-callback.ntdb",
68 flags[i]|MAYBE_NOSYNC,
69 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
74 ok1(store_records(ntdb));
75 for (j = 0; j < NUM_RECORDS; j++)
77 ok1(ntdb_check(ntdb, check, array) == NTDB_SUCCESS);
78 for (j = 0; j < NUM_RECORDS; j++)
81 ok1(j == NUM_RECORDS);
85 ok1(tap_log_messages == 0);