aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_client.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/test_client.c')
-rw-r--r--src/util/test_client.c154
1 files changed, 77 insertions, 77 deletions
diff --git a/src/util/test_client.c b/src/util/test_client.c
index 365b8663f..b49fbcd25 100644
--- a/src/util/test_client.c
+++ b/src/util/test_client.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file util/test_client.c 21 * @file util/test_client.c
22 * @brief tests for client.c 22 * @brief tests for client.c
@@ -36,31 +36,31 @@ static struct GNUNET_MQ_Handle *client_mq;
36 * Callback that just bounces the message back to the sender. 36 * Callback that just bounces the message back to the sender.
37 */ 37 */
38static void 38static void
39handle_echo (void *cls, 39handle_echo(void *cls,
40 const struct GNUNET_MessageHeader *message) 40 const struct GNUNET_MessageHeader *message)
41{ 41{
42 struct GNUNET_SERVICE_Client *c = cls; 42 struct GNUNET_SERVICE_Client *c = cls;
43 struct GNUNET_MQ_Handle *mq = GNUNET_SERVICE_client_get_mq (c); 43 struct GNUNET_MQ_Handle *mq = GNUNET_SERVICE_client_get_mq(c);
44 struct GNUNET_MQ_Envelope *env; 44 struct GNUNET_MQ_Envelope *env;
45 45
46 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 46 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
47 "Receiving message from client, bouncing back\n"); 47 "Receiving message from client, bouncing back\n");
48 env = GNUNET_MQ_msg_copy (message); 48 env = GNUNET_MQ_msg_copy(message);
49 GNUNET_MQ_send (mq, 49 GNUNET_MQ_send(mq,
50 env); 50 env);
51 GNUNET_SERVICE_client_continue (c); 51 GNUNET_SERVICE_client_continue(c);
52} 52}
53 53
54 54
55static void 55static void
56handle_bounce (void *cls, 56handle_bounce(void *cls,
57 const struct GNUNET_MessageHeader *got) 57 const struct GNUNET_MessageHeader *got)
58{ 58{
59 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 59 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
60 "Receiving bounce, checking content\n"); 60 "Receiving bounce, checking content\n");
61 GNUNET_assert (NULL != got); 61 GNUNET_assert(NULL != got);
62 global_ret = 2; 62 global_ret = 2;
63 GNUNET_MQ_destroy (client_mq); 63 GNUNET_MQ_destroy(client_mq);
64 client_mq = NULL; 64 client_mq = NULL;
65} 65}
66 66
@@ -74,45 +74,45 @@ handle_bounce (void *cls,
74 * @param error error code 74 * @param error error code
75 */ 75 */
76static void 76static void
77mq_error_handler (void *cls, 77mq_error_handler(void *cls,
78 enum GNUNET_MQ_Error error) 78 enum GNUNET_MQ_Error error)
79{ 79{
80 GNUNET_assert (0); /* should never happen */ 80 GNUNET_assert(0); /* should never happen */
81} 81}
82 82
83 83
84static void 84static void
85task (void *cls, 85task(void *cls,
86 const struct GNUNET_CONFIGURATION_Handle *cfg, 86 const struct GNUNET_CONFIGURATION_Handle *cfg,
87 struct GNUNET_SERVICE_Handle *sh) 87 struct GNUNET_SERVICE_Handle *sh)
88{ 88{
89 struct GNUNET_MQ_MessageHandler chandlers[] = { 89 struct GNUNET_MQ_MessageHandler chandlers[] = {
90 GNUNET_MQ_hd_fixed_size (bounce, 90 GNUNET_MQ_hd_fixed_size(bounce,
91 MY_TYPE, 91 MY_TYPE,
92 struct GNUNET_MessageHeader, 92 struct GNUNET_MessageHeader,
93 cls), 93 cls),
94 GNUNET_MQ_handler_end () 94 GNUNET_MQ_handler_end()
95 }; 95 };
96 struct GNUNET_MQ_Envelope *env; 96 struct GNUNET_MQ_Envelope *env;
97 struct GNUNET_MessageHeader *msg; 97 struct GNUNET_MessageHeader *msg;
98 98
99 /* test that ill-configured client fails instantly */ 99 /* test that ill-configured client fails instantly */
100 GNUNET_assert (NULL == 100 GNUNET_assert(NULL ==
101 GNUNET_CLIENT_connect (cfg, 101 GNUNET_CLIENT_connect(cfg,
102 "invalid-service", 102 "invalid-service",
103 NULL, 103 NULL,
104 &mq_error_handler, 104 &mq_error_handler,
105 NULL)); 105 NULL));
106 client_mq = GNUNET_CLIENT_connect (cfg, 106 client_mq = GNUNET_CLIENT_connect(cfg,
107 "test_client", 107 "test_client",
108 chandlers, 108 chandlers,
109 &mq_error_handler, 109 &mq_error_handler,
110 NULL); 110 NULL);
111 GNUNET_assert (NULL != client_mq); 111 GNUNET_assert(NULL != client_mq);
112 env = GNUNET_MQ_msg (msg, 112 env = GNUNET_MQ_msg(msg,
113 MY_TYPE); 113 MY_TYPE);
114 GNUNET_MQ_send (client_mq, 114 GNUNET_MQ_send(client_mq,
115 env); 115 env);
116} 116}
117 117
118 118
@@ -125,9 +125,9 @@ task (void *cls,
125 * @return @a c 125 * @return @a c
126 */ 126 */
127static void * 127static void *
128connect_cb (void *cls, 128connect_cb(void *cls,
129 struct GNUNET_SERVICE_Client *c, 129 struct GNUNET_SERVICE_Client *c,
130 struct GNUNET_MQ_Handle *mq) 130 struct GNUNET_MQ_Handle *mq)
131{ 131{
132 return c; 132 return c;
133} 133}
@@ -139,55 +139,55 @@ connect_cb (void *cls,
139 * @param cls our service name 139 * @param cls our service name
140 * @param c disconnecting client 140 * @param c disconnecting client
141 * @param internal_cls must match @a c 141 * @param internal_cls must match @a c
142 */ 142 */
143static void 143static void
144disconnect_cb (void *cls, 144disconnect_cb(void *cls,
145 struct GNUNET_SERVICE_Client *c, 145 struct GNUNET_SERVICE_Client *c,
146 void *internal_cls) 146 void *internal_cls)
147{ 147{
148 if (2 == global_ret) 148 if (2 == global_ret)
149 { 149 {
150 GNUNET_SCHEDULER_shutdown (); 150 GNUNET_SCHEDULER_shutdown();
151 global_ret = 0; 151 global_ret = 0;
152 } 152 }
153} 153}
154 154
155 155
156int 156int
157main (int argc, 157main(int argc,
158 char *argv[]) 158 char *argv[])
159{ 159{
160 struct GNUNET_MQ_MessageHandler shandlers[] = { 160 struct GNUNET_MQ_MessageHandler shandlers[] = {
161 GNUNET_MQ_hd_fixed_size (echo, 161 GNUNET_MQ_hd_fixed_size(echo,
162 MY_TYPE, 162 MY_TYPE,
163 struct GNUNET_MessageHeader, 163 struct GNUNET_MessageHeader,
164 NULL), 164 NULL),
165 GNUNET_MQ_handler_end () 165 GNUNET_MQ_handler_end()
166 }; 166 };
167 char * test_argv[] = { 167 char * test_argv[] = {
168 (char *) "test_client", 168 (char *)"test_client",
169 "-c", 169 "-c",
170 "test_client_data.conf", 170 "test_client_data.conf",
171 NULL 171 NULL
172 }; 172 };
173 173
174 GNUNET_log_setup ("test_client", 174 GNUNET_log_setup("test_client",
175 "WARNING", 175 "WARNING",
176 NULL); 176 NULL);
177 if (0 != strstr (argv[0], 177 if (0 != strstr(argv[0],
178 "unix")) 178 "unix"))
179 test_argv[2] = "test_client_unix.conf"; 179 test_argv[2] = "test_client_unix.conf";
180 global_ret = 1; 180 global_ret = 1;
181 if (0 != 181 if (0 !=
182 GNUNET_SERVICE_run_ (3, 182 GNUNET_SERVICE_run_(3,
183 test_argv, 183 test_argv,
184 "test_client", 184 "test_client",
185 GNUNET_SERVICE_OPTION_NONE, 185 GNUNET_SERVICE_OPTION_NONE,
186 &task, 186 &task,
187 &connect_cb, 187 &connect_cb,
188 &disconnect_cb, 188 &disconnect_cb,
189 NULL, 189 NULL,
190 shandlers)) 190 shandlers))
191 global_ret = 3; 191 global_ret = 3;
192 return global_ret; 192 return global_ret;
193} 193}