]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/test/run-summary.c
tdb2: test: try (almost) all tests with TDB_VERSION1 flag.
[ccan] / ccan / tdb2 / test / run-summary.c
1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
3 #include "logging.h"
4
5 int main(int argc, char *argv[])
6 {
7         unsigned int i, j;
8         struct tdb_context *tdb;
9         int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
10                         TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
11                         TDB_NOMMAP|TDB_CONVERT,
12                         TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
13                         TDB_NOMMAP|TDB_VERSION1,
14                         TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
15                         TDB_CONVERT|TDB_VERSION1,
16                         TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
17         struct tdb_data key = { (unsigned char *)&j, sizeof(j) };
18         struct tdb_data data = { (unsigned char *)&j, sizeof(j) };
19         char *summary;
20
21         plan_tests(sizeof(flags) / sizeof(flags[0]) * (1 + 2 * 5) + 1);
22         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
23                 tdb = tdb_open("run-summary.tdb", flags[i],
24                                O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
25                 ok1(tdb);
26                 if (!tdb)
27                         continue;
28
29                 /* Put some stuff in there. */
30                 for (j = 0; j < 500; j++) {
31                         /* Make sure padding varies to we get some graphs! */
32                         data.dsize = j % (sizeof(j) + 1);
33                         if (tdb_store(tdb, key, data, TDB_REPLACE) != 0)
34                                 fail("Storing in tdb");
35                 }
36
37                 for (j = 0;
38                      j <= TDB_SUMMARY_HISTOGRAMS;
39                      j += TDB_SUMMARY_HISTOGRAMS) {
40                         ok1(tdb_summary(tdb, j, &summary) == TDB_SUCCESS);
41                         ok1(strstr(summary, "Number of records: 500\n"));
42                         ok1(strstr(summary, "Smallest/average/largest keys: 4/4/4\n"));
43                         ok1(strstr(summary, "Smallest/average/largest data: 0/2/4\n"));
44                         if (!(flags[i] & TDB_VERSION1)
45                             && j == TDB_SUMMARY_HISTOGRAMS) {
46                                 ok1(strstr(summary, "|")
47                                     && strstr(summary, "*"));
48                         } else {
49                                 ok1(!strstr(summary, "|")
50                                     && !strstr(summary, "*"));
51                         }
52                         free(summary);
53                 }
54                 tdb_close(tdb);
55         }
56
57         ok1(tap_log_messages == 0);
58         return exit_status();
59 }
60
61