2 This file is part of GNUnet.
3 (C) 2013 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file identity/test_identity.c
23 * @brief testcase for identity service
24 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
28 #include "gnunet_identity_service.h"
29 #include "gnunet_testing_lib.h"
32 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
36 * Return value from 'main'.
41 * Handle to identity service.
43 static struct GNUNET_IDENTITY_Handle *h;
46 * Handle to identity operation.
48 static struct GNUNET_IDENTITY_Operation *op;
51 * Handle for task for timeout termination.
53 static GNUNET_SCHEDULER_TaskIdentifier endbadly_task;
57 * Clean up all resources used.
64 GNUNET_IDENTITY_cancel (op);
69 GNUNET_IDENTITY_disconnect (h);
72 GNUNET_SCHEDULER_shutdown ();
77 * Termiante the testcase (failure).
80 * @param tc scheduler context
83 endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
91 * Termiante the testcase (success).
94 * @param tc scheduler context
97 end_normally (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
105 * Finish the testcase (successfully).
110 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
112 GNUNET_SCHEDULER_cancel (endbadly_task);
113 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
115 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
116 &end_normally, NULL);
121 * Continuation called from successful delete operation.
124 * @param emsg (should also be NULL)
127 delete_cont (void *cls,
131 GNUNET_assert (NULL == emsg);
137 * Continuation called from expected-to-fail rename operation.
140 * @param emsg (should also be NULL)
144 struct GNUNET_IDENTITY_Ego *ego,
146 const char *identifier)
148 GNUNET_assert (NULL != ego);
149 GNUNET_assert (NULL != identifier);
150 GNUNET_assert (0 == strcmp (identifier, "test-id"));
151 op = GNUNET_IDENTITY_delete (h,
159 * Main function of the test, run from scheduler.
162 * @param cfg configuration we use (also to connect to identity service)
163 * @param peer handle to access more of the peer (not used)
167 const struct GNUNET_CONFIGURATION_Handle *cfg,
168 struct GNUNET_TESTING_Peer *peer)
170 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
172 h = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
173 GNUNET_assert (NULL != h);
174 op = GNUNET_IDENTITY_get (h,
182 * Continuation called from successful rename operation.
185 * @param emsg (should also be NULL)
188 success_set_cont (void *cls,
192 GNUNET_assert (NULL == emsg);
198 * Called with events about egos.
201 * @param ego ego handle
202 * @param ego_ctx context for application to store data for this ego
203 * (during the lifetime of this process, initially NULL)
204 * @param identifier identifier assigned by the user for this ego,
205 * NULL if the user just deleted the ego and it
206 * must thus no longer be used
209 notification_cb (void *cls,
210 struct GNUNET_IDENTITY_Ego *ego,
212 const char *identifier)
215 return; /* skip first call */
216 op = GNUNET_IDENTITY_set (h,
225 * Called with events about created ego.
228 * @param emsg error message
231 create_cb (void *cls,
234 GNUNET_assert (NULL == emsg);
240 * Main function of the test, run from scheduler.
243 * @param cfg configuration we use (also to connect to identity service)
244 * @param peer handle to access more of the peer (not used)
248 const struct GNUNET_CONFIGURATION_Handle *cfg,
249 struct GNUNET_TESTING_Peer *peer)
251 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
253 h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL);
254 GNUNET_assert (NULL != h);
255 op = GNUNET_IDENTITY_create (h,
264 main (int argc, char *argv[])
266 GNUNET_DISK_directory_remove ("/tmp/test-identity-service");
269 GNUNET_TESTING_service_run ("test-identity-defaults",
271 "test_identity.conf",
276 GNUNET_TESTING_service_run ("test-identity-defaults",
278 "test_identity.conf",
282 GNUNET_DISK_directory_remove ("/tmp/test-identity-service");
287 /* end of test_identity.c */