2 This file is part of GNUnet.
3 Copyright (C) 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/>.
20 * @file identity/test_identity.c
21 * @brief testcase for identity service
22 * @author Christian Grothoff
25 #include "gnunet_util_lib.h"
26 #include "gnunet_identity_service.h"
27 #include "gnunet_testing_lib.h"
30 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
34 * Return value from 'main'.
39 * Handle to identity service.
41 static struct GNUNET_IDENTITY_Handle *h;
44 * Handle to identity operation.
46 static struct GNUNET_IDENTITY_Operation *op;
49 * Handle for task for timeout termination.
51 static struct GNUNET_SCHEDULER_Task *endbadly_task;
55 * Clean up all resources used.
62 GNUNET_IDENTITY_cancel (op);
67 GNUNET_IDENTITY_disconnect (h);
70 GNUNET_SCHEDULER_shutdown ();
75 * Termiante the testcase (failure).
88 * Termiante the testcase (success).
93 end_normally (void *cls)
101 * Finish the testcase (successfully).
106 if (NULL != endbadly_task)
108 GNUNET_SCHEDULER_cancel (endbadly_task);
109 endbadly_task = NULL;
111 GNUNET_SCHEDULER_shutdown ();
116 * Called with events about egos.
119 * @param ego ego handle
120 * @param ego_ctx context for application to store data for this ego
121 * (during the lifetime of this process, initially NULL)
122 * @param identifier identifier assigned by the user for this ego,
123 * NULL if the user just deleted the ego and it
124 * must thus no longer be used
127 notification_cb (void *cls,
128 struct GNUNET_IDENTITY_Ego *ego,
130 const char *identifier)
132 static struct GNUNET_IDENTITY_Ego *my_ego;
137 case 0: /* end of initial iteration */
138 GNUNET_assert (NULL == ego);
139 GNUNET_assert (NULL == identifier);
142 GNUNET_assert (NULL != ego);
143 GNUNET_assert (0 == strcmp (identifier,
149 GNUNET_assert (my_ego == ego);
150 GNUNET_assert (0 == strcmp (identifier,
152 GNUNET_assert (*ctx == &round);
154 case 3: /* reconnect-down */
155 GNUNET_assert (my_ego == ego);
156 GNUNET_assert (NULL == identifier);
157 GNUNET_assert (*ctx == &round);
160 case 4: /* reconnect-up */
161 GNUNET_assert (0 == strcmp (identifier,
166 case 5: /* end of iteration after reconnect */
167 GNUNET_assert (NULL == ego);
168 GNUNET_assert (NULL == identifier);
171 GNUNET_assert (my_ego == ego);
172 GNUNET_assert (*ctx == &round);
183 * Continuation called from successful delete operation.
186 * @param emsg (should also be NULL)
189 delete_cont (void *cls,
193 GNUNET_assert (NULL == emsg);
199 * Continue by deleting the "test" identity.
204 finally_delete (void *cls)
206 op = GNUNET_IDENTITY_delete (h,
214 * Continuation called from expected-to-fail rename operation.
217 * @param emsg (should also be NULL)
220 fail_rename_cont (void *cls,
223 GNUNET_assert (NULL != emsg);
225 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
232 * Continuation called from successful rename operation.
235 * @param emsg (should also be NULL)
238 success_rename_cont (void *cls,
241 GNUNET_assert (NULL == emsg);
242 op = GNUNET_IDENTITY_rename (h,
251 * Called with events about created ego.
254 * @param emsg error message
257 create_cb (void *cls,
260 GNUNET_assert (NULL == emsg);
261 op = GNUNET_IDENTITY_rename (h,
264 &success_rename_cont,
270 * Main function of the test, run from scheduler.
273 * @param cfg configuration we use (also to connect to identity service)
274 * @param peer handle to access more of the peer (not used)
278 const struct GNUNET_CONFIGURATION_Handle *cfg,
279 struct GNUNET_TESTING_Peer *peer)
281 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
284 GNUNET_SCHEDULER_add_shutdown (&end_normally,
286 h = GNUNET_IDENTITY_connect (cfg,
289 GNUNET_assert (NULL != h);
290 op = GNUNET_IDENTITY_create (h,
299 main (int argc, char *argv[])
301 GNUNET_DISK_directory_remove ("/tmp/test-identity-service");
304 GNUNET_TESTING_service_run ("test-identity",
306 "test_identity.conf",
314 /* end of test_identity.c */