Revert "libwbclient4: Remove unused composite-based functions"
[Samba.git] / lib / ntdb / test / api-summary.c
blobaf1b59581f8da29e5ba49250402755523aed57f2
1 #include "config.h"
2 #include "ntdb.h"
3 #include "private.h"
4 #include "tap-interface.h"
5 #include "logging.h"
7 int main(int argc, char *argv[])
9 unsigned int i, j;
10 struct ntdb_context *ntdb;
11 int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
12 NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
13 NTDB_NOMMAP|NTDB_CONVERT };
14 NTDB_DATA key = { (unsigned char *)&j, sizeof(j) };
15 NTDB_DATA data = { (unsigned char *)&j, sizeof(j) };
16 char *summary;
18 plan_tests(sizeof(flags) / sizeof(flags[0]) * (1 + 2 * 5) + 1);
19 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
20 ntdb = ntdb_open("run-summary.ntdb", flags[i]|MAYBE_NOSYNC,
21 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
22 ok1(ntdb);
23 if (!ntdb)
24 continue;
26 /* Put some stuff in there. */
27 for (j = 0; j < 500; j++) {
28 /* Make sure padding varies to we get some graphs! */
29 data.dsize = j % (sizeof(j) + 1);
30 if (ntdb_store(ntdb, key, data, NTDB_REPLACE) != 0)
31 fail("Storing in ntdb");
34 for (j = 0;
35 j <= NTDB_SUMMARY_HISTOGRAMS;
36 j += NTDB_SUMMARY_HISTOGRAMS) {
37 ok1(ntdb_summary(ntdb, j, &summary) == NTDB_SUCCESS);
38 ok1(strstr(summary, "Number of records: 500\n"));
39 ok1(strstr(summary, "Smallest/average/largest keys: 4/4/4\n"));
40 ok1(strstr(summary, "Smallest/average/largest data: 0/2/4\n"));
41 if (j == NTDB_SUMMARY_HISTOGRAMS) {
42 ok1(strstr(summary, "|")
43 && strstr(summary, "*"));
44 } else {
45 ok1(!strstr(summary, "|")
46 && !strstr(summary, "*"));
48 free(summary);
50 ntdb_close(ntdb);
53 ok1(tap_log_messages == 0);
54 return exit_status();