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 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_service.c
20 * @brief tests for service.c
21 * @author Christian Grothoff
24 #include "gnunet_util_lib.h"
27 * Message type we use for testing.
31 #define TIMEOUT GNUNET_TIME_UNIT_SECONDS
33 static int global_ret = 1;
35 static struct GNUNET_MQ_Handle *mq;
40 static struct GNUNET_SCHEDULER_Task *tt;
44 handle_recv (void *cls,
45 const struct GNUNET_MessageHeader *message)
47 struct GNUNET_SERVICE_Client *client = cls;
49 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
50 "Received client message...\n");
51 GNUNET_SERVICE_client_continue (client);
55 GNUNET_MQ_destroy (mq);
62 * Function called when the client connects to the service.
64 * @param cls the name of the service
65 * @param c connecting client
66 * @param mq message queue to talk to the client
67 * @return @a c so we have the client handle in the future
70 connect_cb (void *cls,
71 struct GNUNET_SERVICE_Client *c,
72 struct GNUNET_MQ_Handle *mq)
74 /* FIXME: in the future, do something with mq
75 to test sending messages to the client! */
81 * Function called when the client disconnects.
83 * @param cls our service name
84 * @param c disconnecting client
85 * @param internal_cls must match @a c
88 disconnect_cb (void *cls,
89 struct GNUNET_SERVICE_Client *c,
92 GNUNET_assert (c == internal_cls);
95 GNUNET_SCHEDULER_shutdown ();
99 GNUNET_SCHEDULER_cancel (tt);
107 timeout_task (void *cls)
112 GNUNET_MQ_destroy (mq);
116 GNUNET_SCHEDULER_shutdown ();
121 * Initialization function of the service. Starts
122 * a client to connect to the service.
124 * @param cls the name of the service (const char *)
125 * @param cfg the configuration we use
126 * @param sh handle to the service
129 service_init (void *cls,
130 const struct GNUNET_CONFIGURATION_Handle *cfg,
131 struct GNUNET_SERVICE_Handle *sh)
133 const char *service_name = cls;
134 struct GNUNET_MQ_Envelope *env;
135 struct GNUNET_MessageHeader *msg;
137 GNUNET_assert (NULL == tt);
138 tt = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
141 mq = GNUNET_CLIENT_connect (cfg,
146 GNUNET_assert (NULL != mq);
147 env = GNUNET_MQ_msg (msg,
155 * Main method, starts the service and initiates
156 * the running of the test.
158 * @param sname name of the service to run
161 check (const char *sname)
163 struct GNUNET_MQ_MessageHandler myhandlers[] = {
164 GNUNET_MQ_hd_fixed_size (recv,
166 struct GNUNET_MessageHeader,
168 GNUNET_MQ_handler_end ()
170 char *const argv[] = {
173 "test_service_data.conf",
177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
178 "Starting `%s' service\n",
182 GNUNET_SERVICE_run_ (3,
185 GNUNET_SERVICE_OPTION_NONE,
200 struct GNUNET_NETWORK_Handle *s = NULL;
202 GNUNET_log_setup ("test-service",
205 ret += check ("test_service");
206 ret += check ("test_service");
208 s = GNUNET_NETWORK_socket_create (PF_INET6,
214 if ( (errno == ENOBUFS) ||
219 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
224 "IPv6 support seems to not be available (%s), not testing it!\n",
229 GNUNET_break (GNUNET_OK ==
230 GNUNET_NETWORK_socket_close (s));
231 ret += check ("test_service6");
236 /* end of test_service.c */