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);
55 GNUNET_MQ_destroy (mq);
61 * Function called when the client connects to the service.
63 * @param cls the name of the service
64 * @param c connecting client
65 * @param mq message queue to talk to the client
66 * @return @a c so we have the client handle in the future
69 connect_cb (void *cls,
70 struct GNUNET_SERVICE_Client *c,
71 struct GNUNET_MQ_Handle *mq)
73 /* FIXME: in the future, do something with mq
74 to test sending messages to the client! */
80 * Function called when the client disconnects.
82 * @param cls our service name
83 * @param c disconnecting client
84 * @param internal_cls must match @a c
87 disconnect_cb (void *cls,
88 struct GNUNET_SERVICE_Client *c,
91 GNUNET_assert (c == internal_cls);
94 GNUNET_SCHEDULER_shutdown ();
98 GNUNET_SCHEDULER_cancel (tt);
106 timeout_task (void *cls)
110 GNUNET_SCHEDULER_shutdown ();
115 * Initialization function of the service. Starts
116 * a client to connect to the service.
118 * @param cls the name of the service (const char *)
119 * @param cfg the configuration we use
120 * @param sh handle to the service
123 service_init (void *cls,
124 const struct GNUNET_CONFIGURATION_Handle *cfg,
125 struct GNUNET_SERVICE_Handle *sh)
127 const char *service_name = cls;
128 struct GNUNET_MQ_Envelope *env;
129 struct GNUNET_MessageHeader *msg;
131 GNUNET_assert (NULL == tt);
132 tt = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
135 mq = GNUNET_CLIENT_connect (cfg,
140 GNUNET_assert (NULL != mq);
141 env = GNUNET_MQ_msg (msg,
149 * Main method, starts the service and initiates
150 * the running of the test.
152 * @param sname name of the service to run
155 check (const char *sname)
157 struct GNUNET_MQ_MessageHandler myhandlers[] = {
158 GNUNET_MQ_hd_fixed_size (recv,
160 struct GNUNET_MessageHeader,
162 GNUNET_MQ_handler_end ()
164 char *const argv[] = {
167 "test_service_data.conf",
171 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
172 "Starting `%s' service\n",
176 GNUNET_SERVICE_run_ (3,
179 GNUNET_SERVICE_OPTION_NONE,
194 struct GNUNET_NETWORK_Handle *s = NULL;
196 GNUNET_log_setup ("test-service",
199 ret += check ("test_service");
200 ret += check ("test_service");
202 s = GNUNET_NETWORK_socket_create (PF_INET6,
208 if ( (errno == ENOBUFS) ||
213 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
218 "IPv6 support seems to not be available (%s), not testing it!\n",
223 GNUNET_break (GNUNET_OK ==
224 GNUNET_NETWORK_socket_close (s));
225 ret += check ("test_service6");
230 /* end of test_service.c */