]> git.ozlabs.org Git - ccan/blob - junkcode/rusty@rustcorp.com.au-ntdb/test/api-summary.c
ccan/ntdb: demote to junkcode.
[ccan] / junkcode / rusty@rustcorp.com.au-ntdb / test / api-summary.c
1 #include "config.h"
2 #include "../ntdb.h"
3 #include "../private.h"
4 #include "tap-interface.h"
5 #include "logging.h"
6 #include "helpapi-external-agent.h"
7
8 int main(int argc, char *argv[])
9 {
10         unsigned int i, j;
11         struct ntdb_context *ntdb;
12         int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
13                         NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
14                         NTDB_NOMMAP|NTDB_CONVERT };
15         NTDB_DATA key = { (unsigned char *)&j, sizeof(j) };
16         NTDB_DATA data = { (unsigned char *)&j, sizeof(j) };
17         char *summary;
18
19         plan_tests(sizeof(flags) / sizeof(flags[0]) * (1 + 2 * 5) + 1);
20         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
21                 ntdb = ntdb_open("run-summary.ntdb", flags[i]|MAYBE_NOSYNC,
22                                  O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
23                 ok1(ntdb);
24                 if (!ntdb)
25                         continue;
26
27                 /* Put some stuff in there. */
28                 for (j = 0; j < 500; j++) {
29                         /* Make sure padding varies to we get some graphs! */
30                         data.dsize = j % (sizeof(j) + 1);
31                         if (ntdb_store(ntdb, key, data, NTDB_REPLACE) != 0)
32                                 fail("Storing in ntdb");
33                 }
34
35                 for (j = 0;
36                      j <= NTDB_SUMMARY_HISTOGRAMS;
37                      j += NTDB_SUMMARY_HISTOGRAMS) {
38                         ok1(ntdb_summary(ntdb, j, &summary) == NTDB_SUCCESS);
39                         ok1(strstr(summary, "Number of records: 500\n"));
40                         ok1(strstr(summary, "Smallest/average/largest keys: 4/4/4\n"));
41                         ok1(strstr(summary, "Smallest/average/largest data: 0/2/4\n"));
42                         if (j == NTDB_SUMMARY_HISTOGRAMS) {
43                                 ok1(strstr(summary, "|")
44                                     && strstr(summary, "*"));
45                         } else {
46                                 ok1(!strstr(summary, "|")
47                                     && !strstr(summary, "*"));
48                         }
49                         free(summary);
50                 }
51                 ntdb_close(ntdb);
52         }
53
54         ok1(tap_log_messages == 0);
55         return exit_status();
56 }