2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file nse/test_nse_api.c
22 * @brief testcase for nse_api.c
25 #include "gnunet_util_lib.h"
26 #include "gnunet_nse_service.h"
27 #include "gnunet_testing_lib.h"
30 static struct GNUNET_NSE_Handle *h;
32 static GNUNET_SCHEDULER_TaskIdentifier die_task;
36 * Signature of the main function of a task.
39 * @param tc context information (why was this task triggered now)
42 end_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
46 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from NSE service.\n");
47 GNUNET_NSE_disconnect (h);
52 * Callback to call when network size estimate is updated.
55 * @param timestamp time when the estimate was received from the server (or created by the server)
56 * @param estimate the value of the current network size estimate
57 * @param std_dev standard deviation (rounded down to nearest integer)
58 * of the size estimation values seen
62 check_nse_message (void *cls, struct GNUNET_TIME_Absolute timestamp,
63 double estimate, double std_dev)
68 "Received NSE message, estimate %f, standard deviation %f.\n",
70 /* Fantastic check below. Expect NaN, the only thing not equal to itself. */
72 if (die_task != GNUNET_SCHEDULER_NO_TASK)
73 GNUNET_SCHEDULER_cancel (die_task);
74 die_task = GNUNET_SCHEDULER_add_now (&end_test, NULL);
80 const struct GNUNET_CONFIGURATION_Handle *cfg,
81 struct GNUNET_TESTING_Peer *peer)
84 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
85 (GNUNET_TIME_UNIT_MINUTES, 1), &end_test,
88 h = GNUNET_NSE_connect (cfg, &check_nse_message, cls);
89 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to NSE service.\n");
90 GNUNET_assert (h != NULL);
95 main (int argc, char *argv[])
99 if (0 != GNUNET_TESTING_peer_run ("test_nse_api",
106 /* end of test_nse_api.c */