2 This file is part of GNUnet.
3 Copyright (C) 2008 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file util/test_common_logging.c
23 * @brief testcase for the logging module
24 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
30 my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component,
31 const char *date, const char *msg)
33 unsigned int *c = ctx;
41 main (int argc, char *argv[])
43 unsigned int failureCount = 0;
44 unsigned int logs = 0;
46 if (0 != putenv ("GNUNET_FORCE_LOG="))
47 FPRINTF (stderr, "Failed to putenv: %s\n", strerror (errno));
48 GNUNET_log_setup ("test-common-logging", "DEBUG", "/dev/null");
49 GNUNET_logger_add (&my_log, &logs);
50 GNUNET_logger_add (&my_log, &logs);
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_log (GNUNET_ERROR_TYPE_BULK, "Testing...\n");
56 GNUNET_log (GNUNET_ERROR_TYPE_BULK, "Testing...\n");
57 GNUNET_logger_remove (&my_log, &logs);
58 GNUNET_log (GNUNET_ERROR_TYPE_BULK, "Flusher...\n");
59 /* the last 6 calls should be merged (repated bulk messages!) */
60 GNUNET_logger_remove (&my_log, &logs);
63 FPRINTF (stdout, "Expected 4 log calls, got %u\n", logs);
68 GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_ERROR)));
71 GNUNET_error_type_to_string
72 (GNUNET_ERROR_TYPE_WARNING)));
75 GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_INFO)));
78 GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG)));
79 GNUNET_log_setup ("test_common_logging", "WARNING", "/dev/null");
81 GNUNET_logger_add (&my_log, &logs);
82 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Checker...\n");
83 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Drop me...\n");
84 GNUNET_logger_remove (&my_log, &logs);
87 FPRINTF (stdout, "Expected 1 log call, got %u\n", logs);
91 if (failureCount != 0)
93 FPRINTF (stdout, "%u TESTS FAILED!\n", failureCount);
99 /* end of test_common_logging.c */