paragraph for gnunet devs that don't know how to use the web
[oweals/gnunet.git] / src / util / test_common_logging.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2008 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      Affero General Public License for more details.
14     
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20  * @file util/test_common_logging.c
21  * @brief testcase for the logging module
22  * @author Christian Grothoff
23  */
24 #include "platform.h"
25 #include "gnunet_util_lib.h"
26
27 static void
28 my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component,
29         const char *date, const char *msg)
30 {
31   unsigned int *c = ctx;
32
33   (*c)++;
34 }
35
36
37
38 int
39 main (int argc, char *argv[])
40 {
41   unsigned int failureCount = 0;
42   unsigned int logs = 0;
43
44   if (0 != putenv ("GNUNET_FORCE_LOG="))
45     FPRINTF (stderr, "Failed to putenv: %s\n", strerror (errno));
46   GNUNET_log_setup ("test-common-logging", "DEBUG", "/dev/null");
47   GNUNET_logger_add (&my_log, &logs);
48   GNUNET_logger_add (&my_log, &logs);
49   GNUNET_log (GNUNET_ERROR_TYPE_BULK, "Testing...\n");
50   GNUNET_log (GNUNET_ERROR_TYPE_BULK, "Testing...\n");
51   GNUNET_log (GNUNET_ERROR_TYPE_BULK, "Testing...\n");
52   GNUNET_log (GNUNET_ERROR_TYPE_BULK, "Testing...\n");
53   GNUNET_log (GNUNET_ERROR_TYPE_BULK, "Testing...\n");
54   GNUNET_log (GNUNET_ERROR_TYPE_BULK, "Testing...\n");
55   GNUNET_logger_remove (&my_log, &logs);
56   GNUNET_log (GNUNET_ERROR_TYPE_BULK, "Flusher...\n");
57   /* the last 6 calls should be merged (repated bulk messages!) */
58   GNUNET_logger_remove (&my_log, &logs);
59   if (logs != 4)
60   {
61     FPRINTF (stdout, "Expected 4 log calls, got %u\n", logs);
62     failureCount++;
63   }
64   GNUNET_break (0 ==
65                 strcmp (_("ERROR"),
66                         GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_ERROR)));
67   GNUNET_break (0 ==
68                 strcmp (_("WARNING"),
69                         GNUNET_error_type_to_string
70                         (GNUNET_ERROR_TYPE_WARNING)));
71   GNUNET_break (0 ==
72                 strcmp (_("INFO"),
73                         GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_INFO)));
74   GNUNET_break (0 ==
75                 strcmp (_("DEBUG"),
76                         GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG)));
77   GNUNET_log_setup ("test_common_logging", "WARNING", "/dev/null");
78   logs = 0;
79   GNUNET_logger_add (&my_log, &logs);
80   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Checker...\n");
81   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Drop me...\n");
82   GNUNET_logger_remove (&my_log, &logs);
83   if (logs != 1)
84   {
85     FPRINTF (stdout, "Expected 1 log call, got %u\n", logs);
86     failureCount++;
87   }
88
89   if (failureCount != 0)
90   {
91     FPRINTF (stdout, "%u TESTS FAILED!\n", failureCount);
92     return -1;
93   }
94   return 0;
95 }                               /* end of main */
96
97 /* end of test_common_logging.c */