diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-06-05 21:33:58 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-06-05 21:33:58 +0000 |
commit | a998e0abbd220035bdb333388da229852980e2cc (patch) | |
tree | addf062abb3cc68ab1103a415fbdec315dd54a63 /src/util/test_service.c | |
parent | 4ce2d673d41ad8a8b9e5389b5b97ecb5e77f190d (diff) | |
download | gnunet-a998e0abbd220035bdb333388da229852980e2cc.tar.gz gnunet-a998e0abbd220035bdb333388da229852980e2cc.zip |
-cleaning up client api to test for service availability
Diffstat (limited to 'src/util/test_service.c')
-rw-r--r-- | src/util/test_service.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/util/test_service.c b/src/util/test_service.c index be49d1877..bdd3d8521 100644 --- a/src/util/test_service.c +++ b/src/util/test_service.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2009, 2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published |
@@ -20,6 +20,7 @@ | |||
20 | /** | 20 | /** |
21 | * @file util/test_service.c | 21 | * @file util/test_service.c |
22 | * @brief tests for service.c | 22 | * @brief tests for service.c |
23 | * @author Christian Grothoff | ||
23 | */ | 24 | */ |
24 | #include "platform.h" | 25 | #include "platform.h" |
25 | #include "gnunet_common.h" | 26 | #include "gnunet_common.h" |
@@ -33,6 +34,9 @@ | |||
33 | 34 | ||
34 | #define PORT 12435 | 35 | #define PORT 12435 |
35 | 36 | ||
37 | /** | ||
38 | * Message type we use for testing. | ||
39 | */ | ||
36 | #define MY_TYPE 256 | 40 | #define MY_TYPE 256 |
37 | 41 | ||
38 | static struct GNUNET_SERVICE_Context *sctx; | 42 | static struct GNUNET_SERVICE_Context *sctx; |
@@ -42,8 +46,6 @@ static int ok = 1; | |||
42 | static struct GNUNET_CLIENT_Connection *client; | 46 | static struct GNUNET_CLIENT_Connection *client; |
43 | 47 | ||
44 | 48 | ||
45 | |||
46 | |||
47 | static void | 49 | static void |
48 | do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 50 | do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
49 | { | 51 | { |
@@ -87,11 +89,12 @@ build_msg (void *cls, size_t size, void *buf) | |||
87 | 89 | ||
88 | 90 | ||
89 | static void | 91 | static void |
90 | ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 92 | ready (void *cls, |
93 | int result) | ||
91 | { | 94 | { |
92 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 95 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
93 | 96 | ||
94 | GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)); | 97 | GNUNET_assert (GNUNET_YES == result); |
95 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service confirmed running\n"); | 98 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service confirmed running\n"); |
96 | client = GNUNET_CLIENT_connect ("test_service", cfg); | 99 | client = GNUNET_CLIENT_connect ("test_service", cfg); |
97 | GNUNET_assert (client != NULL); | 100 | GNUNET_assert (client != NULL); |
@@ -108,8 +111,7 @@ static void | |||
108 | recv_cb (void *cls, struct GNUNET_SERVER_Client *sc, | 111 | recv_cb (void *cls, struct GNUNET_SERVER_Client *sc, |
109 | const struct GNUNET_MessageHeader *message) | 112 | const struct GNUNET_MessageHeader *message) |
110 | { | 113 | { |
111 | if (NULL == message) | 114 | GNUNET_assert (NULL != message); |
112 | return; | ||
113 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving client message...\n"); | 115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving client message...\n"); |
114 | GNUNET_SERVER_receive_done (sc, GNUNET_OK); | 116 | GNUNET_SERVER_receive_done (sc, GNUNET_OK); |
115 | GNUNET_SCHEDULER_add_now (&do_stop, NULL); | 117 | GNUNET_SCHEDULER_add_now (&do_stop, NULL); |
@@ -156,13 +158,15 @@ check () | |||
156 | return ok; | 158 | return ok; |
157 | } | 159 | } |
158 | 160 | ||
161 | |||
159 | static void | 162 | static void |
160 | ready6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 163 | ready6 (void *cls, |
164 | int result) | ||
161 | { | 165 | { |
162 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 166 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
163 | 167 | ||
164 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "V6 ready\n"); | 168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "V6 ready\n"); |
165 | GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)); | 169 | GNUNET_assert (GNUNET_YES == result); |
166 | client = GNUNET_CLIENT_connect ("test_service6", cfg); | 170 | client = GNUNET_CLIENT_connect ("test_service6", cfg); |
167 | GNUNET_assert (client != NULL); | 171 | GNUNET_assert (client != NULL); |
168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "V6 client connected\n"); | 172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "V6 client connected\n"); |
@@ -172,6 +176,7 @@ ready6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
172 | &build_msg, NULL); | 176 | &build_msg, NULL); |
173 | } | 177 | } |
174 | 178 | ||
179 | |||
175 | static void | 180 | static void |
176 | runner6 (void *cls, struct GNUNET_SERVER_Handle *server, | 181 | runner6 (void *cls, struct GNUNET_SERVER_Handle *server, |
177 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 182 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
@@ -182,6 +187,7 @@ runner6 (void *cls, struct GNUNET_SERVER_Handle *server, | |||
182 | &ready6, (void *) cfg); | 187 | &ready6, (void *) cfg); |
183 | } | 188 | } |
184 | 189 | ||
190 | |||
185 | /** | 191 | /** |
186 | * Main method, starts scheduler with task1, | 192 | * Main method, starts scheduler with task1, |
187 | * checks that "ok" is correct at the end. | 193 | * checks that "ok" is correct at the end. |
@@ -205,7 +211,6 @@ check6 () | |||
205 | } | 211 | } |
206 | 212 | ||
207 | 213 | ||
208 | |||
209 | static void | 214 | static void |
210 | start_stop_main (void *cls, char *const *args, const char *cfgfile, | 215 | start_stop_main (void *cls, char *const *args, const char *cfgfile, |
211 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 216 | const struct GNUNET_CONFIGURATION_Handle *cfg) |