1 #include <ccan/tdb2/tdb2.h>
2 #include <ccan/tap/tap.h>
9 int main(int argc, char *argv[])
12 struct tdb_context *tdb;
13 int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
14 TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
15 TDB_NOMMAP|TDB_CONVERT,
16 TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
17 TDB_NOMMAP|TDB_VERSION1,
18 TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
19 TDB_CONVERT|TDB_VERSION1,
20 TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
21 struct tdb_data key = { (unsigned char *)&j, sizeof(j) };
22 struct tdb_data data = { (unsigned char *)&j, sizeof(j) };
25 plan_tests(sizeof(flags) / sizeof(flags[0]) * (1 + 2 * 5) + 1);
26 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
27 tdb = tdb_open("run-summary.tdb", flags[i],
28 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
33 /* Put some stuff in there. */
34 for (j = 0; j < 500; j++) {
35 /* Make sure padding varies to we get some graphs! */
36 data.dsize = j % (sizeof(j) + 1);
37 if (tdb_store(tdb, key, data, TDB_REPLACE) != 0)
38 fail("Storing in tdb");
42 j <= TDB_SUMMARY_HISTOGRAMS;
43 j += TDB_SUMMARY_HISTOGRAMS) {
44 ok1(tdb_summary(tdb, j, &summary) == TDB_SUCCESS);
45 ok1(strstr(summary, "Number of records: 500\n"));
46 ok1(strstr(summary, "Smallest/average/largest keys: 4/4/4\n"));
47 ok1(strstr(summary, "Smallest/average/largest data: 0/2/4\n"));
48 if (!(flags[i] & TDB_VERSION1)
49 && j == TDB_SUMMARY_HISTOGRAMS) {
50 ok1(strstr(summary, "|")
51 && strstr(summary, "*"));
53 ok1(!strstr(summary, "|")
54 && !strstr(summary, "*"));
61 ok1(tap_log_messages == 0);