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.
17 * @file identity/test_identity.c
18 * @brief testcase for identity service
19 * @author Christian Grothoff
22 #include "gnunet_util_lib.h"
23 #include "gnunet_identity_service.h"
24 #include "gnunet_testing_lib.h"
27 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
31 * Return value from 'main'.
36 * Handle to identity service.
38 static struct GNUNET_IDENTITY_Handle *h;
41 * Handle to identity operation.
43 static struct GNUNET_IDENTITY_Operation *op;
46 * Handle for task for timeout termination.
48 static struct GNUNET_SCHEDULER_Task *endbadly_task;
52 * Clean up all resources used.
59 GNUNET_IDENTITY_cancel (op);
64 GNUNET_IDENTITY_disconnect (h);
67 GNUNET_SCHEDULER_shutdown ();
72 * Termiante the testcase (failure).
85 * Termiante the testcase (success).
90 end_normally (void *cls)
98 * Finish the testcase (successfully).
103 if (NULL != endbadly_task)
105 GNUNET_SCHEDULER_cancel (endbadly_task);
106 endbadly_task = NULL;
108 GNUNET_SCHEDULER_shutdown ();
113 * Called with events about egos.
116 * @param ego ego handle
117 * @param ego_ctx context for application to store data for this ego
118 * (during the lifetime of this process, initially NULL)
119 * @param identifier identifier assigned by the user for this ego,
120 * NULL if the user just deleted the ego and it
121 * must thus no longer be used
124 notification_cb (void *cls,
125 struct GNUNET_IDENTITY_Ego *ego,
127 const char *identifier)
129 static struct GNUNET_IDENTITY_Ego *my_ego;
134 case 0: /* end of initial iteration */
135 GNUNET_assert (NULL == ego);
136 GNUNET_assert (NULL == identifier);
139 GNUNET_assert (NULL != ego);
140 GNUNET_assert (0 == strcmp (identifier,
146 GNUNET_assert (my_ego == ego);
147 GNUNET_assert (0 == strcmp (identifier,
149 GNUNET_assert (*ctx == &round);
151 case 3: /* reconnect-down */
152 GNUNET_assert (my_ego == ego);
153 GNUNET_assert (NULL == identifier);
154 GNUNET_assert (*ctx == &round);
157 case 4: /* reconnect-up */
158 GNUNET_assert (0 == strcmp (identifier,
163 case 5: /* end of iteration after reconnect */
164 GNUNET_assert (NULL == ego);
165 GNUNET_assert (NULL == identifier);
168 GNUNET_assert (my_ego == ego);
169 GNUNET_assert (*ctx == &round);
180 * Continuation called from successful delete operation.
183 * @param emsg (should also be NULL)
186 delete_cont (void *cls,
190 GNUNET_assert (NULL == emsg);
196 * Continue by deleting the "test" identity.
201 finally_delete (void *cls)
203 op = GNUNET_IDENTITY_delete (h,
211 * Continuation called from expected-to-fail rename operation.
214 * @param emsg (should also be NULL)
217 fail_rename_cont (void *cls,
220 GNUNET_assert (NULL != emsg);
222 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
229 * Continuation called from successful rename operation.
232 * @param emsg (should also be NULL)
235 success_rename_cont (void *cls,
238 GNUNET_assert (NULL == emsg);
239 op = GNUNET_IDENTITY_rename (h,
248 * Called with events about created ego.
251 * @param emsg error message
254 create_cb (void *cls,
257 GNUNET_assert (NULL == emsg);
258 op = GNUNET_IDENTITY_rename (h,
261 &success_rename_cont,
267 * Main function of the test, run from scheduler.
270 * @param cfg configuration we use (also to connect to identity service)
271 * @param peer handle to access more of the peer (not used)
275 const struct GNUNET_CONFIGURATION_Handle *cfg,
276 struct GNUNET_TESTING_Peer *peer)
278 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
281 GNUNET_SCHEDULER_add_shutdown (&end_normally,
283 h = GNUNET_IDENTITY_connect (cfg,
286 GNUNET_assert (NULL != h);
287 op = GNUNET_IDENTITY_create (h,
296 main (int argc, char *argv[])
298 GNUNET_DISK_directory_remove ("/tmp/test-identity-service");
301 GNUNET_TESTING_service_run ("test-identity",
303 "test_identity.conf",
311 /* end of test_identity.c */