2 This file is part of GNUnet.
3 Copyright (C) 2009, 2013, 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_service.c
22 * @brief tests for service.c
23 * @author Christian Grothoff
26 #include "gnunet_util_lib.h"
29 * Message type we use for testing.
33 #define TIMEOUT GNUNET_TIME_UNIT_SECONDS
35 static int global_ret = 1;
37 static struct GNUNET_MQ_Handle *mq;
42 static struct GNUNET_SCHEDULER_Task *tt;
46 handle_recv (void *cls,
47 const struct GNUNET_MessageHeader *message)
49 struct GNUNET_SERVICE_Client *client = cls;
51 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
52 "Received client message...\n");
53 GNUNET_SERVICE_client_continue (client);
57 GNUNET_MQ_destroy (mq);
64 * Function called when the client connects to the service.
66 * @param cls the name of the service
67 * @param c connecting client
68 * @param mq message queue to talk to the client
69 * @return @a c so we have the client handle in the future
72 connect_cb (void *cls,
73 struct GNUNET_SERVICE_Client *c,
74 struct GNUNET_MQ_Handle *mq)
76 /* FIXME: in the future, do something with mq
77 to test sending messages to the client! */
83 * Function called when the client disconnects.
85 * @param cls our service name
86 * @param c disconnecting client
87 * @param internal_cls must match @a c
90 disconnect_cb (void *cls,
91 struct GNUNET_SERVICE_Client *c,
94 GNUNET_assert (c == internal_cls);
97 GNUNET_SCHEDULER_shutdown ();
101 GNUNET_SCHEDULER_cancel (tt);
109 timeout_task (void *cls)
114 GNUNET_MQ_destroy (mq);
118 GNUNET_SCHEDULER_shutdown ();
123 * Initialization function of the service. Starts
124 * a client to connect to the service.
126 * @param cls the name of the service (const char *)
127 * @param cfg the configuration we use
128 * @param sh handle to the service
131 service_init (void *cls,
132 const struct GNUNET_CONFIGURATION_Handle *cfg,
133 struct GNUNET_SERVICE_Handle *sh)
135 const char *service_name = cls;
136 struct GNUNET_MQ_Envelope *env;
137 struct GNUNET_MessageHeader *msg;
139 GNUNET_assert (NULL == tt);
140 tt = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
143 mq = GNUNET_CLIENT_connect (cfg,
148 GNUNET_assert (NULL != mq);
149 env = GNUNET_MQ_msg (msg,
157 * Main method, starts the service and initiates
158 * the running of the test.
160 * @param sname name of the service to run
163 check (const char *sname)
165 struct GNUNET_MQ_MessageHandler myhandlers[] = {
166 GNUNET_MQ_hd_fixed_size (recv,
168 struct GNUNET_MessageHeader,
170 GNUNET_MQ_handler_end ()
172 char *const argv[] = {
175 "test_service_data.conf",
179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
180 "Starting `%s' service\n",
184 GNUNET_SERVICE_run_ (3,
187 GNUNET_SERVICE_OPTION_NONE,
202 struct GNUNET_NETWORK_Handle *s = NULL;
204 GNUNET_log_setup ("test-service",
207 ret += check ("test_service");
208 ret += check ("test_service");
210 s = GNUNET_NETWORK_socket_create (PF_INET6,
216 if ( (errno == ENOBUFS) ||
221 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
226 "IPv6 support seems to not be available (%s), not testing it!\n",
231 GNUNET_break (GNUNET_OK ==
232 GNUNET_NETWORK_socket_close (s));
233 ret += check ("test_service6");
238 /* end of test_service.c */