api-summary.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. int main(int argc, char *argv[])
  8. {
  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;
  17. plan_tests(sizeof(flags) / sizeof(flags[0]) * (1 + 2 * 5) + 1);
  18. for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
  19. ntdb = ntdb_open("run-summary.ntdb", flags[i]|MAYBE_NOSYNC,
  20. O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
  21. ok1(ntdb);
  22. if (!ntdb)
  23. continue;
  24. /* Put some stuff in there. */
  25. for (j = 0; j < 500; j++) {
  26. /* Make sure padding varies to we get some graphs! */
  27. data.dsize = j % (sizeof(j) + 1);
  28. if (ntdb_store(ntdb, key, data, NTDB_REPLACE) != 0)
  29. fail("Storing in ntdb");
  30. }
  31. for (j = 0;
  32. j <= NTDB_SUMMARY_HISTOGRAMS;
  33. j += NTDB_SUMMARY_HISTOGRAMS) {
  34. ok1(ntdb_summary(ntdb, j, &summary) == NTDB_SUCCESS);
  35. ok1(strstr(summary, "Number of records: 500\n"));
  36. ok1(strstr(summary, "Smallest/average/largest keys: 4/4/4\n"));
  37. ok1(strstr(summary, "Smallest/average/largest data: 0/2/4\n"));
  38. if (j == NTDB_SUMMARY_HISTOGRAMS) {
  39. ok1(strstr(summary, "|")
  40. && strstr(summary, "*"));
  41. } else {
  42. ok1(!strstr(summary, "|")
  43. && !strstr(summary, "*"));
  44. }
  45. free(summary);
  46. }
  47. ntdb_close(ntdb);
  48. }
  49. ok1(tap_log_messages == 0);
  50. return exit_status();
  51. }