2 This file is part of GNUnet.
3 Copyright (C) 2013 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 (endbadly_task != NULL)
108 GNUNET_SCHEDULER_cancel (endbadly_task);
109 endbadly_task = NULL;
111 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
112 &end_normally, NULL);
117 * Continuation called from successful delete operation.
120 * @param emsg (should also be NULL)
123 delete_cont (void *cls,
127 GNUNET_assert (NULL == emsg);
133 * Continuation called from expected-to-fail rename operation.
136 * @param emsg (should also be NULL)
140 struct GNUNET_IDENTITY_Ego *ego,
142 const char *identifier)
144 GNUNET_assert (NULL != ego);
145 GNUNET_assert (NULL != identifier);
146 GNUNET_assert (0 == strcmp (identifier, "test-id"));
147 op = GNUNET_IDENTITY_delete (h,
155 * Main function of the test, run from scheduler.
158 * @param cfg configuration we use (also to connect to identity service)
159 * @param peer handle to access more of the peer (not used)
163 const struct GNUNET_CONFIGURATION_Handle *cfg,
164 struct GNUNET_TESTING_Peer *peer)
166 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
168 h = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
169 GNUNET_assert (NULL != h);
170 op = GNUNET_IDENTITY_get (h,
178 * Continuation called from successful rename operation.
181 * @param emsg (should also be NULL)
184 success_set_cont (void *cls,
188 GNUNET_assert (NULL == emsg);
194 * Called with events about egos.
197 * @param ego ego handle
198 * @param ego_ctx context for application to store data for this ego
199 * (during the lifetime of this process, initially NULL)
200 * @param identifier identifier assigned by the user for this ego,
201 * NULL if the user just deleted the ego and it
202 * must thus no longer be used
205 notification_cb (void *cls,
206 struct GNUNET_IDENTITY_Ego *ego,
208 const char *identifier)
211 return; /* skip first call */
212 if (NULL == identifier)
213 return; /* deletion / shutdown */
214 op = GNUNET_IDENTITY_set (h,
223 * Called with events about created ego.
226 * @param emsg error message
229 create_cb (void *cls,
232 GNUNET_assert (NULL == emsg);
238 * Main function of the test, run from scheduler.
241 * @param cfg configuration we use (also to connect to identity service)
242 * @param peer handle to access more of the peer (not used)
246 const struct GNUNET_CONFIGURATION_Handle *cfg,
247 struct GNUNET_TESTING_Peer *peer)
249 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
251 h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL);
252 GNUNET_assert (NULL != h);
253 op = GNUNET_IDENTITY_create (h,
262 main (int argc, char *argv[])
264 GNUNET_DISK_directory_remove ("/tmp/test-identity-service");
267 GNUNET_TESTING_service_run ("test-identity-defaults",
269 "test_identity.conf",
274 GNUNET_TESTING_service_run ("test-identity-defaults",
276 "test_identity.conf",
280 GNUNET_DISK_directory_remove ("/tmp/test-identity-service");
285 /* end of test_identity.c */