2 This file is part of GNUnet.
3 Copyright (C) 2009, 2012 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;
35 const char *subsystem,
40 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
41 "Received value %llu for `%s:%s\n",
42 (unsigned long long) value,
45 GNUNET_assert (0 == strcmp (name, "test-1"));
46 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
47 GNUNET_assert (value == 1);
48 GNUNET_assert (is_persistent == GNUNET_NO);
55 const char *subsystem,
60 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
61 "Received value %llu for `%s:%s\n",
62 (unsigned long long) value,
65 GNUNET_assert (0 == strcmp (name, "test-2"));
66 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
67 GNUNET_assert (value == 2);
68 GNUNET_assert (is_persistent == GNUNET_NO);
75 const char *subsystem,
80 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
81 "Received value %llu for `%s:%s\n",
82 (unsigned long long) value,
85 GNUNET_assert (0 == strcmp (name, "test-3"));
86 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
87 GNUNET_assert (value == 3);
88 GNUNET_assert (is_persistent == GNUNET_YES);
99 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
100 GNUNET_assert (success == GNUNET_OK);
106 next (void *cls, int success)
108 GNUNET_assert (success == GNUNET_OK);
109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
110 "Issuing GET request\n");
111 GNUNET_break (NULL !=
112 GNUNET_STATISTICS_get (h, NULL, "test-2",
122 const struct GNUNET_CONFIGURATION_Handle *cfg)
124 h = GNUNET_STATISTICS_create ("test-statistics-api", cfg);
125 GNUNET_STATISTICS_set (h, "test-1", 1, GNUNET_NO);
126 GNUNET_STATISTICS_set (h, "test-2", 2, GNUNET_NO);
127 GNUNET_STATISTICS_set (h, "test-3", 2, GNUNET_NO);
128 GNUNET_STATISTICS_update (h, "test-3", 1, GNUNET_YES);
129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Issuing GET request\n");
130 GNUNET_break (NULL !=
131 GNUNET_STATISTICS_get (h, NULL, "test-1",
141 const struct GNUNET_CONFIGURATION_Handle *cfg)
143 h = GNUNET_STATISTICS_create ("test-statistics-api",
145 GNUNET_break (NULL !=
146 GNUNET_STATISTICS_get (h, NULL,
154 main (int argc, char *argv_ign[])
157 char *const argv[] = { "test-statistics-api",
159 "test_statistics_api_data.conf",
163 struct GNUNET_GETOPT_CommandLineOption options[] = {
164 GNUNET_GETOPT_OPTION_END
166 struct GNUNET_OS_Process *proc;
169 GNUNET_log_setup ("test_statistics_api",
172 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics");
174 GNUNET_OS_start_process (GNUNET_YES,
175 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
178 "gnunet-service-statistics",
179 "-c", "test_statistics_api_data.conf", NULL);
180 GNUNET_assert (NULL != proc);
181 GNUNET_PROGRAM_run (5, argv,
182 "test-statistics-api", "nohelp",
185 if (0 != GNUNET_OS_process_kill (proc,
188 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
191 GNUNET_OS_process_wait (proc);
192 GNUNET_OS_process_destroy (proc);
196 GNUNET_free (binary);
200 /* restart to check persistence! */
202 GNUNET_OS_start_process (GNUNET_YES,
203 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
206 "gnunet-service-statistics",
207 "-c", "test_statistics_api_data.conf",
209 GNUNET_PROGRAM_run (5, argv,
210 "test-statistics-api", "nohelp",
213 if (0 != GNUNET_OS_process_kill (proc,
216 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
219 GNUNET_OS_process_wait (proc);
220 GNUNET_OS_process_destroy (proc);
222 GNUNET_free (binary);
226 /* end of test_statistics_api.c */