aboutsummaryrefslogtreecommitdiff
path: root/src/nse/test_nse_api.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2023-10-18 19:35:11 +0200
committerMartin Schanzenbach <schanzen@gnunet.org>2023-10-18 19:35:11 +0200
commitddfee3f564bff9c5d5719af3132d7869b8783ec4 (patch)
treee6fd7801fe6808797f3418bf081ab68d5a5ec27b /src/nse/test_nse_api.c
parent852718c2473e41bc01ada0d53ad93c7da78e6ec8 (diff)
downloadgnunet-ddfee3f564bff9c5d5719af3132d7869b8783ec4.tar.gz
gnunet-ddfee3f564bff9c5d5719af3132d7869b8783ec4.zip
BUILD: more more components into new structure; ftbfs fix
Diffstat (limited to 'src/nse/test_nse_api.c')
-rw-r--r--src/nse/test_nse_api.c107
1 files changed, 0 insertions, 107 deletions
diff --git a/src/nse/test_nse_api.c b/src/nse/test_nse_api.c
deleted file mode 100644
index f1b7c652b..000000000
--- a/src/nse/test_nse_api.c
+++ /dev/null
@@ -1,107 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2011 GNUnet e.V.
4
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.
9
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.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @file nse/test_nse_api.c
22 * @brief testcase for nse_api.c
23 */
24#include "platform.h"
25#include "gnunet_util_lib.h"
26#include "gnunet_nse_service.h"
27#include "gnunet_testing_lib.h"
28
29
30static struct GNUNET_NSE_Handle *h;
31
32static struct GNUNET_SCHEDULER_Task *die_task;
33
34
35/**
36 * Signature of the main function of a task.
37 *
38 * @param cls closure
39 */
40static void
41end_test (void *cls)
42{
43 if (h != NULL)
44 {
45 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from NSE service.\n");
46 GNUNET_NSE_disconnect (h);
47 }
48}
49
50
51/**
52 * Callback to call when network size estimate is updated.
53 *
54 * @param cls unused
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
59 *
60 */
61static void
62check_nse_message (void *cls, struct GNUNET_TIME_Absolute timestamp,
63 double estimate, double std_dev)
64{
65 int *ok = cls;
66
67 fprintf (stderr,
68 "Received NSE message, estimate %f, standard deviation %f.\n",
69 estimate, std_dev);
70 /* Fantastic check below. Expect NaN, the only thing not equal to itself. */
71 (*ok) = 0;
72 if (die_task != NULL)
73 GNUNET_SCHEDULER_cancel (die_task);
74 die_task = GNUNET_SCHEDULER_add_now (&end_test, NULL);
75}
76
77
78static void
79run (void *cls,
80 const struct GNUNET_CONFIGURATION_Handle *cfg,
81 struct GNUNET_TESTING_Peer *peer)
82{
83 die_task =
84 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
85 (GNUNET_TIME_UNIT_MINUTES, 1), &end_test,
86 NULL);
87
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);
91}
92
93
94int
95main (int argc, char *argv[])
96{
97 int ok = 1;
98
99 if (0 != GNUNET_TESTING_peer_run ("test_nse_api",
100 "test_nse.conf",
101 &run, &ok))
102 return 1;
103 return ok;
104}
105
106
107/* end of test_nse_api.c */