tests/src/utils/test-log.c: add AUBIO_INF
[aubio.git] / tests / src / utils / test-log.c
1 #include <aubio.h>
2 #include <stdio.h>
3 #include "aubio_priv.h"
4
5 const char_t *hdr = "CUSTOM HEADER: ";
6 const char_t *hdr2 = "OTHER HEADER: ";
7
8 /* an example of logging function that adds a custom header and prints
9  * aubio debug messages on stdout instead of stderr */
10 void logging(int level, const char_t *message, void *data) {
11   FILE *out;
12   fprintf(stdout, "using custom logging function\n");
13   if (level == AUBIO_LOG_ERR) {
14     out = stderr;
15   } else {
16     out = stdout;
17   }
18   if ((level >= 0) && (data != NULL)) {
19     fprintf(out, "%s", (const char_t *)data);
20   }
21   fprintf(out, "%s", message);
22 }
23
24 int main (void)
25 {
26   fprintf(stdout, "### testing normal logging\n");
27   AUBIO_ERR("testing normal AUBIO_LOG_ERR\n");
28   AUBIO_INF("testing normal AUBIO_LOG_INF\n");
29   AUBIO_WRN("testing normal AUBIO_LOG_WRN\n");
30   AUBIO_MSG("testing normal AUBIO_LOG_MSG\n");
31   AUBIO_DBG("testing normal AUBIO_LOG_DBG\n");
32
33   fprintf(stdout, "### testing with one custom function\n");
34   aubio_log_set_function(logging, (void *)hdr);
35   AUBIO_ERR("testing recustom AUBIO_LOG_ERR\n");
36   AUBIO_INF("testing recustom AUBIO_LOG_INF\n");
37   AUBIO_WRN("testing recustom AUBIO_LOG_WRN\n");
38   AUBIO_MSG("testing recustom AUBIO_LOG_MSG\n");
39   AUBIO_DBG("testing recustom AUBIO_LOG_DBG\n");
40
41   fprintf(stdout, "### testing resetted logging\n");
42   aubio_log_reset();
43   AUBIO_ERR("testing uncustom AUBIO_LOG_ERR\n");
44   AUBIO_INF("testing uncustom AUBIO_LOG_INF\n");
45   AUBIO_WRN("testing uncustom AUBIO_LOG_WRN\n");
46   AUBIO_MSG("testing uncustom AUBIO_LOG_MSG\n");
47   AUBIO_DBG("testing uncustom AUBIO_LOG_DBG\n");
48
49   fprintf(stdout, "### testing per level customization\n");
50   aubio_log_set_level_function(AUBIO_LOG_ERR, logging, (void *)hdr2);
51   aubio_log_set_level_function(AUBIO_LOG_WRN, logging, NULL);
52   aubio_log_set_level_function(AUBIO_LOG_MSG, logging, (void *)hdr);
53   AUBIO_ERR("testing custom AUBIO_LOG_ERR\n");
54   AUBIO_INF("testing custom AUBIO_LOG_INF\n");
55   AUBIO_WRN("testing custom AUBIO_LOG_WRN with data=NULL\n");
56   AUBIO_MSG("testing custom AUBIO_LOG_MSG\n");
57   AUBIO_DBG("testing uncustomized AUBIO_LOG_DBG\n");
58
59   return 0;
60 }