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.
16 * @file statistics/test_statistics_api.c
17 * @brief testcase for statistics_api.c
18 * @author Christian Grothoff
21 #include "gnunet_util_lib.h"
22 #include "gnunet_statistics_service.h"
25 static struct GNUNET_STATISTICS_Handle *h;
27 static struct GNUNET_STATISTICS_GetHandle *g;
35 GNUNET_STATISTICS_get_cancel (g);
38 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
45 const char *subsystem,
50 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
51 "Received value %llu for `%s:%s\n",
52 (unsigned long long) value,
55 GNUNET_assert (0 == strcmp (name, "test-1"));
56 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
57 GNUNET_assert (value == 1);
58 GNUNET_assert (is_persistent == GNUNET_NO);
65 const char *subsystem,
70 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
71 "Received value %llu for `%s:%s\n",
72 (unsigned long long) value,
75 GNUNET_assert (0 == strcmp (name, "test-2"));
76 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
77 GNUNET_assert (value == 2);
78 GNUNET_assert (is_persistent == GNUNET_NO);
85 const char *subsystem,
90 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
91 "Received value %llu for `%s:%s\n",
92 (unsigned long long) value,
95 GNUNET_assert (0 == strcmp (name, "test-3"));
96 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
97 GNUNET_assert (value == 3);
98 GNUNET_assert (is_persistent == GNUNET_YES);
110 GNUNET_SCHEDULER_shutdown ();
111 GNUNET_assert (success == GNUNET_OK);
117 next (void *cls, int success)
120 GNUNET_assert (success == GNUNET_OK);
121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
122 "Issuing GET request\n");
123 GNUNET_break (NULL !=
124 GNUNET_STATISTICS_get (h, NULL, "test-2",
134 const struct GNUNET_CONFIGURATION_Handle *cfg)
136 h = GNUNET_STATISTICS_create ("test-statistics-api", cfg);
142 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
144 GNUNET_STATISTICS_set (h, "test-1", 1, GNUNET_NO);
145 GNUNET_STATISTICS_set (h, "test-2", 2, GNUNET_NO);
146 GNUNET_STATISTICS_set (h, "test-3", 2, GNUNET_NO);
147 GNUNET_STATISTICS_update (h, "test-3", 1, GNUNET_YES);
148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
149 "Issuing GET request\n");
150 GNUNET_break (NULL !=
151 (g = GNUNET_STATISTICS_get (h, NULL, "test-1",
161 const struct GNUNET_CONFIGURATION_Handle *cfg)
163 h = GNUNET_STATISTICS_create ("test-statistics-api",
165 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
167 GNUNET_break (NULL !=
168 (g = GNUNET_STATISTICS_get (h, NULL,
176 main (int argc, char *argv_ign[])
179 char *const argv[] = { "test-statistics-api",
181 "test_statistics_api_data.conf",
185 struct GNUNET_GETOPT_CommandLineOption options[] = {
186 GNUNET_GETOPT_OPTION_END
188 struct GNUNET_OS_Process *proc;
191 GNUNET_log_setup ("test_statistics_api",
194 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics");
196 GNUNET_OS_start_process (GNUNET_YES,
197 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
200 "gnunet-service-statistics",
201 "-c", "test_statistics_api_data.conf", NULL);
202 GNUNET_assert (NULL != proc);
203 GNUNET_PROGRAM_run (5, argv,
204 "test-statistics-api", "nohelp",
207 if (0 != GNUNET_OS_process_kill (proc,
210 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
213 GNUNET_OS_process_wait (proc);
214 GNUNET_OS_process_destroy (proc);
218 GNUNET_free (binary);
222 /* restart to check persistence! */
224 GNUNET_OS_start_process (GNUNET_YES,
225 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
228 "gnunet-service-statistics",
229 "-c", "test_statistics_api_data.conf",
231 GNUNET_PROGRAM_run (5, argv,
232 "test-statistics-api", "nohelp",
235 if (0 != GNUNET_OS_process_kill (proc,
238 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
241 GNUNET_OS_process_wait (proc);
242 GNUNET_OS_process_destroy (proc);
244 GNUNET_free (binary);
248 /* end of test_statistics_api.c */