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
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.
21 * @file statistics/test_statistics_api.c
22 * @brief testcase for statistics_api.c
23 * @author Christian Grothoff
26 #include "gnunet_util_lib.h"
27 #include "gnunet_statistics_service.h"
30 static struct GNUNET_STATISTICS_Handle *h;
32 static struct GNUNET_STATISTICS_GetHandle *g;
40 GNUNET_STATISTICS_get_cancel (g);
43 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
50 const char *subsystem,
55 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
56 "Received value %llu for `%s:%s\n",
57 (unsigned long long) value,
60 GNUNET_assert (0 == strcmp (name, "test-1"));
61 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
62 GNUNET_assert (value == 1);
63 GNUNET_assert (is_persistent == GNUNET_NO);
70 const char *subsystem,
75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
76 "Received value %llu for `%s:%s\n",
77 (unsigned long long) value,
80 GNUNET_assert (0 == strcmp (name, "test-2"));
81 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
82 GNUNET_assert (value == 2);
83 GNUNET_assert (is_persistent == GNUNET_NO);
90 const char *subsystem,
95 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
96 "Received value %llu for `%s:%s\n",
97 (unsigned long long) value,
100 GNUNET_assert (0 == strcmp (name, "test-3"));
101 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
102 GNUNET_assert (value == 3);
103 GNUNET_assert (is_persistent == GNUNET_YES);
115 GNUNET_SCHEDULER_shutdown ();
116 GNUNET_assert (success == GNUNET_OK);
122 next (void *cls, int success)
125 GNUNET_assert (success == GNUNET_OK);
126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
127 "Issuing GET request\n");
128 GNUNET_break (NULL !=
129 GNUNET_STATISTICS_get (h, NULL, "test-2",
139 const struct GNUNET_CONFIGURATION_Handle *cfg)
141 h = GNUNET_STATISTICS_create ("test-statistics-api", cfg);
147 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
149 GNUNET_STATISTICS_set (h, "test-1", 1, GNUNET_NO);
150 GNUNET_STATISTICS_set (h, "test-2", 2, GNUNET_NO);
151 GNUNET_STATISTICS_set (h, "test-3", 2, GNUNET_NO);
152 GNUNET_STATISTICS_update (h, "test-3", 1, GNUNET_YES);
153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
154 "Issuing GET request\n");
155 GNUNET_break (NULL !=
156 (g = GNUNET_STATISTICS_get (h, NULL, "test-1",
166 const struct GNUNET_CONFIGURATION_Handle *cfg)
168 h = GNUNET_STATISTICS_create ("test-statistics-api",
170 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
172 GNUNET_break (NULL !=
173 (g = GNUNET_STATISTICS_get (h, NULL,
181 main (int argc, char *argv_ign[])
184 char *const argv[] = { "test-statistics-api",
186 "test_statistics_api_data.conf",
190 struct GNUNET_GETOPT_CommandLineOption options[] = {
191 GNUNET_GETOPT_OPTION_END
193 struct GNUNET_OS_Process *proc;
196 GNUNET_log_setup ("test_statistics_api",
199 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics");
201 GNUNET_OS_start_process (GNUNET_YES,
202 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
205 "gnunet-service-statistics",
206 "-c", "test_statistics_api_data.conf", NULL);
207 GNUNET_assert (NULL != proc);
208 GNUNET_PROGRAM_run (5, argv,
209 "test-statistics-api", "nohelp",
212 if (0 != GNUNET_OS_process_kill (proc,
215 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
218 GNUNET_OS_process_wait (proc);
219 GNUNET_OS_process_destroy (proc);
223 GNUNET_free (binary);
227 /* restart to check persistence! */
229 GNUNET_OS_start_process (GNUNET_YES,
230 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
233 "gnunet-service-statistics",
234 "-c", "test_statistics_api_data.conf",
236 GNUNET_PROGRAM_run (5, argv,
237 "test-statistics-api", "nohelp",
240 if (0 != GNUNET_OS_process_kill (proc,
243 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
246 GNUNET_OS_process_wait (proc);
247 GNUNET_OS_process_destroy (proc);
249 GNUNET_free (binary);
253 /* end of test_statistics_api.c */