1 #include <ccan/tdb2/tdb2.h>
2 #include <ccan/tap/tap.h>
8 #define NUM_RECORDS 1000
10 static bool store_records(struct tdb_context *tdb)
13 struct tdb_data key = { (unsigned char *)&i, sizeof(i) };
14 struct tdb_data data = { (unsigned char *)&i, sizeof(i) };
16 for (i = 0; i < NUM_RECORDS; i++)
17 if (tdb_store(tdb, key, data, TDB_REPLACE) != 0)
22 static enum TDB_ERROR check(struct tdb_data key,
28 if (key.dsize != sizeof(val)) {
29 diag("Wrong key size: %u\n", key.dsize);
30 return TDB_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 TDB_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 TDB_ERR_CORRUPT;
46 diag("Value %i already seen\n", val);
47 return TDB_ERR_CORRUPT;
54 int main(int argc, char *argv[])
57 struct tdb_context *tdb;
58 int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
59 TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
60 TDB_NOMMAP|TDB_CONVERT,
61 TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
62 TDB_NOMMAP|TDB_VERSION1,
63 TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
64 TDB_CONVERT|TDB_VERSION1,
65 TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
67 plan_tests(sizeof(flags) / sizeof(flags[0]) * 4 + 1);
68 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
69 bool array[NUM_RECORDS];
71 tdb = tdb_open("run-check-callback.tdb", flags[i],
72 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
77 ok1(store_records(tdb));
78 for (j = 0; j < NUM_RECORDS; j++)
80 ok1(tdb_check(tdb, check, array) == TDB_SUCCESS);
81 for (j = 0; j < NUM_RECORDS; j++)
84 ok1(j == NUM_RECORDS);
88 ok1(tap_log_messages == 0);