diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-07-17 19:33:34 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-07-17 19:33:34 +0000 |
commit | 4fbefa9b5336452df611c4f02232a45caa1d0e6f (patch) | |
tree | 417a499b31f0f5f719bd4b713fb57b316824b339 /src/identity/test_identity_defaults.c | |
parent | 58f3fcb5fbdaabd767443c5b1baeb28964175777 (diff) | |
download | gnunet-4fbefa9b5336452df611c4f02232a45caa1d0e6f.tar.gz gnunet-4fbefa9b5336452df611c4f02232a45caa1d0e6f.zip |
-skeleton for 2nd test
Diffstat (limited to 'src/identity/test_identity_defaults.c')
-rw-r--r-- | src/identity/test_identity_defaults.c | 321 |
1 files changed, 321 insertions, 0 deletions
diff --git a/src/identity/test_identity_defaults.c b/src/identity/test_identity_defaults.c new file mode 100644 index 000000000..c0b6efc50 --- /dev/null +++ b/src/identity/test_identity_defaults.c | |||
@@ -0,0 +1,321 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2013 Christian Grothoff (and other contributing authors) | ||
4 | |||
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. | ||
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 | General Public License for more details. | ||
14 | |||
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. | ||
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_common.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_identity_service.h" | ||
30 | #include "gnunet_testing_lib.h" | ||
31 | |||
32 | |||
33 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
34 | |||
35 | |||
36 | /** | ||
37 | * Return value from 'main'. | ||
38 | */ | ||
39 | static int res; | ||
40 | |||
41 | /** | ||
42 | * Handle to identity service. | ||
43 | */ | ||
44 | static struct GNUNET_IDENTITY_Handle *h; | ||
45 | |||
46 | /** | ||
47 | * Handle to identity operation. | ||
48 | */ | ||
49 | static struct GNUNET_IDENTITY_Operation *op; | ||
50 | |||
51 | /** | ||
52 | * Handle for task for timeout termination. | ||
53 | */ | ||
54 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; | ||
55 | |||
56 | |||
57 | /** | ||
58 | * Clean up all resources used. | ||
59 | */ | ||
60 | static void | ||
61 | cleanup () | ||
62 | { | ||
63 | if (NULL != op) | ||
64 | { | ||
65 | GNUNET_IDENTITY_cancel (op); | ||
66 | op = NULL; | ||
67 | } | ||
68 | if (NULL != h) | ||
69 | { | ||
70 | GNUNET_IDENTITY_disconnect (h); | ||
71 | h = NULL; | ||
72 | } | ||
73 | GNUNET_SCHEDULER_shutdown (); | ||
74 | } | ||
75 | |||
76 | |||
77 | /** | ||
78 | * Termiante the testcase (failure). | ||
79 | * | ||
80 | * @param cls NULL | ||
81 | * @param tc scheduler context | ||
82 | */ | ||
83 | static void | ||
84 | endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
85 | { | ||
86 | cleanup (); | ||
87 | res = 1; | ||
88 | } | ||
89 | |||
90 | |||
91 | /** | ||
92 | * Termiante the testcase (success). | ||
93 | * | ||
94 | * @param cls NULL | ||
95 | * @param tc scheduler context | ||
96 | */ | ||
97 | static void | ||
98 | end_normally (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
99 | { | ||
100 | cleanup (); | ||
101 | res = 0; | ||
102 | } | ||
103 | |||
104 | |||
105 | /** | ||
106 | * Finish the testcase (successfully). | ||
107 | */ | ||
108 | static void | ||
109 | end () | ||
110 | { | ||
111 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | ||
112 | { | ||
113 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
114 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | ||
115 | } | ||
116 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, | ||
117 | &end_normally, NULL); | ||
118 | } | ||
119 | |||
120 | |||
121 | /** | ||
122 | * Called with events about egos. | ||
123 | * | ||
124 | * @param cls NULL | ||
125 | * @param ego ego handle | ||
126 | * @param ego_ctx context for application to store data for this ego | ||
127 | * (during the lifetime of this process, initially NULL) | ||
128 | * @param identifier identifier assigned by the user for this ego, | ||
129 | * NULL if the user just deleted the ego and it | ||
130 | * must thus no longer be used | ||
131 | */ | ||
132 | static void | ||
133 | notification_cb (void *cls, | ||
134 | struct GNUNET_IDENTITY_Ego *ego, | ||
135 | void **ctx, | ||
136 | const char *identifier) | ||
137 | { | ||
138 | #if 0 | ||
139 | static struct GNUNET_IDENTITY_Ego *my_ego; | ||
140 | static int round; | ||
141 | |||
142 | switch (round) | ||
143 | { | ||
144 | case 0: /* end of initial iteration */ | ||
145 | GNUNET_assert (NULL == ego); | ||
146 | GNUNET_assert (NULL == identifier); | ||
147 | break; | ||
148 | case 1: /* create */ | ||
149 | GNUNET_assert (NULL != ego); | ||
150 | GNUNET_assert (0 == strcmp (identifier, "test-id")); | ||
151 | my_ego = ego; | ||
152 | *ctx = &round; | ||
153 | break; | ||
154 | case 2: /* rename */ | ||
155 | GNUNET_assert (my_ego == ego); | ||
156 | GNUNET_assert (0 == strcmp (identifier, "test")); | ||
157 | GNUNET_assert (*ctx == &round); | ||
158 | break; | ||
159 | case 3: /* delete */ | ||
160 | GNUNET_assert (my_ego == ego); | ||
161 | GNUNET_assert (NULL == identifier); | ||
162 | GNUNET_assert (*ctx == &round); | ||
163 | *ctx = NULL; | ||
164 | break; | ||
165 | default: | ||
166 | GNUNET_break (0); | ||
167 | } | ||
168 | round++; | ||
169 | #endif | ||
170 | } | ||
171 | |||
172 | |||
173 | /** | ||
174 | * Continuation called from successful delete operation. | ||
175 | * | ||
176 | * @param cls NULL | ||
177 | * @param emsg (should also be NULL) | ||
178 | */ | ||
179 | static void | ||
180 | delete_cont (void *cls, | ||
181 | const char *emsg) | ||
182 | { | ||
183 | op = NULL; | ||
184 | GNUNET_assert (NULL == emsg); | ||
185 | end (); | ||
186 | } | ||
187 | |||
188 | |||
189 | /** | ||
190 | * Continuation called from expected-to-fail rename operation. | ||
191 | * | ||
192 | * @param cls NULL | ||
193 | * @param emsg (should also be NULL) | ||
194 | */ | ||
195 | static void | ||
196 | get_cb (void *cls, | ||
197 | struct GNUNET_IDENTITY_Ego *ego, | ||
198 | void **ctx, | ||
199 | const char *identifier) | ||
200 | { | ||
201 | GNUNET_assert (NULL != emsg); | ||
202 | GNUNET_assert (my_ego == ego); | ||
203 | GNUNET_assert (0 == strcmp (identifier, "test-id")); | ||
204 | op = GNUNET_IDENTITY_delete (h, | ||
205 | "test-id", | ||
206 | &delete_cont, | ||
207 | NULL); | ||
208 | } | ||
209 | |||
210 | |||
211 | /** | ||
212 | * Main function of the test, run from scheduler. | ||
213 | * | ||
214 | * @param cls NULL | ||
215 | * @param cfg configuration we use (also to connect to identity service) | ||
216 | * @param peer handle to access more of the peer (not used) | ||
217 | */ | ||
218 | static void | ||
219 | run_get (void *cls, | ||
220 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
221 | struct GNUNET_TESTING_Peer *peer) | ||
222 | { | ||
223 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
224 | &endbadly, NULL); | ||
225 | h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); | ||
226 | GNUNET_assert (NULL != h); | ||
227 | op = GNUNET_IDENTITY_get (h, | ||
228 | "test-service", | ||
229 | &get_cb, | ||
230 | NULL); | ||
231 | } | ||
232 | |||
233 | |||
234 | /** | ||
235 | * Continuation called from successful rename operation. | ||
236 | * | ||
237 | * @param cls NULL | ||
238 | * @param emsg (should also be NULL) | ||
239 | */ | ||
240 | static void | ||
241 | success_set_cont (void *cls, | ||
242 | const char *emsg) | ||
243 | { | ||
244 | op = NULL; | ||
245 | GNUNET_assert (NULL == emsg); | ||
246 | end (); | ||
247 | } | ||
248 | |||
249 | |||
250 | /** | ||
251 | * Called with events about created ego. | ||
252 | * | ||
253 | * @param cls NULL | ||
254 | * @param ego ego handle | ||
255 | * @param ego_ctx context for application to store data for this ego | ||
256 | * (during the lifetime of this process, initially NULL) | ||
257 | * @param identifier identifier assigned by the user for this ego, | ||
258 | * NULL if the user just deleted the ego and it | ||
259 | * must thus no longer be used | ||
260 | */ | ||
261 | static void | ||
262 | create_cb (void *cls, | ||
263 | struct GNUNET_IDENTITY_Ego *ego, | ||
264 | void **ctx, | ||
265 | const char *identifier) | ||
266 | { | ||
267 | op = GNUNET_IDENTITY_set (h, | ||
268 | "test-service", | ||
269 | ego, | ||
270 | &success_set_cont, | ||
271 | NULL); | ||
272 | } | ||
273 | |||
274 | |||
275 | /** | ||
276 | * Main function of the test, run from scheduler. | ||
277 | * | ||
278 | * @param cls NULL | ||
279 | * @param cfg configuration we use (also to connect to identity service) | ||
280 | * @param peer handle to access more of the peer (not used) | ||
281 | */ | ||
282 | static void | ||
283 | run_set (void *cls, | ||
284 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
285 | struct GNUNET_TESTING_Peer *peer) | ||
286 | { | ||
287 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
288 | &endbadly, NULL); | ||
289 | h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); | ||
290 | GNUNET_assert (NULL != h); | ||
291 | op = GNUNET_IDENTITY_create (h, | ||
292 | "test-id", | ||
293 | &create_cb, | ||
294 | NULL); | ||
295 | |||
296 | } | ||
297 | |||
298 | |||
299 | int | ||
300 | main (int argc, char *argv[]) | ||
301 | { | ||
302 | res = 1; | ||
303 | if (0 != | ||
304 | GNUNET_TESTING_service_run ("test-identity", | ||
305 | "identity", | ||
306 | "test_identity.conf", | ||
307 | &run_set, | ||
308 | NULL)) | ||
309 | return 1; | ||
310 | if (0 != | ||
311 | GNUNET_TESTING_service_run ("test-identity", | ||
312 | "identity", | ||
313 | "test_identity.conf", | ||
314 | &run_get, | ||
315 | NULL)) | ||
316 | return 1; | ||
317 | return res; | ||
318 | } | ||
319 | |||
320 | |||
321 | /* end of test_identity.c */ | ||