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 static int global_ret = 1;
35 static struct GNUNET_MQ_Handle *mq;
39 handle_recv (void *cls,
40 const struct GNUNET_MessageHeader *message)
42 struct GNUNET_SERVICE_Client *client = cls;
44 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
45 "Received client message...\n");
46 GNUNET_SERVICE_client_continue (client);
48 GNUNET_MQ_destroy (mq);
54 * Function called when the client connects to the service.
56 * @param cls the name of the service
57 * @param c connecting client
58 * @param mq message queue to talk to the client
59 * @return @a c so we have the client handle in the future
62 connect_cb (void *cls,
63 struct GNUNET_SERVICE_Client *c,
64 struct GNUNET_MQ_Handle *mq)
66 /* FIXME: in the future, do something with mq
67 to test sending messages to the client! */
73 * Function called when the client disconnects.
75 * @param cls our service name
76 * @param c disconnecting client
77 * @param internal_cls must match @a c
80 disconnect_cb (void *cls,
81 struct GNUNET_SERVICE_Client *c,
84 GNUNET_assert (c == internal_cls);
87 GNUNET_SCHEDULER_shutdown ();
94 * Initialization function of the service. Starts
95 * a client to connect to the service.
97 * @param cls the name of the service (const char *)
98 * @param cfg the configuration we use
99 * @param sh handle to the service
102 service_init (void *cls,
103 const struct GNUNET_CONFIGURATION_Handle *cfg,
104 struct GNUNET_SERVICE_Handle *sh)
106 const char *service_name = cls;
107 struct GNUNET_MQ_Envelope *env;
108 struct GNUNET_MessageHeader *msg;
110 mq = GNUNET_CLIENT_connect (cfg,
115 GNUNET_assert (NULL != mq);
116 env = GNUNET_MQ_msg (msg,
124 * Main method, starts the service and initiates
125 * the running of the test.
127 * @param sname name of the service to run
130 check (const char *sname)
132 struct GNUNET_MQ_MessageHandler myhandlers[] = {
133 GNUNET_MQ_hd_fixed_size (recv,
135 struct GNUNET_MessageHeader,
137 GNUNET_MQ_handler_end ()
139 char *const argv[] = {
142 "test_service_data.conf",
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
147 "Starting `%s' service\n",
151 GNUNET_SERVICE_run_ (3,
154 GNUNET_SERVICE_OPTION_NONE,
169 struct GNUNET_NETWORK_Handle *s = NULL;
171 GNUNET_log_setup ("test-service",
174 ret += check ("test_service");
175 ret += check ("test_service");
177 s = GNUNET_NETWORK_socket_create (PF_INET6,
183 if ( (errno == ENOBUFS) ||
188 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
193 "IPv6 support seems to not be available (%s), not testing it!\n",
198 GNUNET_break (GNUNET_OK ==
199 GNUNET_NETWORK_socket_close (s));
200 ret += check ("test_service6");
205 /* end of test_service.c */