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_common.h"
28 #include "gnunet_util_lib.h"
29 #include "gnunet_identity_service.h"
30 #include "gnunet_testing_lib.h"
33 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
37 * Return value from 'main'.
42 * Handle to identity service.
44 static struct GNUNET_IDENTITY_Handle *h;
47 * Handle to identity operation.
49 static struct GNUNET_IDENTITY_Operation *op;
52 * Handle for task for timeout termination.
54 static GNUNET_SCHEDULER_TaskIdentifier endbadly_task;
58 * Clean up all resources used.
65 GNUNET_IDENTITY_cancel (op);
70 GNUNET_IDENTITY_disconnect (h);
73 GNUNET_SCHEDULER_shutdown ();
78 * Termiante the testcase (failure).
81 * @param tc scheduler context
84 endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
92 * Termiante the testcase (success).
95 * @param tc scheduler context
98 end_normally (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
106 * Finish the testcase (successfully).
111 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
113 GNUNET_SCHEDULER_cancel (endbadly_task);
114 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
116 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
117 &end_normally, NULL);
122 * Continuation called from successful delete operation.
125 * @param emsg (should also be NULL)
128 delete_cont (void *cls,
132 GNUNET_assert (NULL == emsg);
138 * Continuation called from expected-to-fail rename operation.
141 * @param emsg (should also be NULL)
145 struct GNUNET_IDENTITY_Ego *ego,
147 const char *identifier)
149 GNUNET_assert (NULL != ego);
150 GNUNET_assert (NULL != identifier);
151 GNUNET_assert (0 == strcmp (identifier, "test-id"));
152 op = GNUNET_IDENTITY_delete (h,
160 * Main function of the test, run from scheduler.
163 * @param cfg configuration we use (also to connect to identity service)
164 * @param peer handle to access more of the peer (not used)
168 const struct GNUNET_CONFIGURATION_Handle *cfg,
169 struct GNUNET_TESTING_Peer *peer)
171 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
173 h = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
174 GNUNET_assert (NULL != h);
175 op = GNUNET_IDENTITY_get (h,
183 * Continuation called from successful rename operation.
186 * @param emsg (should also be NULL)
189 success_set_cont (void *cls,
193 GNUNET_assert (NULL == emsg);
199 * Called with events about egos.
202 * @param ego ego handle
203 * @param ego_ctx context for application to store data for this ego
204 * (during the lifetime of this process, initially NULL)
205 * @param identifier identifier assigned by the user for this ego,
206 * NULL if the user just deleted the ego and it
207 * must thus no longer be used
210 notification_cb (void *cls,
211 struct GNUNET_IDENTITY_Ego *ego,
213 const char *identifier)
216 return; /* skip first call */
217 op = GNUNET_IDENTITY_set (h,
226 * Called with events about created ego.
229 * @param emsg error message
232 create_cb (void *cls,
235 GNUNET_assert (NULL == emsg);
241 * Main function of the test, run from scheduler.
244 * @param cfg configuration we use (also to connect to identity service)
245 * @param peer handle to access more of the peer (not used)
249 const struct GNUNET_CONFIGURATION_Handle *cfg,
250 struct GNUNET_TESTING_Peer *peer)
252 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
254 h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL);
255 GNUNET_assert (NULL != h);
256 op = GNUNET_IDENTITY_create (h,
265 main (int argc, char *argv[])
267 GNUNET_DISK_directory_remove ("/tmp/test-identity-service");
270 GNUNET_TESTING_service_run ("test-identity-defaults",
272 "test_identity.conf",
277 GNUNET_TESTING_service_run ("test-identity-defaults",
279 "test_identity.conf",
283 GNUNET_DISK_directory_remove ("/tmp/test-identity-service");
288 /* end of test_identity.c */