2 This file is part of GNUnet.
3 Copyright (C) 2009, 2012, 2016 GNUnet e.V.
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.
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.
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/>.
19 * @file statistics/test_statistics_api.c
20 * @brief testcase for statistics_api.c
21 * @author Christian Grothoff
24 #include "gnunet_util_lib.h"
25 #include "gnunet_statistics_service.h"
28 static struct GNUNET_STATISTICS_Handle *h;
30 static struct GNUNET_STATISTICS_GetHandle *g;
38 GNUNET_STATISTICS_get_cancel (g);
41 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
48 const char *subsystem,
53 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
54 "Received value %llu for `%s:%s\n",
55 (unsigned long long) value,
58 GNUNET_assert (0 == strcmp (name, "test-1"));
59 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
60 GNUNET_assert (value == 1);
61 GNUNET_assert (is_persistent == GNUNET_NO);
68 const char *subsystem,
73 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
74 "Received value %llu for `%s:%s\n",
75 (unsigned long long) value,
78 GNUNET_assert (0 == strcmp (name, "test-2"));
79 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
80 GNUNET_assert (value == 2);
81 GNUNET_assert (is_persistent == GNUNET_NO);
88 const char *subsystem,
93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
94 "Received value %llu for `%s:%s\n",
95 (unsigned long long) value,
98 GNUNET_assert (0 == strcmp (name, "test-3"));
99 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
100 GNUNET_assert (value == 3);
101 GNUNET_assert (is_persistent == GNUNET_YES);
113 GNUNET_SCHEDULER_shutdown ();
114 GNUNET_assert (success == GNUNET_OK);
120 next (void *cls, int success)
123 GNUNET_assert (success == GNUNET_OK);
124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
125 "Issuing GET request\n");
126 GNUNET_break (NULL !=
127 GNUNET_STATISTICS_get (h, NULL, "test-2",
137 const struct GNUNET_CONFIGURATION_Handle *cfg)
139 h = GNUNET_STATISTICS_create ("test-statistics-api", cfg);
145 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
147 GNUNET_STATISTICS_set (h, "test-1", 1, GNUNET_NO);
148 GNUNET_STATISTICS_set (h, "test-2", 2, GNUNET_NO);
149 GNUNET_STATISTICS_set (h, "test-3", 2, GNUNET_NO);
150 GNUNET_STATISTICS_update (h, "test-3", 1, GNUNET_YES);
151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
152 "Issuing GET request\n");
153 GNUNET_break (NULL !=
154 (g = GNUNET_STATISTICS_get (h, NULL, "test-1",
164 const struct GNUNET_CONFIGURATION_Handle *cfg)
166 h = GNUNET_STATISTICS_create ("test-statistics-api",
168 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
170 GNUNET_break (NULL !=
171 (g = GNUNET_STATISTICS_get (h, NULL,
179 main (int argc, char *argv_ign[])
182 char *const argv[] = { "test-statistics-api",
184 "test_statistics_api_data.conf",
188 struct GNUNET_GETOPT_CommandLineOption options[] = {
189 GNUNET_GETOPT_OPTION_END
191 struct GNUNET_OS_Process *proc;
194 GNUNET_log_setup ("test_statistics_api",
197 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics");
199 GNUNET_OS_start_process (GNUNET_YES,
200 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
203 "gnunet-service-statistics",
204 "-c", "test_statistics_api_data.conf", NULL);
205 GNUNET_assert (NULL != proc);
206 GNUNET_PROGRAM_run (5, argv,
207 "test-statistics-api", "nohelp",
210 if (0 != GNUNET_OS_process_kill (proc,
213 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
216 GNUNET_OS_process_wait (proc);
217 GNUNET_OS_process_destroy (proc);
221 GNUNET_free (binary);
225 /* restart to check persistence! */
227 GNUNET_OS_start_process (GNUNET_YES,
228 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
231 "gnunet-service-statistics",
232 "-c", "test_statistics_api_data.conf",
234 GNUNET_PROGRAM_run (5, argv,
235 "test-statistics-api", "nohelp",
238 if (0 != GNUNET_OS_process_kill (proc,
241 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
244 GNUNET_OS_process_wait (proc);
245 GNUNET_OS_process_destroy (proc);
247 GNUNET_free (binary);
251 /* end of test_statistics_api.c */