aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_common_logging.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-05-29 00:46:26 +0000
committerChristian Grothoff <christian@grothoff.org>2009-05-29 00:46:26 +0000
commit0a217a8df1657b4334b55b0e4a6c7837a8dbcfd9 (patch)
tree6b552f40eb089db96409a312a98d9b12bd669102 /src/util/test_common_logging.c
downloadgnunet-0a217a8df1657b4334b55b0e4a6c7837a8dbcfd9.tar.gz
gnunet-0a217a8df1657b4334b55b0e4a6c7837a8dbcfd9.zip
ng
Diffstat (limited to 'src/util/test_common_logging.c')
-rw-r--r--src/util/test_common_logging.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/util/test_common_logging.c b/src/util/test_common_logging.c
new file mode 100644
index 000000000..eb337aac4
--- /dev/null
+++ b/src/util/test_common_logging.c
@@ -0,0 +1,100 @@
1/*
2 This file is part of GNUnet.
3 (C) 2008 Christian Grothoff (and other contributing authors)
4
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 2, or (at your
8 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 General Public License for more details.
14
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file util/test_common_logging.c
23 * @brief testcase for the logging module
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "gnunet_common.h"
28
29static void
30my_log (void *ctx, enum GNUNET_ErrorType kind,
31 const char *component, const char *date, const char *msg)
32{
33 unsigned int *c = ctx;
34 (*c)++;
35}
36
37
38
39int
40main (int argc, char *argv[])
41{
42 unsigned int failureCount = 0;
43 unsigned int logs = 0;
44
45 fclose (stderr);
46 stderr = 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
67 (GNUNET_ERROR_TYPE_ERROR)));
68 GNUNET_break (0 ==
69 strcmp (_("WARNING"),
70 GNUNET_error_type_to_string
71 (GNUNET_ERROR_TYPE_WARNING)));
72 GNUNET_break (0 ==
73 strcmp (_("INFO"),
74 GNUNET_error_type_to_string
75 (GNUNET_ERROR_TYPE_INFO)));
76 GNUNET_break (0 ==
77 strcmp (_("DEBUG"),
78 GNUNET_error_type_to_string
79 (GNUNET_ERROR_TYPE_DEBUG)));
80 GNUNET_log_setup ("test_common_logging", "WARNING", "/dev/null");
81 logs = 0;
82 GNUNET_logger_add (&my_log, &logs);
83 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Checker...\n");
84 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Drop me...\n");
85 GNUNET_logger_remove (&my_log, &logs);
86 if (logs != 1)
87 {
88 fprintf (stdout, "Expected 1 log call, got %u\n", logs);
89 failureCount++;
90 }
91
92 if (failureCount != 0)
93 {
94 fprintf (stdout, "%u TESTS FAILED!\n", failureCount);
95 return -1;
96 }
97 return 0;
98} /* end of main */
99
100/* end of test_common_logging.c */