1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
5 #define NUM_RECORDS 1000
7 static bool store_records(struct tdb_context *tdb)
10 struct tdb_data key = { (unsigned char *)&i, sizeof(i) };
11 struct tdb_data data = { (unsigned char *)&i, sizeof(i) };
13 for (i = 0; i < NUM_RECORDS; i++)
14 if (tdb_store(tdb, key, data, TDB_REPLACE) != 0)
19 static enum TDB_ERROR check(struct tdb_data key,
25 if (key.dsize != sizeof(val)) {
26 diag("Wrong key size: %u\n", key.dsize);
27 return TDB_ERR_CORRUPT;
30 if (key.dsize != data.dsize
31 || memcmp(key.dptr, data.dptr, sizeof(val)) != 0) {
32 diag("Key and data differ\n");
33 return TDB_ERR_CORRUPT;
36 memcpy(&val, key.dptr, sizeof(val));
37 if (val >= NUM_RECORDS || val < 0) {
38 diag("check value %i\n", val);
39 return TDB_ERR_CORRUPT;
43 diag("Value %i already seen\n", val);
44 return TDB_ERR_CORRUPT;
51 int main(int argc, char *argv[])
54 struct tdb_context *tdb;
55 int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
56 TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
57 TDB_NOMMAP|TDB_CONVERT };
59 plan_tests(sizeof(flags) / sizeof(flags[0]) * 4 + 1);
60 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
61 bool array[NUM_RECORDS];
63 tdb = tdb_open("run-check-callback.tdb", flags[i],
64 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
69 ok1(store_records(tdb));
70 for (j = 0; j < NUM_RECORDS; j++)
72 ok1(tdb_check(tdb, check, array) == TDB_SUCCESS);
73 for (j = 0; j < NUM_RECORDS; j++)
76 ok1(j == NUM_RECORDS);
80 ok1(tap_log_messages == 0);