aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo/test_peerinfo_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-10 01:20:55 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-10 01:20:55 +0000
commitc25db0cd4a0c561323b47cdd880866eab473ed49 (patch)
tree7d6ca5eb8cea6dc1503a1f21f718f2e207e27ff6 /src/peerinfo/test_peerinfo_api.c
parent5ab33d2f38aa43fd772e33e70fb709e6c91b1d8a (diff)
downloadgnunet-c25db0cd4a0c561323b47cdd880866eab473ed49.tar.gz
gnunet-c25db0cd4a0c561323b47cdd880866eab473ed49.zip
-using new testing library for peerinfo test
Diffstat (limited to 'src/peerinfo/test_peerinfo_api.c')
-rw-r--r--src/peerinfo/test_peerinfo_api.c79
1 files changed, 20 insertions, 59 deletions
diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c
index e66878ea6..0bd5ef707 100644
--- a/src/peerinfo/test_peerinfo_api.c
+++ b/src/peerinfo/test_peerinfo_api.c
@@ -26,24 +26,22 @@
26 * TODO: 26 * TODO:
27 * - test merging of HELLOs (add same peer twice...) 27 * - test merging of HELLOs (add same peer twice...)
28 */ 28 */
29
30#include "platform.h" 29#include "platform.h"
31#include "gnunet_hello_lib.h" 30#include "gnunet_hello_lib.h"
32#include "gnunet_getopt_lib.h" 31#include "gnunet_util_lib.h"
33#include "gnunet_os_lib.h"
34#include "gnunet_peerinfo_service.h" 32#include "gnunet_peerinfo_service.h"
35#include "gnunet_program_lib.h" 33#include "gnunet_testing_lib-new.h"
36#include "gnunet_time_lib.h"
37#include "peerinfo.h" 34#include "peerinfo.h"
38 35
39static const struct GNUNET_CONFIGURATION_Handle *cfg;
40
41static struct GNUNET_PEERINFO_IteratorContext *ic; 36static struct GNUNET_PEERINFO_IteratorContext *ic;
42 37
43static struct GNUNET_PEERINFO_Handle *h; 38static struct GNUNET_PEERINFO_Handle *h;
44 39
45static unsigned int retries; 40static unsigned int retries;
46 41
42static int global_ret;
43
44
47static int 45static int
48check_it (void *cls, const struct GNUNET_HELLO_Address *address, 46check_it (void *cls, const struct GNUNET_HELLO_Address *address,
49 struct GNUNET_TIME_Absolute expiration) 47 struct GNUNET_TIME_Absolute expiration)
@@ -106,7 +104,6 @@ static void
106process (void *cls, const struct GNUNET_PeerIdentity *peer, 104process (void *cls, const struct GNUNET_PeerIdentity *peer,
107 const struct GNUNET_HELLO_Message *hello, const char *err_msg) 105 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
108{ 106{
109 int *ok = cls;
110 unsigned int agc; 107 unsigned int agc;
111 108
112 if (err_msg != NULL) 109 if (err_msg != NULL)
@@ -118,7 +115,7 @@ process (void *cls, const struct GNUNET_PeerIdentity *peer,
118 if (peer == NULL) 115 if (peer == NULL)
119 { 116 {
120 ic = NULL; 117 ic = NULL;
121 if ((3 == *ok) && (retries < 50)) 118 if ((3 == global_ret) && (retries < 50))
122 { 119 {
123 /* try again */ 120 /* try again */
124 retries++; 121 retries++;
@@ -130,30 +127,29 @@ process (void *cls, const struct GNUNET_PeerIdentity *peer,
130 return; 127 return;
131 } 128 }
132 GNUNET_assert (peer == NULL); 129 GNUNET_assert (peer == NULL);
133 GNUNET_assert (2 == *ok); 130 GNUNET_assert (2 == global_ret);
134 GNUNET_PEERINFO_disconnect (h); 131 GNUNET_PEERINFO_disconnect (h);
135 h = NULL; 132 h = NULL;
136 *ok = 0; 133 global_ret = 0;
137 return; 134 return;
138 } 135 }
139 if (hello != NULL) 136 if (hello != NULL)
140 { 137 {
141 GNUNET_assert (3 == *ok); 138 GNUNET_assert (3 == global_ret);
142 agc = 3; 139 agc = 3;
143 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, &agc); 140 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, &agc);
144 GNUNET_assert (agc == 0); 141 GNUNET_assert (agc == 0);
145 *ok = 2; 142 global_ret = 2;
146 } 143 }
147} 144}
148 145
149 146
150static void 147static void
151run (void *cls, char *const *args, const char *cfgfile, 148run (void *cls,
152 const struct GNUNET_CONFIGURATION_Handle *c) 149 const struct GNUNET_CONFIGURATION_Handle *cfg)
153{ 150{
154 cfg = c;
155 h = GNUNET_PEERINFO_connect (cfg); 151 h = GNUNET_PEERINFO_connect (cfg);
156 GNUNET_assert (h != NULL); 152 GNUNET_assert (NULL != h);
157 add_peer (); 153 add_peer ();
158 ic = GNUNET_PEERINFO_iterate (h, NULL, 154 ic = GNUNET_PEERINFO_iterate (h, NULL,
159 GNUNET_TIME_relative_multiply 155 GNUNET_TIME_relative_multiply
@@ -161,51 +157,16 @@ run (void *cls, char *const *args, const char *cfgfile,
161} 157}
162 158
163 159
164static int
165check ()
166{
167 int ok = 3;
168 struct GNUNET_OS_Process *proc;
169
170 char *const argv[] = { "test-peerinfo-api",
171 "-c",
172 "test_peerinfo_api_data.conf",
173 NULL
174 };
175 struct GNUNET_GETOPT_CommandLineOption options[] = {
176 GNUNET_GETOPT_OPTION_END
177 };
178 proc =
179 GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-peerinfo",
180 "gnunet-service-peerinfo",
181 "-c", "test_peerinfo_api_data.conf", NULL);
182 GNUNET_assert (NULL != proc);
183 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
184 "test-peerinfo-api", "nohelp", options, &run, &ok);
185 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
186 {
187 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
188 ok = 1;
189 }
190 GNUNET_OS_process_wait (proc);
191 GNUNET_OS_process_destroy (proc);
192 proc = NULL;
193 return ok;
194}
195
196
197int 160int
198main (int argc, char *argv[]) 161main (int argc, char *argv[])
199{ 162{
200 int ret = 0; 163 global_ret = 3;
201 164 if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerinfo",
202 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-peerinfo"); 165 "peerinfo",
203 GNUNET_log_setup ("test_peerinfo_api", 166 "test_peerinfo_api_data.conf",
204 "WARNING", 167 &run, NULL))
205 NULL); 168 return 1;
206 ret = check (); 169 return global_ret;
207 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-peerinfo");
208 return ret;
209} 170}
210 171
211/* end of test_peerinfo_api.c */ 172/* end of test_peerinfo_api.c */