2 This file is part of GNUnet.
3 Copyright (C) 2009, 2016 GNUnet e.V.
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.
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.
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/>.
19 * @file util/test_client.c
20 * @brief tests for client.c
21 * @author Christian Grothoff
24 #include "gnunet_util_lib.h"
26 static int global_ret;
28 static struct GNUNET_MQ_Handle *client_mq;
34 * Callback that just bounces the message back to the sender.
37 handle_echo (void *cls,
38 const struct GNUNET_MessageHeader *message)
40 struct GNUNET_SERVICE_Client *c = cls;
41 struct GNUNET_MQ_Handle *mq = GNUNET_SERVICE_client_get_mq (c);
42 struct GNUNET_MQ_Envelope *env;
44 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
45 "Receiving message from client, bouncing back\n");
46 env = GNUNET_MQ_msg_copy (message);
49 GNUNET_SERVICE_client_continue (c);
54 handle_bounce (void *cls,
55 const struct GNUNET_MessageHeader *got)
57 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
58 "Receiving bounce, checking content\n");
59 GNUNET_assert (NULL != got);
61 GNUNET_MQ_destroy (client_mq);
67 * Generic error handler, called with the appropriate error code and
68 * the same closure specified at the creation of the message queue.
69 * Not every message queue implementation supports an error handler.
71 * @param cls closure with the `struct GNUNET_STATISTICS_Handle *`
72 * @param error error code
75 mq_error_handler (void *cls,
76 enum GNUNET_MQ_Error error)
78 GNUNET_assert (0); /* should never happen */
84 const struct GNUNET_CONFIGURATION_Handle *cfg,
85 struct GNUNET_SERVICE_Handle *sh)
87 struct GNUNET_MQ_MessageHandler chandlers[] = {
88 GNUNET_MQ_hd_fixed_size (bounce,
90 struct GNUNET_MessageHeader,
92 GNUNET_MQ_handler_end ()
94 struct GNUNET_MQ_Envelope *env;
95 struct GNUNET_MessageHeader *msg;
97 /* test that ill-configured client fails instantly */
98 GNUNET_assert (NULL ==
99 GNUNET_CLIENT_connect (cfg,
104 client_mq = GNUNET_CLIENT_connect (cfg,
109 GNUNET_assert (NULL != client_mq);
110 env = GNUNET_MQ_msg (msg,
112 GNUNET_MQ_send (client_mq,
118 * Function called when the client connects to the service.
120 * @param cls the name of the service
121 * @param c connecting client
122 * @param mq message queue to talk to the client
126 connect_cb (void *cls,
127 struct GNUNET_SERVICE_Client *c,
128 struct GNUNET_MQ_Handle *mq)
135 * Function called when the client disconnects.
137 * @param cls our service name
138 * @param c disconnecting client
139 * @param internal_cls must match @a c
142 disconnect_cb (void *cls,
143 struct GNUNET_SERVICE_Client *c,
148 GNUNET_SCHEDULER_shutdown ();
158 struct GNUNET_MQ_MessageHandler shandlers[] = {
159 GNUNET_MQ_hd_fixed_size (echo,
161 struct GNUNET_MessageHeader,
163 GNUNET_MQ_handler_end ()
165 char * test_argv[] = {
166 (char *) "test_client",
168 "test_client_data.conf",
172 GNUNET_log_setup ("test_client",
175 if (0 != strstr (argv[0],
177 test_argv[2] = "test_client_unix.conf";
180 GNUNET_SERVICE_run_ (3,
183 GNUNET_SERVICE_OPTION_NONE,
193 /* end of test_client.c */