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