2 This file is part of GNUnet.
3 Copyright (C) 2009, 2011, 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_watch.c
22 * @brief testcase for statistics_api.c watch functions
23 * @author Christian Grothoff
26 #include "gnunet_util_lib.h"
27 #include "gnunet_statistics_service.h"
32 static struct GNUNET_STATISTICS_Handle *h;
34 static struct GNUNET_STATISTICS_Handle *h2;
36 static struct GNUNET_SCHEDULER_Task *shutdown_task;
40 force_shutdown (void *cls)
42 fprintf (stderr, "Timeout, failed to receive notifications: %d\n", ok);
43 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
44 GNUNET_STATISTICS_destroy (h2, GNUNET_NO);
50 normal_shutdown (void *cls)
52 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
53 GNUNET_STATISTICS_destroy (h2, GNUNET_NO);
59 const char *subsystem,
64 GNUNET_assert (value == 42);
65 GNUNET_assert (0 == strcmp (name, "test-1"));
69 GNUNET_SCHEDULER_cancel (shutdown_task);
70 GNUNET_SCHEDULER_add_now (&normal_shutdown, NULL);
78 const char *subsystem,
83 GNUNET_assert (value == 43);
84 GNUNET_assert (0 == strcmp (name, "test-2"));
88 GNUNET_SCHEDULER_cancel (shutdown_task);
89 GNUNET_SCHEDULER_add_now (&normal_shutdown, NULL);
99 const struct GNUNET_CONFIGURATION_Handle *cfg)
101 h = GNUNET_STATISTICS_create ("dummy", cfg);
102 GNUNET_assert (GNUNET_OK ==
103 GNUNET_STATISTICS_watch (h, "test-statistics-api-watch",
104 "test-1", &watch_1, NULL));
105 GNUNET_assert (GNUNET_OK ==
106 GNUNET_STATISTICS_watch (h, "test-statistics-api-watch",
107 "test-2", &watch_2, NULL));
108 h2 = GNUNET_STATISTICS_create ("test-statistics-api-watch", cfg);
109 GNUNET_STATISTICS_set (h2, "test-1", 42, GNUNET_NO);
110 GNUNET_STATISTICS_set (h2, "test-2", 43, GNUNET_NO);
112 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
119 main (int argc, char *argv_ign[])
121 char *const argv[] = { "test-statistics-api",
123 "test_statistics_api_data.conf",
126 struct GNUNET_GETOPT_CommandLineOption options[] = {
127 GNUNET_GETOPT_OPTION_END
129 struct GNUNET_OS_Process *proc;
132 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics");
134 GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
137 "gnunet-service-statistics",
138 "-c", "test_statistics_api_data.conf", NULL);
139 GNUNET_assert (NULL != proc);
141 GNUNET_PROGRAM_run (3, argv, "test-statistics-api", "nohelp", options, &run,
143 if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG))
145 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
148 GNUNET_OS_process_wait (proc);
149 GNUNET_OS_process_destroy (proc);
151 GNUNET_free (binary);
156 /* end of test_statistics_api_watch.c */