aboutsummaryrefslogtreecommitdiff
path: root/src/identity/test_identity.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/identity/test_identity.c')
-rw-r--r--src/identity/test_identity.c225
1 files changed, 116 insertions, 109 deletions
diff --git a/src/identity/test_identity.c b/src/identity/test_identity.c
index 74c052917..7f7371422 100644
--- a/src/identity/test_identity.c
+++ b/src/identity/test_identity.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file identity/test_identity.c 22 * @file identity/test_identity.c
@@ -29,7 +29,7 @@
29#include "gnunet_testing_lib.h" 29#include "gnunet_testing_lib.h"
30 30
31 31
32#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) 32#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
33 33
34 34
35/** 35/**
@@ -54,33 +54,33 @@ static struct GNUNET_SCHEDULER_Task *endbadly_task;
54 54
55#define CHECK(cond) \ 55#define CHECK(cond) \
56 do \ 56 do \
57 { \ 57 { \
58 if (! (cond)) \ 58 if (!(cond)) \
59 { \ 59 { \
60 GNUNET_break (0); \ 60 GNUNET_break(0); \
61 end (); \ 61 end(); \
62 return; \ 62 return; \
63 } \ 63 } \
64 } while (0) 64 } while (0)
65 65
66 66
67/** 67/**
68 * Clean up all resources used. 68 * Clean up all resources used.
69 */ 69 */
70static void 70static void
71cleanup (void *cls) 71cleanup(void *cls)
72{ 72{
73 (void) cls; 73 (void)cls;
74 if (NULL != op) 74 if (NULL != op)
75 { 75 {
76 GNUNET_IDENTITY_cancel (op); 76 GNUNET_IDENTITY_cancel(op);
77 op = NULL; 77 op = NULL;
78 } 78 }
79 if (NULL != h) 79 if (NULL != h)
80 { 80 {
81 GNUNET_IDENTITY_disconnect (h); 81 GNUNET_IDENTITY_disconnect(h);
82 h = NULL; 82 h = NULL;
83 } 83 }
84} 84}
85 85
86 86
@@ -90,9 +90,9 @@ cleanup (void *cls)
90 * @param cls NULL 90 * @param cls NULL
91 */ 91 */
92static void 92static void
93endbadly (void *cls) 93endbadly(void *cls)
94{ 94{
95 GNUNET_SCHEDULER_shutdown (); 95 GNUNET_SCHEDULER_shutdown();
96} 96}
97 97
98 98
@@ -100,14 +100,14 @@ endbadly (void *cls)
100 * Finish the testcase (successfully). 100 * Finish the testcase (successfully).
101 */ 101 */
102static void 102static void
103end () 103end()
104{ 104{
105 if (NULL != endbadly_task) 105 if (NULL != endbadly_task)
106 { 106 {
107 GNUNET_SCHEDULER_cancel (endbadly_task); 107 GNUNET_SCHEDULER_cancel(endbadly_task);
108 endbadly_task = NULL; 108 endbadly_task = NULL;
109 } 109 }
110 GNUNET_SCHEDULER_shutdown (); 110 GNUNET_SCHEDULER_shutdown();
111} 111}
112 112
113 113
@@ -123,57 +123,64 @@ end ()
123 * must thus no longer be used 123 * must thus no longer be used
124 */ 124 */
125static void 125static void
126notification_cb (void *cls, 126notification_cb(void *cls,
127 struct GNUNET_IDENTITY_Ego *ego, 127 struct GNUNET_IDENTITY_Ego *ego,
128 void **ctx, 128 void **ctx,
129 const char *identifier) 129 const char *identifier)
130{ 130{
131 static struct GNUNET_IDENTITY_Ego *my_ego; 131 static struct GNUNET_IDENTITY_Ego *my_ego;
132 static int round; 132 static int round;
133 133
134 switch (round) 134 switch (round)
135 { 135 {
136 case 0: /* end of initial iteration */ 136 case 0: /* end of initial iteration */
137 CHECK (NULL == ego); 137 CHECK(NULL == ego);
138 CHECK (NULL == identifier); 138 CHECK(NULL == identifier);
139 break; 139 break;
140 case 1: /* create */ 140
141 CHECK (NULL != ego); 141 case 1: /* create */
142 CHECK (NULL != identifier); 142 CHECK(NULL != ego);
143 CHECK (0 == strcmp (identifier, "test-id")); 143 CHECK(NULL != identifier);
144 my_ego = ego; 144 CHECK(0 == strcmp(identifier, "test-id"));
145 *ctx = &round; 145 my_ego = ego;
146 break; 146 *ctx = &round;
147 case 2: /* rename */ 147 break;
148 CHECK (my_ego == ego); 148
149 CHECK (NULL != identifier); 149 case 2: /* rename */
150 CHECK (0 == strcmp (identifier, "test")); 150 CHECK(my_ego == ego);
151 CHECK (*ctx == &round); 151 CHECK(NULL != identifier);
152 break; 152 CHECK(0 == strcmp(identifier, "test"));
153 case 3: /* reconnect-down */ 153 CHECK(*ctx == &round);
154 CHECK (my_ego == ego); 154 break;
155 CHECK (NULL == identifier); 155
156 CHECK (*ctx == &round); 156 case 3: /* reconnect-down */
157 *ctx = NULL; 157 CHECK(my_ego == ego);
158 break; 158 CHECK(NULL == identifier);
159 case 4: /* reconnect-up */ 159 CHECK(*ctx == &round);
160 CHECK (NULL != identifier); 160 *ctx = NULL;
161 CHECK (0 == strcmp (identifier, "test")); 161 break;
162 my_ego = ego; 162
163 *ctx = &round; 163 case 4: /* reconnect-up */
164 break; 164 CHECK(NULL != identifier);
165 case 5: /* end of iteration after reconnect */ 165 CHECK(0 == strcmp(identifier, "test"));
166 CHECK (NULL == ego); 166 my_ego = ego;
167 CHECK (NULL == identifier); 167 *ctx = &round;
168 break; 168 break;
169 case 6: /* delete */ 169
170 CHECK (my_ego == ego); 170 case 5: /* end of iteration after reconnect */
171 CHECK (*ctx == &round); 171 CHECK(NULL == ego);
172 *ctx = NULL; 172 CHECK(NULL == identifier);
173 break; 173 break;
174 default: 174
175 CHECK (0); 175 case 6: /* delete */
176 } 176 CHECK(my_ego == ego);
177 CHECK(*ctx == &round);
178 *ctx = NULL;
179 break;
180
181 default:
182 CHECK(0);
183 }
177 round++; 184 round++;
178} 185}
179 186
@@ -185,12 +192,12 @@ notification_cb (void *cls,
185 * @param emsg (should also be NULL) 192 * @param emsg (should also be NULL)
186 */ 193 */
187static void 194static void
188delete_cont (void *cls, const char *emsg) 195delete_cont(void *cls, const char *emsg)
189{ 196{
190 op = NULL; 197 op = NULL;
191 CHECK (NULL == emsg); 198 CHECK(NULL == emsg);
192 res = 0; 199 res = 0;
193 end (); 200 end();
194} 201}
195 202
196 203
@@ -200,9 +207,9 @@ delete_cont (void *cls, const char *emsg)
200 * @param cls NULL 207 * @param cls NULL
201 */ 208 */
202static void 209static void
203finally_delete (void *cls) 210finally_delete(void *cls)
204{ 211{
205 op = GNUNET_IDENTITY_delete (h, "test", &delete_cont, NULL); 212 op = GNUNET_IDENTITY_delete(h, "test", &delete_cont, NULL);
206} 213}
207 214
208 215
@@ -213,13 +220,13 @@ finally_delete (void *cls)
213 * @param emsg (should also be NULL) 220 * @param emsg (should also be NULL)
214 */ 221 */
215static void 222static void
216fail_rename_cont (void *cls, const char *emsg) 223fail_rename_cont(void *cls, const char *emsg)
217{ 224{
218 CHECK (NULL != emsg); 225 CHECK(NULL != emsg);
219 op = NULL; 226 op = NULL;
220 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 227 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
221 &finally_delete, 228 &finally_delete,
222 NULL); 229 NULL);
223} 230}
224 231
225 232
@@ -230,10 +237,10 @@ fail_rename_cont (void *cls, const char *emsg)
230 * @param emsg (should also be NULL) 237 * @param emsg (should also be NULL)
231 */ 238 */
232static void 239static void
233success_rename_cont (void *cls, const char *emsg) 240success_rename_cont(void *cls, const char *emsg)
234{ 241{
235 CHECK (NULL == emsg); 242 CHECK(NULL == emsg);
236 op = GNUNET_IDENTITY_rename (h, "test-id", "test", &fail_rename_cont, NULL); 243 op = GNUNET_IDENTITY_rename(h, "test-id", "test", &fail_rename_cont, NULL);
237} 244}
238 245
239 246
@@ -245,14 +252,14 @@ success_rename_cont (void *cls, const char *emsg)
245 * @param emsg error message 252 * @param emsg error message
246 */ 253 */
247static void 254static void
248create_cb (void *cls, 255create_cb(void *cls,
249 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, 256 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
250 const char *emsg) 257 const char *emsg)
251{ 258{
252 CHECK (NULL != pk); 259 CHECK(NULL != pk);
253 CHECK (NULL == emsg); 260 CHECK(NULL == emsg);
254 op = 261 op =
255 GNUNET_IDENTITY_rename (h, "test-id", "test", &success_rename_cont, NULL); 262 GNUNET_IDENTITY_rename(h, "test-id", "test", &success_rename_cont, NULL);
256} 263}
257 264
258 265
@@ -264,30 +271,30 @@ create_cb (void *cls,
264 * @param peer handle to access more of the peer (not used) 271 * @param peer handle to access more of the peer (not used)
265 */ 272 */
266static void 273static void
267run (void *cls, 274run(void *cls,
268 const struct GNUNET_CONFIGURATION_Handle *cfg, 275 const struct GNUNET_CONFIGURATION_Handle *cfg,
269 struct GNUNET_TESTING_Peer *peer) 276 struct GNUNET_TESTING_Peer *peer)
270{ 277{
271 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); 278 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL);
272 GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); 279 GNUNET_SCHEDULER_add_shutdown(&cleanup, NULL);
273 h = GNUNET_IDENTITY_connect (cfg, &notification_cb, NULL); 280 h = GNUNET_IDENTITY_connect(cfg, &notification_cb, NULL);
274 CHECK (NULL != h); 281 CHECK(NULL != h);
275 op = GNUNET_IDENTITY_create (h, "test-id", &create_cb, NULL); 282 op = GNUNET_IDENTITY_create(h, "test-id", &create_cb, NULL);
276} 283}
277 284
278 285
279int 286int
280main (int argc, char *argv[]) 287main(int argc, char *argv[])
281{ 288{
282 GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service"); 289 GNUNET_DISK_directory_remove("/tmp/gnunet/test-identity-service");
283 res = 1; 290 res = 1;
284 if (0 != GNUNET_TESTING_service_run ("test-identity", 291 if (0 != GNUNET_TESTING_service_run("test-identity",
285 "identity", 292 "identity",
286 "test_identity.conf", 293 "test_identity.conf",
287 &run, 294 &run,
288 NULL)) 295 NULL))
289 return 1; 296 return 1;
290 GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service"); 297 GNUNET_DISK_directory_remove("/tmp/gnunet/test-identity-service");
291 return res; 298 return res;
292} 299}
293 300