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.
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 (endbadly_task != NULL)
105 GNUNET_SCHEDULER_cancel (endbadly_task);
106 endbadly_task = NULL;
108 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
109 &end_normally, NULL);
114 * Continuation called from successful delete operation.
117 * @param emsg (should also be NULL)
120 delete_cont (void *cls,
124 GNUNET_assert (NULL == emsg);
130 * Continuation called from expected-to-fail rename operation.
133 * @param emsg (should also be NULL)
137 struct GNUNET_IDENTITY_Ego *ego,
139 const char *identifier)
141 GNUNET_assert (NULL != ego);
142 GNUNET_assert (NULL != identifier);
143 GNUNET_assert (0 == strcmp (identifier, "test-id"));
144 op = GNUNET_IDENTITY_delete (h,
152 * Main function of the test, run from scheduler.
155 * @param cfg configuration we use (also to connect to identity service)
156 * @param peer handle to access more of the peer (not used)
160 const struct GNUNET_CONFIGURATION_Handle *cfg,
161 struct GNUNET_TESTING_Peer *peer)
163 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
165 h = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
166 GNUNET_assert (NULL != h);
167 op = GNUNET_IDENTITY_get (h,
175 * Continuation called from successful rename operation.
178 * @param emsg (should also be NULL)
181 success_set_cont (void *cls,
185 GNUNET_assert (NULL == emsg);
191 * Called with events about egos.
194 * @param ego ego handle
195 * @param ego_ctx context for application to store data for this ego
196 * (during the lifetime of this process, initially NULL)
197 * @param identifier identifier assigned by the user for this ego,
198 * NULL if the user just deleted the ego and it
199 * must thus no longer be used
202 notification_cb (void *cls,
203 struct GNUNET_IDENTITY_Ego *ego,
205 const char *identifier)
208 return; /* skip first call */
209 if (NULL == identifier)
210 return; /* deletion / shutdown */
211 op = GNUNET_IDENTITY_set (h,
220 * Called with events about created ego.
223 * @param emsg error message
226 create_cb (void *cls,
229 GNUNET_assert (NULL == emsg);
235 * Main function of the test, run from scheduler.
238 * @param cfg configuration we use (also to connect to identity service)
239 * @param peer handle to access more of the peer (not used)
243 const struct GNUNET_CONFIGURATION_Handle *cfg,
244 struct GNUNET_TESTING_Peer *peer)
246 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
248 h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL);
249 GNUNET_assert (NULL != h);
250 op = GNUNET_IDENTITY_create (h,
259 main (int argc, char *argv[])
261 GNUNET_DISK_directory_remove ("/tmp/test-identity-service");
264 GNUNET_TESTING_service_run ("test-identity-defaults",
266 "test_identity.conf",
271 GNUNET_TESTING_service_run ("test-identity-defaults",
273 "test_identity.conf",
277 GNUNET_DISK_directory_remove ("/tmp/test-identity-service");
282 /* end of test_identity.c */