aboutsummaryrefslogtreecommitdiff
path: root/src/identity/test_identity_defaults.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/identity/test_identity_defaults.c')
-rw-r--r--src/identity/test_identity_defaults.c299
1 files changed, 0 insertions, 299 deletions
diff --git a/src/identity/test_identity_defaults.c b/src/identity/test_identity_defaults.c
deleted file mode 100644
index 2d5244d1b..000000000
--- a/src/identity/test_identity_defaults.c
+++ /dev/null
@@ -1,299 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V.
4
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.
9
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.
14
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/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file identity/test_identity.c
23 * @brief testcase for identity service
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_identity_service.h"
29#include "gnunet_testing_lib.h"
30
31
32#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
33
34
35/**
36 * Return value from 'main'.
37 */
38static int res;
39
40/**
41 * Handle to identity service.
42 */
43static struct GNUNET_IDENTITY_Handle *h;
44
45/**
46 * Handle to identity operation.
47 */
48static struct GNUNET_IDENTITY_Operation *op;
49
50/**
51 * Handle for task for timeout termination.
52 */
53static struct GNUNET_SCHEDULER_Task *endbadly_task;
54
55#define CHECK(cond) \
56 do \
57 { \
58 if (! (cond)) \
59 { \
60 GNUNET_break (0); \
61 end (); \
62 return; \
63 } \
64 } while (0)
65
66
67/**
68 * Clean up all resources used.
69 */
70static void
71cleanup (void *cls)
72{
73 (void) cls;
74 if (NULL != op)
75 {
76 GNUNET_IDENTITY_cancel (op);
77 op = NULL;
78 }
79 if (NULL != h)
80 {
81 GNUNET_IDENTITY_disconnect (h);
82 h = NULL;
83 }
84}
85
86
87/**
88 * Termiante the testcase (failure).
89 *
90 * @param cls NULL
91 */
92static void
93endbadly (void *cls)
94{
95 GNUNET_SCHEDULER_shutdown ();
96 res = 1;
97}
98
99
100/**
101 * Termiante the testcase.
102 */
103static void
104end ()
105{
106 if (NULL != endbadly_task)
107 {
108 GNUNET_SCHEDULER_cancel (endbadly_task);
109 endbadly_task = NULL;
110 }
111 GNUNET_SCHEDULER_shutdown ();
112}
113
114
115/**
116 * Continuation called from successful delete operation.
117 *
118 * @param cls NULL
119 * @param emsg (should also be NULL)
120 */
121static void
122delete_cont (void *cls, const char *emsg)
123{
124 op = NULL;
125 CHECK (NULL == emsg);
126 res = 0;
127 end ();
128}
129
130
131/**
132 * Continuation called from expected-to-fail rename operation.
133 *
134 * @param cls NULL
135 * @param emsg (should also be NULL)
136 */
137static void
138get_cb (void *cls,
139 struct GNUNET_IDENTITY_Ego *ego,
140 void **ctx,
141 const char *identifier)
142{
143 op = NULL;
144 CHECK (NULL != ego);
145 CHECK (NULL != identifier);
146 CHECK (0 == strcmp (identifier, "test-id"));
147 op = GNUNET_IDENTITY_delete (h, "test-id", &delete_cont, NULL);
148}
149
150
151/**
152 * Called with events about egos.
153 *
154 * @param cls NULL
155 * @param ego ego handle
156 * @param ego_ctx context for application to store data for this ego
157 * (during the lifetime of this process, initially NULL)
158 * @param identifier identifier assigned by the user for this ego,
159 * NULL if the user just deleted the ego and it
160 * must thus no longer be used
161 */
162static void
163dummy_cb (void *cls,
164 struct GNUNET_IDENTITY_Ego *ego,
165 void **ctx,
166 const char *identifier)
167{
168 (void) cls;
169 (void) ego;
170 (void) ctx;
171 (void) identifier;
172}
173
174
175/**
176 * Main function of the test, run from scheduler.
177 *
178 * @param cls NULL
179 * @param cfg configuration we use (also to connect to identity service)
180 * @param peer handle to access more of the peer (not used)
181 */
182static void
183run_get (void *cls,
184 const struct GNUNET_CONFIGURATION_Handle *cfg,
185 struct GNUNET_TESTING_Peer *peer)
186{
187 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL);
188 GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL);
189 h = GNUNET_IDENTITY_connect (cfg, &dummy_cb, NULL);
190 CHECK (NULL != h);
191 op = GNUNET_IDENTITY_get (h, "test-service", &get_cb, NULL);
192}
193
194
195/**
196 * Continuation called from successful rename operation.
197 *
198 * @param cls NULL
199 * @param emsg (should also be NULL)
200 */
201static void
202success_set_cont (void *cls, const char *emsg)
203{
204 op = NULL;
205 CHECK (NULL == emsg);
206 end ();
207}
208
209
210/**
211 * Called with events about egos.
212 *
213 * @param cls NULL
214 * @param ego ego handle
215 * @param ego_ctx context for application to store data for this ego
216 * (during the lifetime of this process, initially NULL)
217 * @param identifier identifier assigned by the user for this ego,
218 * NULL if the user just deleted the ego and it
219 * must thus no longer be used
220 */
221static void
222notification_cb (void *cls,
223 struct GNUNET_IDENTITY_Ego *ego,
224 void **ctx,
225 const char *identifier)
226{
227 if (NULL == ego)
228 return; /* skip first call */
229 if (NULL == identifier)
230 return; /* deletion / shutdown */
231 op = GNUNET_IDENTITY_set (h, "test-service", ego, &success_set_cont, NULL);
232}
233
234
235/**
236 * Called with events about created ego.
237 *
238 * @param cls NULL
239 * @param pk private key of the ego, or NULL on error
240 * @param emsg error message
241 */
242static void
243create_cb (void *cls,
244 const struct GNUNET_IDENTITY_PrivateKey *pk,
245 const char *emsg)
246{
247 CHECK (NULL == emsg);
248 CHECK (NULL != pk);
249 op = NULL;
250}
251
252
253/**
254 * Main function of the test, run from scheduler.
255 *
256 * @param cls NULL
257 * @param cfg configuration we use (also to connect to identity service)
258 * @param peer handle to access more of the peer (not used)
259 */
260static void
261run_set (void *cls,
262 const struct GNUNET_CONFIGURATION_Handle *cfg,
263 struct GNUNET_TESTING_Peer *peer)
264{
265 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL);
266 GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL);
267 h = GNUNET_IDENTITY_connect (cfg, &notification_cb, NULL);
268 CHECK (NULL != h);
269 op = GNUNET_IDENTITY_create (h,
270 "test-id",
271 NULL,
272 GNUNET_IDENTITY_TYPE_ECDSA,
273 &create_cb, NULL);
274}
275
276
277int
278main (int argc, char *argv[])
279{
280 GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service");
281 res = 1;
282 if (0 != GNUNET_TESTING_service_run ("test-identity-defaults",
283 "identity",
284 "test_identity.conf",
285 &run_set,
286 NULL))
287 return 1;
288 if (0 != GNUNET_TESTING_service_run ("test-identity-defaults",
289 "identity",
290 "test_identity.conf",
291 &run_get,
292 NULL))
293 return 1;
294 GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service");
295 return res;
296}
297
298
299/* end of test_identity_defaults.c */