2 This file is part of GNUnet.
3 Copyright (C) 2009, 2011, 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 arm/test_arm_api.c
20 * @brief testcase for arm_api.c
23 #include "gnunet_util_lib.h"
24 #include "gnunet_arm_service.h"
25 #include "gnunet_resolver_service.h"
27 #define LOG(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
29 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
31 static const struct GNUNET_CONFIGURATION_Handle *cfg;
33 static struct GNUNET_ARM_Handle *arm;
35 static struct GNUNET_ARM_Operation *op;
43 arm_stop_cb (void *cls,
44 enum GNUNET_ARM_RequestStatus status,
45 enum GNUNET_ARM_Result result)
48 /* (6), a stop request should be sent to ARM successfully */
49 /* ARM should report that it is stopping */
50 GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
51 GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED);
52 GNUNET_break (phase == 6);
54 LOG ("Sent 'STOP' request for arm to ARM %s\n",
55 (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
56 GNUNET_SCHEDULER_shutdown ();
61 resolver_stop_cb (void *cls,
62 enum GNUNET_ARM_RequestStatus status,
63 enum GNUNET_ARM_Result result)
66 /* (5), a stop request should be sent to ARM successfully.
67 * ARM should report that resolver is stopped.
69 GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
70 GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED);
71 GNUNET_break (phase == 5);
72 LOG ("Sent 'STOP' request for resolver to ARM %s\n",
73 (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
75 GNUNET_assert (NULL == op);
76 op = GNUNET_ARM_request_service_stop (arm,
84 dns_notify (void *cls,
85 const struct sockaddr *addr,
90 /* (4), resolver should finish resolving localhost */
91 GNUNET_break (phase == 4);
93 LOG ("Finished resolving localhost\n");
96 GNUNET_assert (NULL == op);
97 op = GNUNET_ARM_request_service_stop (arm,
103 /* (3), resolver should resolve localhost */
104 GNUNET_break (phase == 3);
105 LOG ("Resolved localhost\n");
107 GNUNET_break (addr != NULL);
113 resolver_start_cb (void *cls,
114 enum GNUNET_ARM_RequestStatus status,
115 enum GNUNET_ARM_Result result)
118 /* (2), the start request for resolver should be sent successfully
119 * ARM should report that resolver service is starting.
121 GNUNET_assert (status == GNUNET_ARM_REQUEST_SENT_OK);
122 GNUNET_break (phase == 2);
123 GNUNET_break (result == GNUNET_ARM_RESULT_STARTING);
124 LOG ("Sent 'START' request for resolver to ARM %s\n",
125 (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
127 GNUNET_RESOLVER_ip_get ("localhost",
138 if (GNUNET_SYSERR == connected)
140 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
141 _("Fatal error initializing ARM API.\n"));
142 GNUNET_SCHEDULER_shutdown ();
146 if (GNUNET_YES == connected)
148 /* (1), arm connection should be established */
149 LOG ("Connected to ARM\n");
150 GNUNET_break (phase == 1);
152 GNUNET_assert (NULL == op);
153 op = GNUNET_ARM_request_service_start (arm,
155 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
161 /* (7), ARM should stop (we disconnect from it) */
162 LOG ("Disconnected from ARM\n");
163 GNUNET_break (phase == 7);
173 arm_start_cb (void *cls,
174 enum GNUNET_ARM_RequestStatus status,
175 enum GNUNET_ARM_Result result)
178 /* (0) The request should be "sent" successfully
179 * ("sent", because it isn't going anywhere, ARM API starts ARM service
181 * ARM API should report that ARM service is starting.
183 GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
184 GNUNET_break (phase == 0);
185 LOG ("Sent 'START' request for arm to ARM %s\n",
186 (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
187 GNUNET_break (result == GNUNET_ARM_RESULT_STARTING);
193 do_shutdown (void *cls)
197 GNUNET_ARM_operation_cancel (op);
202 GNUNET_ARM_disconnect (arm);
212 const struct GNUNET_CONFIGURATION_Handle *c)
215 arm = GNUNET_ARM_connect (cfg,
220 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
222 op = GNUNET_ARM_request_service_start (arm,
224 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
231 main (int argc, char *argvx[])
233 char *const argv[] = {
235 "-c", "test_arm_api_data.conf",
238 struct GNUNET_GETOPT_CommandLineOption options[] = {
239 GNUNET_GETOPT_OPTION_END
241 GNUNET_log_setup ("test-arm-api",
244 GNUNET_assert (GNUNET_OK ==
245 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
246 argv, "test-arm-api", "nohelp", options,
251 /* end of test_arm_api.c */