VERSION: Bump version number up to 4.1.3...
[Samba.git] / lib / ntdb / test / api-summary.c
blobdf5d092a60b9ad1a6450abc7cd3bc319d70763e9
1 #include "config.h"
2 #include "ntdb.h"
3 #include "tap-interface.h"
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include <stdlib.h>
8 #include "logging.h"
10 int main(int argc, char *argv[])
12 unsigned int i, j;
13 struct ntdb_context *ntdb;
14 int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
15 NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
16 NTDB_NOMMAP|NTDB_CONVERT };
17 NTDB_DATA key = { (unsigned char *)&j, sizeof(j) };
18 NTDB_DATA data = { (unsigned char *)&j, sizeof(j) };
19 char *summary;
21 plan_tests(sizeof(flags) / sizeof(flags[0]) * (1 + 2 * 5) + 1);
22 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
23 ntdb = ntdb_open("run-summary.ntdb", flags[i]|MAYBE_NOSYNC,
24 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
25 ok1(ntdb);
26 if (!ntdb)
27 continue;
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 (ntdb_store(ntdb, key, data, NTDB_REPLACE) != 0)
34 fail("Storing in ntdb");
37 for (j = 0;
38 j <= NTDB_SUMMARY_HISTOGRAMS;
39 j += NTDB_SUMMARY_HISTOGRAMS) {
40 ok1(ntdb_summary(ntdb, j, &summary) == NTDB_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 (j == NTDB_SUMMARY_HISTOGRAMS) {
45 ok1(strstr(summary, "|")
46 && strstr(summary, "*"));
47 } else {
48 ok1(!strstr(summary, "|")
49 && !strstr(summary, "*"));
51 free(summary);
53 ntdb_close(ntdb);
56 ok1(tap_log_messages == 0);
57 return exit_status();