aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo/test_peerinfo_shipped_hellos.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/peerinfo/test_peerinfo_shipped_hellos.c')
-rw-r--r--src/peerinfo/test_peerinfo_shipped_hellos.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/peerinfo/test_peerinfo_shipped_hellos.c b/src/peerinfo/test_peerinfo_shipped_hellos.c
new file mode 100644
index 000000000..e8cbd519d
--- /dev/null
+++ b/src/peerinfo/test_peerinfo_shipped_hellos.c
@@ -0,0 +1,118 @@
1/*
2 This file is part of GNUnet.
3 (C) 2004, 2009 Christian Grothoff (and other contributing authors)
4
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.
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 General Public License for more details.
14
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.
19*/
20
21/**
22 * @file peerinfo/test_peerinfo_api.c
23 * @brief testcase for shipped HELLOs getting parsed
24 * @author Christian Grothoff
25 * @author Matthias Wachs
26 *
27 */
28#include "platform.h"
29#include "gnunet_hello_lib.h"
30#include "gnunet_util_lib.h"
31#include "gnunet_peerinfo_service.h"
32#include "gnunet_testing_lib.h"
33#include "peerinfo.h"
34
35static struct GNUNET_PEERINFO_IteratorContext *ic;
36
37static struct GNUNET_PEERINFO_Handle *h;
38
39static int global_ret;
40
41static int
42addr_cb (void *cls,
43 const struct GNUNET_HELLO_Address *address,
44 struct GNUNET_TIME_Absolute expiration)
45{;
46 int *addr = cls;
47 (*addr) ++;
48 return GNUNET_OK;
49}
50
51static void
52process (void *cls, const struct GNUNET_PeerIdentity *peer,
53 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
54{
55 static unsigned int calls = 0;
56 int addr;
57
58 if (err_msg != NULL)
59 {
60 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
61 _("Error in communication with PEERINFO service\n"));
62 }
63 if (NULL != peer)
64 {
65 addr = 0;
66 if (NULL != hello)
67 {
68 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &addr_cb, &addr);
69 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got information about peer `%s' with %u addresses \n",
70 GNUNET_i2s (peer), addr);
71 calls++;
72 }
73 else
74 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail: Got information about peer `%s' without HELLO \n",
75 GNUNET_i2s (peer));
76 }
77 else
78 {
79 if (0 == calls)
80 {
81 fprintf (stderr, "Failed: %u callbacks\n", calls);
82 global_ret = 1;
83 }
84 else
85 {
86 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed: %u callbacks\n", calls);
87 global_ret = 0;
88 }
89 }
90}
91
92
93static void
94run (void *cls,
95 const struct GNUNET_CONFIGURATION_Handle *cfg,
96 struct GNUNET_TESTING_Peer *peer)
97{
98 h = GNUNET_PEERINFO_connect (cfg);
99 GNUNET_assert (NULL != h);
100 ic = GNUNET_PEERINFO_iterate (h, GNUNET_YES, NULL,
101 GNUNET_TIME_relative_multiply
102 (GNUNET_TIME_UNIT_SECONDS, 15), &process, cls);
103}
104
105
106int
107main (int argc, char *argv[])
108{
109 global_ret = 3;
110 if (0 != GNUNET_TESTING_service_run ("test_peerinfo_system_hellos",
111 "peerinfo",
112 "test_peerinfo_api_data.conf",
113 &run, NULL))
114 return 1;
115 return global_ret;
116}
117
118/* end of test_peerinfo_shipped_hellos.c */