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
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.
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.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @file util/test_client.c
22 * @brief tests for client.c
23 * @author Christian Grothoff
26 #include "gnunet_util_lib.h"
28 static int global_ret;
30 static struct GNUNET_MQ_Handle *client_mq;
36 * Callback that just bounces the message back to the sender.
39 handle_echo (void *cls,
40 const struct GNUNET_MessageHeader *message)
42 struct GNUNET_SERVICE_Client *c = cls;
43 struct GNUNET_MQ_Handle *mq = GNUNET_SERVICE_client_get_mq (c);
44 struct GNUNET_MQ_Envelope *env;
46 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
47 "Receiving message from client, bouncing back\n");
48 env = GNUNET_MQ_msg_copy (message);
51 GNUNET_SERVICE_client_continue (c);
56 handle_bounce (void *cls,
57 const struct GNUNET_MessageHeader *got)
59 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
60 "Receiving bounce, checking content\n");
61 GNUNET_assert (NULL != got);
63 GNUNET_MQ_destroy (client_mq);
69 * Generic error handler, called with the appropriate error code and
70 * the same closure specified at the creation of the message queue.
71 * Not every message queue implementation supports an error handler.
73 * @param cls closure with the `struct GNUNET_STATISTICS_Handle *`
74 * @param error error code
77 mq_error_handler (void *cls,
78 enum GNUNET_MQ_Error error)
80 GNUNET_assert (0); /* should never happen */
86 const struct GNUNET_CONFIGURATION_Handle *cfg,
87 struct GNUNET_SERVICE_Handle *sh)
89 struct GNUNET_MQ_MessageHandler chandlers[] = {
90 GNUNET_MQ_hd_fixed_size (bounce,
92 struct GNUNET_MessageHeader,
94 GNUNET_MQ_handler_end ()
96 struct GNUNET_MQ_Envelope *env;
97 struct GNUNET_MessageHeader *msg;
99 /* test that ill-configured client fails instantly */
100 GNUNET_assert (NULL ==
101 GNUNET_CLIENT_connect (cfg,
106 client_mq = GNUNET_CLIENT_connect (cfg,
111 GNUNET_assert (NULL != client_mq);
112 env = GNUNET_MQ_msg (msg,
114 GNUNET_MQ_send (client_mq,
120 * Function called when the client connects to the service.
122 * @param cls the name of the service
123 * @param c connecting client
124 * @param mq message queue to talk to the client
128 connect_cb (void *cls,
129 struct GNUNET_SERVICE_Client *c,
130 struct GNUNET_MQ_Handle *mq)
137 * Function called when the client disconnects.
139 * @param cls our service name
140 * @param c disconnecting client
141 * @param internal_cls must match @a c
144 disconnect_cb (void *cls,
145 struct GNUNET_SERVICE_Client *c,
150 GNUNET_SCHEDULER_shutdown ();
160 struct GNUNET_MQ_MessageHandler shandlers[] = {
161 GNUNET_MQ_hd_fixed_size (echo,
163 struct GNUNET_MessageHeader,
165 GNUNET_MQ_handler_end ()
167 char * test_argv[] = {
168 (char *) "test_client",
170 "test_client_data.conf",
174 GNUNET_log_setup ("test_client",
177 if (0 != strstr (argv[0],
179 test_argv[2] = "test_client_unix.conf";
182 GNUNET_SERVICE_run_ (3,
185 GNUNET_SERVICE_OPTION_NONE,
195 /* end of test_client.c */